diff --git a/broker_sync/providers/trading212.py b/broker_sync/providers/trading212.py new file mode 100644 index 0000000..06da489 --- /dev/null +++ b/broker_sync/providers/trading212.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +import re + +_SUFFIX_RE = re.compile(r"(?:_US)?(?:[a-z])?_EQ$") + + +def _normalise_ticker(raw: str) -> str: + """Strip T212's exchange-suffix decoration from a ticker. + + T212 tags every ticker with `_EQ`, optionally preceded by a lowercase + letter ("l" for LSE) or `_US` for a US listing. Peel those off so the + symbol matches what Schwab / InvestEngine emit. + """ + return _SUFFIX_RE.sub("", raw) diff --git a/tests/providers/__init__.py b/tests/providers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/providers/test_trading212_ticker.py b/tests/providers/test_trading212_ticker.py new file mode 100644 index 0000000..da918b6 --- /dev/null +++ b/tests/providers/test_trading212_ticker.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +import pytest + +from broker_sync.providers.trading212 import _normalise_ticker + + +@pytest.mark.parametrize( + ("raw", "expected"), + [ + # T212 LSE suffix: lowercase "l" before _EQ means London listing. + ("VUAGl_EQ", "VUAG"), + ("VUSAl_EQ", "VUSA"), + ("VWRPl_EQ", "VWRP"), + ("METAl_EQ", "META"), + # T212 US suffix: _US_EQ means US listing. Strip the whole suffix. + ("META_US_EQ", "META"), + ("AAPL_US_EQ", "AAPL"), + # Plain _EQ suffix with no exchange letter. + ("FOO_EQ", "FOO"), + # Already canonical — passes through. + ("VUAG", "VUAG"), + ("META", "META"), + ], +) +def test_normalise_ticker(raw: str, expected: str) -> None: + assert _normalise_ticker(raw) == expected