Files
2026-07-06 21:58:56 +08:00

28 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Root symbol alias resolver (pure lookup, no auto-switching).
用户视角的"逻辑品种"(如 XAUUSD)映射到 MT5 里实际使用的品种。
ponytail:
- 没有别名表 / 没条目 -> 原样返回(零行为变化,向后兼容)
- 有条目 -> 一比一映射,写啥用啥,不做任何基于日期/优化/周期的判断
- 升级路径:要从 yaml 切到数据库 / MT5 SymbolSelect 校验,只改这里
配置示例(ea_configs.yaml:
symbol_aliases:
XAUUSD: XAUUSDc # 逻辑 XAUUSD -> 实际 XAUUSDc
XAGUSD: XAGUSDm # 逻辑 XAGUSD -> 实际 XAGUSDm
# EURUSD 没列 -> 始终 EURUSD
"""
from typing import Any, Dict
def resolve_symbol(symbol: str, bt_settings: Dict[str, Any]) -> str:
"""逻辑品种 -> 实际 MT5 品种。无任何自动判断,按表直查。"""
if not symbol:
return symbol
aliases = bt_settings.get("symbol_aliases") or {}
mapped = aliases.get(symbol)
if not mapped: # None / "" / 缺失 -> 直通
return symbol
return mapped