[Mod] convert coin volume to contract volume for inverse contract

This commit is contained in:
vn.py 2019-10-22 15:17:13 +08:00
parent 8781aa72d5
commit 7a72d5f63f
2 changed files with 11 additions and 1 deletions

View File

@ -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:
""""""

View File

@ -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,