From f53f5ea7dd8ecc13700398dd94164dece511dcbe Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 9 Apr 2019 11:27:12 +0800 Subject: [PATCH 1/2] [Mod]remove default proxy setting --- vnpy/gateway/bitmex/bitmex_gateway.py | 9 +++++++-- vnpy/gateway/huobi/huobi_gateway.py | 9 +++++++-- vnpy/gateway/okex/okex_gateway.py | 10 +++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/vnpy/gateway/bitmex/bitmex_gateway.py b/vnpy/gateway/bitmex/bitmex_gateway.py index 3c3e6879..11579c4b 100644 --- a/vnpy/gateway/bitmex/bitmex_gateway.py +++ b/vnpy/gateway/bitmex/bitmex_gateway.py @@ -71,8 +71,8 @@ class BitmexGateway(BaseGateway): "Secret": "", "会话数": 3, "服务器": ["REAL", "TESTNET"], - "代理地址": "127.0.0.1", - "代理端口": 1080, + "代理地址": "", + "代理端口": "", } def __init__(self, event_engine): @@ -91,6 +91,11 @@ class BitmexGateway(BaseGateway): proxy_host = 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, server, proxy_host, proxy_port) diff --git a/vnpy/gateway/huobi/huobi_gateway.py b/vnpy/gateway/huobi/huobi_gateway.py index 2123fc2b..474e6f69 100644 --- a/vnpy/gateway/huobi/huobi_gateway.py +++ b/vnpy/gateway/huobi/huobi_gateway.py @@ -73,8 +73,8 @@ class HuobiGateway(BaseGateway): "API Key": "", "Secret Key": "", "会话数": 3, - "代理地址": "127.0.0.1", - "代理端口": 1080, + "代理地址": "", + "代理端口": "", } def __init__(self, event_engine): @@ -95,6 +95,11 @@ class HuobiGateway(BaseGateway): proxy_host = 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, proxy_host, proxy_port) self.trade_ws_api.connect(key, secret, proxy_host, proxy_port) diff --git a/vnpy/gateway/okex/okex_gateway.py b/vnpy/gateway/okex/okex_gateway.py index 4a1b2a93..ded30c13 100644 --- a/vnpy/gateway/okex/okex_gateway.py +++ b/vnpy/gateway/okex/okex_gateway.py @@ -74,8 +74,8 @@ class OkexGateway(BaseGateway): "Secret Key": "", "Passphrase": "", "会话数": 3, - "代理地址": "127.0.0.1", - "代理端口": 1080, + "代理地址": "", + "代理端口": "", } def __init__(self, event_engine): @@ -94,9 +94,13 @@ class OkexGateway(BaseGateway): proxy_host = setting["代理地址"] proxy_port = setting["代理端口"] + if proxy_port.isdigit(): + proxy_port = int(proxy_port) + else: + proxy_port = 0 + self.rest_api.connect(key, secret, passphrase, session_number, proxy_host, proxy_port) - self.ws_api.connect(key, secret, passphrase, proxy_host, proxy_port) def subscribe(self, req: SubscribeRequest): From 1a79ba37db118b570c94960dce239c19267239fb Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 9 Apr 2019 18:21:28 +0800 Subject: [PATCH 2/2] [Mod]add on_cancel_order_failed callback for OkexGateway --- vnpy/gateway/okex/okex_gateway.py | 21 +++++++++++++++++++++ vnpy/trader/utility.py | 2 -- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/vnpy/gateway/okex/okex_gateway.py b/vnpy/gateway/okex/okex_gateway.py index ded30c13..9ca18217 100644 --- a/vnpy/gateway/okex/okex_gateway.py +++ b/vnpy/gateway/okex/okex_gateway.py @@ -85,6 +85,8 @@ class OkexGateway(BaseGateway): self.rest_api = OkexRestApi(self) self.ws_api = OkexWebsocketApi(self) + self.orders = {} + def connect(self, setting: dict): """""" key = setting["API Key"] @@ -128,6 +130,15 @@ class OkexGateway(BaseGateway): self.rest_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): """ @@ -258,6 +269,8 @@ class OkexRestApi(RestClient): callback=self.on_cancel_order, data=data, on_error=self.on_cancel_order_error, + on_failed=self.on_cancel_order_failed, + extra=req ) def query_contract(self): @@ -406,6 +419,14 @@ class OkexRestApi(RestClient): """Websocket will push a new order status""" 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): """ Callback to handle request failed. diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 9951e1f1..89c412a1 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -394,5 +394,3 @@ def virtual(func: "callable"): that can be (re)implemented by subclasses. """ return func - -