
    ik                     L   d Z ddlZddlZddlZddlmZmZ  ej                  e      Zej                  j                  ej                  j                  e            Zej                  j                  ed      ZdZdedz  fdZdedefd	Zddedz  d
edefdZdedz  defdZy)u:  
signals_consumer.py — Lecture du cache signal_aggregator pour market_spy.py
Import : from signals_consumer import get_signal_snapshot, signal_log_entry

Usage dans market_spy.py (observation mode) :
    snap = get_signal_snapshot()
    if snap:
        logger.info(f"   📡 Signaux: {signal_log_entry(snap)}")
    N)datetimetimezonezsignal_cache.json   returnc                     	 t         j                  j                  t              syt         j                  j	                  t              } t        j                  t        j                        j                         | z
  }|t        kD  r"t        j                  d|ddt         d       yt        t              5 }t        j                  |      }ddd       h d}|j!                  j#                               st        j                  d       y|S # 1 sw Y   DxY w# t$        $ r"}t        j                  d|        Y d}~yd}~ww xY w)	u   
    Lit le cache JSON écrit par signal_aggregator.py.
    Retourne None si le cache est absent, corrompu ou trop vieux.
    Ne lève jamais d'exception (FAIL_OPEN).
    NzCache signal trop vieux (z.0fzs > zs)>   netflow
funding_oiscore_totalinterpretationzCache signal incompletu    Lecture cache signal échouée: )ospathexists
CACHE_FILEgetmtimer   nowr   utc	timestampCACHE_MAX_AGE_SEClogdebugopenjsonloadissubsetkeys	Exception)mtimeagefdatarequiredes         signals_consumer.pyget_signal_snapshotr$      s    ww~~j)  ,X\\*446>""II1#c$?P>QQSTU* 	 99Q<D	  N  -II./	  	   		4QC89sB   #D BD (D 7DA D D DD 	E%EEsnapc                    | sy| j                  dd      }| j                  dd      }| j                  di       j                  dd      }| j                  di       j                  d	d      }| j                  di       j                  d
d      }| j                  dd      }| j                  d      rdnd}d|dd| d| d|dd|dd|dd|dS )z
    Retourne une ligne de log lisible pour un snapshot signal.
    Ex: "score=13.5/20 (BULLISH) | funding=+0.00800% | netflow=+234500$ (ratio=0.55)"
    zN/Ar
   r   r   ?r	   avg_funding_pctr   net_flow_usd	buy_ratiog      ?size_modulator      ?veto_activeu    ⚠️VETO zscore=z.1fz/20 ()z | funding=z+.5fz% | netflow=z+.0fz	$ (ratio=z.3fu   ) | size_mod=×z.2fget)r%   scoreinterpfundingr   ratiomodvetos           r#   signal_log_entryr8   7   s    
 hh}a(Ehh'-Fhh|R(,,->BGhhy"%)).!<Ghhy"%))+s;Ehh'-C#xx6mBD
s5$ 04. !4.	% 5#Y	     defaultc                 .    | |S | j                  d|      S )u   
    Retourne le modulateur de taille (0.5-1.0) depuis le snapshot.
    Retourne default si snap=None (fail-open).
    NOTE: En observation mode, ce modulateur N'EST PAS appliqué — utilisé seulement pour log.
    r+   r0   )r%   r:   s     r#   get_size_modulatorr<   M   s      |88$g..r9   c                 R    | y| j                  dd      ry| j                  dd      S )zj
    Retourne True si le veto est actif.
    NOTE: En observation mode obs_mode=True, toujours False.
    Fobs_modeTr-   r0   )r%   s    r#   is_veto_activer?   X   s.    
 |xx
D!88M5))r9   )r,   )__doc__r   r   loggingr   r   	getLogger__name__r   r   dirnameabspath__file__
SCRIPT_DIRjoinr   r   dictr$   strr8   floatr<   boolr?    r9   r#   <module>rN      s    
   'g!ggoobggooh78
ggll:':;
 TD[ @4 C ,/TD[ /5 /5 /	* 	* 	*r9   