From 72af1912caff5862938bd0c71eff4998314d6107 Mon Sep 17 00:00:00 2001 From: Rahul Date: Fri, 17 Feb 2023 22:01:00 +0000 Subject: [PATCH] added new text --- freqtrade/enums/__init__.py | 2 +- freqtrade/enums/marketstatetype.py | 15 --------------- freqtrade/rpc/telegram.py | 16 ++++++++++++---- freqtrade/strategy/interface.py | 4 ++-- tests/rpc/test_rpc_telegram.py | 14 +++++++++++++- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/freqtrade/enums/__init__.py b/freqtrade/enums/__init__.py index 160ebc052..69ef345e8 100644 --- a/freqtrade/enums/__init__.py +++ b/freqtrade/enums/__init__.py @@ -5,6 +5,7 @@ from freqtrade.enums.exitchecktuple import ExitCheckTuple from freqtrade.enums.exittype import ExitType from freqtrade.enums.hyperoptstate import HyperoptState from freqtrade.enums.marginmode import MarginMode +from freqtrade.enums.marketstatetype import MarketDirection from freqtrade.enums.ordertypevalue import OrderTypeValues from freqtrade.enums.pricetype import PriceType from freqtrade.enums.rpcmessagetype import NO_ECHO_MESSAGES, RPCMessageType, RPCRequestType @@ -12,4 +13,3 @@ from freqtrade.enums.runmode import NON_UTIL_MODES, OPTIMIZE_MODES, TRADING_MODE from freqtrade.enums.signaltype import SignalDirection, SignalTagType, SignalType from freqtrade.enums.state import State from freqtrade.enums.tradingmode import TradingMode -from freqtrade.enums.marketstatetype import MarketDirection diff --git a/freqtrade/enums/marketstatetype.py b/freqtrade/enums/marketstatetype.py index 5f3f219d8..8132be74a 100644 --- a/freqtrade/enums/marketstatetype.py +++ b/freqtrade/enums/marketstatetype.py @@ -9,18 +9,3 @@ class MarketDirection(Enum): SHORT = "short" EVEN = "even" NONE = '' - - @staticmethod - def string_to_enum(label : str) -> str: - match label: - case "long": - return MarketDirection.LONG - case "short": - return MarketDirection.SHORT - case "even": - return MarketDirection.EVEN - case 'none': - return MarketDirection.NONE - case _: - return None - diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 750f0dd5f..60a5bcce6 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -1689,7 +1689,15 @@ class Telegram(RPCHandler): :return: None """ if context.args and len(context.args) == 1: - market_dir = MarketDirection.string_to_enum(context.args[0]) - if market_dir: - self._rpc._freqtrade.strategy.market_direction = market_dir - + 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") diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index d53f57d17..96b2ac8ce 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -12,8 +12,8 @@ from pandas import DataFrame from freqtrade.constants import Config, IntOrInf, ListPairsWithTimeframes from freqtrade.data.dataprovider import DataProvider -from freqtrade.enums import (CandleType, ExitCheckTuple, ExitType, MarketDirection, RunMode, SignalDirection, - SignalTagType, SignalType, TradingMode) +from freqtrade.enums import (CandleType, ExitCheckTuple, ExitType, MarketDirection, RunMode, + SignalDirection, SignalTagType, SignalType, TradingMode) from freqtrade.exceptions import OperationalException, StrategyError from freqtrade.exchange import timeframe_to_minutes, timeframe_to_next_date, timeframe_to_seconds from freqtrade.misc import remove_entry_exit_signals diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 050d7b7c0..a63d7f9be 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -20,7 +20,7 @@ from telegram.error import BadRequest, NetworkError, TelegramError from freqtrade import __version__ from freqtrade.constants import CANCEL_REASON from freqtrade.edge import PairInfo -from freqtrade.enums import ExitType, RPCMessageType, RunMode, SignalDirection, State +from freqtrade.enums import ExitType, MarketDirection, RPCMessageType, RunMode, SignalDirection, State from freqtrade.exceptions import OperationalException from freqtrade.freqtradebot import FreqtradeBot from freqtrade.loggers import setup_logging @@ -2394,3 +2394,15 @@ def test__send_msg_keyboard(default_conf, mocker, caplog) -> None: assert log_has("using custom keyboard from config.json: " "[['/daily', '/stats', '/balance', '/profit', '/profit 5'], ['/count', " "'/start', '/reload_config', '/help']]", caplog) + + +def test_change_market_direction(default_conf, mocker, update) -> None: + telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) + assert telegram._rpc._freqtrade.strategy.market_direction == MarketDirection.NONE + context = MagicMock() + context.args = ["long"] + telegram._changemarketdir(update, context) + assert telegram._rpc._freqtrade.strategy.market_direction == MarketDirection.LONG + context = MagicMock() + context.args = ["invalid"] + assert telegram._rpc._freqtrade.strategy.market_direction == MarketDirection.LONG