"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(backtest): route BASE-USDT-PERP perpetuals to the crypto market
Jackzigen7fa444d34862
diff --git a/agent/backtest/engines/_market_hooks.py b/agent/backtest/engines/_market_hooks.pyindex bde045d62..969e875c3 100644--- a/agent/backtest/engines/_market_hooks.py+++ b/agent/backtest/engines/_market_hooks.py@@ -120,6 +120,14 @@ _MARKET_PATTERNS = [# the class stays broad to admit fund certificates and ETF codes.(re.compile(r"^[A-Z0-9]+\.VN$", re.I), "vietnam_equity"),(re.compile(r"^[A-Z]+-USDT$", re.I), "crypto"),+ # USD-M perpetuals in their documented BASE-USDT-PERP spelling+ # (ccxt_loader._parse_ccxt_symbol / binance_loader). Without this entry+ # the symbol matched nothing above and fell through to the a_share+ # default, so a leveraged perpetual ran under China A-share rules+ # (100-share board-lot rounding) and every computed size rounded to a+ # zero_size rejection (#1863). Base alphabet matches the loader's own+ # ``([A-Z0-9]+)-USDT-PERP`` fullmatch.+ (re.compile(r"^[A-Z0-9]+-USDT-PERP$", re.I), "crypto"),(re.compile(r"^[A-Z]+/USDT$", re.I), "crypto"),# yfinance's native crypto spelling (BTC-USD, ETH-USD). Distinct from# USDT pairs only in the quote currency; both belong to CryptoEngine.diff --git a/agent/tests/test_equity_crypto_suffix_regressions.py b/agent/tests/test_equity_crypto_suffix_regressions.pyindex 37a5f293e..9b53284d0 100644--- a/agent/tests/test_equity_crypto_suffix_regressions.py+++ b/agent/tests/test_equity_crypto_suffix_regressions.py@@ -48,6 +48,29 @@ def test_shared_engine_recognizes_known_slash_usd_crypto(symbol):assert _detect_market(symbol) == "crypto"+ "symbol",+ [+ "BTC-USDT-PERP",+ "ETH-USDT-PERP",+ # Numeric bases are legal on Binance USD-M (1000PEPE, 1MBABYDOGE)+ # and ccxt_loader's own fullmatch allows [A-Z0-9]+ for the base.+ "1000PEPE-USDT-PERP",+ "1MBABYDOGE-USDT-PERP",+ ],+)+def test_usdm_perpetual_symbols_route_to_crypto(symbol):+ """BASE-USDT-PERP must run under CryptoEngine, not the a_share default.++ Before #1863's fix the perpetual spelling matched no pattern, fell+ through to ``a_share``, and the 100-share board-lot rounding turned+ every computed size into a zero_size rejection.+ """+ from backtest.engines._market_hooks import _detect_market++ assert _detect_market(symbol) == "crypto"++@pytest.mark.parametrize("symbol, expected",[