From 7a72d5f63fb03e8b9090e22521169520d37c3d93 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 22 Oct 2019 15:17:13 +0800 Subject: [PATCH] [Mod] convert coin volume to contract volume for inverse contract --- vnpy/app/spread_trading/base.py | 5 +++++ vnpy/app/spread_trading/template.py | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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,