update login
This commit is contained in:
parent
ee165eb6fe
commit
5b97619411
@ -15,7 +15,7 @@ class SimulationTrader(BaseTrader):
|
||||
def __init__(self, logger=None):
|
||||
self.logger = logger or get_logger("simulation_trader")
|
||||
# 模拟资金账户信息
|
||||
self.sim_balance = {"cash": 1000000.00, "frozen": 0.00, "total": 1000000.00}
|
||||
self.sim_balance = {"account_id": "simulation", "cash": 1000000.00, "frozen": 0.00, "total": 1000000.00}
|
||||
|
||||
def is_logged_in(self):
|
||||
"""检查交易系统是否已经登录
|
||||
|
@ -4,11 +4,7 @@ import time
|
||||
from real.xt_trader import XtTrader
|
||||
from flask import Flask, request, abort, jsonify
|
||||
from config import Config
|
||||
from concurrent.futures import TimeoutError
|
||||
import concurrent.futures
|
||||
import atexit
|
||||
from simulation.simulation_trader import SimulationTrader
|
||||
import datetime
|
||||
from logger_config import get_logger
|
||||
from real.real_trader_manager import RealTraderManager
|
||||
from trade_constants import *
|
||||
@ -45,6 +41,23 @@ def get_trader():
|
||||
|
||||
return _trader_instance
|
||||
|
||||
def login():
|
||||
try:
|
||||
get_trader().login()
|
||||
result = get_trader().get_balance()
|
||||
if result and result["account_id"] == "simulation":
|
||||
logger.info(f"登录成功: {result}")
|
||||
else:
|
||||
logger.error(f"登录失败: {result}")
|
||||
raise Exception(f"登录失败: {result}")
|
||||
except Exception as e:
|
||||
logger.error(f"登录失败: {e}")
|
||||
raise Exception(f"登录失败: {e}")
|
||||
|
||||
def logout():
|
||||
get_trader().logout()
|
||||
logger.info("登出成功")
|
||||
|
||||
|
||||
def is_real_mode():
|
||||
return not Config.SIMULATION_MODE
|
||||
@ -80,15 +93,15 @@ _scheduler_thread_running = True
|
||||
_scheduler_thread = threading.Thread(target=run_pending_tasks, daemon=True)
|
||||
_scheduler_thread.start()
|
||||
|
||||
# 初始化交易环境
|
||||
get_trader().login()
|
||||
# 程序启动时初始化交易实例
|
||||
login()
|
||||
|
||||
# 添加请求频率限制
|
||||
app = Flask(__name__)
|
||||
|
||||
# 使用配置文件中的时间
|
||||
run_daily(Config.MARKET_OPEN_TIME, lambda: get_trader().login())
|
||||
run_daily(Config.MARKET_CLOSE_TIME, lambda: get_trader().logout())
|
||||
run_daily(Config.MARKET_OPEN_TIME, lambda: login())
|
||||
run_daily(Config.MARKET_CLOSE_TIME, lambda: logout())
|
||||
|
||||
|
||||
@app.route("/yu/healthcheck", methods=["GET"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user