Skip to content

Commit

Permalink
[Modes] add trading_mode.ensure_supported
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jan 23, 2025
1 parent 162bccf commit e1291f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down
11 changes: 8 additions & 3 deletions Trading/Mode/daily_trading_mode/daily_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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} "
Expand Down
1 change: 1 addition & 0 deletions Trading/Mode/dca_trading_mode/dca_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit e1291f2

Please sign in to comment.