[Mod] change to use position summary instead of indvidual position

This commit is contained in:
vn.py 2019-06-08 22:34:46 +08:00
parent d072543dd6
commit 981c666f4d

View File

@ -19,7 +19,7 @@ from vnpy.api.tap.vntap.ITapTrade import (
TapAPIApplicationInfo as TapTradeAPIApplicationInfo, TapAPIApplicationInfo as TapTradeAPIApplicationInfo,
TapAPITradeLoginAuth, TapAPIAccQryReq, TapAPIFundReq, TapAPITradeLoginAuth, TapAPIAccQryReq, TapAPIFundReq,
TapAPIAccountInfo, TapAPIFundData, TapAPIAccountInfo, TapAPIFundData,
TapAPIPositionQryReq, TapAPIPositionInfo, TapAPIPositionQryReq, TapAPIPositionSummary,
TapAPIOrderQryReq, TapAPIFillQryReq, TapAPIOrderQryReq, TapAPIFillQryReq,
TapAPIOrderInfo, TapAPIFillInfo, TapAPIOrderInfo, TapAPIFillInfo,
TapAPINewOrder, TapAPIOrderCancelReq, TapAPINewOrder, TapAPIOrderCancelReq,
@ -502,12 +502,12 @@ class TradeApi(ITapTradeAPINotify):
"""""" """"""
self.update_account(info) self.update_account(info)
def OnRspQryPosition( def OnRspQryPositionSummary(
self, self,
sessionID: int, sessionID: int,
errorCode: int, errorCode: int,
isLast: str, isLast: str,
info: TapAPIPositionInfo info: TapAPIPositionSummary
): ):
if errorCode != TAPIERROR_SUCCEED: if errorCode != TAPIERROR_SUCCEED:
self.gateway.write_log(f"查询持仓信息失败") self.gateway.write_log(f"查询持仓信息失败")
@ -520,7 +520,7 @@ class TradeApi(ITapTradeAPINotify):
self.gateway.write_log(f"查询持仓信息成功") self.gateway.write_log(f"查询持仓信息成功")
self.query_order() self.query_order()
def OnRtnPosition(self, info: TapAPIPositionInfo): def OnRtnPositionSummary(self, info: TapAPIPositionSummary):
"""""" """"""
self.update_position(info) self.update_position(info)
@ -581,7 +581,7 @@ class TradeApi(ITapTradeAPINotify):
) )
self.gateway.on_account(account) self.gateway.on_account(account)
def update_position(self, info: TapAPIPositionInfo): def update_position(self, info: TapAPIPositionSummary):
"""""" """"""
position = PositionData( position = PositionData(
symbol=info.CommodityNo + info.ContractNo, symbol=info.CommodityNo + info.ContractNo,
@ -589,7 +589,6 @@ class TradeApi(ITapTradeAPINotify):
direction=DIRECTION_TAP2VT[info.MatchSide], direction=DIRECTION_TAP2VT[info.MatchSide],
volume=info.PositionQty, volume=info.PositionQty,
price=info.PositionPrice, price=info.PositionPrice,
pnl=info.PositionProfit,
gateway_name=self.gateway_name gateway_name=self.gateway_name
) )
self.gateway.on_position(position) self.gateway.on_position(position)
@ -711,7 +710,7 @@ class TradeApi(ITapTradeAPINotify):
def query_position(self): def query_position(self):
"""""" """"""
req = TapAPIPositionQryReq() req = TapAPIPositionQryReq()
self.api.QryPosition(req) self.api.QryPositionSummary(req)
def query_order(self): def query_order(self):
"""""" """"""