def process_rtn_order(self): try: last_rtn_order_index = len(self.rtn_order_list) for rtn_order in self.rtn_order_list[self.last_rtn_order_index:last_rtn_order_index]: # 未成交 if rtn_order['OrderStatus'] == OrderStatus_NoTradeQueueing: pass # 全部成交 elif rtn_order['OrderStatus'] == OrderStatus_AllTraded or rtn_order['OrderStatus'] == OrderStatus_PartTradedQueueing: self.on_order_traded(rtn_order) # 撤单成功 elif rtn_order['OrderStatus'] == OrderStatus_Canceled: if rtn_order['InstrumentID'] in self.action_num_dict.keys(): self.action_num_dict[rtn_order['InstrumentID']] += 1 else: self.action_num_dict[rtn_order['InstrumentID']] = 1 self.on_order_action(rtn_order) # 委托失败 elif rtn_order['OrderSubmitStatus'] == OrderSubmitStatus_InsertRejected: self.on_order_insert_fail(rtn_order) # 撤单失败 elif rtn_order['OrderSubmitStatus'] == OrderSubmitStatus_CancelRejected: self.on_order_action_fail(rtn_order) self.write_log(to_str(rtn_order['StatusMsg']), rtn_order) self.last_rtn_order_index = last_rtn_order_index except Exception as err_msg: self.write_log('process_rtn_order', err_msg.__doc__)
def OnRtnDepthMarketData(self, pDepthMarketData): try: for key in pDepthMarketData.keys(): pDepthMarketData[key] = to_str(pDepthMarketData[key]) # 写入行情 self.csv_writer[pDepthMarketData['InstrumentID']].writerow(pDepthMarketData) # 刷新缓冲区 self.csv_file_dict[pDepthMarketData['InstrumentID']].flush() except Exception as err_msg: self.write_log(err_msg, pDepthMarketData)
def init_extra(self): self.csv_file_dict = {} self.csv_writer = {} # 深度行情结构体字段名列表 header = list(DepthMarketDataField().to_dict()) for instrument_id in self.instrument_id_list: instrument_id = to_str(instrument_id) # file object file_dir = os.path.join(self.page_dir, f'{instrument_id}-{to_str(self.GetTradingDay())}.csv') self.csv_file_dict[instrument_id] = open(file_dir, 'a', newline='') # writer object self.csv_writer[instrument_id] = csv.DictWriter(self.csv_file_dict[instrument_id], header) # 写入表头 self.csv_writer[instrument_id].writeheader() self.csv_file_dict[instrument_id].flush()