Skip to content

Commit

Permalink
修复了vn.trader中xspeedGateway的几个bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxy123 committed Apr 3, 2016
1 parent 5d47910 commit 52c4ff2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
48 changes: 26 additions & 22 deletions vn.trader/xspeedGateway/xspeedGateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import json
import time
from copy import copy

from vnxspeedmd import MdApi
Expand Down Expand Up @@ -50,6 +51,7 @@
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


########################################################################
Expand Down Expand Up @@ -422,6 +424,7 @@ def __init__(self, gateway):

self.posDict = {} # 缓存持仓数据的字典
self.orderDict = {} # 缓存委托数据的字典
self.spdOrderDict = {} # 飞创柜台委托号字典

#----------------------------------------------------------------------
def connect(self, accountID, password, address):
Expand Down Expand Up @@ -514,7 +517,13 @@ def cancelOrder(self, cancelOrderReq):
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):
Expand Down Expand Up @@ -653,41 +662,32 @@ def onRtnMatchedInfo(self, data) :
# 推送
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) :
"""报单回报"""
# 更新最大报单编号
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

# 保存后续不会变化的数据
Expand All @@ -704,7 +704,8 @@ def onRtnOrder(self, data) :
# 价格、报单量等数值
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)

Expand All @@ -723,6 +724,7 @@ def onRtnCancelOrder(self, data) :
order = self.orderDict[newLocalID]
else:
order = VtOrderData()
self.orderDict[newLocalID] = order
order.gatewayName = self.gatewayName

# 保存后续不会变化的数据
Expand Down Expand Up @@ -756,12 +758,14 @@ def onRspQryOrderInfo(self, data, error, last) :
# 更新最大报单编号
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

# 保存后续不会变化的数据
Expand All @@ -773,11 +777,11 @@ def onRspQryOrderInfo(self, data, error, last) :
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']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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">
<Items />
<TokenCache>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAADdKqCExbfQ0qmV8fAhwxJ3ziOWd8i4kgHKWaahbmhZpwAAAAAOgAAAAAIAACAAAACIs6nje6UjzBQhCRlDYPyT/WvjZ7HWe6fwrCRtdSUF6hAAAABX62nkc+hjHXTxtgPsdkBcQAAAAOlZDGXW8lDNFQGhZ5pLW0aGiuUFyFCyt4EoRQh92KTtiXhOeaxEBfA6MbkxnzyJ4B/ZmwskriS/m0CTVTZFRUY=</TokenCache>
<TokenCache>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAhE4p+D02F0WYPy8qCmMXxAAAAAACAAAAAAAQZgAAAAEAACAAAAA6nZeMmbpp7864KoLkSmJz/so1IKtCa7i91O4JJcD6ZwAAAAAOgAAAAAIAACAAAADHPVQMA3OVICvokzgXxWpIA6rD9Yx0fN+YmnHfmx6qSRAAAAD9plAQJWruJsGVioIAbnrYQAAAAAm99ZTmGU9Cx1mka7wlZG54rO9dahDJbcjFFuiJqTB7k9x1zl4uev63L2ecuaFf5swnUTU/VvuczBdubr0ebSs=</TokenCache>
</SubscriptionDataContainer>
Binary file removed vn.xspeed/vnxspeedtd/vnxspeedtd.opensdf
Binary file not shown.
Binary file modified vn.xspeed/vnxspeedtd/vnxspeedtd.v12.suo
Binary file not shown.

0 comments on commit 52c4ff2

Please sign in to comment.