[Mod] record coin (not contract) traded volume for inverse contract

This commit is contained in:
vn.py 2019-10-22 15:24:11 +08:00
parent 7a72d5f63f
commit 44bd65b502

View File

@ -117,10 +117,21 @@ class SpreadAlgoTemplate:
def update_trade(self, trade: TradeData): def update_trade(self, trade: TradeData):
"""""" """"""
if trade.direction == Direction.LONG: # For inverse contract:
self.leg_traded[trade.vt_symbol] += trade.volume # record coin trading volume as leg trading volume,
# not contract volume!
if self.spread.is_inverse(trade.vt_symbol):
trade_volume = calculate_inverse_volume(
trade.volume,
trade.price
)
else: else:
self.leg_traded[trade.vt_symbol] -= trade.volume trade_volume = trade.volume
if trade.direction == Direction.LONG:
self.leg_traded[trade.vt_symbol] += trade_volume
else:
self.leg_traded[trade.vt_symbol] -= trade_volume
msg = "委托成交,{}{}{}@{}".format( msg = "委托成交,{}{}{}@{}".format(
trade.vt_symbol, trade.vt_symbol,