diff --git a/vnpy/trader/app/spreadTrading/stEngine.py b/vnpy/trader/app/spreadTrading/stEngine.py index 808bf565..f6d63347 100644 --- a/vnpy/trader/app/spreadTrading/stEngine.py +++ b/vnpy/trader/app/spreadTrading/stEngine.py @@ -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) diff --git a/vnpy/trader/language/chinese/constant.py b/vnpy/trader/language/chinese/constant.py index 53f53741..1aadb9b4 100644 --- a/vnpy/trader/language/chinese/constant.py +++ b/vnpy/trader/language/chinese/constant.py @@ -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 = '' # 价格类型常量 diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index c5c0979f..29376662 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -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()) diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 37920001..45ccf025 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -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) diff --git a/vnpy/trader/vtObject.py b/vnpy/trader/vtObject.py index e5d86f08..a0881b7a 100644 --- a/vnpy/trader/vtObject.py +++ b/vnpy/trader/vtObject.py @@ -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 # 报单号