From a68773fec96fdd19c7441555f009b30e3a82222b Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 8 May 2019 15:57:35 +0800 Subject: [PATCH] [Mod] change query_bar -> query_history for rqdata_client --- vnpy/app/cta_backtester/engine.py | 23 +++++++++++------------ vnpy/app/cta_backtester/ui/widget.py | 4 ++-- vnpy/app/cta_strategy/engine.py | 10 ++++++++-- vnpy/gateway/bitmex/bitmex_gateway.py | 7 +------ vnpy/trader/rqdata.py | 19 +++++++++---------- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/vnpy/app/cta_backtester/engine.py b/vnpy/app/cta_backtester/engine.py index 40b3fb03..7ed94fbf 100644 --- a/vnpy/app/cta_backtester/engine.py +++ b/vnpy/app/cta_backtester/engine.py @@ -338,25 +338,24 @@ class BacktesterEngine(BaseEngine): """ self.write_log(f"{vt_symbol}-{interval}开始下载历史数据") + symbol, exchange = extract_vt_symbol(vt_symbol) + + req = HistoryRequest( + symbol=symbol, + exchange=exchange, + interval=Interval(interval), + start=start, + end=end + ) + contract = self.main_engine.get_contract(vt_symbol) # If history data provided in gateway, then query if contract and contract.history_data: - req = HistoryRequest( - symbol=contract.symbol, - exchange=contract.exchange, - interval=Interval(interval), - start=start, - end=end - ) data = self.main_engine.query_history(req, contract.gateway_name) # Otherwise use RQData to query data else: - symbol, exchange = extract_vt_symbol(vt_symbol) - - data = rqdata_client.query_bar( - symbol, exchange, Interval(interval), start, end - ) + data = rqdata_client.query_history(req) if data: database_manager.save_bar_data(data) diff --git a/vnpy/app/cta_backtester/ui/widget.py b/vnpy/app/cta_backtester/ui/widget.py index 6be8f167..2198c11d 100644 --- a/vnpy/app/cta_backtester/ui/widget.py +++ b/vnpy/app/cta_backtester/ui/widget.py @@ -56,14 +56,14 @@ class BacktesterManager(QtWidgets.QWidget): self.class_combo = QtWidgets.QComboBox() self.class_combo.addItems(self.class_names) - self.symbol_line = QtWidgets.QLineEdit("XBTUSD.BITMEX") + self.symbol_line = QtWidgets.QLineEdit("IF88.CFFEX") self.interval_combo = QtWidgets.QComboBox() for inteval in Interval: self.interval_combo.addItem(inteval.value) end_dt = datetime.now() - start_dt = end_dt - timedelta(days=30)# * 365) + start_dt = end_dt - timedelta(days=3 * 365) self.start_date_edit = QtWidgets.QDateEdit( QtCore.QDate( diff --git a/vnpy/app/cta_strategy/engine.py b/vnpy/app/cta_strategy/engine.py index a28b4878..e17f49ec 100644 --- a/vnpy/app/cta_strategy/engine.py +++ b/vnpy/app/cta_strategy/engine.py @@ -16,6 +16,7 @@ from vnpy.trader.engine import BaseEngine, MainEngine from vnpy.trader.object import ( OrderRequest, SubscribeRequest, + HistoryRequest, LogData, TickData, BarData, @@ -136,9 +137,14 @@ class CtaEngine(BaseEngine): """ Query bar data from RQData. """ - data = rqdata_client.query_bar( - symbol, exchange, interval, start, end + req = HistoryRequest( + symbol=symbol, + exchange=exchange, + interval=interval, + start=start, + end=end ) + data = rqdata_client.query_history(req) return data def process_tick_event(self, event: Event): diff --git a/vnpy/gateway/bitmex/bitmex_gateway.py b/vnpy/gateway/bitmex/bitmex_gateway.py index 338ebfad..cb815936 100644 --- a/vnpy/gateway/bitmex/bitmex_gateway.py +++ b/vnpy/gateway/bitmex/bitmex_gateway.py @@ -360,12 +360,7 @@ class BitmexRestApi(RestClient): # Update start time start_time = bar.datetime + TIMEDELTA_MAP[req.interval] - return history - - - - - + return history def on_send_order_failed(self, status_code: str, request: Request): """ diff --git a/vnpy/trader/rqdata.py b/vnpy/trader/rqdata.py index 965d32c7..f3e650bc 100644 --- a/vnpy/trader/rqdata.py +++ b/vnpy/trader/rqdata.py @@ -7,7 +7,7 @@ from rqdatac.services.get_price import get_price as rqdata_get_price from .setting import SETTINGS from .constant import Exchange, Interval -from .object import BarData +from .object import BarData, HistoryRequest INTERVAL_VT2RQ = { @@ -89,17 +89,16 @@ class RqdataClient: return rq_symbol - def query_bar( - self, - symbol: str, - exchange: Exchange, - interval: Interval, - start: datetime, - end: datetime - ): + def query_history(self, req: HistoryRequest): """ - Query bar data from RQData. + Query history bar data from RQData. """ + symbol = req.symbol + exchange = req.exchange + interval = req.interval + start = req.start + end = req.end + rq_symbol = self.to_rq_symbol(symbol, exchange) if rq_symbol not in self.symbols: return None