From cf546672fd6d02d172725b3eda0407969c70f386 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 11 Oct 2018 04:05:00 -0400 Subject: [PATCH] =?UTF-8?q?[Add]=20=E5=AE=8C=E6=88=90okexFutureGateway.sen?= =?UTF-8?q?dOrder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../okexFutureGateway/okexFutureGateway.py | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py b/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py index 252e856d..b3b1624e 100644 --- a/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py +++ b/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py @@ -86,6 +86,13 @@ class VnpyGateway(VtGateway): """ pass +class _Order(object): + _lastLocalId = 0 + def __init__(self): + _Order._lastLocalId += 1 + self.localId = str(_Order._lastLocalId) + self.remoteId = None + self.vtOrder = None # type: VtOrderData ######################################################################## class OkexFutureGateway(VnpyGateway): @@ -98,9 +105,10 @@ class OkexFutureGateway(VnpyGateway): self.apiKey = None # type: str self.apiSecret = None # type: str self.api = OkexFutureRestClient() - self.leverRate = 1.0 + self.leverRate = 1 self.symbols = [] + self.orders = #---------------------------------------------------------------------- @property def gatewayName(self): @@ -142,9 +150,42 @@ class OkexFutureGateway(VnpyGateway): pass #---------------------------------------------------------------------- - def sendOrder(self, orderReq): + def sendOrder(self, vtRequest): # type: (VtOrderReq)->str """发单""" - return self.api.sendOrder(orderReq) + myorder = _Order() + localId = myorder.localId + + vtOrder = VtOrderData() + vtOrder.orderID = localId + vtOrder.vtOrderID = ".".join([self.gatewayName, localId]) + vtOrder.exchange = self.exchange + + vtOrder.symbol = vtRequest.symbol + vtOrder.vtSymbol = '.'.join([vtOrder.symbol, vtOrder.exchange]) + vtOrder.price = vtRequest.price + vtOrder.totalVolume = vtRequest.volume + vtOrder.direction = vtRequest.direction + + myorder.vtOrder = vtOrder + + symbol, contractType = symbolsForUi[vtRequest.symbol] + orderType = orderTypeMap[(vtRequest.priceType, vtRequest.offset)] # 开多、开空、平多、平空 + userMarketPrice = False + + if vtRequest.priceType == constant.PRICETYPE_MARKETPRICE: + userMarketPrice = True + + self.api.sendOrder(symbol=symbol, + contractType=contractType, + orderType=orderType, + volume=vtRequest.volume, + price=vtRequest.price, + useMarketPrice=userMarketPrice, + leverRate=self.leverRate, + onSuccess=self.onOrderSent, + extra=None) + + return myorder.localId #---------------------------------------------------------------------- def cancelOrder(self, cancelOrderReq): @@ -165,3 +206,9 @@ class OkexFutureGateway(VnpyGateway): def close(self): """关闭""" self.api.close() + + def onOrderSent(self, remoteId, myorder): #type: (int, _Order)->None + myorder.remoteId = remoteId + myorder.vtOrder.status = constant.STATUS_NOTTRADED + self.onOrder(myorder.vtOrder) + \ No newline at end of file