
    ȅ%jM                     d    d dl Zd dlmc mZ d dlZd dlZd dlZd dl	m
Z
 d dlZd Zd Zd Zd ZdS )    N)Pathc                 z   | dz  }|                     t          j        dddddddd	d
dddt          | dz            dddidgd                     |                    dd           |                    dt          | dz                       ddlm} |                    |          }|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}}|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}}|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}}|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-}||u }|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}
| |
z  }||k    }|st          j
        d|fd0||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          d1t          j                    v st          j        |           rt          j        |           nd1t          j        |
          d2z  }	d3d4|	iz  }t          t          j        |                    d x}x}x}
}d S )5Nzstrategy_config.json         i  g      ?risk   <      g      @-   Fzruntime-from-config)max_total_tradesdefault_leveragetrade_size_usdwallet_equity_usdcrisk_per_trade_pctposition_sizing_modemax_position_margin_pctmax_position_notional_pctmin_order_notional_usdflash_crash_trigger_pctcooldown_minutesdry_runruntime_dirmin_volume_24hi90  BAD)
parametersfilters	blacklistCTB_DRY_RUNtrueCTB_RUNTIME_DIRzruntime-from-envr   )	BotConfig==)z8%(py2)s
{%(py2)s = %(py0)s.max_total_trades
} == %(py5)scfg)py0py2py5zassert %(py7)spy7)z8%(py2)s
{%(py2)s = %(py0)s.default_leverage
} == %(py5)s)z6%(py2)s
{%(py2)s = %(py0)s.trade_size_usd
} == %(py5)s)z:%(py2)s
{%(py2)s = %(py0)s.wallet_equity_usdc
} == %(py5)s)z:%(py2)s
{%(py2)s = %(py0)s.risk_per_trade_pct
} == %(py5)s)z<%(py2)s
{%(py2)s = %(py0)s.position_sizing_mode
} == %(py5)s)z?%(py2)s
{%(py2)s = %(py0)s.max_position_margin_pct
} == %(py5)s)zA%(py2)s
{%(py2)s = %(py0)s.max_position_notional_pct
} == %(py5)s)z>%(py2)s
{%(py2)s = %(py0)s.min_order_notional_usd
} == %(py5)s)z?%(py2)s
{%(py2)s = %(py0)s.flash_crash_trigger_pct
} == %(py5)s)z8%(py2)s
{%(py2)s = %(py0)s.cooldown_minutes
} == %(py5)s)z6%(py2)s
{%(py2)s = %(py0)s.min_volume_24h
} == %(py5)s)r   )z1%(py2)s
{%(py2)s = %(py0)s.blacklist
} == %(py5)sTis)z/%(py2)s
{%(py2)s = %(py0)s.dry_run
} is %(py5)sz?%(py2)s
{%(py2)s = %(py0)s.runtime_dir
} == (%(py4)s / %(py6)s)tmp_pathr&   r'   py4py6assert %(py9)spy9)
write_textjsondumpsstrsetenvconfigr"   	from_filer   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationr   r   r   r   r   r   r   r   r   r   r   r   r   r   )r-   monkeypatchconfig_pathr"   r%   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert5@py_assert7@py_format10s                N/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_safety_config.py7test_config_loads_strategy_parameters_and_env_overridesrM   	   se   33K4: ! ! "%"&$*'))+&('* "x*??@@
 
 %e,W#' '     & }f---(#h9K.K*L*LMMM      


