From e1291f221fc3f6cbd12a9b8a3e9cb3bcec63d5d3 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 23 Jan 2025 19:02:46 +0100 Subject: [PATCH] [Modes] add trading_mode.ensure_supported --- .../order_types/test_multiple_orders_creation.py | 3 ++- Trading/Mode/daily_trading_mode/daily_trading.py | 11 ++++++++--- Trading/Mode/dca_trading_mode/dca_trading.py | 1 + .../tests/test_trading_view_signals_trading.py | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Meta/Keywords/scripting_library/tests/orders/order_types/test_multiple_orders_creation.py b/Meta/Keywords/scripting_library/tests/orders/order_types/test_multiple_orders_creation.py index e26422622..c050f3b92 100644 --- a/Meta/Keywords/scripting_library/tests/orders/order_types/test_multiple_orders_creation.py +++ b/Meta/Keywords/scripting_library/tests/orders/order_types/test_multiple_orders_creation.py @@ -107,7 +107,8 @@ async def test_orders_amount_then_position_sequence(mock_context): api.load_pair_contract( mock_context.exchange_manager, api.create_default_future_contract( - mock_context.symbol, decimal.Decimal(1), trading_enums.FutureContractType.LINEAR_PERPETUAL + mock_context.symbol, decimal.Decimal(1), trading_enums.FutureContractType.LINEAR_PERPETUAL, + trading_constants.DEFAULT_SYMBOL_POSITION_MODE ).to_dict() ) diff --git a/Trading/Mode/daily_trading_mode/daily_trading.py b/Trading/Mode/daily_trading_mode/daily_trading.py index 585cfe9bb..f49094021 100644 --- a/Trading/Mode/daily_trading_mode/daily_trading.py +++ b/Trading/Mode/daily_trading_mode/daily_trading.py @@ -587,6 +587,7 @@ async def create_new_orders(self, symbol, final_note, state, **kwargs): spot_increasing_position = state in (trading_enums.EvaluatorStates.VERY_LONG.value, trading_enums.EvaluatorStates.LONG.value) if self.exchange_manager.is_future: + self.trading_mode.ensure_supported(symbol) # on futures, current_symbol_holding = current_market_holding = market_quantity max_buy_size, buy_increasing_position = trading_personal_data.get_futures_max_order_size( self.exchange_manager, symbol, trading_enums.TradeOrderSide.BUY, @@ -868,9 +869,13 @@ async def create_new_orders(self, symbol, final_note, state, **kwargs): raise trading_errors.OrderCreationError() raise trading_errors.MissingMinimalExchangeTradeVolume() - except (trading_errors.MissingFunds, - trading_errors.MissingMinimalExchangeTradeVolume, - trading_errors.OrderCreationError): + except ( + trading_errors.MissingFunds, + trading_errors.MissingMinimalExchangeTradeVolume, + trading_errors.OrderCreationError, + trading_errors.InvalidPositionSide, + trading_errors.UnsupportedContractConfigurationError + ): raise except asyncio.TimeoutError as e: self.logger.error(f"Impossible to create order for {symbol} on {self.exchange_manager.exchange_name}: {e} " diff --git a/Trading/Mode/dca_trading_mode/dca_trading.py b/Trading/Mode/dca_trading_mode/dca_trading.py index 2bc2c9b0d..af3aac521 100644 --- a/Trading/Mode/dca_trading_mode/dca_trading.py +++ b/Trading/Mode/dca_trading_mode/dca_trading.py @@ -134,6 +134,7 @@ async def create_new_orders(self, symbol, _, state, **kwargs): ) ) if self.exchange_manager.is_future: + self.trading_mode.ensure_supported(symbol) # on futures, current_symbol_holding = current_market_holding = market_quantity initial_available_funds, _ = trading_personal_data.get_futures_max_order_size( self.exchange_manager, symbol, side, diff --git a/Trading/Mode/trading_view_signals_trading_mode/tests/test_trading_view_signals_trading.py b/Trading/Mode/trading_view_signals_trading_mode/tests/test_trading_view_signals_trading.py index cf2768caa..ebd8ea8cd 100644 --- a/Trading/Mode/trading_view_signals_trading_mode/tests/test_trading_view_signals_trading.py +++ b/Trading/Mode/trading_view_signals_trading_mode/tests/test_trading_view_signals_trading.py @@ -387,7 +387,8 @@ async def test_signal_callback(tools): trading_api.load_pair_contract( exchange_manager, trading_api.create_default_future_contract( - "BTC/USDT", decimal.Decimal(4), trading_enums.FutureContractType.LINEAR_PERPETUAL + "BTC/USDT", decimal.Decimal(4), trading_enums.FutureContractType.LINEAR_PERPETUAL, + trading_constants.DEFAULT_SYMBOL_POSITION_MODE ).to_dict() ) await producer.signal_callback({