diff --git a/vn.trader/xspeedGateway/xspeedGateway.py b/vn.trader/xspeedGateway/xspeedGateway.py index 13434d37..e365ae53 100644 --- a/vn.trader/xspeedGateway/xspeedGateway.py +++ b/vn.trader/xspeedGateway/xspeedGateway.py @@ -6,6 +6,7 @@ vn.xspeed的gateway接入 import os import json +import time from copy import copy from vnxspeedmd import MdApi @@ -50,6 +51,7 @@ orderStatusMap[STATUS_PARTTRADED] = defineDict["DFITC_SPD_PARTIAL"] orderStatusMap[STATUS_NOTTRADED] = defineDict["DFITC_SPD_IN_QUEUE"] orderStatusMap[STATUS_CANCELLED] = defineDict["DFITC_SPD_CANCELED"] orderStatusMapReverse = {v:k for k,v in orderStatusMap.items()} +orderStatusMapReverse[defineDict["DFITC_SPD_PARTIAL_CANCELED"]] = STATUS_CANCELLED ######################################################################## @@ -422,6 +424,7 @@ class XspeedTdApi(TdApi): self.posDict = {} # 缓存持仓数据的字典 self.orderDict = {} # 缓存委托数据的字典 + self.spdOrderDict = {} # 飞创柜台委托号字典 #---------------------------------------------------------------------- def connect(self, accountID, password, address): @@ -514,7 +517,13 @@ class XspeedTdApi(TdApi): req['accountID'] = self.accountID req['lRequestID'] = self.reqID - self.reqOrderAction(req, self.reqID) + # 添加柜台委托号字段 + localID = int(cancelOrderReq.orderID) + if localID in self.spdOrderDict: + req['spdOrderID'] = self.spdOrderDict[localID] + del req['localOrderID'] + + self.reqCancelOrder(req) #---------------------------------------------------------------------- def close(self): @@ -653,28 +662,17 @@ class XspeedTdApi(TdApi): # 推送 self.gateway.onTrade(trade) + # 获取报单数据对象 + localID = data['localOrderID'] + if localID not in self.orderDict: + return + order = self.orderDict[localID] - # 更新委托信息 - # 创建报单数据对象 - order = VtOrderData() - order.gatewayName = self.gatewayName - - # 保存代码和报单号 - order.symbol = data['instrumentID'] - order.exchange = exchangeMapReverse[data['exchangeID']] - order.vtSymbol = order.symbol - order.orderID = str(data['localOrderID']) - order.vtOrderID = '.'.join([self.gatewayName, order.orderID]) - - order.direction = directionMapReverse.get(data['buySellType'], DIRECTION_UNKNOWN) - order.offset = offsetMapReverse.get(data['openCloseType'], OFFSET_UNKNOWN) order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN) - - order.price = data['insertPrice'] - order.totalVolume = data['orderAmount'] + order.tradedVolume += trade.volume # 推送 - self.gateway.onOrder(order) + self.gateway.onOrder(copy(order)) #---------------------------------------------------------------------- def onRtnOrder(self, data) : @@ -682,12 +680,14 @@ class XspeedTdApi(TdApi): # 更新最大报单编号 newLocalID = data['localOrderID'] self.localID = max(self.localID, newLocalID) + self.spdOrderDict[newLocalID] = data['spdOrderID'] # 获取报单数据对象 if newLocalID in self.orderDict: order = self.orderDict[newLocalID] else: order = VtOrderData() + self.orderDict[newLocalID] = order order.gatewayName = self.gatewayName # 保存后续不会变化的数据 @@ -704,7 +704,8 @@ class XspeedTdApi(TdApi): # 价格、报单量等数值 order.price = data['insertPrice'] order.totalVolume = data['orderAmount'] - order.sessionID = data['sessionID'] + order.sessionID = data['sessionID'] + order.orderTime = time.strftime('%H:%M:%S') order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN) @@ -723,6 +724,7 @@ class XspeedTdApi(TdApi): order = self.orderDict[newLocalID] else: order = VtOrderData() + self.orderDict[newLocalID] = order order.gatewayName = self.gatewayName # 保存后续不会变化的数据 @@ -756,12 +758,14 @@ class XspeedTdApi(TdApi): # 更新最大报单编号 newLocalID = data['localOrderID'] self.localID = max(self.localID, int(newLocalID)) + self.spdOrderDict[newLocalID] = data['spdOrderID'] # 获取报单数据对象 if newLocalID in self.orderDict: order = self.orderDict[newLocalID] else: order = VtOrderData() + self.orderDict[newLocalID] = order order.gatewayName = self.gatewayName # 保存后续不会变化的数据 @@ -773,11 +777,11 @@ class XspeedTdApi(TdApi): order.vtOrderID = '.'.join([self.gatewayName, order.orderID]) order.direction = directionMapReverse.get(data['buySellType'], DIRECTION_UNKNOWN) - order.offset = offsetMapReverse.get(data['openCloseType'], OFFSET_UNKNOWN) + order.offset = offsetMapReverse.get(data['openClose'], OFFSET_UNKNOWN) order.price = data['insertPrice'] order.totalVolume = data['orderAmount'] - order.sessionID = data['sessionID'] + #order.sessionID = data['sessionID'] order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN) order.tradedVolume = data['matchedAmount'] diff --git a/vn.xspeed/vnxspeedtd/Visual Studio 2013/settings/Windows Azure Subscriptions.xml b/vn.xspeed/vnxspeedtd/Visual Studio 2013/settings/Windows Azure Subscriptions.xml index 0568c66a..73e501d2 100644 --- a/vn.xspeed/vnxspeedtd/Visual Studio 2013/settings/Windows Azure Subscriptions.xml +++ b/vn.xspeed/vnxspeedtd/Visual Studio 2013/settings/Windows Azure Subscriptions.xml @@ -1,5 +1,5 @@ - AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAADdKqCExbfQ0qmV8fAhwxJ3ziOWd8i4kgHKWaahbmhZpwAAAAAOgAAAAAIAACAAAACIs6nje6UjzBQhCRlDYPyT/WvjZ7HWe6fwrCRtdSUF6hAAAABX62nkc+hjHXTxtgPsdkBcQAAAAOlZDGXW8lDNFQGhZ5pLW0aGiuUFyFCyt4EoRQh92KTtiXhOeaxEBfA6MbkxnzyJ4B/ZmwskriS/m0CTVTZFRUY= + AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAAA6nZeMmbpp7864KoLkSmJz/so1IKtCa7i91O4JJcD6ZwAAAAAOgAAAAAIAACAAAADHPVQMA3OVICvokzgXxWpIA6rD9Yx0fN+YmnHfmx6qSRAAAAD9plAQJWruJsGVioIAbnrYQAAAAAm99ZTmGU9Cx1mka7wlZG54rO9dahDJbcjFFuiJqTB7k9x1zl4uev63L2ecuaFf5swnUTU/VvuczBdubr0ebSs= \ No newline at end of file diff --git a/vn.xspeed/vnxspeedtd/vnxspeedtd.opensdf b/vn.xspeed/vnxspeedtd/vnxspeedtd.opensdf deleted file mode 100644 index 6eb9f3e0..00000000 Binary files a/vn.xspeed/vnxspeedtd/vnxspeedtd.opensdf and /dev/null differ diff --git a/vn.xspeed/vnxspeedtd/vnxspeedtd.v12.suo b/vn.xspeed/vnxspeedtd/vnxspeedtd.v12.suo index cabdc19b..4ab2545a 100644 Binary files a/vn.xspeed/vnxspeedtd/vnxspeedtd.v12.suo and b/vn.xspeed/vnxspeedtd/vnxspeedtd.v12.suo differ