From e6251c7467649ca1298c39b65c2e0d9dc4a29b14 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Fri, 15 May 2020 14:14:56 +0800 Subject: [PATCH] =?UTF-8?q?[bug=20fix]=20=E4=BF=AE=E5=A4=8D=E9=83=91?= =?UTF-8?q?=E5=95=86=E6=89=80=E6=97=A5=E6=9C=9F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/gateway/ctp/ctp_gateway.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/vnpy/gateway/ctp/ctp_gateway.py b/vnpy/gateway/ctp/ctp_gateway.py index 35c13fcd..dd0bcaa3 100644 --- a/vnpy/gateway/ctp/ctp_gateway.py +++ b/vnpy/gateway/ctp/ctp_gateway.py @@ -497,9 +497,11 @@ class CtpMdApi(MdApi): exchange = symbol_exchange_map.get(symbol, "") if not exchange: return - - timestamp = f"{data['ActionDay']} {data['UpdateTime']}.{int(data['UpdateMillisec'] / 100)}" - dt = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f") + # 取当前时间 + dt = datetime.now() + s_date = dt.strftime('%Y-%m-%d') + timestamp = f"{s_date} {data['UpdateTime']}.{int(data['UpdateMillisec'] / 100)}" + dt = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") # 不处理开盘前的tick数据 if dt.hour in [8, 20] and dt.minute < 59: @@ -511,7 +513,7 @@ class CtpMdApi(MdApi): symbol=symbol, exchange=exchange, datetime=dt, - date=dt.strftime('%Y-%m-%d'), + date=s_date, time=dt.strftime('%H:%M:%S.%f'), trading_day=get_trading_date(dt), name=symbol_name_map[symbol], @@ -640,7 +642,7 @@ class CtpTdApi(TdApi): self.sysid_orderid_map = {} self.future_contract_changed = False - self.accountid = "" + self.accountid = self.userid def onFrontConnected(self): """""" @@ -804,7 +806,7 @@ class CtpTdApi(TdApi): """""" if "AccountID" not in data: return - if not self.accountid: + if len(self.accountid)== 0: self.accountid = data['AccountID'] account = AccountData( @@ -941,10 +943,11 @@ class CtpTdApi(TdApi): order_type = OrderType.MARKET order = OrderData( + accountid=self.accountid, symbol=symbol, exchange=exchange, orderid=orderid, - sys_orderid=data.get('OrderSysID', ""), + sys_orderid=data.get('OrderSysID', orderid), type=order_type, direction=DIRECTION_CTP2VT[data["Direction"]], offset=OFFSET_CTP2VT[data["CombOffsetFlag"]], @@ -976,13 +979,14 @@ class CtpTdApi(TdApi): trade_date = trade_date[0:4] + '-' + trade_date[4:6] + '-' + trade_date[6:8] trade_time = data['TradeTime'] trade_datetime = datetime.strptime(f'{trade_date} {trade_time}', '%Y-%m-%d %H:%M:%S') - + tradeid = data["TradeID"] trade = TradeData( + accountid=self.accountid, symbol=symbol, exchange=exchange, orderid=orderid, - sys_orderid=data.get("OrderSysID", ""), - tradeid=data["TradeID"], + sys_orderid=data.get("OrderSysID", orderid), + tradeid=tradeid.replace(' ',''), direction=DIRECTION_CTP2VT[data["Direction"]], offset=OFFSET_CTP2VT[data["OffsetFlag"]], price=data["Price"], @@ -1057,7 +1061,7 @@ class CtpTdApi(TdApi): "BrokerID": self.brokerid, "AppID": self.appid } - + self.accountid = copy(self.userid) if self.product_info: req["UserProductInfo"] = self.product_info @@ -1109,6 +1113,8 @@ class CtpTdApi(TdApi): orderid = f"{self.frontid}_{self.sessionid}_{self.order_ref}" order = req.create_order_data(orderid, self.gateway_name) + order.accountid = self.accountid + order.vt_accountid = f"{self.gateway_name}.{self.accountid}" self.gateway.on_order(order) return order.vt_orderid