Skip to content

Commit

Permalink
[TradingView] add ";" separator
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Oct 17, 2024
1 parent d3f61ce commit e11e395
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e11e395

Please sign in to comment.