diff --git a/vnpy/app/spread_trading/base.py b/vnpy/app/spread_trading/base.py index d04689f9..d9589817 100644 --- a/vnpy/app/spread_trading/base.py +++ b/vnpy/app/spread_trading/base.py @@ -268,6 +268,11 @@ class SpreadData: ) return tick + def is_inverse(self, vt_symbol: str) -> bool: + """""" + inverse_contract = self.inverse_contracts[vt_symbol] + return inverse_contract + def calculate_inverse_volume(original_volume: float, price: float) -> float: """""" diff --git a/vnpy/app/spread_trading/template.py b/vnpy/app/spread_trading/template.py index de4ca343..2b460ce1 100644 --- a/vnpy/app/spread_trading/template.py +++ b/vnpy/app/spread_trading/template.py @@ -8,7 +8,7 @@ from vnpy.trader.object import TickData, TradeData, OrderData, ContractData from vnpy.trader.constant import Direction, Status, Offset from vnpy.trader.utility import virtual -from .base import SpreadData +from .base import SpreadData, calculate_inverse_volume class SpreadAlgoTemplate: @@ -177,6 +177,11 @@ class SpreadAlgoTemplate: direction: Direction, ): """""" + # For inverse contract: + # contract trading volume = coin trading volume * trading price + if self.spread.is_inverse(vt_symbol): + volume = volume * price + vt_orderids = self.algo_engine.send_order( self, vt_symbol,