k
*
*C$1$1$$$$$$$$$$1$$$$$$$$$$$$3$$$$$3$$$$$$$$$$1$$$$$$$$$$$$$$$$$$$$$$$$$$$$1$1$$$$$$$$$$1$$$$$$$$$$$$3$$$$$3$$$$$$$$$$1$$$$$$$$$$$$$$$$$$$$$$$$$$$########################3#####3#####################################!(S(!S((((((((((!S((((((((((((3(((((3((((((!((((S(((((((((((((((((((((((((((!)T)!T))))))))))!T))))))))))))3)))))3))))))!))))T)))))))))))))))))))))))))))#-v-#v----------#v------------3-----3------#----v---------------------------&,",&",,,,,,,,,,&",,,,,,,,,,,,3,,,,,3,,,,,,&,,,,",,,,,,,,,,,,,,,,,,,,,,,,,,,(.B.(B..........(B............3.....3......(....B...........................%++%++++++++++%++++++++++++3+++++3++++++%+++++++++++++++++++++++++++++++&-#-&#----------&#------------3-----3------&----#---------------------------%2%2%%%%%%%%%%2%%%%%%%%%%%%3%%%%%3%%%%%%%%%%2%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&&&&&&&&&&&&&&&&&&3&&&&&3&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&=$H$=H$$$$$$$$$$=H$$$$$$$$$$$$3$$$$$3$$$$$$=$$$$H$$$$$$$$$$$$$$$$$$$$$$$$$$$;$;$;$33;$?;);;h);;;?;;;;;;;;;;;?;;;;;;;;;;;;;3;;;;;3;;;;;;?;;;;;;;;;;;h;;;;;h;;;;;;);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    c                 

   ddl m}m}  || dz            }|                    |          }|                                 |j        }d}| |z  }||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}x}}|j        }|j        } |            }|sddt          j	                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          t          j        |          d	z  }t          t          j        |                    d x}x}}|j        }|j        } |            }|sddt          j	                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          t          j        |          d	z  }t          t          j        |                    d x}x}}|j        }|j        }|j        }||k    }|st          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        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}|j        }|j        }|j        }||k    }|st          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        |          dz  }dd|iz  }t          t          j        |                    d x}x}x}}d S )Nr   )r"   RuntimePathsruntime)r   r#   r,   pathsr-   r.   r1   r2   zgassert %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.tradeanalyse_dir
}.exists
}()
}zbassert %(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.reports_dir
}.exists
}()
})zu%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.trading_log
}.parent
} == %(py8)s
{%(py8)s = %(py6)s.tradeanalyse_dir
})r&   r'   r/   r0   py8zassert %(py10)spy10)zw%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.trade_journal
}.parent
} == %(py8)s
{%(py8)s = %(py6)s.tradeanalyse_dir
})r8   r"   rP   from_configensure_dirsr   r:   r;   r<   r=   r>   r?   r@   rA   tradeanalyse_direxistsreports_dirtrading_logparenttrade_journal)r-   r"   rP   r%   rR   rD   rI   rJ   rF   rH   rK   @py_format7@py_format9@py_format11s                 rL   +test_runtime_paths_are_created_outside_repor`   6   s   ........
)9 4
5
5
5C$$S))E	4949 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45444445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49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!*!(*((***************5*****5******!****(**************************%#%##%%%%%%%%%%%%%%%5%%%%%5%%%%%%%%%%#%%%%%%%%%%%%%%%%%%%%%%%%%%=#=u'==#'===========#'=============5=====5==========#===========u=====u======'==============================?%?)??%)???????????%)?????????????5?????5??????????%??????????????????????)????????????????????????????????rN   c                    ddl m} g  G fdd          } | |            d          }|                    dd          d	         }d}||u }|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dd          d	         }d}||u }|slt          j        d
|fd||f          t          j        |          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}x}}g }|k    }	|	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}	}d S )Nr   TradingExecutorc                   $    e Zd Z fdZ fdZdS )Ltest_dry_run_executor_records_without_calling_exchange.<locals>.FakeExchangec                 8                         d||f           d S )Nset_leverageappendselfargskwargscallss      rL   rg   zYtest_dry_run_executor_records_without_calling_exchange.<locals>.FakeExchange.set_leverageJ   "    LL.$788888rN   c                 8                         d||f           d S )Ncreate_orderrh   rj   s      rL   rq   zYtest_dry_run_executor_records_without_calling_exchange.<locals>.FakeExchange.create_orderM   ro   rN   N__name__
__module____qualname__rg   rq   rn   s   rL   FakeExchangere   I   sG        	9 	9 	9 	9 	9	9 	9 	9 	9 	9 	9 	9rN   rw   Tr      BTC/USDC:USDCr   r*   )z%(py1)s is %(py4)spy1r/   assert %(py6)sr0   marketbuy{Gz?      Y@r#   )z%(py0)s == %(py3)srn   )r&   py3zassert %(py5)sr(   )	executionrc   rg   r:   r;   r?   r@   rA   rq   r<   r=   r>   )r-   rc   rw   executor@py_assert0rF   @py_assert2@py_format5r]   rD   @py_format4rG   rn   s               @rL   6test_dry_run_executor_records_without_calling_exchanger   D   s   ))))))E9 9 9 9 9 9 9 9 9 9 ||~~t<<<H  O44Y?G4G?4GGGGGGGGGG?4GGGGG?GGGG4GGGGGGGGGGGGGGGGGGGGGGGGGGG  (E4OOPYZb^bbZ^bbbbbbbbbbbZ^bbbbbbZ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5B;5B55BrN   c                    ddl m} |                     dd           g  G fdd          } | |            d          }|j        }d	}d
} |||          }ddi}||k    }	|	st	          j        d|	fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          dz  }
dd|
iz  }t          t	          j        |                    d x}x}x}x}x}	}|j        }d
}d}d}d}	d} |||||	|          }ddi}||k    }|st	          j        d|fd||f          dt          j                    v st	          j        |          rt	          j	        |          ndt	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |          t	          j	        |	          t	          j	        |          t	          j	        |          t	          j	        |          d	z  }dd|iz  }t          t	          j        |                    d x}x}x}x}x}	x}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          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   rb   CTB_ALLOW_LEGACY_EXECUTIONr    c                   $    e Zd Z fdZ fdZdS )>test_live_executor_delegates_to_exchange.<locals>.FakeExchangec                 <                         d||f           ddiS )Nrg   statusokrh   rj   s      rL   rg   zKtest_live_executor_delegates_to_exchange.<locals>.FakeExchange.set_leverage^   '    LL.$7888d##rN   c                 <                         d||f           ddiS )Nrq   r   r   rh   rj   s      rL   rq   zKtest_live_executor_delegates_to_exchange.<locals>.FakeExchange.create_orderb   r   rN   Nrr   rv   s   rL   rw   r   ]   sG        	$ 	$ 	$ 	$ 	$	$ 	$ 	$ 	$ 	$ 	$ 	$rN   rw   Frx   ry   rz   r   r   r#   )z\%(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.set_leverage
}(%(py4)s, %(py6)s)
} == %(py11)sr   )r&   r'   r/   r0   rS   py11zassert %(py13)spy13r~   r   r   r   )z{%(py14)s
{%(py14)s = %(py2)s
{%(py2)s = %(py0)s.create_order
}(%(py4)s, %(py6)s, %(py8)s, %(py10)s, %(py12)s)
} == %(py17)s)	r&   r'   r/   r0   rS   rT   py12py14py17zassert %(py19)spy19rg   )z%(py1)s == %(py4)sr{   r}   r0      rq   )r   rc   r7   rg   r:   r;   r<   r=   r>   r?   r@   rA   rq   )rB   rc   rw   r   rD   rF   rI   rJ   @py_assert10@py_assert9@py_format12@py_format14@py_assert11@py_assert13@py_assert16@py_assert15@py_format18@py_format20r   r   r   r]   rn   s                         @rL   (test_live_executor_delegates_to_exchanger   W   s   ))))))3V<<<E$ $ $ $ $ $ $ $ $ $ ||~~u===H HHOH  O44H48HH48HHHHHHHHHHH48HHHHHHHHHHHHH8HHHHH8HHHHHH HHHHHHHHOHHHH4HHHH8HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH cc(cEc4cc  (E4OOcT\^bSccOScccccccccccOSccccccccccccc8ccccc8cccccc cccccccc(ccccEcccc4ccccccccOccccScccccccccccccccccccccccccccccccccccccccc8A;(.(;.((((((((((;.(((((;((((.(((((((((((((((((((((((((((8A;(.(;.((((((((((;.(((((;((((.(((((((((((((((((((((((((((((rN   )builtinsr<   _pytest.assertion.rewrite	assertionrewriter:   	importlibr4   ospathlibr   pytestrM   r`   r   r    rN   rL   <module>r      s                       				       *< *< *<Z@ @ @  &) ) ) ) )rN   