From 7b576d8a2c87646093a68031e2c80cbdac773bfd Mon Sep 17 00:00:00 2001 From: chrisnov-it Date: Tue, 23 Jun 2026 15:32:33 +0800 Subject: [PATCH] Fix symbol mapping bug + filling mode for XM broker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - find_mt5_symbol: broker-specific priority (XM/MetaQuotes/Exness/etc) was overwriting symbol_variants for ALL symbols, not just XAUUSD. EURUSD/GBPUSD/etc were being mapped to GOLD on XM broker. Fixed by guarding with base_symbol_cleaned == 'XAUUSD' check. - place_trade: ORDER_FILLING_FOK → ORDER_FILLING_IOC for broker compatibility (XM and most forex brokers use IOC, not FOK). Co-Authored-By: Claude --- core/mt5/trade.py | 4 ++-- core/utils/mt5.py | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/mt5/trade.py b/core/mt5/trade.py index ca7cc6c..b37ba3f 100644 --- a/core/mt5/trade.py +++ b/core/mt5/trade.py @@ -112,7 +112,7 @@ def place_trade(symbol, order_type, risk_percent, sl_atr_multiplier, tp_atr_mult "magic": magic_id, "comment": "QuantumBotX Trade", "type_time": mt5.ORDER_TIME_GTC, - "type_filling": mt5.ORDER_FILLING_FOK, + "type_filling": mt5.ORDER_FILLING_IOC, } result = mt5.order_send(request) @@ -137,7 +137,7 @@ def close_trade(position): request = { "action": mt5.TRADE_ACTION_DEAL, "position": position.ticket, "symbol": position.symbol, "volume": position.volume, "type": close_order_type, "price": price, "magic": position.magic, - "comment": "QuantumBotX Close", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_FOK, + "comment": "QuantumBotX Close", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC, } result = mt5.order_send(request) diff --git a/core/utils/mt5.py b/core/utils/mt5.py index 3274ed2..d4a4470 100644 --- a/core/utils/mt5.py +++ b/core/utils/mt5.py @@ -178,22 +178,24 @@ def find_mt5_symbol(base_symbol: str) -> Optional[str]: if base_symbol_cleaned in BROKER_SYMBOL_MAP: symbol_variants = BROKER_SYMBOL_MAP[base_symbol_cleaned] - # Prioritize based on broker + # Broker-specific priority (only for XAUUSD/GOLD variants) + # IMPORTANT: guard with base_symbol_cleaned check to avoid + # overwriting symbol_variants for EURUSD, GBPUSD, etc. if 'XM' in broker_name: - # XM Global: prioritize GOLD, GOLDmicro - symbol_variants = ['GOLD', 'GOLDmicro', 'XAUUSD'] + [s for s in symbol_variants if s not in ['GOLD', 'GOLDmicro', 'XAUUSD']] + if base_symbol_cleaned == 'XAUUSD': + symbol_variants = ['GOLD', 'GOLDmicro', 'XAUUSD'] + [s for s in symbol_variants if s not in ['GOLD', 'GOLDmicro', 'XAUUSD']] elif 'DEMO' in broker_name or 'METAQUOTES' in broker_name: - # MetaTrader Demo: prioritize XAUUSD - symbol_variants = ['XAUUSD', 'GOLD'] + [s for s in symbol_variants if s not in ['XAUUSD', 'GOLD']] + if base_symbol_cleaned == 'XAUUSD': + symbol_variants = ['XAUUSD', 'GOLD'] + [s for s in symbol_variants if s not in ['XAUUSD', 'GOLD']] elif 'EXNESS' in broker_name: - # Exness: prioritize XAUUSDm, GOLD - symbol_variants = ['XAUUSDm', 'GOLD', 'XAUUSD'] + [s for s in symbol_variants if s not in ['XAUUSDm', 'GOLD', 'XAUUSD']] + if base_symbol_cleaned == 'XAUUSD': + symbol_variants = ['XAUUSDm', 'GOLD', 'XAUUSD'] + [s for s in symbol_variants if s not in ['XAUUSDm', 'GOLD', 'XAUUSD']] elif 'ALPARI' in broker_name: - # Alpari: prioritize XAUUSD.c - symbol_variants = ['XAUUSD.c', 'XAUUSD'] + [s for s in symbol_variants if s not in ['XAUUSD.c', 'XAUUSD']] + if base_symbol_cleaned == 'XAUUSD': + symbol_variants = ['XAUUSD.c', 'XAUUSD'] + [s for s in symbol_variants if s not in ['XAUUSD.c', 'XAUUSD']] elif 'FBS' in broker_name: - # FBS: typically uses standard naming - symbol_variants = ['XAUUSD', 'GOLD'] + [s for s in symbol_variants if s not in ['XAUUSD', 'GOLD']] + if base_symbol_cleaned == 'XAUUSD': + symbol_variants = ['XAUUSD', 'GOLD'] + [s for s in symbol_variants if s not in ['XAUUSD', 'GOLD']] # Test each variant in priority order for variant in symbol_variants: