[Mod] change query_bar -> query_history for rqdata_client
This commit is contained in:
parent
8c707435e8
commit
a68773fec9
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user