
    j6                     H    d dl Zd dlmc mZ d dlmZmZ d Zd Z	d Z
d ZdS )    N)datetimetimezonec                     ddl m}  d t          dd          D             } | |          }|j        }|j        }||k    }|st          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	        |          rt          j
        |          ndt          j
        |          d	z  }d
d|iz  }t          t          j        |                    d x}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}||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        }|j        }||k    }|st          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	        |          rt          j
        |          ndt          j
        |          d	z  }d
d|iz  }t          t          j        |                    d x}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}}d S )Nr   )compute_chart_indicatorsc                 6    g | ]}||d z   |dz
  |dz   d|z   dS )      d   openhighlowclosevolume .0is     O/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_market_context.py
<listcomp>z=test_compute_chart_indicators_for_uptrend.<locals>.<listcomp>   sG        AE!a%!a%3QR7SS      r	      >)zM%(py2)s
{%(py2)s = %(py0)s.sma_fast
} > %(py6)s
{%(py6)s = %(py4)s.sma_slow
}
indicators)py0py2py4py6assert %(py8)spy82   )z-%(py2)s
{%(py2)s = %(py0)s.rsi_14
} > %(py5)sr   r   py5assert %(py7)spy7)z-%(py2)s
{%(py2)s = %(py0)s.atr_14
} > %(py5)s)z[%(py2)s
{%(py2)s = %(py0)s.bollinger_upper
} > %(py6)s
{%(py6)s = %(py4)s.bollinger_lower
})z+%(py2)s
{%(py2)s = %(py0)s.vwap
} > %(py5)s)market_contextr   rangesma_fastsma_slow
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationrsi_14atr_14bollinger_upperbollinger_lowervwap)r   candlesr   @py_assert1@py_assert5@py_assert3@py_format7@py_format9@py_assert4@py_format6@py_format8s              r   )test_compute_chart_indicators_for_uptrendrA      s3   777777 q"  G
 *)'22J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: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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4444444!r!r!!!!!!!!!!r!!!!!!!!!!!!:!!!!!:!!!!!!!!!!r!!!!!!!!!!!!!!!!!!!!!!!!!!! q q          q            :     :          q                           %B
(BB%(BBBBBBBBBBB%(BBBBBBBBBBBBB:BBBBB:BBBBBB%BBBBBBBBBBB
BBBBB
BBBBBB(BBBBBBBBBBBBBBBBBBBBBBBBBBBB?Q?Q?Q::?Qr   c            	      
   ddl m}  d t          d          D             } | d|ddd	          }|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}||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        }|j        }|j        }|j        }	||	k    }
|
st	          j        d|
fd||	f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          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}x}
x}}	d}|j        }||v }|st	          j        d|fd||f          t	          j	        |          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}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}}|                                d         }d}||k    }|slt	          j        d
|fd||f          t	          j	        |          t	          j	        |          dz  }d d!|iz  }t          t	          j        |                    d x}x}}d S )"Nr   )build_market_context_snapshotc                 <    g | ]}d |z   d|z   d|z   d|z   d|z   dS )r
   g   c   f   i  r   r   r   s     r   r   zCtest_context_snapshot_classifies_market_context.<locals>.<listcomp>   sM        q#'"q&37VZ]^V^__  r   (   BTCi@B g-C6?hyperliquid)coinr8   open_interest_usdfunding_ratesource==)z,%(py2)s
{%(py2)s = %(py0)s.coin
} == %(py5)ssnapshotr#   r%   r&   )z.%(py2)s
{%(py2)s = %(py0)s.source
} == %(py5)sr   )z%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.indicators
}.sma_fast
} > %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py6)s.indicators
}.sma_slow
})r   r   r   r   r!   py10zassert %(py12)spy12trend_upin)z,%(py1)s in %(py5)s
{%(py5)s = %(py3)s.tags
})py1py3r$   g      ?)z8%(py2)s
{%(py2)s = %(py0)s.reliability_score
} > %(py5)s
event_typer'   )z%(py1)s == %(py4)s)rW   r   zassert %(py6)sr   )r'   rC   r(   rK   r+   r,   r-   r.   r/   r0   r1   r2   rN   r   r)   r*   tagsreliability_scoreas_event)rC   r8   rQ   r9   r>   r;   r?   r@   @py_assert7@py_assert9r:   @py_format11@py_format13@py_assert0@py_assert2@py_format5r<   s                    r   /test_context_snapshot_classifies_market_contextrd      s   <<<<<< r  G
 -,#  H =!E!=E!!!!!!!!!!=E!!!!!!!!!!!!8!!!!!8!!!!!!=!!!!E!!!!!!!!!!!!!!!!!!!!!!!!!!!?+m+?m++++++++++?m++++++++++++8+++++8++++++?++++m+++++++++++++++++++++++++++F'F(*=F*=*FF'*FFFFFFFFFFF'*FFFFFFFFFFFFF8FFFFF8FFFFFFFFFF'FFFFFFFFFFF(FFFFF(FFFFFF*=FFFF*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&&:&&&&&&&&&&:&&&&&:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%++%++++++++++%++++++++++++8+++++8++++++%+++++++++++++++++++++++++++++++|,@0@@,0@@@@@@@@@@@,0@@@@@@,@@@@0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@r   c                  T   ddl m}  ddddddddddd	dd
