Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(loaders): ask Tiingo for class shares by their hyphenated ticker

Rudy Celekli69862b68d079
diff --git a/agent/backtest/loaders/tiingo_loader.py b/agent/backtest/loaders/tiingo_loader.py
index 64d786b23..2904c0f63 100644
--- a/agent/backtest/loaders/tiingo_loader.py
+++ b/agent/backtest/loaders/tiingo_loader.py
@@ -61,23 +61,45 @@ def _resolve_key() -> str:
return "" if key.lower() in _KEY_PLACEHOLDERS else key
+# Market suffixes that remain after the project ``.US`` marker is removed.
+# A class-share dot (``BRK.B``) is not one of these.
+_NON_US_SUFFIXES = (
+ ".HK", ".SZ", ".SH", ".BJ", ".SS", ".NS", ".BO", ".KS", ".KQ",
+ ".TO", ".V", ".VN", ".SA", ".L", ".T", ".TW", ".TWO", ".FX",
+)
+
+
def _to_tiingo_symbol(code: str) -> Optional[str]:
"""Map a project symbol to a Tiingo ticker, or ``None`` when unsupported.
Args:
- code: Project symbol such as ``AAPL.US`` or ``AAPL``.
+ code: Project symbol such as ``AAPL.US``, ``BRK.B.US``, or ``AAPL``.
Returns:
- The bare lower-cased ticker Tiingo expects (e.g. ``aapl``), or ``None``
- for symbols that are clearly not US equities (HK/crypto/A-share).
+ The bare lower-cased ticker Tiingo expects (``aapl``, ``brk-b``), or
+ ``None`` for symbols that are clearly not US equities (HK/crypto/A-share).
+ Tiingo hyphenates class shares; the dotted form is not a ticker.
"""
upper = code.strip().upper()
if not upper:
return None
if upper.endswith(".US"):
upper = upper[:-3]
- # Reject non-US market suffixes and crypto pairs outright.
+ if any(upper.endswith(suffix) for suffix in _NON_US_SUFFIXES):
+ return None
+ # Crypto pairs (BTC-USDT, ETH-USD) share a separator with class shares.
+ # A class is one letter (BRK.B / BRK-B); a quote currency is longer.
if "." in upper or "-" in upper:
+ separator = "." if "." in upper else "-"
+ left, right = upper.split(separator, 1)
+ if (
+ left.isalpha()
+ and right.isalpha()
+ and len(right) == 1
+ and "." not in left
+ and "-" not in left
+ ):
+ return f"{left}-{right}".lower()
return None
if not upper.isalnum():
return None
diff --git a/agent/tests/test_tiingo_loader.py b/agent/tests/test_tiingo_loader.py
index c36d6f6d5..a2eeae144 100644
--- a/agent/tests/test_tiingo_loader.py
+++ b/agent/tests/test_tiingo_loader.py
@@ -33,9 +33,13 @@ from tests.loader_contract import assert_loader_contract
("AAPL", "aapl"),
("msft", "msft"),
("BRK", "brk"),
+ ("BRK.B.US", "brk-b"), # class share; Tiingo hyphenates
+ ("BRK.B", "brk-b"),
+ ("brk-b", "brk-b"),
("00700.HK", None), # HK suffix
("000001.SZ", None), # A-share suffix
("BTC-USDT", None), # crypto pair
+ ("ETH-USD", None),
("", None),
],
)