update login
This commit is contained in:
parent
1d893aa629
commit
65f91c56b2
@ -94,19 +94,10 @@ def login() -> bool:
|
|||||||
global _trader_instance
|
global _trader_instance
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if _trader_instance is not None and is_real_mode():
|
logout()
|
||||||
# _trader_instance is BaseTrader or its child, which should have logout
|
|
||||||
_trader_instance.logout()
|
|
||||||
_trader_instance = None
|
|
||||||
|
|
||||||
_trader_instance = SimulationTrader() if Config.SIMULATION_MODE else XtTrader(connect_failed_callback=on_connect_failed)
|
_trader_instance = SimulationTrader() if Config.SIMULATION_MODE else XtTrader(connect_failed_callback=on_connect_failed)
|
||||||
|
|
||||||
logger.info("开始登录")
|
logger.info("开始登录")
|
||||||
|
|
||||||
if Config.SIMULATION_MODE:
|
|
||||||
return True
|
|
||||||
|
|
||||||
# _trader_instance is XtTrader here, which has login
|
|
||||||
login_success = _trader_instance.login()
|
login_success = _trader_instance.login()
|
||||||
|
|
||||||
if login_success:
|
if login_success:
|
||||||
@ -117,7 +108,7 @@ def login() -> bool:
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.error(f"登录成功但查询余额失败: {result}")
|
logger.error(f"登录成功但查询余额失败: {result}")
|
||||||
if _trader_instance:
|
if _trader_instance and is_real_mode():
|
||||||
_trader_instance.connection_failed = True # BaseTrader property
|
_trader_instance.connection_failed = True # BaseTrader property
|
||||||
_trader_instance.last_reconnect_time = time.time() # BaseTrader property
|
_trader_instance.last_reconnect_time = time.time() # BaseTrader property
|
||||||
_trader_instance.notify_connection_failure("登录成功但查询余额失败") # BaseTrader method
|
_trader_instance.notify_connection_failure("登录成功但查询余额失败") # BaseTrader method
|
||||||
@ -127,7 +118,7 @@ def login() -> bool:
|
|||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"登录初始化异常: {str(e)}")
|
logger.error(f"登录初始化异常: {str(e)}")
|
||||||
if is_real_mode() and _trader_instance is not None:
|
if _trader_instance and is_real_mode():
|
||||||
_trader_instance.connection_failed = True
|
_trader_instance.connection_failed = True
|
||||||
_trader_instance.last_reconnect_time = time.time()
|
_trader_instance.last_reconnect_time = time.time()
|
||||||
_trader_instance.notify_connection_failure(f"登录初始化异常: {str(e)}")
|
_trader_instance.notify_connection_failure(f"登录初始化异常: {str(e)}")
|
||||||
@ -139,7 +130,7 @@ def logout() -> None:
|
|||||||
"""登出并销毁交易实例。"""
|
"""登出并销毁交易实例。"""
|
||||||
global _trader_instance
|
global _trader_instance
|
||||||
|
|
||||||
if _trader_instance is not None:
|
if _trader_instance:
|
||||||
_trader_instance.logout()
|
_trader_instance.logout()
|
||||||
logger.info("登出成功")
|
logger.info("登出成功")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user