[bug fix] 修复郑商所日期的bug

This commit is contained in:
msincenselee 2020-05-15 14:14:56 +08:00
parent 66de40e5f7
commit e6251c7467

View File

@ -497,9 +497,11 @@ class CtpMdApi(MdApi):
exchange = symbol_exchange_map.get(symbol, "") exchange = symbol_exchange_map.get(symbol, "")
if not exchange: if not exchange:
return return
# 取当前时间
timestamp = f"{data['ActionDay']} {data['UpdateTime']}.{int(data['UpdateMillisec'] / 100)}" dt = datetime.now()
dt = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f") 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数据 # 不处理开盘前的tick数据
if dt.hour in [8, 20] and dt.minute < 59: if dt.hour in [8, 20] and dt.minute < 59:
@ -511,7 +513,7 @@ class CtpMdApi(MdApi):
symbol=symbol, symbol=symbol,
exchange=exchange, exchange=exchange,
datetime=dt, datetime=dt,
date=dt.strftime('%Y-%m-%d'), date=s_date,
time=dt.strftime('%H:%M:%S.%f'), time=dt.strftime('%H:%M:%S.%f'),
trading_day=get_trading_date(dt), trading_day=get_trading_date(dt),
name=symbol_name_map[symbol], name=symbol_name_map[symbol],
@ -640,7 +642,7 @@ class CtpTdApi(TdApi):
self.sysid_orderid_map = {} self.sysid_orderid_map = {}
self.future_contract_changed = False self.future_contract_changed = False
self.accountid = "" self.accountid = self.userid
def onFrontConnected(self): def onFrontConnected(self):
"""""" """"""
@ -804,7 +806,7 @@ class CtpTdApi(TdApi):
"""""" """"""
if "AccountID" not in data: if "AccountID" not in data:
return return
if not self.accountid: if len(self.accountid)== 0:
self.accountid = data['AccountID'] self.accountid = data['AccountID']
account = AccountData( account = AccountData(
@ -941,10 +943,11 @@ class CtpTdApi(TdApi):
order_type = OrderType.MARKET order_type = OrderType.MARKET
order = OrderData( order = OrderData(
accountid=self.accountid,
symbol=symbol, symbol=symbol,
exchange=exchange, exchange=exchange,
orderid=orderid, orderid=orderid,
sys_orderid=data.get('OrderSysID', ""), sys_orderid=data.get('OrderSysID', orderid),
type=order_type, type=order_type,
direction=DIRECTION_CTP2VT[data["Direction"]], direction=DIRECTION_CTP2VT[data["Direction"]],
offset=OFFSET_CTP2VT[data["CombOffsetFlag"]], 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_date = trade_date[0:4] + '-' + trade_date[4:6] + '-' + trade_date[6:8]
trade_time = data['TradeTime'] trade_time = data['TradeTime']
trade_datetime = datetime.strptime(f'{trade_date} {trade_time}', '%Y-%m-%d %H:%M:%S') trade_datetime = datetime.strptime(f'{trade_date} {trade_time}', '%Y-%m-%d %H:%M:%S')
tradeid = data["TradeID"]
trade = TradeData( trade = TradeData(
accountid=self.accountid,
symbol=symbol, symbol=symbol,
exchange=exchange, exchange=exchange,
orderid=orderid, orderid=orderid,
sys_orderid=data.get("OrderSysID", ""), sys_orderid=data.get("OrderSysID", orderid),
tradeid=data["TradeID"], tradeid=tradeid.replace(' ',''),
direction=DIRECTION_CTP2VT[data["Direction"]], direction=DIRECTION_CTP2VT[data["Direction"]],
offset=OFFSET_CTP2VT[data["OffsetFlag"]], offset=OFFSET_CTP2VT[data["OffsetFlag"]],
price=data["Price"], price=data["Price"],
@ -1057,7 +1061,7 @@ class CtpTdApi(TdApi):
"BrokerID": self.brokerid, "BrokerID": self.brokerid,
"AppID": self.appid "AppID": self.appid
} }
self.accountid = copy(self.userid)
if self.product_info: if self.product_info:
req["UserProductInfo"] = self.product_info req["UserProductInfo"] = self.product_info
@ -1109,6 +1113,8 @@ class CtpTdApi(TdApi):
orderid = f"{self.frontid}_{self.sessionid}_{self.order_ref}" orderid = f"{self.frontid}_{self.sessionid}_{self.order_ref}"
order = req.create_order_data(orderid, self.gateway_name) 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) self.gateway.on_order(order)
return order.vt_orderid return order.vt_orderid