From 4ed16b48ac2666161126ca7e313cd146fe67a8fa Mon Sep 17 00:00:00 2001 From: msincenselee Date: Tue, 24 Nov 2020 16:26:48 +0800 Subject: [PATCH] =?UTF-8?q?[bug=20fix]=20=E4=BF=AE=E5=A4=8D=E5=A4=A7?= =?UTF-8?q?=E8=BF=9E=E3=80=81=E9=83=91=E5=B7=9E=E7=9A=84on=5Ftrade?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/gateway/ctp/ctp_gateway.py | 24 +++++++++++++++++++++++- vnpy/gateway/rohon/rohon_gateway.py | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/vnpy/gateway/ctp/ctp_gateway.py b/vnpy/gateway/ctp/ctp_gateway.py index 4084aa4b..318a28f3 100644 --- a/vnpy/gateway/ctp/ctp_gateway.py +++ b/vnpy/gateway/ctp/ctp_gateway.py @@ -653,7 +653,7 @@ class CtpMdApi(MdApi): # 不处理开盘前的tick数据 if dt.hour in [8, 20] and dt.minute < 59: return - if exchange is Exchange.CFFEX and dt.hour == 9 and dt.minute < 14: + if exchange is Exchange.CFFEX and dt.hour == 9 and dt.minute < 29: return tick = TickData( @@ -1181,6 +1181,28 @@ 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') + #print(f'raw_data:{print_dict(data)}') + # 修正 郑商所、大商所的TradeDate错误 + if exchange in [Exchange.DCE, Exchange.CZCE]: + dt_now = datetime.now() + # 交易发生在夜盘 + if trade_datetime.hour >= 21: + # 系统时间在夜盘,使用系统时间 + if dt_now.hour >= 21: + trade_date = dt_now.strftime('%Y-%m-%d') + trade_datetime = datetime.strptime(f'{trade_date} {trade_time}', '%Y-%m-%d %H:%M:%S') + + # 系统时间在日盘 + else: + # 星期一 =》 星期五 + if dt_now.isoweekday() == 1: + trade_datetime -= timedelta(days=3) + #print(f'trade time =>{trade_datetime}') + # 星期二~星期五 =》上一天 + else: + trade_datetime -= timedelta(days=1) + #print(f'trade time =>{trade_datetime}') + tradeid = data["TradeID"] trade = TradeData( accountid=self.accountid, diff --git a/vnpy/gateway/rohon/rohon_gateway.py b/vnpy/gateway/rohon/rohon_gateway.py index b03bc3fc..8fe69462 100644 --- a/vnpy/gateway/rohon/rohon_gateway.py +++ b/vnpy/gateway/rohon/rohon_gateway.py @@ -1108,6 +1108,25 @@ class RohonTdApi(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') + # 修正 郑商所、大商所的TradeDate错误 + if exchange in [Exchange.DCE, Exchange.CZCE]: + dt_now = datetime.now() + # 交易发生在夜盘 + if trade_datetime.hour >= 21: + # 系统时间在夜盘,使用系统时间 + if dt_now.hour >= 21: + trade_date = dt_now.strftime('%Y-%m-%d') + trade_datetime = datetime.strptime(f'{trade_date} {trade_time}', '%Y-%m-%d %H:%M:%S') + + # 系统时间在日盘 + else: + # 星期一 =》 星期五 + if dt_now.isoweekday() == 1: + trade_datetime -= timedelta(days=3) + # 星期二~星期五 =》上一天 + else: + trade_datetime -= timedelta(days=1) + tradeid = data["TradeID"] trade = TradeData( accountid=self.accountid,