| | |
| | | self.call_back_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=10) |
| | | |
| | | def OnFrontConnected(self) -> "void": |
| | | print('Trader OnFrontConnected') |
| | | logger.info('Trader OnFrontConnected') |
| | | |
| | | # 获取终端信息 |
| | | TradeSimpleApi.req_id += 1 |
| | | |
| | | ret = api.ReqGetConnectionInfo(TradeSimpleApi.req_id) |
| | | if ret != 0: |
| | | print('ReqGetConnectionInfo fail, ret[%d]' % ret) |
| | | logger.info('ReqGetConnectionInfo fail, ret[%d]' % ret) |
| | | |
| | | def OnFrontDisconnected(self, nReason: "int") -> "void": |
| | | print('OnFrontDisconnected: [%d]' % nReason) |
| | | logger.info('OnFrontDisconnected: [%d]' % nReason) |
| | | |
| | | def OnRspGetConnectionInfo(self, pConnectionInfoField: "CTORATstpConnectionInfoField", |
| | | pRspInfoField: "CTORATstpRspInfoField", nRequestID: "int") -> "void": |
| | |
| | | TradeSimpleApi.req_id += 1 |
| | | ret = api.ReqUserLogin(login_req, TradeSimpleApi.req_id) |
| | | if ret != 0: |
| | | print('ReqUserLogin fail, ret[%d]' % ret) |
| | | logger.info('ReqUserLogin fail, ret[%d]' % ret) |
| | | else: |
| | | print('GetConnectionInfo fail, [%d] [%d] [%s]!!!' % ( |
| | | logger.info('GetConnectionInfo fail, [%d] [%d] [%s]!!!' % ( |
| | | nRequestID, pRspInfoField.ErrorID, pRspInfoField.ErrorMsg)) |
| | | |
| | | def OnRspUserLogin(self, pRspUserLoginField: "CTORATstpRspUserLoginField", pRspInfoField: "CTORATstpRspInfoField", |
| | | nRequestID: "int") -> "void": |
| | | if pRspInfoField.ErrorID == 0: |
| | | logger_local_huaxin_trade_debug.info("交易登录成功") |
| | | print('Login success! [%d]' % nRequestID) |
| | | logger.info('Login success! [%d]' % nRequestID) |
| | | self.__front_id = pRspUserLoginField.FrontID |
| | | self.__session_id = pRspUserLoginField.SessionID |
| | | TradeSimpleApi.set_login_info(self.__session_id, self.__front_id) |
| | |
| | | |
| | | |
| | | def __init_trade_data_server(): |
| | | print("初始化交易服务器") |
| | | logger.info("初始化交易服务器") |
| | | global api |
| | | api = traderapi.CTORATstpTraderApi.CreateTstpTraderApi('./flow', False) |
| | | # 创建回调对象 |
| | |
| | | logger_system.info(f"trade 线程ID:{tool.get_thread_id()}") |
| | | __init_trade_data_server() |
| | | |
| | | # 运行日志同步 |
| | | threading.Thread(target=lambda: async_log_util.run_sync(), daemon=True).start() |
| | | |
| | | global queue_strategy_trade_write |
| | | queue_strategy_trade_write = queue_strategy_r_trade_w |
| | | # 运行日志同步 |
| | |
| | | tradeCommandManager.run() |
| | | except Exception as e: |
| | | logger_system.exception(e) |
| | | finally: |
| | | logger_system.info("华鑫交易服务进程结束") |
| | | # 不需要运行命令解析 |
| | | # tradeCommandManager.run() |
| | | while True: |