[Mod]add on_cancel_order_failed callback for OkexGateway

This commit is contained in:
vn.py 2019-04-09 18:21:28 +08:00
parent f53f5ea7dd
commit 1a79ba37db
2 changed files with 21 additions and 2 deletions

View File

@ -85,6 +85,8 @@ class OkexGateway(BaseGateway):
self.rest_api = OkexRestApi(self) self.rest_api = OkexRestApi(self)
self.ws_api = OkexWebsocketApi(self) self.ws_api = OkexWebsocketApi(self)
self.orders = {}
def connect(self, setting: dict): def connect(self, setting: dict):
"""""" """"""
key = setting["API Key"] key = setting["API Key"]
@ -128,6 +130,15 @@ class OkexGateway(BaseGateway):
self.rest_api.stop() self.rest_api.stop()
self.ws_api.stop() self.ws_api.stop()
def on_order(self, order: OrderData):
""""""
self.orders[order.vt_orderid] = order
super().on_order(order)
def get_order(self, vt_orderid: str):
""""""
return self.orders.get(vt_orderid, None)
class OkexRestApi(RestClient): class OkexRestApi(RestClient):
""" """
@ -258,6 +269,8 @@ class OkexRestApi(RestClient):
callback=self.on_cancel_order, callback=self.on_cancel_order,
data=data, data=data,
on_error=self.on_cancel_order_error, on_error=self.on_cancel_order_error,
on_failed=self.on_cancel_order_failed,
extra=req
) )
def query_contract(self): def query_contract(self):
@ -406,6 +419,14 @@ class OkexRestApi(RestClient):
"""Websocket will push a new order status""" """Websocket will push a new order status"""
pass pass
def on_cancel_order_failed(self, status_code: int, request: Request):
"""If cancel failed, mark order status to be rejected."""
req = request.extra
order = self.gateway.get_order(req.vt_orderid)
if order:
order.status = Status.REJECTED
self.gateway.on_order(order)
def on_failed(self, status_code: int, request: Request): def on_failed(self, status_code: int, request: Request):
""" """
Callback to handle request failed. Callback to handle request failed.

View File

@ -394,5 +394,3 @@ def virtual(func: "callable"):
that can be (re)implemented by subclasses. that can be (re)implemented by subclasses.
""" """
return func return func