
    !Sj                        d dl mZ d dlZd dlmc mZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZ dd	Zd
 Zd Zd Zd ZdS )    )annotationsN)replace)Decimal)TrendRetestFeatures)MOMENTUM_RESEARCH_IDMOMENTUM_VERSIONbuild_momentum_intentmomentum_blockersreturnr   c                    t          dAi dddt          d          ddddd	t          d
          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          dt          d          d t          d!          d"t          d#          d$t          d%          d&t          d'          d(t          d)          d*t          d+          d,t          d-          d.t          d/          d0t          d/          d1t          d-          d2t          d-          d3t          d4          d5t          d6          d7t          d8          d9d:d;d<d=t          d>          d?d@}t          |fi | S )BNcoinETHcurrent_price102	candle_ts   data_window_idw1open_15mz101.5high_15mz102.2low_15mz101.3	close_15mmove_15m_pctz0.49move_1h_pctz1.20sma_1h_fast101sma_1h_slow99sma_4h_fast98sma_4h_slow96atr_pctz0.70rsi_15m64
volume_24h80000000volume_ratioz1.15recent_highz101.8
recent_lowz99.5pullback_from_high_pctz-0.20rebound_from_low_pctz2.51
spread_pctz0.02bid_depth_notional_550000ask_depth_notional_5buy_impact_1k_pctsell_impact_1k_pctfunding_rate_hourly_pctz0.001open_interest1000premium_pct0strength_rank   weakness_rank   breadth_positive_pct75continuation_closes_confirmedT )r   r   r   )changesbases     a/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_relative_strength_momentum_v77_2.py_featurerC      s      U")%...<?CPTPT!!!,3G,<,<,<FMgFVFVFVbijobpbpbp V___ 3:&/// ENNN	 18	 LSSW===	 gnnrfsfsfs	
 
 *1
 DK:CVCVCV
 fmmsetetet G$$$ 29 ZaahYiYiYi AH  IO  AP  AP  AP 6??? :A9I9I9I ahho`p`p`p "&/// ?Ffooo hoovgwgwgw fooo 4;3<<< PQq ab`a y@  AE  yF  yF  yF '+dD 4##7###    c                 P   t                      } t          |           }g }||k    }|st          j        d|fd||f          dt	          j                    v st          j        t                    rt          j        t                    nddt	          j                    v st          j        |           rt          j        |           ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}}t          | d	          }d }||u}|st          j        d
|fd||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          dz  }dd|iz  }	t          t          j	        |	                    d x}}|j        }|t          k    }
|
st          j        d|
fd|t          f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          dt	          j                    v st          j        t                    rt          j        t                    nddz  }dd|iz  }t          t          j	        |                    d x}}
|j        }d}||k    }
|
st          j        d|
fd||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |          dz  }	dd|	iz  }t          t          j	        |                    d x}x}
}|j        }d}t          |          }||k    }
|
st          j        d|
fd||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          dt	          j                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}
x}}|j        }d }t          |          }||k    }
|
st          j        d!|
fd"||f          dt	          j                    v st          j        |          rt          j        |          ndt          j        |          dt	          j                    v st          j        t                    rt          j        t                    ndt          j        |          t          j        |          dz  }dd|iz  }t          t          j	        |                    d x}x}
x}}d#}t"          |k    }|st          j        d|fd$t"          |f          d%t	          j                    v st          j        t"                    rt          j        t"                    nd%t          j        |          dz  }dd|iz  }	t          t          j	        |	                    d x}}d S )&N)==)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sr
   feature)py0py1py3py6zassert %(py8)spy8m1)client_order_id)is not)z%(py0)s is not %(py3)sintent)rH   rJ   assert %(py5)spy5)z3%(py2)s
{%(py2)s = %(py0)s.strategy_id
} == %(py4)sr   )rH   py2py4zassert %(py6)srK   buy)z,%(py2)s
{%(py2)s = %(py0)s.side
} == %(py5)s)rH   rS   rR   zassert %(py7)spy710)z\%(py2)s
{%(py2)s = %(py0)s.estimated_notional_usd
} == %(py8)s
{%(py8)s = %(py4)s(%(py6)s)
}r   )rH   rS   rT   rK   rL   zassert %(py10)spy10z0.075)<=)zN%(py2)s
{%(py2)s = %(py0)s.risk_usd
} <= %(py8)s
{%(py8)s = %(py4)s(%(py6)s)
}zv77.2.0)z%(py0)s == %(py3)sr   )rC   r
   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr	   strategy_idr   sideestimated_notional_usdr   risk_usdr   )rG   @py_assert2@py_assert5@py_assert4@py_format7@py_format9rP   @py_assert1@py_format4@py_format6@py_assert3@py_format5@py_format8@py_assert7@py_format11s                  rB   Ftest_momentum_candidate_accepts_strong_non_overheated_eth_continuationrs      s%   jjGW%%++%++++++++++%++++++++++++++++++++++++++++++W+++++W++++++%+++++++++++++++++++++++++++++++"7DAAAF66665!55555555555!5555555555555655555655555555555555555!555555!5555555555555555555555555555;%;%;%66;%(9D9GDMM9(M9999999999(M9999999999996999996999999(99999999999G99999G999999D9999M99999999999999999999999999999?.g.gg...?...........?.............6.....6......?...........g.....g......g..................................((y((((((((((y(((((((((((((((((((((((y(((((((((((((((((((((((((((rD   c                 0   t          t          dt          d          d                    } d}|| v }|st          j        d|fd|| f          t          j        |          dt          j                    v st          j        |           rt          j        |           ndd	z  }d
