"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
Merge PR #481: feat: MetaTrader 5 (Exness) broker connector + mt5 market-data source
Haozhe Wu11b4f623405f
diff --cc CHANGELOG.mdindex a67bdc1ef,13535c9f1..137e7c056--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -6,33 -6,21 +6,48 @@@ This project adheres to [Semantic Versi## [Unreleased]### Added+- **User swarm-presets directory**: preset YAMLs dropped into+ `~/.vibe-trading/swarm/presets/` are discovered alongside the bundled+ roster (same-name files override it — the same rule as user skills) and+ survive `pip install -U`. `list_presets()` entries now carry a+ `source: "user" | "bundled"` field; explicitly named user presets run+ through `run_swarm(preset_name=...)`, while keyword auto-routing stays+ limited to the curated table. Preset names are validated to a single path+ segment before any filesystem lookup.+- **Security hardening**: all 10 findings from the 2026-07-10 external audit+ closed (#476, tracking discussion #468) — Docker multi-stage rebuild with+ digest-pinned base images, AST-hardened backtest sandbox (blocks+ network/subprocess/eval/os.environ/unsafe-open reachable from generated+ code, including inside nested function bodies), short-lived single-use SSE+ auth tickets replacing a long-lived key in the URL/logs, hardened Compose+ (`read_only`, dropped capabilities, `no-new-privileges`, resource limits),+ auth + rate limiting on `/correlation`, security headers (CSP+ Report-Only, `X-Content-Type-Options`, `Permissions-Policy`), `/live` ++ `/ready` health split, hash-locked dependencies wired into the Docker+ build, GitHub Actions pinned by commit SHA, and an HMAC-authenticated+ factor cache.+- Opt-in **TAP mode** for Alpaca (#377, thanks @0xZKnw) — routes all broker+ egress through a self-hosted TAP proxy so the agent process never holds+ the raw API key, with writes blocking on human approval.+- Realized portfolio turnover (`avg_turnover` / `total_turnover`) surfaced+ in backtest metrics for every optimizer (#478, thanks @Robin1987China).+- **Frazzini-Pedersen betting-against-beta** academic factor (#480, thanks+ @YogeshModi24) — Alpha Zoo: 460 → **461**.+ - **MetaTrader 5 connector + data source** (Exness-style MT5 brokers,+ Windows-only `pip install "vibe-trading-ai[mt5]"`). Broker connectors:+ 11 → **12** — full read surface plus order placement against a locally+ running terminal, with a bidirectional identity guard (paper profile ⇔+ demo `trade_mode`, login pinned, contest rejected), connector-level+ `max_order_volume`/`max_order_notional_usd` guards on demo AND live, and+ hedging-safe position close by ticket. The live mandate gate gains+ `forex`/`cfd` instrument vocabulary (schema v1 unchanged) and a lot-aware+ `quantity_notional_usd` sizing hook so USD caps bind on lot-sized orders+ (0.1 lot EURUSD ≈ $10,800, never 0.1 × quote). Market-data sources:+ 20 → **21** — the `mt5` loader heads the forex fallback chain (broker-exact+ symbols with Exness suffix discovery, 1m–1D bars), `get_market_data` learns+ forex/metal symbol routing (`EUR/USD`, `XAUUSD.FX` previously fell through+ to tushare), and akshare's forex path accepts the canonical slash form so+ degradation off-Windows keeps working.- **Strategy Development Manager** skill (#457, thanks @shadowinlife, closes#455) — `sdm_register` / `sdm_status` / `sdm_decay_scan` turn academicpapers and broker research into registered factors/strategies with adiff --cc README_zh.mdindex 574c2b4ae,c0bc9a5b8..fae3a708a--- a/README_zh.md+++ b/README_zh.md@@@ -332,41 -318,12 +333,42 @@@ vibe-trading run -p "Analyze my tradin**Fallback 链(按被封 IP 风险排序):**- **A股** → `tencent` · `mootdx` · `eastmoney` · `baostock` · `akshare` · `tushare` · `local`-- **美股** → `yahoo` · `stooq` · `sina` · `eastmoney` · `yfinance` · `tiingo` · `fmp` · `finnhub` · `alphavantage` · `akshare` · `local`-- **港股** → `eastmoney` · `yahoo` · `futu` · `yfinance` · `akshare` · `local`+- **美股** → `yahoo` · `stooq` · `sina` · `eastmoney` · `yfinance` · `tiingo` · `fmp` · `finnhub` · `alphavantage` · `longbridge` · `akshare` · `local`+- **港股** → `eastmoney` · `yahoo` · `futu` · `yfinance` · `akshare` · `longbridge` · `local`- **印度(NSE/BSE)** → `yahoo` · `yfinance` · `india_broker` · `local`- - **加密** → `okx` · `ccxt` · `yfinance` · `local` · *(期货 / 基金 / 宏观 / 外汇 → `tushare`/`akshare` → `local`)*+ - **加密** → `okx` · `ccxt` · `yfinance` · `local` · *(期货 / 基金 / 宏观 → `tushare`/`akshare` → `local`)*+ - **外汇/贵金属** → `mt5` · `akshare` · `yfinance` · `local`+### 显式使用长桥++Longbridge 是可选的美股/港股历史 OHLCV 数据源。安装 SDK:++```bash+pip install "vibe-trading-ai[longbridge]"+```++在 `.env` 配置三个凭证:++```dotenv+LONGBRIDGE_APP_KEY=...+LONGBRIDGE_APP_SECRET=...+LONGBRIDGE_ACCESS_TOKEN=...+```++回测时在 `config.json` 指定:++```json+{+ "codes": ["QQQ.US"],+ "start_date": "2025-01-01",+ "end_date": "2025-01-10",+ "interval": "1D",+ "source": "longbridge"+}+```++与 Agent 对话时可以直接说:**“用长桥获取 QQQ.US 的历史行情。”** 显式指定数据源与 `source: "auto"` 不同;`auto` 仍按正常的同市场 fallback 链选择数据源。+除 OHLCV 外,**18 个只读数据工具**深入基本面与资金面——资金流、龙虎榜、北向、两融、大宗交易、股东户数、解禁、板块、研报、新闻、SEC 文件、财务报表、期权链、机构持仓、全市场筛选、代码搜索、宏观——全部经 MCP 暴露。显式 `local:` 源永不静默 fallback 到网络源。<!-- QVERIS-START -->diff --cc agent/backtest/loaders/registry.pyindex 7e1c360c4,a0d93752b..4cb97d9ed--- a/agent/backtest/loaders/registry.py+++ b/agent/backtest/loaders/registry.py@@@ -51,7 -50,7 +51,8 @@@ VALID_SOURCES: set[str] ="fmp","qveris", # QVERIS-INTEGRATION"india_broker",+ "longbridge",+ "mt5","local","auto",}@@@ -99,7 -97,7 +100,8 @@@ def _ensure_registered() -> None"backtest.loaders.fmp_loader","backtest.loaders.qveris_loader", # QVERIS-INTEGRATION"backtest.loaders.india_broker_loader",+ "backtest.loaders.longbridge",+ "backtest.loaders.mt5_loader","backtest.loaders.local_loader",]import importlibdiff --cc agent/src/market_data.pyindex 01153ffd0,db90087d3..06856d955--- a/agent/src/market_data.py+++ b/agent/src/market_data.py@@@ -26,14 -26,14 +26,20 @@@ _SOURCE_PATTERNS =# India: NSE (RELIANCE.NS) / BSE (500325.BO). Tickers may carry '&' and '-'# (e.g. M&M.NS, BAJAJ-AUTO.NS). Served by Yahoo's public chart endpoint.(re.compile(r"^[A-Z0-9&.\-]+\.(NS|BO)$", 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+ # China-market loaders that cannot resolve them.+ (re.compile(r"^[A-Z0-9]+=F$", re.I), "yahoo"),+ (re.compile(r"^[A-Z]+=X$", re.I), "yahoo"),(re.compile(r"^[A-Z]+-USDT$", re.I), "okx"),(re.compile(r"^[A-Z]+/USDT$", re.I), "ccxt"),+ # Forex pairs and metals (EUR/USD, XAU/USD, EURUSD.FX). mt5 is the head of+ # the forex chain and degrades to akshare/yfinance via the registry when no+ # local MT5 terminal is attached. The 3-letter quote cannot collide with+ # the 4-letter /USDT crypto rule above.+ (re.compile(r"^[A-Z]{3}/[A-Z]{3}$", re.I), "mt5"),+ (re.compile(r"^[A-Z]{6}\.FX$", re.I), "mt5"),]diff --cc agent/tests/test_market_data.pyindex d1e12bc67,5e157475d..3737d261d--- a/agent/tests/test_market_data.py+++ b/agent/tests/test_market_data.py@@@ -46,13 -46,11 +46,17 @@@ from src.market_data import("500325.BO", "yahoo"), # India BSE (numeric scrip code)("BTC-USDT", "okx"),("ETH/USDT", "ccxt"),+ ("EUR/USD", "mt5"), # forex pair → mt5 chain head (registry fallback)+ ("XAU/USD", "mt5"), # metals share the forex route+ ("EURUSD.FX", "mt5"),+ ("XAUUSD.FX", "mt5"),("local:my_file", "local"),+ # Yahoo futures / forex suffix conventions (#718) — must not fall to the+ # ``tushare`` default (which routed them to China-market loaders).+ ("GC=F", "yahoo"), # gold future+ ("CL=F", "yahoo"), # crude future+ ("EURUSD=X", "yahoo"), # forex pair+ ("JPY=X", "yahoo"),("something_weird", "tushare"), # documented fallback],)diff --cc pyproject.tomlindex cedcdd55e,ec8768591..664c7e6f6--- a/pyproject.toml+++ b/pyproject.toml@@@ -97,9 -97,12 +97,15 @@@ include = ["src*", "backtest*", "cli*"ibkr = ["ib_async>=2.0",]+longbridge = [+ "longbridge>=0.2.5",+]+ mt5 = [+ # Official Windows-only bridge to a locally running MetaTrader 5 terminal+ # (broker connector + mt5 data loader). Lazy-imported; on other platforms+ # the marker makes this a no-op and everything degrades gracefully.+ "MetaTrader5>=5.0.45; sys_platform == 'win32'",+ ]deepseek = ["langchain-deepseek>=1.0.0,<2",]