Skip to content

"Vibe-Trading: Your Personal Trading Agent"

feat(market-data): add UK/Irish equity market support (.L/.IL)

cgycorey1bef67f15e38
diff --git a/agent/backtest/engines/_market_hooks.py b/agent/backtest/engines/_market_hooks.py
index 116af8fa1..8a13c624e 100644
--- a/agent/backtest/engines/_market_hooks.py
+++ b/agent/backtest/engines/_market_hooks.py
@@ -35,6 +35,9 @@ _MARKET_PATTERNS = [
# Canada equities: Toronto Stock Exchange (TD.TO) and TSX Venture
# (PNG.V). Yahoo carries both suffixes verbatim.
(re.compile(r"^[A-Z0-9&.\-]+\.(TO|V)$", re.I), "ca_equity"),
+ # UK equities: London Stock Exchange (VOD.L, SHEL.L) and Irish Stock
+ # Exchange (DCC.IL). Yahoo carries both suffixes verbatim.
+ (re.compile(r"^[A-Z0-9&.\-]+\.(L|IL)$", re.I), "uk_equity"),
# Vietnam equities: HOSE (VIC.VN). Tickers are three letters in practice;
# the class stays broad to admit fund certificates and ETF codes.
(re.compile(r"^[A-Z0-9]+\.VN$", re.I), "vietnam_equity"),
@@ -74,6 +77,7 @@ _MARKET_CURRENCY = {
"india_equity": "INR",
"kr_equity": "KRW",
"ca_equity": "CAD",
+ "uk_equity": "GBP",
"vietnam_equity": "VND",
# Every crypto pattern in _MARKET_PATTERNS is USDT-quoted, and USDT is
# carried at its USD peg. This is the one approximation in the table: a
@@ -186,13 +190,14 @@ def _is_china_futures(code: str) -> bool:
def _detect_submarket(codes: List[str]) -> str:
- """Detect US, HK, or Canada from symbol suffixes.
+ """Detect US, HK, Canada, or UK from symbol suffixes.
Args:
codes: Instrument codes.
Returns:
- ``"hk"`` for ``.HK``, ``"ca"`` for ``.TO``/``.V``, else ``"us"``.
+ ``"hk"`` for ``.HK``, ``"ca"`` for ``.TO``/``.V``, ``"uk"`` for
+ ``.L``/``.IL``, else ``"us"``.
"""
for code in codes:
upper = code.upper()
@@ -200,6 +205,8 @@ def _detect_submarket(codes: List[str]) -> str:
return "hk"
if upper.endswith((".TO", ".V")):
return "ca"
+ if upper.endswith((".L", ".IL")):
+ return "uk"
return "us"
# ── Crypto: OKX tiered maintenance margin table (simplified) ──
diff --git a/agent/backtest/engines/composite.py b/agent/backtest/engines/composite.py
index e2b1b039c..6046bc2e3 100644
--- a/agent/backtest/engines/composite.py
+++ b/agent/backtest/engines/composite.py
@@ -50,6 +50,9 @@ def _build_rule_engines(config: dict, codes: List[str]) -> Dict[str, BaseEngine]
elif market == "ca_equity":
from backtest.engines.global_equity import GlobalEquityEngine
engines["ca_equity"] = GlobalEquityEngine(config, market="ca")
+ elif market == "uk_equity":
+ from backtest.engines.global_equity import GlobalEquityEngine
+ engines["uk_equity"] = GlobalEquityEngine(config, market="uk")
elif market == "crypto":
from backtest.engines.crypto import CryptoEngine
engines["crypto"] = CryptoEngine(config)
diff --git a/agent/backtest/loaders/registry.py b/agent/backtest/loaders/registry.py
index 6e0669537..97f13f9d3 100644
--- a/agent/backtest/loaders/registry.py
+++ b/agent/backtest/loaders/registry.py
@@ -151,6 +151,8 @@ FALLBACK_CHAINS: dict[str, list[str]] = {
"kr_equity": ["pykrx", "yahoo", "yfinance", "local"],
# TSX (.TO) / TSX Venture (.V): direct Yahoo first, SDK fallback second.
"ca_equity": ["yahoo", "yfinance", "local"],
+ # UK (.L) / Irish (.IL): direct Yahoo first, SDK fallback second.
+ "uk_equity": ["yahoo", "yfinance", "local"],
# Vietnam (.VN): Yahoo lists HOSE only — HNX and UPCOM are unsupported,
# so those two are reachable only through the user's local files.
"vietnam_equity": ["yahoo", "yfinance", "local"],
diff --git a/agent/backtest/runner.py b/agent/backtest/runner.py
index a7bd38ec9..68f8f9450 100644
--- a/agent/backtest/runner.py
+++ b/agent/backtest/runner.py
@@ -824,6 +824,7 @@ _MARKET_TO_SOURCE = {
"india_equity": "yahoo",
"kr_equity": "pykrx",
"ca_equity": "yahoo",
+ "uk_equity": "yahoo",
"vietnam_equity": "yahoo",
"crypto": "okx",
"futures": "tushare",
@@ -1344,7 +1345,7 @@ def _create_market_engine(source: str, config: dict, codes: List[str]):
from backtest.engines.crypto import CryptoEngine
return CryptoEngine(config)
elif source in ("tushare", "akshare"):
- if markets & {"us_equity", "hk_equity", "ca_equity"}:
+ if markets & {"us_equity", "hk_equity", "ca_equity", "uk_equity"}:
from backtest.engines.global_equity import GlobalEquityEngine
market = _detect_submarket(codes)
return GlobalEquityEngine(config, market=market)
@@ -1366,7 +1367,7 @@ def _create_market_engine(source: str, config: dict, codes: List[str]):
# Sources without a dedicated branch (local, stooq, ...): follow the
# instrument market rather than the loader name, so e.g. a local
# AAPL.US dataset gets US-equity execution rules instead of crypto.
- if markets & {"us_equity", "hk_equity", "ca_equity"}:
+ if markets & {"us_equity", "hk_equity", "ca_equity", "uk_equity"}:
from backtest.engines.global_equity import GlobalEquityEngine
market = _detect_submarket(codes)
return GlobalEquityEngine(config, market=market)
diff --git a/agent/src/market_data.py b/agent/src/market_data.py
index f7b867f12..76d8f8b8c 100644
--- a/agent/src/market_data.py
+++ b/agent/src/market_data.py
@@ -28,6 +28,10 @@ _SOURCE_PATTERNS = [
(re.compile(r"^[A-Z0-9&.\-]+\.(NS|BO)$", re.I), "yahoo"),
# Canada: Toronto Stock Exchange (TD.TO) / TSX Venture (PNG.V).
(re.compile(r"^[A-Z0-9&.\-]+\.(TO|V)$", re.I), "yahoo"),
+ # UK: London Stock Exchange (VOD.L, SHEL.L) / Irish (DCC.IL). Yahoo serves
+ # both suffixes verbatim; without this they fell through to the tushare
+ # default and were routed to China-market loaders that cannot resolve them.
+ (re.compile(r"^[A-Z0-9&.\-]+\.(L|IL)$", re.I), "yahoo"),
# Yahoo futures (GC=F, CL=F) and forex (EURUSD=X) suffix conventions —
# served verbatim by Yahoo's public chart endpoint (#718). Without these,
# such symbols fell through to the ``tushare`` default and were routed to
diff --git a/agent/tests/test_market_detection.py b/agent/tests/test_market_detection.py
index c85f4768a..492f53667 100644
--- a/agent/tests/test_market_detection.py
+++ b/agent/tests/test_market_detection.py
@@ -68,10 +68,14 @@ class TestDetectMarket:
# Korea equity (KRX)
("005930.KS", "kr_equity"), # KOSPI
("247540.KQ", "kr_equity"), # KOSDAQ
- # Canada equity (TSX / TSX Venture)
- ("TD.TO", "ca_equity"),
- ("BBD-B.TO", "ca_equity"),
- ("PNG.V", "ca_equity"),
+# Canada equity (TSX / TSX Venture)
+ ("TD.TO", "ca_equity"),
+ ("BBD-B.TO", "ca_equity"),
+ ("PNG.V", "ca_equity"),
+ # UK / Irish equity (LSE / ISE)
+ ("VOD.L", "uk_equity"),
+ ("SHEL.L", "uk_equity"),
+ ("DCC.IL", "uk_equity"),
# Crypto
("BTC-USDT", "crypto"),
("ETH-USDT", "crypto"),