diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 83bffb779..10ea04c6c 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -20,7 +20,7 @@ from freqtrade.constants import CANCEL_REASON, DATETIME_PRINT_FORMAT, Config from freqtrade.data.history import load_data from freqtrade.data.metrics import calculate_max_drawdown from freqtrade.enums import (CandleType, ExitCheckTuple, ExitType, SignalDirection, State, - TradingMode) + TradingMode, MarketDirection) from freqtrade.exceptions import ExchangeError, PricingError from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs from freqtrade.loggers import bufferHandler @@ -1205,3 +1205,6 @@ class RPC: 'last_process_loc': last_p.astimezone(tzlocal()).strftime(DATETIME_PRINT_FORMAT), 'last_process_ts': int(last_p.timestamp()), } + + def _update_market_direction(self, direction: MarketDirection): + self._freqtrade.strategy.market_direction = direction \ No newline at end of file diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 60a5bcce6..65ef1bb21 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -129,7 +129,7 @@ class Telegram(RPCHandler): r'/weekly$', r'/weekly \d+$', r'/monthly$', r'/monthly \d+$', r'/forcebuy$', r'/forcelong$', r'/forceshort$', r'/forcesell$', r'/forceexit$', - r'/edge$', r'/health$', r'/help$', r'/version$', r'/marketdir$' + r'/edge$', r'/health$', r'/help$', r'/version$', r'/marketdir \d+$' ] # Create keys for generation valid_keys_print = [k.replace('$', '') for k in valid_keys] @@ -1690,14 +1690,15 @@ class Telegram(RPCHandler): """ if context.args and len(context.args) == 1: new_market_dir = context.args[0] - match new_market_dir: - case "long": - self._rpc._freqtrade.strategy.market_direction = MarketDirection.LONG - case "short": - self._rpc._freqtrade.strategy.market_direction = MarketDirection.SHORT - case "even": - self._rpc._freqtrade.strategy.market_direction = MarketDirection.EVEN - case "none": - self._rpc._freqtrade.strategy.market_direction = MarketDirection.NONE - case _: - raise RPCException("Invalid market direction provided") + if new_market_dir == "long": + self._rpc._update_market_direction(MarketDirection.LONG) + elif new_market_dir == "short": + self._rpc._update_market_direction(MarketDirection.SHORT) + elif new_market_dir == "even": + self._rpc._update_market_direction(MarketDirection.EVEN) + elif new_market_dir == "none": + self._rpc._update_market_direction(MarketDirection.NONE) + else: + raise RPCException("Invalid market direction provided") + else: + raise RPCException("Invalid usage of command /marketdir.")