| | |
| | | def cancel_buy(self, code, order_sys_id, sinfo): |
| | | if sinfo in self.__cancel_buy_sinfo_set: |
| | | raise Exception(f'撤单请求已经提交:{sinfo}') |
| | | logger_local_huaxin_trade_debug.info(f"进入撤单方法:code-{code} order_sys_id-{order_sys_id} sinfo-{sinfo}") |
| | | self.__cancel_buy_sinfo_set.add(sinfo) |
| | | self.req_id += 1 |
| | | # 请求撤单 |
| | |
| | | "orderStatusMsg": pRspInfoField.ErrorMsg}), |
| | | daemon=True).start() |
| | | |
| | | # 撤单响应 |
| | | def OnRspOrderAction(self, pInputOrderActionField: "CTORATstpInputOrderActionField", |
| | | pRspInfoField: "CTORATstpRspInfoField", nRequestID: "int") -> "void": |
| | | if pRspInfoField.ErrorID == 0: |
| | | logger.info('OnRspOrderAction: OK! [%d]' % nRequestID) |
| | | logger_local_huaxin_trade_debug.info('OnRspOrderAction: OK! [%d]' % nRequestID) |
| | | threading.Thread(target=lambda: self.__data_callback(TYPE_CANCEL_ORDER, nRequestID, |
| | | {"sinfo": pInputOrderActionField.SInfo, |
| | | "orderSysID": pInputOrderActionField.OrderSysID, |
| | | "cancel": 1}), daemon=True).start() |
| | | |
| | | else: |
| | | logger.info('OnRspOrderAction: Error! [%d] [%d] [%s]' |
| | | % (nRequestID, pRspInfoField.ErrorID, pRspInfoField.ErrorMsg)) |
| | | logger_local_huaxin_trade_debug.info('OnRspOrderAction: Error! [%d] [%d] [%s]' |
| | | % (nRequestID, pRspInfoField.ErrorID, pRspInfoField.ErrorMsg)) |
| | | threading.Thread(target=lambda: self.__data_callback(TYPE_CANCEL_ORDER, nRequestID, |
| | | {"sinfo": pInputOrderActionField.SInfo, |
| | | "orderSysID": pInputOrderActionField.OrderSysID, |
| | | "cancel": 0, "errorID": pRspInfoField.ErrorID, |
| | | "errorMsg": pRspInfoField.ErrorMsg}), |
| | | daemon=True).start() |
| | | |
| | | # 撤单错误回报 |
| | | def OnErrRtnOrderAction(self, pInputOrderActionField: "CTORATstpInputOrderActionField", |
| | | pRspInfoField: "CTORATstpRspInfoField", nRequestID: "int") -> "void": |
| | | logger_local_huaxin_trade_debug.info('OnErrRtnOrderAction: Error! [%d] [%d] [%d] [%s]' |
| | | % (nRequestID, pInputOrderActionField.OrderSysID, pRspInfoField.ErrorID, |
| | | pRspInfoField.ErrorMsg)) |
| | | |
| | | def OnRspInquiryJZFund(self, pRspInquiryJZFundField: "CTORATstpRspInquiryJZFundField", |
| | | pRspInfoField: "CTORATstpRspInfoField", nRequestID: "int") -> "void": |
| | |
| | | pOrderField.OrderRef, pOrderField.OrderLocalID, |
| | | pOrderField.LimitPrice, pOrderField.VolumeTotalOriginal, pOrderField.OrderSysID, |
| | | pOrderField.OrderStatus)) |
| | | OrderIDManager.set_system_order_id(pOrderField.SecurityID, pOrderField.SInfo, pOrderField.OrderSysID) |
| | | if pOrderField.OrderStatus != traderapi.TORA_TSTP_OST_Unknown: |
| | | OrderIDManager.set_system_order_id(pOrderField.SecurityID, pOrderField.SInfo, pOrderField.OrderSysID) |
| | | threading.Thread(target=lambda: self.__data_callback(TYPE_ORDER, 0, {"sinfo": pOrderField.SInfo, |
| | | "securityId": pOrderField.SecurityID, |
| | | "orderLocalId": pOrderField.OrderLocalID, |
| | |
| | | daemon=True).start() |
| | | self.__temp_order_list_dict.pop(nRequestID) |
| | | |
| | | |
| | | # 获取响应发送socket |
| | | global req_rid_dict |
| | | req_rid_dict = {} |
| | |
| | | send_response(json.dumps({"code": 1, "msg": str(e)}), "common", client_id, |
| | | request_id) |
| | | |
| | | def OnTest(self, client_id, request_id, data): |
| | | logger_local_huaxin_trade_debug.info(f"测试通道:client_id-{client_id} request_id-{request_id} data-{data}") |
| | | send_response( |
| | | json.dumps({"type": "response", "data": {"code": 0, "data": data}, "client_id": client_id, |
| | | "request_id": request_id}), type, client_id, request_id) |
| | | |
| | | |
| | | def __init_trade_data_server(): |
| | | logger.info("初始化交易服务器") |
| | |
| | | if local_order_id: |
| | | if local_order_id not in cls.local_order_id_map and orderSystemId: |
| | | cls.local_order_id_map[local_order_id] = orderSystemId |
| | | logger_local_huaxin_trade_debug.info(f"本地订单号与系统订单号映射,{code}:{local_order_id} {orderSystemId}") |
| | | if local_order_id in cls.not_canceled_local_order_ids: |
| | | logger_local_huaxin_trade_debug.info(f"执行等待撤单,{code}:{local_order_id} {orderSystemId}") |
| | | # 执行撤单 |
| | | cls.not_canceled_local_order_ids.discard(local_order_id) |
| | | cls.__TradeSimpleApi.cancel_buy(code, orderSystemId, |