d|iz  }t          t          j
        |                    d x}}d}|| v }|st          j        d|fd|| f          t          j        |          dt          j                    v st          j        |           rt          j        |           ndd	z  }d
d|iz  }t          t          j
        |                    d x}}d}|| v }|st          j        d|fd|| f          t          j        |          dt          j                    v st          j        |           rt          j        |           ndd	z  }d
d|iz  }t          t          j
        |                    d x}}d S )N   25F)r8   r<   r>   not_top_two_relative_strengthinz%(py1)s in %(py3)sblockersrI   rJ   rQ   rR   breadth_not_supportivetwo_close_confirmation_missingr
   rC   r   rZ   r[   r_   r\   r]   r^   r`   ra   r{   @py_assert0rf   rl   rm   s        rB   Stest_momentum_candidate_blocks_weak_breadth_rank_and_missing_two_close_confirmationr   +   s    PWX\P]P]  ~C  "D  "D  "D  E  EH*6*h6666666666*h66666*66666666666h66666h666666666666666666666666666#/#x//////////#x/////#///////////x/////x///////////////////////////+7+x7777777777+x77777+77777777777x77777x77777777777777777777777777777rD   c            
     f   t          t          dt          d          t          d          t          d                              } d}|| v }|st          j        d|fd|| f          t          j        |          d	t          j                    v st          j        |           rt          j        |           nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d}|| v }|st          j        d|fd|| f          t          j        |          d	t          j                    v st          j        |           rt          j        |           nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d}|| v }|st          j        d|fd|| f          t          j        |          d	t          j                    v st          j        |           rt          j        |           nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d S )NSOLz1.10z3.1r=   )r   r   r   r$   coin_not_momentum_universerx   rz   r{   r|   rQ   rR   momentum_overheatedrsi_overheatedr   r   s        rB   8test_momentum_candidate_blocks_chase_and_unapproved_coinr   2   s    u76??`ghm`n`nx  AE  yF  yF  "G  "G  "G  H  HH'3'83333333333'833333'333333333338333338333333333333333333333333333 , H,,,,,,,,,, H,,,,, ,,,,,,,,,,,H,,,,,H,,,,,,,,,,,,,,,,,,,,,,,,,,,'x''''''''''x''''''''''''''''x'''''x'''''''''''''''''''''''''''''rD   c                    t          t          d          t          d          t          d          t          d                    } t          |           }d}||v }|st          j        d|fd||f          t          j        |          d	t          j                    v st          j        |          rt          j        |          nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d}||v }|st          j        d|fd||f          t          j        |          d	t          j                    v st          j        |          rt          j        |          nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d}||v }|st          j        d|fd||f          t          j        |          d	t          j                    v st          j        |          rt          j        |          nd	d
z  }dd|iz  }t          t          j
        |                    d x}}d S )Nz1.01z0.0995r"   )r(   r-   r   r!   volume_confirmation_missingrx   rz   r{   r|   rQ   rR   spread_too_widetrend_4h_not_bullish)rC   r   r
   rZ   r[   r_   r\   r]   r^   r`   ra   )rG   r{   r   rf   rl   rm   s         rB   @test_momentum_candidate_requires_real_liquidity_volume_and_trendr   9   s   GFOO]dei]j]jx  AE  yF  yF  G  G  GG ))H(4(H4444444444(H44444(44444444444H44444H444444444444444444444444444(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((!-!X----------!X-----!-----------X-----X-----------------------------rD   )r   r   )
__future__r   builtinsr\   _pytest.assertion.rewrite	assertionrewriterZ   dataclassesr   decimalr    src.market.trend_retest_featuresr   /src.strategies.relative_strength_momentum_v77_2r   r   r	   r
   rC   rs   r   r   r   r?   rD   rB   <module>r      s    " " " " " "                           @ @ @ @ @ @           $ $ $ $ 	) 	) 	)8 8 8( ( (. . . . .rD   