修复了vn.trader中xspeedGateway的几个bug

This commit is contained in:
chenxy123 2016-04-03 14:41:52 +08:00
parent 5d479101c4
commit 52c4ff2583
4 changed files with 27 additions and 23 deletions

View File

@ -6,6 +6,7 @@ vn.xspeed的gateway接入
import os import os
import json import json
import time
from copy import copy from copy import copy
from vnxspeedmd import MdApi 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_NOTTRADED] = defineDict["DFITC_SPD_IN_QUEUE"]
orderStatusMap[STATUS_CANCELLED] = defineDict["DFITC_SPD_CANCELED"] orderStatusMap[STATUS_CANCELLED] = defineDict["DFITC_SPD_CANCELED"]
orderStatusMapReverse = {v:k for k,v in orderStatusMap.items()} 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.posDict = {} # 缓存持仓数据的字典
self.orderDict = {} # 缓存委托数据的字典 self.orderDict = {} # 缓存委托数据的字典
self.spdOrderDict = {} # 飞创柜台委托号字典
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def connect(self, accountID, password, address): def connect(self, accountID, password, address):
@ -514,7 +517,13 @@ class XspeedTdApi(TdApi):
req['accountID'] = self.accountID req['accountID'] = self.accountID
req['lRequestID'] = self.reqID 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): def close(self):
@ -653,28 +662,17 @@ class XspeedTdApi(TdApi):
# 推送 # 推送
self.gateway.onTrade(trade) 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.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN)
order.tradedVolume += trade.volume
order.price = data['insertPrice']
order.totalVolume = data['orderAmount']
# 推送 # 推送
self.gateway.onOrder(order) self.gateway.onOrder(copy(order))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onRtnOrder(self, data) : def onRtnOrder(self, data) :
@ -682,12 +680,14 @@ class XspeedTdApi(TdApi):
# 更新最大报单编号 # 更新最大报单编号
newLocalID = data['localOrderID'] newLocalID = data['localOrderID']
self.localID = max(self.localID, newLocalID) self.localID = max(self.localID, newLocalID)
self.spdOrderDict[newLocalID] = data['spdOrderID']
# 获取报单数据对象 # 获取报单数据对象
if newLocalID in self.orderDict: if newLocalID in self.orderDict:
order = self.orderDict[newLocalID] order = self.orderDict[newLocalID]
else: else:
order = VtOrderData() order = VtOrderData()
self.orderDict[newLocalID] = order
order.gatewayName = self.gatewayName order.gatewayName = self.gatewayName
# 保存后续不会变化的数据 # 保存后续不会变化的数据
@ -705,6 +705,7 @@ class XspeedTdApi(TdApi):
order.price = data['insertPrice'] order.price = data['insertPrice']
order.totalVolume = data['orderAmount'] 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) order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN)
@ -723,6 +724,7 @@ class XspeedTdApi(TdApi):
order = self.orderDict[newLocalID] order = self.orderDict[newLocalID]
else: else:
order = VtOrderData() order = VtOrderData()
self.orderDict[newLocalID] = order
order.gatewayName = self.gatewayName order.gatewayName = self.gatewayName
# 保存后续不会变化的数据 # 保存后续不会变化的数据
@ -756,12 +758,14 @@ class XspeedTdApi(TdApi):
# 更新最大报单编号 # 更新最大报单编号
newLocalID = data['localOrderID'] newLocalID = data['localOrderID']
self.localID = max(self.localID, int(newLocalID)) self.localID = max(self.localID, int(newLocalID))
self.spdOrderDict[newLocalID] = data['spdOrderID']
# 获取报单数据对象 # 获取报单数据对象
if newLocalID in self.orderDict: if newLocalID in self.orderDict:
order = self.orderDict[newLocalID] order = self.orderDict[newLocalID]
else: else:
order = VtOrderData() order = VtOrderData()
self.orderDict[newLocalID] = order
order.gatewayName = self.gatewayName order.gatewayName = self.gatewayName
# 保存后续不会变化的数据 # 保存后续不会变化的数据
@ -773,11 +777,11 @@ class XspeedTdApi(TdApi):
order.vtOrderID = '.'.join([self.gatewayName, order.orderID]) order.vtOrderID = '.'.join([self.gatewayName, order.orderID])
order.direction = directionMapReverse.get(data['buySellType'], DIRECTION_UNKNOWN) 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.price = data['insertPrice']
order.totalVolume = data['orderAmount'] order.totalVolume = data['orderAmount']
order.sessionID = data['sessionID'] #order.sessionID = data['sessionID']
order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN) order.status = orderStatusMapReverse.get(data['orderStatus'], STATUS_UNKNOWN)
order.tradedVolume = data['matchedAmount'] order.tradedVolume = data['matchedAmount']

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<SubscriptionDataContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Microsoft.VisualStudio.WindowsAzure.CommonAzureTools.Authentication.CacheManagement"> <SubscriptionDataContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Microsoft.VisualStudio.WindowsAzure.CommonAzureTools.Authentication.CacheManagement">
<Items /> <Items />
<TokenCache>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAADdKqCExbfQ0qmV8fAhwxJ3ziOWd8i4kgHKWaahbmhZpwAAAAAOgAAAAAIAACAAAACIs6nje6UjzBQhCRlDYPyT/WvjZ7HWe6fwrCRtdSUF6hAAAABX62nkc+hjHXTxtgPsdkBcQAAAAOlZDGXW8lDNFQGhZ5pLW0aGiuUFyFCyt4EoRQh92KTtiXhOeaxEBfA6MbkxnzyJ4B/ZmwskriS/m0CTVTZFRUY=</TokenCache> <TokenCache>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAAA6nZeMmbpp7864KoLkSmJz/so1IKtCa7i91O4JJcD6ZwAAAAAOgAAAAAIAACAAAADHPVQMA3OVICvokzgXxWpIA6rD9Yx0fN+YmnHfmx6qSRAAAAD9plAQJWruJsGVioIAbnrYQAAAAAm99ZTmGU9Cx1mka7wlZG54rO9dahDJbcjFFuiJqTB7k9x1zl4uev63L2ecuaFf5swnUTU/VvuczBdubr0ebSs=</TokenCache>
</SubscriptionDataContainer> </SubscriptionDataContainer>