
    @j%                       d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ  e
e      j                         j                  j                  Zedz  Zed	z  Z G d
 dee      Z G d dee      Zej,                   ej.                  dd      ej0                   ej.                  dd      iZe G d d             ZddZy)u  
APEX V16 — Runtime configuration.

Single source of truth for paths, modes, account selection, and
runtime defaults. Asset-specific config (tick values, contracts)
lives in config_futures.py.

Environment variables (.env) override defaults where applicable.
    )annotationsN)	dataclassfield)Enum)Path)Optionalstatelogsc                      e Zd ZdZdZdZy)RunModedrypaperliveN)__name__
__module____qualname__DRYPAPERLIVE     "/home/work/apex_v16/core/config.pyr   r   !   s    
CEDr   r   c                      e Zd ZdZdZy)AccountKind
ineligibleexpressN)r   r   r   
INELIGIBLEEXPRESSr   r   r   r   r   '   s    JGr   r   TOPSTEP_INELIGIBLE_IDz100KTC-V2-566414-41410336TOPSTEP_EXPRESS_IDzEXPRESS-V2-566414-12462346c                     e Zd ZU dZej
                  Zded<   ej                  Z
ded<   dZded<   d	Zd
ed<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded <   d!Zded"<   d#Zded$<   dZded%<   d&Zded'<   dZded(<   d)Zded*<   d+Zded,<   d-Zded.<   d/Zded0<   d1Z ded2<   d3Z!d4ed5<   dZ"ded6<   d7Z#ded8<   d9Z$ded:<   d;Z%ded<<   d7Z&ded=<   d7Z'ded><   d?Z(ded@<   dAZ)dedB<   dCZ*dDedE<   dFZ+dDedG<    e,dH      Z-dIedJ<    e,dH      Z.dIedK<   dQdLZ/e0dRdM       Z1e0dRdN       Z2e0dSdO       Z3dQdPZ4y	)TRuntimeConfigz~
    Runtime parameters. Built once at startup from CLI + .env.
    Passed by reference to orchestrator and risk_manager.
    r   moder   accountFboolfresh_startNzOptional[list[str]]asset_filterg~jth?floatrisk_per_tradeg     @@daily_profit_target     pdaily_loss_hard_stopg     @daily_loss_soft_stop   intmax_daily_trades   max_open_trades_totalQ?max_risk_vs_daily_budgetg     j@dry_run_balanceenable_correlation   $last_friday_of_month_cutoff_utc_hour   force_flat_utc_hour   force_flat_utc_minuteloop_sleep_secondsg      @scan_loop_phase_offset_secondsmanage_loop_interval_seconds<   !maintenance_loop_interval_secondsg      @candle_close_delay_secondsg      N@candle_max_age_seconds   reconcile_interval_iterations
   mid_loop_reconnect_max_attempts)
r1   rF   r.      rH   r@   r@   r@   x   rI   tuple!mid_loop_reconnect_delays_secondsbroker_degraded_max_minutesg      >@market_data_timeout_secondsg      .@h4_fetch_timeout_secondsg      $@broker_call_timeout_secondswatchdog_timeout_secondsnews_sync_timeout_secondsTmaintenance_heartbeat_enabledi  max_trades_sessionzclaude-haiku-4-5-20251001strai_modelANTHROPIC_API_KEYai_keys_env_prefix)initr   
state_filelog_dirc                
   | j                   j                   d| j                  j                   }t        d| dz  | _        t
        |z  | _        t        j                  dd       | j                  j                  dd       y )N_state_z.jsonT)parentsexist_ok)r#   valuer$   	STATE_DIRrY   LOGS_DIRrZ   mkdir)selfscopes     r   __post_init__zRuntimeConfig.__post_init__   sp    99??#1T\\%7%7$89#ugU&;;%' 	t44$7r   c                <    | j                   t        j                  k(  S N)r#   r   r   rd   s    r   is_livezRuntimeConfig.is_live   s    yyGLL((r   c                <    | j                   t        j                  k(  S rh   )r$   r   r   ri   s    r   
is_expresszRuntimeConfig.is_express   s    ||{2222r   c                (    t         | j                     S rh   )ACCOUNT_IDSr$   ri   s    r   
account_idzRuntimeConfig.account_id   s    4<<((r   c                   | j                   r| j                  syt        d       t        d       t        d| j                          t        d| j                  dz  dd       t        d	| j
                  d       t        d
| j                          t        d       t        d      j                         }|dk7  rt        d      y)z
        Interactive safety check before live trading on EXPRESS (funded).
        Called by main.py before orchestrator starts.
        Nz<============================================================z1WARNING: LIVE TRADING ON EXPRESS (FUNDED) ACCOUNTzAccount ID: zRisk per trade: d   z.2f%zDaily loss hard stop: $zCorrelation enabled: zType EXPRESS to confirm: r   z(Aborted: EXPRESS confirmation not given.)
rj   rl   printro   r)   r,   r6   inputstrip
SystemExit)rd   anss     r   require_express_confirmationz*RuntimeConfig.require_express_confirmation   s    
 hABT__-./ !4!4s!:3 ?qAB'(A(A#'FGH%d&=&=%>?@h/0668)GHH r   )returnNone)ry   r%   )ry   rT   )5r   r   r   __doc__r   r   r#   __annotations__r   r   r$   r&   r'   r)   r*   r,   r-   r0   r2   r4   r5   r6   r8   r:   r<   r=   r>   r?   rA   rB   rC   rE   rG   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rU   rW   r   rY   rZ   rf   propertyrj   rl   ro   rx   r   r   r   r"   r"   :   s   
 MMD'!&11G[1K )-L%, "NE!!''")%)")%) c!"3"&*e* 'OU&  %$02(#2!!!"3" !  -0"E/(* #*-/%s/ ),+$(E( *+!3* ,.#S-/X%uX (*) *.-&*e*)--&*e*'+u+ +/!4. "! 0Hc/11 %(J(u%GT%8 ) ) 3 3 ) )Ir   r"   c                >    d| _         d| _        d| _        d| _        | S )z
    Returns a tightened copy of cfg suitable for funded trading.
    Caller decides whether to use it (e.g., main.py applies by default
    when --account express is selected).
    g~jtX?Tr3   r+   )r)   r6   r4   r,   )cfgs    r   apply_express_profiler      s)      C!C#'C &CJr   )r   r"   ry   r"   )r{   
__future__r   osdataclassesr   r   enumr   pathlibr   typingr   __file__resolveparentPROJECT_ROOTra   rb   rT   r   r   r   getenvr   rn   r"   r   r   r   r   <module>r      s    # 	 (    H~%%'..557"	& c4 #t  IBII&='BDIBII&:'CE VI VI VI|
r   