diff --git a/examples/vn_trader/run.py b/examples/vn_trader/run.py index bc0a304d..92cc8257 100644 --- a/examples/vn_trader/run.py +++ b/examples/vn_trader/run.py @@ -77,7 +77,7 @@ def main(): # main_engine.add_gateway(OkexsGateway) # main_engine.add_gateway(DaGateway) # main_engine.add_gateway(CoinbaseGateway) - # main_engine.add_gateway(BitstampGateway) + main_engine.add_gateway(BitstampGateway) # main_engine.add_gateway(GateiosGateway) main_engine.add_gateway(BybitGateway) diff --git a/vnpy/app/spread_trading/base.py b/vnpy/app/spread_trading/base.py index c0874ee2..62973f00 100644 --- a/vnpy/app/spread_trading/base.py +++ b/vnpy/app/spread_trading/base.py @@ -150,17 +150,27 @@ class SpreadData: # Calculate volume trading_multiplier = self.trading_multipliers[leg.vt_symbol] + inverse_contract = self.inverse_contracts[leg.vt_symbol] + + if not inverse_contract: + leg_bid_volume = leg.bid_volume + leg_ask_volume = leg.ask_volume + else: + leg_bid_volume = calculate_inverse_volume( + leg.bid_volume, leg.bid_price) + leg_ask_volume = calculate_inverse_volume( + leg.ask_volume, leg.ask_price) if trading_multiplier > 0: adjusted_bid_volume = floor( - leg.bid_volume / trading_multiplier) + leg_bid_volume / trading_multiplier) adjusted_ask_volume = floor( - leg.ask_volume / trading_multiplier) + leg_ask_volume / trading_multiplier) else: adjusted_bid_volume = floor( - leg.ask_volume / abs(trading_multiplier)) + leg_bid_volume / abs(trading_multiplier)) adjusted_ask_volume = floor( - leg.bid_volume / abs(trading_multiplier)) + leg_ask_volume / abs(trading_multiplier)) # For the first leg, just initialize if not n: @@ -247,3 +257,10 @@ class SpreadData: gateway_name="SPREAD" ) return tick + + +def calculate_inverse_volume(original_volume: float, price: float) -> float: + """""" + if not price: + return 0 + return original_volume / price