Merge pull request #8 from vnpy/DEV

Dev
This commit is contained in:
RobinLiu 2019-04-10 10:14:47 +08:00 committed by GitHub
commit 4bf4d7ac49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 9 deletions

View File

@ -71,8 +71,8 @@ class BitmexGateway(BaseGateway):
"Secret": "", "Secret": "",
"会话数": 3, "会话数": 3,
"服务器": ["REAL", "TESTNET"], "服务器": ["REAL", "TESTNET"],
"代理地址": "127.0.0.1", "代理地址": "",
"代理端口": 1080, "代理端口": "",
} }
def __init__(self, event_engine): def __init__(self, event_engine):
@ -91,6 +91,11 @@ class BitmexGateway(BaseGateway):
proxy_host = setting["代理地址"] proxy_host = setting["代理地址"]
proxy_port = setting["代理端口"] proxy_port = setting["代理端口"]
if proxy_port.isdigit():
proxy_port = int(proxy_port)
else:
proxy_port = 0
self.rest_api.connect(key, secret, session_number, self.rest_api.connect(key, secret, session_number,
server, proxy_host, proxy_port) server, proxy_host, proxy_port)

View File

@ -73,8 +73,8 @@ class HuobiGateway(BaseGateway):
"API Key": "", "API Key": "",
"Secret Key": "", "Secret Key": "",
"会话数": 3, "会话数": 3,
"代理地址": "127.0.0.1", "代理地址": "",
"代理端口": 1080, "代理端口": "",
} }
def __init__(self, event_engine): def __init__(self, event_engine):
@ -95,6 +95,11 @@ class HuobiGateway(BaseGateway):
proxy_host = setting["代理地址"] proxy_host = setting["代理地址"]
proxy_port = setting["代理端口"] proxy_port = setting["代理端口"]
if proxy_port.isdigit():
proxy_port = int(proxy_port)
else:
proxy_port = 0
self.rest_api.connect(key, secret, session_number, self.rest_api.connect(key, secret, session_number,
proxy_host, proxy_port) proxy_host, proxy_port)
self.trade_ws_api.connect(key, secret, proxy_host, proxy_port) self.trade_ws_api.connect(key, secret, proxy_host, proxy_port)

View File

@ -74,8 +74,8 @@ class OkexGateway(BaseGateway):
"Secret Key": "", "Secret Key": "",
"Passphrase": "", "Passphrase": "",
"会话数": 3, "会话数": 3,
"代理地址": "127.0.0.1", "代理地址": "",
"代理端口": 1080, "代理端口": "",
} }
def __init__(self, event_engine): def __init__(self, event_engine):
@ -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"]
@ -94,9 +96,13 @@ class OkexGateway(BaseGateway):
proxy_host = setting["代理地址"] proxy_host = setting["代理地址"]
proxy_port = setting["代理端口"] proxy_port = setting["代理端口"]
if proxy_port.isdigit():
proxy_port = int(proxy_port)
else:
proxy_port = 0
self.rest_api.connect(key, secret, passphrase, self.rest_api.connect(key, secret, passphrase,
session_number, proxy_host, proxy_port) session_number, proxy_host, proxy_port)
self.ws_api.connect(key, secret, passphrase, proxy_host, proxy_port) self.ws_api.connect(key, secret, passphrase, proxy_host, proxy_port)
def subscribe(self, req: SubscribeRequest): def subscribe(self, req: SubscribeRequest):
@ -124,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):
""" """
@ -254,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):
@ -402,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