From 9932045b5964bd4f05fa5d956bde2c363416c194 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 8 May 2019 11:26:42 +0800 Subject: [PATCH] [Add] HistoryRequest and related query functions in BaseGateway --- vnpy/trader/gateway.py | 18 ++++++++++++++---- vnpy/trader/object.py | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/vnpy/trader/gateway.py b/vnpy/trader/gateway.py index edd2c6ab..0583f125 100644 --- a/vnpy/trader/gateway.py +++ b/vnpy/trader/gateway.py @@ -27,12 +27,13 @@ from .object import ( OrderRequest, CancelRequest, SubscribeRequest, + HistoryRequest ) class BaseGateway(ABC): """ - Abstract gateway class for creating gateways connection + Abstract gateway class for creating gateways connection to different trading systems. # How to implement a gateway: @@ -206,8 +207,6 @@ class BaseGateway(ABC): Cancel an existing order. implementation should finish the tasks blow: * send request to server - - """ pass @@ -215,7 +214,6 @@ class BaseGateway(ABC): def query_account(self): """ Query account balance. - """ pass @@ -226,6 +224,18 @@ class BaseGateway(ABC): """ pass + def query_bar_history(self, req: HistoryRequest): + """ + Query bar history data. + """ + pass + + def query_tick_history(self, req: HistoryRequest): + """ + Query tick history data. + """ + pass + def get_default_setting(self): """ Return default setting dict. diff --git a/vnpy/trader/object.py b/vnpy/trader/object.py index 734093cb..7a551a85 100644 --- a/vnpy/trader/object.py +++ b/vnpy/trader/object.py @@ -236,6 +236,8 @@ class ContractData(BaseData): min_volume: float = 1 # minimum trading volume of the contract stop_supported: bool = False # whether server supports stop order net_position: bool = False # whether gateway uses net position volume + bar_history: bool = False # whether gateway provides bar history data + tick_history: bool = False # whether gateway provides tick history data option_strike: float = 0 option_underlying: str = "" # vt_symbol of underlying contract @@ -310,3 +312,20 @@ class CancelRequest: def __post_init__(self): """""" self.vt_symbol = f"{self.symbol}.{self.exchange.value}" + + +@dataclass +class HistoryRequest: + """ + Request sending to specific gateway for querying history data. + """ + + symbol: str + exchange: Exchange + start: datetime + end: datetime = None + interval: Interval = None + + def __post_init__(self): + """""" + self.vt_symbol = f"{self.symbol}.{self.exchange.value}"