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 f950b0674..4351625f8 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 @@ -160,6 +160,33 @@ async def test_parse_signal_data(): assert "nPLOp" not in str(errors[0]) assert "KEY" not in str(errors[0]) + errors = [] + assert Mode.TradingViewSignalsTradingMode.parse_signal_data( + "KEY=value;EXCHANGE;PLOp=ABC", + errors + ) == { + "KEY": "value", + "PLOp": "ABC", + } + assert len(errors) == 1 + assert "EXCHANGE" in str(errors[0]) + assert "nPLOp" not in str(errors[0]) + assert "KEY" not in str(errors[0]) + + errors = [] + assert Mode.TradingViewSignalsTradingMode.parse_signal_data( + "KEY=value;EXCHANGE\nPLOp=ABC\\nGG=HIHI", + errors + ) == { + "KEY": "value", + "PLOp": "ABC", + "GG": "HIHI", + } + assert len(errors) == 1 + assert "EXCHANGE" in str(errors[0]) + assert "nPLOp" not in str(errors[0]) + assert "KEY" not in str(errors[0]) + async def test_trading_view_signal_callback(tools): exchange_manager, symbol, mode, producer, consumer = tools diff --git a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py index fce9d3c4f..1582d58d8 100644 --- a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py +++ b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py @@ -32,6 +32,7 @@ class TradingViewSignalsTradingMode(trading_modes.AbstractTradingMode): SERVICE_FEED_CLASS = trading_view_service_feed.TradingViewServiceFeed TRADINGVIEW_FUTURES_SUFFIXES = [".P"] + PARAM_SEPARATORS = [";", "\\n", "\n"] EXCHANGE_KEY = "EXCHANGE" SYMBOL_KEY = "SYMBOL" @@ -140,7 +141,12 @@ def _adapt_symbol(cls, parsed_data): @classmethod def parse_signal_data(cls, signal_data: str, errors: list) -> dict: parsed_data = {} - for line in signal_data.replace("\\n", "\n").split("\n"): + # replace all split char by a single one + splittable_data = signal_data + final_split_char = cls.PARAM_SEPARATORS[0] + for split_char in cls.PARAM_SEPARATORS[1:]: + splittable_data = splittable_data.replace(split_char, final_split_char) + for line in splittable_data.split(final_split_char): if not line.strip(): # ignore empty lines continue