def _extract_group_path(sym) -> str:
"""Extract pure group path from a symbol, stripping the symbol name if present.
MT5 sometimes reports `symbol.path` including the symbol at the tail. This trims the
last component when it equals the symbol name (case-insensitive).
"""
raw = getattr(sym, 'path', '') or ''
name = getattr(sym, 'name', '') or ''
if not raw:
return 'Unknown'
parts = raw.split('\\')
if parts and name and parts[-1].lower() == name.lower():
parts = parts[:-1]
group = '\\'.join(parts).strip('\\')
return group or 'Unknown'