
    j                    p    d dl mZ d dlZd dlmc mZ d dlZd dl	m
Z
 d dlmZ d dlmZmZmZ ddZddZdS )    )annotationsN)Path)	BotConfig)append_near_missbuild_near_miss_eventtop_near_missesreturnNonec            	     H   t          dddd          } g d}t          dd|d	d
| 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
        }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        }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}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        }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}x}}
d S )#N      @i       .@   flash_crash_trigger_pctmin_volume_24hcrash_roe_trigger_pctdefault_leverage))g      ?g      Y@)g       @g     X@)g      @      X@	candidateWLDr   no_flash_crashg     ^@strategy_idcoinhistorycurrent_pricereasoncfgnow_tsis notz%(py0)s is not %(py3)srowpy0py3assert %(py5)spy5==)z3%(py2)s
{%(py2)s = %(py0)s.strategy_id
} == %(py5)s)r%   py2r(   zassert %(py7)spy7)z,%(py2)s
{%(py2)s = %(py0)s.coin
} == %(py5)sg      @)z1%(py2)s
{%(py2)s = %(py0)s.drop_pct
} == -%(py5)szassert %(py8)spy8)z9%(py2)s
{%(py2)s = %(py0)s.required_drop_pct
} == %(py5)sg      ?)z4%(py2)s
{%(py2)s = %(py0)s.distance_pct
} == %(py5)s)z.%(py2)s
{%(py2)s = %(py0)s.reason
} == %(py5)sg      4@)z5%(py2)s
{%(py2)s = %(py0)s.roe_drop_pct
} == -%(py5)s)r   r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr   r   drop_pctrequired_drop_pctdistance_pctr   roe_drop_pct)r   r   r#   @py_assert2@py_assert1@py_format4@py_format6@py_assert4@py_assert3@py_format8@py_assert6@py_format7@py_format9s                J/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_near_miss.pyBtest_build_near_miss_event_reports_distance_to_flash_crash_triggerrE   
   sL   
C
bfyz
{
{
{C666G
  C 3d?3d33d?)k)?k))))))))))?k))))))))))))3)))))3))))))?))))k)))))))))))))))))))))))))))8u8u8u338u<CC4<4<433<C 'C' C'''''''''' C''''''''''''3'''''3'''''' ''''C'''''''''''''''''''''''''''"s"s""""""""""s""""""""""""3"""""3""""""""""s""""""""""""""""""""""""""":))):))))))))))):)))))))))))))3)))))3)))))):))))))))))))))))))))))))))))))))$$u$u$$$$$$$$$$u$$$$$$$$$$$$3$$$$$3$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    tmp_pathr   c                   t          dddd          }t          dddd	gd
d|d          t          ddddgdd|d          t          ddddgdd|d          g}| dz  }|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}}t          ||           d |                    d                                          D             }	t          d |D             d          }
d  |
D             }ddg}||k    }|slt          j        d!|fd"||f          t          j        |          t          j        |          d#z  }d$d%|iz  }t          t          j	        |                    d x}x}}|	d&         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(}t          j        } ||	          }|j        } |            }||v}|s+t          j        d)|fd*||f          t          j        |          d+t	          j                    v st          j        t                    rt          j        t                    nd+t          j        |          d,t	          j                    v st          j        |	          rt          j        |	          nd,t          j        |          t          j        |          t          j        |          d-z  }d.d/|iz  }t          t          j	        |                    d x}x}x}x}x}}d S )0Nr      r   r   r   sA)rI   d   )   c   rN   r   r   B)rM   `   rP   C)rM   a   rR   znear_miss.jsonlr    r"   r#   r$   r'   r(   c                6    g | ]}t          j        |          S  )jsonloads).0lines     rD   
<listcomp>zGtest_append_near_miss_journal_and_rank_closest_rows.<locals>.<listcomp>/   s"    YYY4djYYYrF   zutf-8)encodingc                    g | ]}||S )NrT   rW   r#   s     rD   rY   zGtest_append_near_miss_journal_and_rank_closest_rows.<locals>.<listcomp>0   s    EEEcS_c___rF   rM   )limitc                    g | ]	}|j         
S rT   )r   r\   s     rD   rY   zGtest_append_near_miss_journal_and_rank_closest_rows.<locals>.<listcomp>2   s    '''CH'''rF   r)   )z%(py1)s == %(py4)s)py1py4zassert %(py6)spy6r   r   private)not in)z%(py1)s not in %(py12)s
{%(py12)s = %(py10)s
{%(py10)s = %(py8)s
{%(py8)s = %(py5)s
{%(py5)s = %(py3)s.dumps
}(%(py6)s)
}.lower
}()
}rU   loaded)r_   r&   r(   ra   r-   py10py12zassert %(py14)spy14)r   r   r.   r/   r0   r1   r2   r3   r4   r5   r   	read_text
splitlinesr   rU   dumpslower)rG   r   rowspathr#   r:   r;   r<   r=   rd   ranked@py_assert0r?   @py_format5rB   r>   @py_assert7@py_assert9@py_assert11@py_format13@py_format15s                        rD   3test_append_near_miss_journal_and_rank_closest_rowsrv   "   s   
CY]pq
r
r
rC#C(GATdfo  FI  RS  	T  	T  	T#C(GATdfo  FI  RS  	T  	T  	T#C(GATdfo  FI  RS  	T  	T  	TD
 ''D $ $s$s$ss$s####YY4>>7>+K+K+V+V+X+XYYYFEETEEEQOOOF'''''5C: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!9]#*s*#s**********#s*****#****s***************************6DJ6JJv..6.46446669666666666669666666966666666666D66666D666666J66666666666v66666v666666.66664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6666666666666rF   )r	   r
   )rG   r   r	   r
   )
__future__r   builtinsr0   _pytest.assertion.rewrite	assertionrewriter.   rU   pathlibr   configr   	near_missr   r   r   rE   rv   rT   rF   rD   <module>r      s    " " " " " "                           N N N N N N N N N N% % % %07 7 7 7 7 7rF   