diff --git a/vnpy/app/spread_trading/base.py b/vnpy/app/spread_trading/base.py index e6777d30..c0874ee2 100644 --- a/vnpy/app/spread_trading/base.py +++ b/vnpy/app/spread_trading/base.py @@ -78,7 +78,8 @@ class SpreadData: legs: List[LegData], price_multipliers: Dict[str, int], trading_multipliers: Dict[str, int], - active_symbol: str + active_symbol: str, + inverse_contracts: Dict[str, bool] ): """""" self.name: str = name @@ -88,10 +89,13 @@ class SpreadData: self.passive_legs: List[LegData] = [] # For calculating spread price - self.price_multipliers: Dict[str: int] = price_multipliers + self.price_multipliers: Dict[str, int] = price_multipliers # For calculating spread pos and sending orders - self.trading_multipliers: Dict[str: int] = trading_multipliers + self.trading_multipliers: Dict[str, int] = trading_multipliers + + # For inverse derivative contracts of crypto market + self.inverse_contracts: Dict[str, bool] = inverse_contracts self.price_formula: str = "" self.trading_formula: str = "" diff --git a/vnpy/app/spread_trading/engine.py b/vnpy/app/spread_trading/engine.py index 433eb19d..15c58c75 100644 --- a/vnpy/app/spread_trading/engine.py +++ b/vnpy/app/spread_trading/engine.py @@ -253,6 +253,7 @@ class SpreadDataEngine: legs: List[LegData] = [] price_multipliers: Dict[str, int] = {} trading_multipliers: Dict[str, int] = {} + inverse_contracts: Dict[str, bool] = {} for leg_setting in leg_settings: vt_symbol = leg_setting["vt_symbol"] @@ -261,13 +262,15 @@ class SpreadDataEngine: legs.append(leg) price_multipliers[vt_symbol] = leg_setting["price_multiplier"] trading_multipliers[vt_symbol] = leg_setting["trading_multiplier"] + inverse_contracts[vt_symbol] = leg_setting.get("inverse_contracts", False) spread = SpreadData( name, legs, price_multipliers, trading_multipliers, - active_symbol + active_symbol, + inverse_contracts ) self.spreads[name] = spread diff --git a/vnpy/app/spread_trading/ui/widget.py b/vnpy/app/spread_trading/ui/widget.py index 00ef63a5..72fa2551 100644 --- a/vnpy/app/spread_trading/ui/widget.py +++ b/vnpy/app/spread_trading/ui/widget.py @@ -392,6 +392,7 @@ class SpreadDataDialog(QtWidgets.QDialog): grid.addWidget(Label("本地代码"), 3, 1) grid.addWidget(Label("价格乘数"), 3, 2) grid.addWidget(Label("交易乘数"), 3, 3) + grid.addWidget(Label("合约模式"), 3, 4) int_validator = QtGui.QIntValidator() @@ -405,15 +406,20 @@ class SpreadDataDialog(QtWidgets.QDialog): trading_line = QtWidgets.QLineEdit() trading_line.setValidator(int_validator) + inverse_combo = QtWidgets.QComboBox() + inverse_combo.addItems(["正向", "反向"]) + grid.addWidget(Label("腿{}".format(i + 1)), 4 + i, 0) grid.addWidget(symbol_line, 4 + i, 1) grid.addWidget(price_line, 4 + i, 2) grid.addWidget(trading_line, 4 + i, 3) + grid.addWidget(inverse_combo, 4 + i, 4) d = { "symbol": symbol_line, "price": price_line, - "trading": trading_line + "trading": trading_line, + "inverse": inverse_combo } self.leg_widgets.append(d) @@ -443,10 +449,16 @@ class SpreadDataDialog(QtWidgets.QDialog): price_multiplier = int(d["price"].text()) trading_multiplier = int(d["trading"].text()) + if d["inverse"].currentText() == "正向": + inverse_contract = False + else: + inverse_contract = True + leg_settings[vt_symbol] = { "vt_symbol": vt_symbol, "price_multiplier": price_multiplier, - "trading_multiplier": trading_multiplier + "trading_multiplier": trading_multiplier, + "inverse_contract": inverse_contract } except ValueError: pass