Merge pull request #1883 from xldistance/patch-27

Fix onetoken order and trade
This commit is contained in:
vn.py 2019-06-30 17:18:46 +08:00 committed by GitHub
commit 0be4db26c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -619,20 +619,22 @@ class OnetokenTradeWebsocketApi(WebsocketClient):
elif _type == "future":
long_position = PositionData(
symbol=account_data["contract"],
exchange=Exchange.OKEX, # todo add Exchange
exchange=Exchange(self.exchange.upper()),
direction=Direction.LONG,
price=account_data["average_open_price_long"],
volume=account_data["total_amount_long"],
frozen=account_data["total_amount_long"] - \
account_data["available_long"],
pnl=account_data["unrealized_long"],
frozen=account_data["frozen_position_long"],
gateway_name=self.gateway_name,
)
short_position = PositionData(
symbol=account_data["contract"],
exchange=Exchange.OKEX, # todo add Exchange
exchange=Exchange(self.exchange.upper()),
direction=Direction.SHORT,
price=account_data["average_open_price_short"],
volume=account_data["total_amount_short"],
frozen=account_data["total_amount_short"] - \
account_data["available_short"],
pnl=account_data["unrealized_short"],
frozen=account_data["frozen_position_short"],
gateway_name=self.gateway_name,
)
self.gateway.on_position(long_position)
@ -659,7 +661,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:
@ -677,19 +679,18 @@ class OnetokenTradeWebsocketApi(WebsocketClient):
trade_timestamp = order_data["last_update"][11:19]
self.trade_count += 1
if order_data["dealt_amount"]:
self.trade_count += 1
trade = TradeData(
symbol=order.symbol,
exchange=order.exchange,
orderid=order.orderid,
orderid=orderid,
tradeid=str(self.trade_count),
direction=order.direction,
price=order_data["average_dealt_price"],
volume=order_data["last_dealt_amount"],
volume=order_data["dealt_amount"],
gateway_name=self.gateway_name,
time=trade_timestamp
)
time=trade_timestamp)
self.gateway.on_trade(trade)
def ping(self):