
    9>j                       d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ e	d         Z ed           G d	 d
                      Z ed           G d d                      Z ed           G d d                      Z ed           G d d                      Z ed           G d d                      Z ed           G d d                      ZddZddZdS )    )annotations)	dataclassfield)Decimal)AnyLiteral)OrderIntent)v76_anti_chasemarket_regimecopycopy_confirmationresearch_samplerT)frozenc                  b    e Zd ZU ded<   ded<   dZded<   edd            Zedd	            Zd
S )MarketRegimeContextstr	btc_trend	eth_trendFboolchoppyreturnc                >    | j          o| j        dk    o
| j        dk    S )Nbullishr   r   r   selfs    [/home/agent/projects/CryptoTradingBot/Crypto_Agent/src/strategies/global_strategy_policy.pylong_allowedz MarketRegimeContext.long_allowed   %    ;^4>Y#>^4>U^C^^    c                >    | j          o| j        dk    o
| j        dk    S )Nbearishr   r   s    r   short_allowedz!MarketRegimeContext.short_allowed   r   r    Nr   r   )__name__
__module____qualname____annotations__r   propertyr   r#    r    r   r   r      s         NNNNNNF_ _ _ X_ _ _ _ X_ _ _r    r   c                  Z    e Zd ZU ded<   ded<   ded<   ded<   ded<   edd	            Zd
S )CopyObservationEvidenceintcycles_completedexpected_cyclesallowed_signalsshadow_decisionsr   data_quality_okr   c                8    | j         dk    o| j        | j         k    S )Nr   )r/   r.   r   s    r   completez CopyObservationEvidence.complete)   s     #a'YD,ATEY,YYr    Nr$   )r%   r&   r'   r(   r)   r4   r*   r    r   r,   r,   !   sv         Z Z Z XZ Z Zr    r,   c                  |    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded	<   ded
<   dZded<   dZded<   dS )PromotionEvidencer-   closed_tradesr   total_net_pnllast_20_net_pnlwin_rate_pctprofit_factortop_coin_share_pctshort_scalp_share_pctmax_drawdown_usdFr   replay_onlyTsimulator_sanity_okN)r%   r&   r'   r(   r?   r@   r*   r    r   r6   r6   .   s         """"K $$$$$$$r    r6   c                      e Zd ZU ded<   ded<   ded<   ded<    ed	          Zd
ed<   dZded<   dZded<   dZded<    ed          Z	d
ed<   dZ
ded<   dS )StrategyCandidater   strategy_idStrategyFamilyfamilyzOrderIntent | Noneintentr6   	promotion0r   expected_move_vs_costFr   anti_chase_okretest_confirmedcopy_confirmation_ok1max_effective_leverage   r-   max_open_positionsN)r%   r&   r'   r(   r   rI   rJ   rK   rL   rN   rP   r*   r    r   rB   rB   <   s             %,WS\\1111M"""""!&&&&&&-gcll2222r    rB   c                  Z    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<   d
Zded<   dS )GlobalStrategyContextr   r   r,   copy_observationr   reconcile_cleanstops_confirmedalerts_confirmedkill_switch_activeTlive_entries_blockedN)r%   r&   r'   r(   rX   r*   r    r   rR   rR   J   sl         &&&&----!%%%%%%%r    rR   c                  ^    e Zd ZU ded<   ded<   ded<   dZded<    ee	          Zd
ed<   dS )GlobalStrategyDecisionr   allowedr   statusrecommended_moder*   ztuple[str, ...]reasons)default_factoryzdict[str, Any]risk_limitsN)r%   r&   r'   r(   r^   r   dictr`   r*   r    r   rZ   rZ   U   s_         MMMKKK!G!!!!"'%"="="=K======r    rZ   evidencer   	list[str]c                x   g }| j         dk     r|                    d           | j        dk    r|                    d           | j        dk    r|                    d           | j        t          d          k     r-| j        t          d          k     r|                    d           | j        t          d	          k    r|                    d
           | j        t          d          k    r|                    d           | j	        r|                    d           | j
        s|                    d           |S )N   sample_too_smallr   paper_total_pnl_not_positivelast_20_not_positive45z1.25$winrate_and_profit_factor_below_gate35coin_concentration25short_scalp_dominancereplay_only_not_promotablesimulator_sanity_failed)r7   appendr8   r9   r:   r   r;   r<   r=   r?   r@   )rb   r^   s     r   _promotion_blockersrr   ^   s4   G"")***""56661$$-...wt}},,1G'RX//1Y1Y=>>>"WT]]22+,,,%55./// 53444' 20111Nr    	candidatecontextc                |   g | j         }|                    d           n{|j        j        r                    d           nY|j        dk    r"|j        j        s                    d           n,|j        dk    r!|j        j        s                    d           | j        dk    rh|j        j	        d	k    r                    d
           |j        j
        s                    d           |j        j        s                    d           n| j        dk    r| j        s                    d           ne| j        t          d          k     r                    d           | j        s                    d           | j        s                    d                               t%          | j                             |j        s                    d           |j        s                    d           |j        s                    d           |j        r                    d           | j        t          d          k    r                    d           | j        dk    r                    d            }|r0t5          dddt7          | j                  | j        dddd          S | j        dk    rd }d!}n:t9          fd"d#D                       rd$}d%}nd$}t%          | j                  sd&nd!}t5          d'||t;          t<                                                  ddd'd()          S )*aS  Evaluate whether a strategy may progress from research/paper to tiny live preview.

    This is intentionally conservative. It combines the hard lessons from live fills,
    paper artefact reviews, copy observation, and v76 paper work into one no-trade-first
    gate. It never executes orders; it only returns a decision and reasons.
    Nno_order_intentmarket_regime_choppy_no_tradebuymarket_regime_blocks_longsellmarket_regime_blocks_shortr   r   'copy_observation_has_no_allowed_signalscopy_observation_incompletecopy_data_quality_not_okr   copy_confirmation_missing4expected_move_below_cost_hurdleanti_chase_not_confirmedretest_not_confirmedreconcile_not_cleanstops_not_confirmedalerts_not_confirmedrW   rM   leverage_above_tiny_live_caprO   too_many_initial_open_positionsTtiny_live_preview_readytiny_live_preview)rN   rP   daily_loss_cap_required$reduce_only_stop_required_after_fillno_averaging_down)r[   r\   r]   r`   copy_research_onlyresearchc              3      K   | ]}|v V  	d S )Nr*   ).0rr^   s     r   	<genexpr>z+evaluate_global_strategy.<locals>.<genexpr>   s?        A  AaQ'\  A  A  A  A  A  Ar    )r   r   r   rW   paper_shadow_onlyblockedrs   F)rN   rP   live_entries_allowed)r[   r\   r]   r^   r`   ) rF   rq   r   r   sider   r#   rE   rS   r0   r4   r2   rL   rI   r   rJ   rK   extendrr   rG   rT   rU   rV   rW   rN   rP   rZ   r   anytuplera   fromkeys)rs   rt   rF   r[   moder\   r^   s         @r   evaluate_global_strategyr   s   s    GF~()))) ' 	9NN:;;;;[E!!'*?*L!NN67777[F""7+@+N"NN78886!! #3q88NNDEEE'0 	:NN8999'7 	7NN5666		0	0	0- 	8NN6777*WS\\99NN<===& 	7NN5666) 	3NN1222NN&y':;;<<<" .,---" .,---# /-...! -+,,,''#,,665666#a''8999kG 
%,0*-i.N*O*O&/&B+/8<%) 	
 
 
 	
 6!!#	  A  A  A  A#  A  A  A  
A  
A ]""$7	8K$L$L\R\!dmmG,,--&)"#$)
 

 
 
 
r    N)rb   r6   r   rc   )rs   rB   rt   rR   r   rZ   )
__future__r   dataclassesr   r   decimalr   typingr   r   src.execution.order_intentr	   rD   r   r,   r6   rB   rR   rZ   rr   r   r*   r    r   <module>r      sN   " " " " " " ( ( ( ( ( ( ( (               2 2 2 2 2 2 $_ _ _ _ _ _ _ _ $	Z 	Z 	Z 	Z 	Z 	Z 	Z 	Z $
% 
% 
% 
% 
% 
% 
% 
% $
  
  
  
  
  
  
  
  $& & & & & & & & $> > > > > > > >   *\ \ \ \ \ \r    