From b8c6c92c43294f261ae31d7c279c4a0c80174d64 Mon Sep 17 00:00:00 2001 From: nanoric Date: Mon, 15 Oct 2018 04:36:00 -0400 Subject: [PATCH] =?UTF-8?q?[Mod]=20=E4=BD=BF=E7=94=A8=E4=B8=80=E4=BA=9BVtO?= =?UTF-8?q?bject=E7=9B=B8=E5=85=B3=E7=9A=84=E9=9D=99=E6=80=81=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../okexFutureGateway/okexFutureGateway.py | 74 +++++++++---------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py b/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py index aa258fe9..23bc9bed 100644 --- a/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py +++ b/vnpy/trader/gateway/okexFutureGateway/okexFutureGateway.py @@ -98,11 +98,6 @@ class VnpyGateway(VtGateway): def gatewayName(self): # type: ()->str return 'VnpyGateway' - #---------------------------------------------------------------------- - @abstractproperty - def exchange(self): # type: ()->str - return constant.EXCHANGE_UNKNOWN - #---------------------------------------------------------------------- def readConfig(self): """ @@ -168,7 +163,7 @@ class OkexFutureGateway(VnpyGateway): return 'OkexFutureGateway' #---------------------------------------------------------------------- - @abstractproperty + @property def exchange(self): # type: ()->str return constant.EXCHANGE_OKEXFUTURE @@ -216,20 +211,18 @@ class OkexFutureGateway(VnpyGateway): self._remoteIds[remoteId] = myorder #---------------------------------------------------------------------- - def _genereteLocalOrder(self, symbol, price, volume, direction): + def _genereteLocalOrder(self, symbol, price, volume, direction, offset): myorder = _Order() localId = myorder.localId self._orders[localId] = myorder - vtOrder = VtOrderData() - vtOrder.orderID = localId - vtOrder.vtOrderID = ".".join([self.gatewayName, localId]) - vtOrder.exchange = self.exchange - vtOrder.symbol = symbol - vtOrder.vtSymbol = '.'.join([vtOrder.symbol, vtOrder.exchange]) - vtOrder.price = price - vtOrder.totalVolume = volume - vtOrder.direction = direction - myorder.vtOrder = vtOrder + myorder.vtOrder = VtOrderData.createFromGateway(self, + self.exchange, + localId, + symbol, + price, + volume, + direction, + offset) return myorder #---------------------------------------------------------------------- @@ -238,7 +231,8 @@ class OkexFutureGateway(VnpyGateway): myorder = self._genereteLocalOrder(vtRequest.symbol, vtRequest.price, vtRequest.volume, - vtRequest.direction) + vtRequest.direction, + vtRequest.offset) remoteSymbol, remoteContractType = localSymbolToRemote(vtRequest.symbol) orderType = _orderTypeMap[(vtRequest.priceType, vtRequest.offset)] # 开多、开空、平多、平空 @@ -325,22 +319,22 @@ class OkexFutureGateway(VnpyGateway): self._saveRemoteId(remoteId, myorder) self.onOrder(myorder.vtOrder) - #---------------------------------------------------------------------- - def _pushOrderAsTraded(self, order): - trade = VtTradeData() - trade.gatewayName = order.gatewayName - trade.symbol = order.symbol - trade.vtSymbol = order.vtSymbol - trade.orderID = order.orderID - trade.vtOrderID = order.vtOrderID - self.tradeID += 1 - trade.tradeID = str(self.tradeID) - trade.vtTradeID = '.'.join([self.gatewayName, trade.tradeID]) - trade.direction = order.direction - trade.price = order.price - trade.volume = order.tradedVolume - trade.tradeTime = datetime.now().strftime('%H:%M:%S') - self.onTrade(trade) + # #---------------------------------------------------------------------- + # def _pushOrderAsTraded(self, order): + # trade = VtTradeData() + # trade.gatewayName = order.gatewayName + # trade.symbol = order.symbol + # trade.vtSymbol = order.vtSymbol + # trade.orderID = order.orderID + # trade.vtOrderID = order.vtOrderID + # self.tradeID += 1 + # trade.tradeID = str(self.tradeID) + # trade.vtTradeID = '.'.join([self.gatewayName, trade.tradeID]) + # trade.direction = order.direction + # trade.price = order.price + # trade.volume = order.tradedVolume + # trade.tradeTime = datetime.now().strftime('%H:%M:%S') + # self.onTrade(trade) #---------------------------------------------------------------------- @staticmethod @@ -367,17 +361,17 @@ class OkexFutureGateway(VnpyGateway): # 缓存该订单,并推送 symbol = remoteSymbolToLocal(order.symbol, localContractType) direction, offset = remoteOrderTypeToLocal(order.orderType) - myorder = self._genereteLocalOrder(symbol, order.price, order.volume, direction) + myorder = self._genereteLocalOrder(symbol, order.price, order.volume, direction, offset) myorder.vtOrder.tradedVolume = order.tradedVolume myorder.remoteId = order.remoteId self._saveRemoteId(myorder.remoteId, myorder) self.onOrder(myorder.vtOrder) - # 如果该订单已经交易完成,推送交易完成消息 - # todo: 这样写会导致同一个订单产生多次交易完成消息 - if order.status == OkexFutureOrderStatus.Finished: - myorder.vtOrder.status = constant.STATUS_ALLTRADED - self._pushOrderAsTraded(myorder.vtOrder) + # # 如果该订单已经交易完成,推送交易完成消息 + # # todo: 这样写会导致同一个订单产生多次交易完成消息 + # if order.status == OkexFutureOrderStatus.Finished: + # myorder.vtOrder.status = constant.STATUS_ALLTRADED + # self._pushOrderAsTraded(myorder.vtOrder) #---------------------------------------------------------------------- def _onQueryAccount(self, infos, _): # type: (List[OkexFutureUserInfo], Any)->None