[Add]on_send_order_fail callback for HuobiGateway
This commit is contained in:
parent
0646e1ccd2
commit
4472e026c9
@ -15,7 +15,7 @@ from copy import copy
|
||||
from datetime import datetime
|
||||
|
||||
from vnpy.event import Event
|
||||
from vnpy.api.rest import RestClient
|
||||
from vnpy.api.rest import RestClient, Request
|
||||
from vnpy.api.websocket import WebsocketClient
|
||||
from vnpy.trader.constant import (
|
||||
Direction,
|
||||
@ -275,6 +275,8 @@ class HuobiRestApi(RestClient):
|
||||
callback=self.on_send_order,
|
||||
data=data,
|
||||
extra=order,
|
||||
on_error=self.on_send_order_error,
|
||||
on_failed=self.on_send_order_failed
|
||||
)
|
||||
|
||||
self.order_manager.on_order(order)
|
||||
@ -397,19 +399,44 @@ class HuobiRestApi(RestClient):
|
||||
sys_orderid = data["data"]
|
||||
self.order_manager.update_orderid_map(order.orderid, sys_orderid)
|
||||
|
||||
def on_send_order_failed(self, status_code: str, request: Request):
|
||||
"""
|
||||
Callback when sending order failed on server.
|
||||
"""
|
||||
order = request.extra
|
||||
order.status = Status.REJECTED
|
||||
self.gateway.on_order(order)
|
||||
|
||||
msg = f"委托失败,状态码:{status_code},信息:{request.response.text}"
|
||||
self.gateway.write_log(msg)
|
||||
|
||||
def on_send_order_error(
|
||||
self, exception_type: type, exception_value: Exception, tb, request: Request
|
||||
):
|
||||
"""
|
||||
Callback when sending order caused exception.
|
||||
"""
|
||||
order = request.extra
|
||||
order.status = Status.REJECTED
|
||||
self.gateway.on_order(order)
|
||||
|
||||
# Record exception if not ConnectionError
|
||||
if not issubclass(exception_type, ConnectionError):
|
||||
self.on_error(exception_type, exception_value, tb, request)
|
||||
|
||||
def on_cancel_order(self, data, request):
|
||||
""""""
|
||||
if self.check_error(data, "撤单"):
|
||||
return
|
||||
|
||||
cancel_request = request.extra
|
||||
local_orderid = cancel_request.orderid
|
||||
|
||||
order = self.order_manager.get_order_with_local_orderid(local_orderid)
|
||||
order.status = Status.CANCELLED
|
||||
|
||||
if self.check_error(data, "撤单"):
|
||||
order.status = Status.REJECTED
|
||||
else:
|
||||
order.status = Status.CANCELLED
|
||||
self.gateway.write_log(f"委托撤单成功:{order.orderid}")
|
||||
|
||||
self.order_manager.on_order(order)
|
||||
self.gateway.write_log(f"委托撤单成功:{order.orderid}")
|
||||
|
||||
def check_error(self, data: dict, func: str = ""):
|
||||
""""""
|
||||
|
Loading…
Reference in New Issue
Block a user