dddg} | |          }|d         }|j        }d}||k    }|st          j        d|fd||f          t          j        |          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}|d         }|j        }d}||k    }|st          j        d|fd||f          t          j        |          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}|d         }|j	        }d}||k    }|st          j        d|fd||f          t          j        |          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}|d
         }|j        }d}||k    }|st          j        d|fd||f          t          j        |          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}d S )Nr   )score_signal_reliabilitylisting_newsupg      @)rN   predicted_directionactual_return_pctg      ?downg       rumorg         rO   )z3%(py3)s
{%(py3)s = %(py1)s.sample_size
} == %(py6)s)rW   rX   r   r    r!   )z0%(py3)s
{%(py3)s = %(py1)s.hit_rate
} == %(py6)sr   )z5%(py3)s
{%(py3)s = %(py1)s.avg_return_pct
} > %(py6)sg        )
r'   rf   sample_sizer+   r,   r0   r1   r2   hit_rateavg_return_pct)	rf   observationsscoresra   rb   r:   r>   r<   r=   s	            r   8test_signal_reliability_scores_historical_predictivenessrs   -   s   777777 "$UXYY!$UXYY!&W[\\4dSS	L &%l33F.!2!-22-2222222222-22222!2222-222222222222222222222222222222222.!1!*1c1*c1111111111*c11111!1111*1111c11111111111111111111111111111.!4!04140144444444440144444!4444044441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44'?*?#*s*#s**********#s*****?****#****s*******************************r   c                 n   ddl m}m}m}  |t	          dddt
          j                  ddd |d	d
ddddd          dddd	  	        }| dz  } |||           |                                }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 )Nr   )MarketContextSnapshotChartIndicatorsappend_market_context_eventi  r	   )tzinfoETHrJ   15m
   	   7   g333333?      gffffff$@)r)   r*   r3   r4   r5   r6   r7   {   g{Gz?)rT   g?)	tsrK   rN   	timeframer   rL   rM   rZ   r[   zmarket_context.jsonlz"event_type": "market_context"rU   )z%(py1)s in %(py3)stext)rW   rX   zassert %(py5)sr$   z"coin": "ETH")r'   ru   rv   rw   r   r   utc	read_textr+   r,   r0   r-   r.   r/   r1   r2   )tmp_pathru   rv   rw   rQ   pathr   ra   rb   @py_format4r?   s              r   -test_append_market_context_event_writes_jsonlr   ?   sJ   bbbbbbbbbb$$D!Qx|444"?B2ccewx  @D  E  E  E
 
 
H ,,Dh///>>D+3+t3333333333+t33333+33333333333t33333t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"?d""""""""""?d"""""?"""""""""""d"""""d"""""""""""""""""""""""""""""r   )builtinsr-   _pytest.assertion.rewrite	assertionrewriter+   r   r   rA   rd   rs   r   r   r   r   <module>r      s                  ' ' ' ' ' ' ' '  "A A A0+ + +$# # # # #r   