
    zCj	                     j    d Z ddlZddlZddlZddlmZ ddlmZ  G d d          Z ee          Z	dS )u  
Symbol synonym resolution.

The EA always sends whatever MQL5's _Symbol reports for the chart it's
running on — which, for a Pepperstone-connected terminal, should already
BE the Pepperstone designation in the normal case. This resolver exists
for the cases where it isn't an exact match:

  - A different broker connection is ever used for testing/comparison
    (different symbol naming/suffixes, e.g. "USDJPY.a" vs "USDJPY").
  - Human-friendly aliases someone might reference when manually
    publishing params (e.g. "NASDAQ" instead of whatever Pepperstone
    actually calls it).
  - Minor naming drift between what the walk-forward Python pipeline
    calls an instrument internally vs. what the broker calls it.

Resolution rule: if the incoming symbol has an explicit entry in the
synonym table, use the canonical value it maps to. If it has NO entry,
assume the incoming symbol already IS canonical (identity fallback) —
this matches the common case where the EA's _Symbol already matches
Pepperstone's own naming directly, so most instruments may need no entry
in this table at all.

File format (data/symbol_synonyms.json):
{
  "_comment": "alias -> canonical Pepperstone designation",
  "NASDAQ": "NAS100",
  "GOLD": "XAUUSD",
  "SILVER": "XAGUSD",
  "USDJPY.a": "USDJPY"
}
    N)Dict)SYMBOL_SYNONYMS_PATHc                   0    e Zd ZdefdZd ZdedefdZdS )SymbolResolverpathc                     || _         t          j                    | _        d | _        i | _        |                                  d S N)_path	threadingLock_lock_mtime_table_load)selfr   s     '/wd/td-params-server/symbol_resolver.py__init__zSymbolResolver.__init__+   s7    
^%%
&(

    c                    t           j                            | j                  si | _        d | _        d S t           j                            | j                  }|| j        k    rd S t          | j        dd          5 }t          j	        |          }d d d            n# 1 swxY w Y   d |
                                D             | _        || _        d S )Nrzutf-8)encodingc                 D    i | ]\  }}|                     d           ||S )_)
startswith).0kvs      r   
<dictcomp>z(SymbolResolver._load.<locals>.<dictcomp>=   s?     
 
 
QS0A0A
q
 
 
r   )osr   existsr
   r   r   getmtimeopenjsonloaditems)r   mtimefhraws       r   r   zSymbolResolver._load2   s   w~~dj)) 	DKDKF  ,,DKF$*cG444 	 )B--C	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 
 
 YY[[
 
 
 s   =BB"%B"incoming_symbolreturnc                     | j         5  |                                  | j                            ||          cd d d            S # 1 swxY w Y   d S r	   )r   r   r   get)r   r)   s     r   resolvezSymbolResolver.resolveB   s     Z 	E 	EJJLLL;???ODD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es   /AAAN)__name__
__module____qualname__strr   r   r-    r   r   r   r   *   sh        S       Es Es E E E E E Er   r   )
__doc__r#   r   r   typingr   configr   r   resolverr2   r   r   <module>r7      s    B  				           ' ' ' ' ' 'E E E E E E E E@ >.//r   