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"],