From 0fae58f333f63a8da7b0d8729140c41c11628d62 Mon Sep 17 00:00:00 2001 From: xldistance <819873074@qq.com> Date: Sun, 30 Jun 2019 12:06:59 +0800 Subject: [PATCH 1/3] fix onetoken order.status fix onetoken order.status --- vnpy/gateway/onetoken/onetoken_gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnpy/gateway/onetoken/onetoken_gateway.py b/vnpy/gateway/onetoken/onetoken_gateway.py index 22a5bb5d..de7aac6d 100644 --- a/vnpy/gateway/onetoken/onetoken_gateway.py +++ b/vnpy/gateway/onetoken/onetoken_gateway.py @@ -659,7 +659,7 @@ class OnetokenTradeWebsocketApi(WebsocketClient): gateway_name=self.gateway_name ) - if order_data["canceled_time"]: + if order_data["status"] in ("withdrawn","part-deal-withdrawn"): order.status = Status.CANCELLED else: if order.traded == order.volume: From e14672ab8c84f93e654facd3aa8ac794ea6f22f9 Mon Sep 17 00:00:00 2001 From: xldistance <819873074@qq.com> Date: Sun, 30 Jun 2019 13:55:11 +0800 Subject: [PATCH 2/3] Update onetoken_gateway.py --- vnpy/gateway/onetoken/onetoken_gateway.py | 49 ++++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/vnpy/gateway/onetoken/onetoken_gateway.py b/vnpy/gateway/onetoken/onetoken_gateway.py index de7aac6d..f6834e9f 100644 --- a/vnpy/gateway/onetoken/onetoken_gateway.py +++ b/vnpy/gateway/onetoken/onetoken_gateway.py @@ -618,21 +618,23 @@ class OnetokenTradeWebsocketApi(WebsocketClient): # Futures elif _type == "future": long_position = PositionData( - symbol=account_data["contract"], - exchange=Exchange.OKEX, # todo add Exchange + symbol=X["contract"], + exchange=Exchange(self.exchange.upper()), direction=Direction.LONG, - volume=account_data["total_amount_long"], - frozen=account_data["total_amount_long"] - \ - account_data["available_long"], + price=X["average_open_price_long"], + volume=X["total_amount_long"], + pnl=X["unrealized_long"], + frozen=X["frozen_position_long"], gateway_name=self.gateway_name, ) short_position = PositionData( - symbol=account_data["contract"], - exchange=Exchange.OKEX, # todo add Exchange + symbol=X["contract"], + exchange=Exchange(self.exchange.upper()), direction=Direction.SHORT, - volume=account_data["total_amount_short"], - frozen=account_data["total_amount_short"] - \ - account_data["available_short"], + price=X["average_open_price_short"], + volume=X["total_amount_short"], + pnl=X["unrealized_short"], + frozen=X["frozen_position_short"], gateway_name=self.gateway_name, ) self.gateway.on_position(long_position) @@ -677,20 +679,19 @@ class OnetokenTradeWebsocketApi(WebsocketClient): trade_timestamp = order_data["last_update"][11:19] self.trade_count += 1 - - trade = TradeData( - symbol=order.symbol, - exchange=order.exchange, - orderid=order.orderid, - tradeid=str(self.trade_count), - direction=order.direction, - price=order_data["average_dealt_price"], - volume=order_data["last_dealt_amount"], - gateway_name=self.gateway_name, - time=trade_timestamp - ) - - self.gateway.on_trade(trade) + if order_data["dealt_amount"]: + self.trade_count += 1 + trade = TradeData( + symbol=order.symbol, + exchange=order.exchange, + orderid=orderid, + tradeid=str(self.trade_count), + direction=order.direction, + price=order_data["average_dealt_price"], + volume=order_data["dealt_amount"], + gateway_name=self.gateway_name, + time=trade_timestamp) + self.gateway.on_trade(trade) def ping(self): """""" From 88ea19d9db6063dfc2baec8b61df5bb8ae7e2b78 Mon Sep 17 00:00:00 2001 From: xldistance <819873074@qq.com> Date: Sun, 30 Jun 2019 13:56:34 +0800 Subject: [PATCH 3/3] Update onetoken_gateway.py --- vnpy/gateway/onetoken/onetoken_gateway.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vnpy/gateway/onetoken/onetoken_gateway.py b/vnpy/gateway/onetoken/onetoken_gateway.py index f6834e9f..e140c37f 100644 --- a/vnpy/gateway/onetoken/onetoken_gateway.py +++ b/vnpy/gateway/onetoken/onetoken_gateway.py @@ -618,23 +618,23 @@ class OnetokenTradeWebsocketApi(WebsocketClient): # Futures elif _type == "future": long_position = PositionData( - symbol=X["contract"], + symbol=account_data["contract"], exchange=Exchange(self.exchange.upper()), direction=Direction.LONG, - price=X["average_open_price_long"], - volume=X["total_amount_long"], - pnl=X["unrealized_long"], - frozen=X["frozen_position_long"], + price=account_data["average_open_price_long"], + volume=account_data["total_amount_long"], + pnl=account_data["unrealized_long"], + frozen=account_data["frozen_position_long"], gateway_name=self.gateway_name, ) short_position = PositionData( - symbol=X["contract"], + symbol=account_data["contract"], exchange=Exchange(self.exchange.upper()), direction=Direction.SHORT, - price=X["average_open_price_short"], - volume=X["total_amount_short"], - pnl=X["unrealized_short"], - frozen=X["frozen_position_short"], + price=account_data["average_open_price_short"], + volume=account_data["total_amount_short"], + pnl=account_data["unrealized_short"], + frozen=account_data["frozen_position_short"], gateway_name=self.gateway_name, ) self.gateway.on_position(long_position)