From 791fb0d840279f195f3498d1e459367bec0800f0 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 30 Apr 2019 14:29:35 +0800 Subject: [PATCH] [Add]adjust timestamp of bar data from RQData, close #1573 --- vnpy/trader/rqdata.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vnpy/trader/rqdata.py b/vnpy/trader/rqdata.py index 1e1b3209..965d32c7 100644 --- a/vnpy/trader/rqdata.py +++ b/vnpy/trader/rqdata.py @@ -16,6 +16,12 @@ INTERVAL_VT2RQ = { Interval.DAILY: "1d", } +INTERVAL_ADJUSTMENT_MAP = { + Interval.MINUTE: timedelta(minutes=1), + Interval.HOUR: timedelta(hours=1), + Interval.DAILY: timedelta() # no need to adjust for daily bar +} + class RqdataClient: """ @@ -102,7 +108,11 @@ class RqdataClient: if not rq_interval: return None - end += timedelta(1) # For querying night trading period data + # For adjust timestamp from bar close point (RQData) to open point (VN Trader) + adjustment = INTERVAL_ADJUSTMENT_MAP[interval] + + # For querying night trading period data + end += timedelta(1) df = rqdata_get_price( rq_symbol, @@ -118,7 +128,7 @@ class RqdataClient: symbol=symbol, exchange=exchange, interval=interval, - datetime=row.name.to_pydatetime(), + datetime=row.name.to_pydatetime() - adjustment, open_price=row["open"], high_price=row["high"], low_price=row["low"],