[Mod] calculate inverse bid/ask volume

This commit is contained in:
vn.py 2019-10-22 14:36:37 +08:00
parent b5892b9607
commit 66cf47db3d
2 changed files with 22 additions and 5 deletions

View File

@ -77,7 +77,7 @@ def main():
# main_engine.add_gateway(OkexsGateway) # main_engine.add_gateway(OkexsGateway)
# main_engine.add_gateway(DaGateway) # main_engine.add_gateway(DaGateway)
# main_engine.add_gateway(CoinbaseGateway) # main_engine.add_gateway(CoinbaseGateway)
# main_engine.add_gateway(BitstampGateway) main_engine.add_gateway(BitstampGateway)
# main_engine.add_gateway(GateiosGateway) # main_engine.add_gateway(GateiosGateway)
main_engine.add_gateway(BybitGateway) main_engine.add_gateway(BybitGateway)

View File

@ -150,17 +150,27 @@ class SpreadData:
# Calculate volume # Calculate volume
trading_multiplier = self.trading_multipliers[leg.vt_symbol] 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: if trading_multiplier > 0:
adjusted_bid_volume = floor( adjusted_bid_volume = floor(
leg.bid_volume / trading_multiplier) leg_bid_volume / trading_multiplier)
adjusted_ask_volume = floor( adjusted_ask_volume = floor(
leg.ask_volume / trading_multiplier) leg_ask_volume / trading_multiplier)
else: else:
adjusted_bid_volume = floor( adjusted_bid_volume = floor(
leg.ask_volume / abs(trading_multiplier)) leg_bid_volume / abs(trading_multiplier))
adjusted_ask_volume = floor( adjusted_ask_volume = floor(
leg.bid_volume / abs(trading_multiplier)) leg_ask_volume / abs(trading_multiplier))
# For the first leg, just initialize # For the first leg, just initialize
if not n: if not n:
@ -247,3 +257,10 @@ class SpreadData:
gateway_name="SPREAD" gateway_name="SPREAD"
) )
return tick return tick
def calculate_inverse_volume(original_volume: float, price: float) -> float:
""""""
if not price:
return 0
return original_volume / price