[Add] HistoryRequest and related query functions in BaseGateway

This commit is contained in:
vn.py 2019-05-08 11:26:42 +08:00
parent 66cdf33b23
commit 9932045b59
2 changed files with 33 additions and 4 deletions

View File

@ -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.

View File

@ -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}"