[Mod]修改平今、平昨自动转换中的逻辑实现
This commit is contained in:
parent
19bf554ecb
commit
f3eea4a1c0
@ -356,6 +356,7 @@ class StAlgoEngine(object):
|
||||
req = VtOrderReq()
|
||||
req.symbol = contract.symbol
|
||||
req.exchange = contract.exchange
|
||||
req.vtSymbol = contract.vtSymbol
|
||||
req.direction = direction
|
||||
req.offset = offset
|
||||
req.volume = int(volume)
|
||||
|
@ -41,6 +41,9 @@ PRODUCT_FOREX = u'外汇'
|
||||
PRODUCT_UNKNOWN = u'未知'
|
||||
PRODUCT_SPOT = u'现货'
|
||||
PRODUCT_DEFER = u'延期'
|
||||
PRODUCT_ETF = u'ETF'
|
||||
PRODUCT_WARRANT = u'权证'
|
||||
PRODUCT_BOND = u'债券'
|
||||
PRODUCT_NONE = ''
|
||||
|
||||
# 价格类型常量
|
||||
|
@ -1046,6 +1046,7 @@ class TradingWidget(QtWidgets.QFrame):
|
||||
req = VtOrderReq()
|
||||
req.symbol = symbol
|
||||
req.exchange = exchange
|
||||
req.vtSymbol = contract.vtSymbol
|
||||
req.price = self.spinPrice.value()
|
||||
req.volume = self.spinVolume.value()
|
||||
req.direction = unicode(self.comboDirection.currentText())
|
||||
|
@ -477,6 +477,8 @@ class DataEngine(object):
|
||||
contract = self.getContract(vtSymbol)
|
||||
|
||||
if contract:
|
||||
detail.exchange = contract.exchange
|
||||
|
||||
# 上期所合约
|
||||
if contract.exchange is EXCHANGE_SHFE:
|
||||
detail.mode = detail.MODE_SHFE
|
||||
@ -491,10 +493,7 @@ class DataEngine(object):
|
||||
#----------------------------------------------------------------------
|
||||
def updateOrderReq(self, req, vtOrderID):
|
||||
"""委托请求更新"""
|
||||
if req.exchange:
|
||||
vtSymbol = '.'.join([req.symbol, req.exchange])
|
||||
else:
|
||||
vtSymbol = req.symbol
|
||||
vtSymbol = req.vtSymbol
|
||||
|
||||
detail = self.getPositionDetail(vtSymbol)
|
||||
detail.updateOrderReq(req, vtOrderID)
|
||||
@ -637,6 +636,7 @@ class PositionDetail(object):
|
||||
self.shortTdFrozen = EMPTY_INT
|
||||
|
||||
self.mode = self.MODE_NORMAL
|
||||
self.exchange = EMPTY_STRING
|
||||
|
||||
self.workingOrderDict = {}
|
||||
|
||||
@ -714,10 +714,7 @@ class PositionDetail(object):
|
||||
#----------------------------------------------------------------------
|
||||
def updateOrderReq(self, req, vtOrderID):
|
||||
"""发单更新"""
|
||||
if req.exchange:
|
||||
vtSymbol = '.'.join([req.symbol, req.exchange])
|
||||
else:
|
||||
vtSymbol = req.symbol
|
||||
vtSymbol = req.vtSymbol
|
||||
|
||||
# 基于请求生成委托对象
|
||||
order = VtOrderData()
|
||||
@ -794,7 +791,7 @@ class PositionDetail(object):
|
||||
self.longPosFrozen = self.longYdFrozen + self.longTdFrozen
|
||||
self.shortPosFrozen = self.shortYdFrozen + self.shortTdFrozen
|
||||
|
||||
#self.output()
|
||||
self.output()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def output(self):
|
||||
@ -867,12 +864,18 @@ class PositionDetail(object):
|
||||
return [req]
|
||||
# 如果平仓量小于昨可用,全部平昨
|
||||
elif req.volume <= ydAvailable:
|
||||
req.offset = OFFSET_CLOSE # OFFSET_CLOSE在上期所等于平昨
|
||||
if self.exchange is EXCHANGE_SHFE:
|
||||
req.offset = OFFSET_CLOSEYESTERDAY
|
||||
else:
|
||||
req.offset = OFFSET_CLOSE
|
||||
return [req]
|
||||
# 平仓量大于昨可用,平仓再反向开仓
|
||||
else:
|
||||
reqClose = copy(req)
|
||||
reqClose.offset = OFFSET_CLOSE
|
||||
if self.exchange is EXCHANGE_SHFE:
|
||||
req.offset = OFFSET_CLOSEYESTERDAY
|
||||
else:
|
||||
req.offset = OFFSET_CLOSE
|
||||
reqClose.volume = ydAvailable
|
||||
|
||||
reqOpen = copy(req)
|
||||
|
@ -292,6 +292,7 @@ class VtOrderReq(object):
|
||||
"""Constructor"""
|
||||
self.symbol = EMPTY_STRING # 代码
|
||||
self.exchange = EMPTY_STRING # 交易所
|
||||
self.vtSymbol = EMPTY_STRING # VT合约代码
|
||||
self.price = EMPTY_FLOAT # 价格
|
||||
self.volume = EMPTY_INT # 数量
|
||||
|
||||
@ -318,6 +319,7 @@ class VtCancelOrderReq(object):
|
||||
"""Constructor"""
|
||||
self.symbol = EMPTY_STRING # 代码
|
||||
self.exchange = EMPTY_STRING # 交易所
|
||||
self.vtSymbol = EMPTY_STRING # VT合约代码
|
||||
|
||||
# 以下字段主要和CTP、LTS类接口相关
|
||||
self.orderID = EMPTY_STRING # 报单号
|
||||
|
Loading…
Reference in New Issue
Block a user