[Add] some docs for BaseGateway
This commit is contained in:
parent
cc129b3e2c
commit
51c8ed3b03
@ -33,6 +33,28 @@ class BaseGateway(ABC):
|
|||||||
"""
|
"""
|
||||||
Abstract gateway class for creating gateways connection
|
Abstract gateway class for creating gateways connection
|
||||||
to different trading systems.
|
to different trading systems.
|
||||||
|
|
||||||
|
# How to implement a gateway:
|
||||||
|
|
||||||
|
A gateway should satisfies:
|
||||||
|
* this class should be thread-safe:
|
||||||
|
* all methods should be thread-safe
|
||||||
|
* no mutable shared properties between objects.
|
||||||
|
* all methods should be non-blocked
|
||||||
|
* satisfies all requirements written in docstring for every method and callbacks.
|
||||||
|
* automatically reconnect if connection lost.
|
||||||
|
|
||||||
|
methods must implements:
|
||||||
|
all @abstractmethod
|
||||||
|
|
||||||
|
callbacks must response manually:
|
||||||
|
* on_tick
|
||||||
|
* on_trade
|
||||||
|
* on_order
|
||||||
|
* on_position
|
||||||
|
* on_account
|
||||||
|
* on_contract
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Fields required in setting dict for connect function.
|
# Fields required in setting dict for connect function.
|
||||||
@ -113,6 +135,21 @@ class BaseGateway(ABC):
|
|||||||
def connect(self, setting: dict):
|
def connect(self, setting: dict):
|
||||||
"""
|
"""
|
||||||
Start gateway connection.
|
Start gateway connection.
|
||||||
|
|
||||||
|
to implement this method, you must:
|
||||||
|
* connect to server if necessary
|
||||||
|
* log connected if all necessary connection is established
|
||||||
|
* do the following query and response corresponding on_xxxx and write_log
|
||||||
|
* contracts : on_contract
|
||||||
|
* account asset : on_account
|
||||||
|
* account holding: on_position
|
||||||
|
* orders of account: on_order
|
||||||
|
* trades of account: on_trade
|
||||||
|
* if any of query above is failed, write log.
|
||||||
|
|
||||||
|
future plan:
|
||||||
|
response callback/change status instead of write_log
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -131,9 +168,19 @@ class BaseGateway(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def send_order(self, req: OrderRequest):
|
def send_order(self, req: OrderRequest) -> str:
|
||||||
"""
|
"""
|
||||||
Send a new order.
|
Send a new order to server.
|
||||||
|
|
||||||
|
implementation should finish the tasks blow:
|
||||||
|
* create an OrderData from req using OrderRequest.create_order_data
|
||||||
|
* send request to server
|
||||||
|
* if request is sent, OrderData.status should be set to Status.SUBMITTING
|
||||||
|
* if request is failed to sent, OrderData.status should be set to Status.REJECTED
|
||||||
|
* response on_order:
|
||||||
|
* return OrderData.vt_orderid
|
||||||
|
|
||||||
|
:return str vt_orderid for created OrderData
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -141,6 +188,10 @@ class BaseGateway(ABC):
|
|||||||
def cancel_order(self, req: CancelRequest):
|
def cancel_order(self, req: CancelRequest):
|
||||||
"""
|
"""
|
||||||
Cancel an existing order.
|
Cancel an existing order.
|
||||||
|
implementation should finish the tasks blow:
|
||||||
|
* send request to server
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -148,6 +199,7 @@ class BaseGateway(ABC):
|
|||||||
def query_account(self):
|
def query_account(self):
|
||||||
"""
|
"""
|
||||||
Query account balance.
|
Query account balance.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user