def test_generate_pair_metrics(): results = pd.DataFrame({ 'pair': ['ETH/BTC', 'ETH/BTC'], 'profit_ratio': [0.1, 0.2], 'profit_abs': [0.2, 0.4], 'trade_duration': [10, 30], 'wins': [2, 0], 'draws': [0, 0], 'losses': [0, 0] }) pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC', max_open_trades=2, results=results) assert isinstance(pair_results, list) assert len(pair_results) == 2 assert pair_results[-1]['key'] == 'TOTAL' assert (pytest.approx( pair_results[-1]['profit_mean_pct']) == pair_results[-1]['profit_mean'] * 100) assert (pytest.approx( pair_results[-1]['profit_sum_pct']) == pair_results[-1]['profit_sum'] * 100)
def test_text_table_bt_results(): results = pd.DataFrame({ 'pair': ['ETH/BTC', 'ETH/BTC'], 'profit_ratio': [0.1, 0.2], 'profit_abs': [0.2, 0.4], 'trade_duration': [10, 30], 'wins': [2, 0], 'draws': [0, 0], 'losses': [0, 0] }) result_str = ( '| Pair | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC |' ' Tot Profit % | Avg Duration | Wins | Draws | Losses |\n' '|---------+--------+----------------+----------------+------------------+' '----------------+----------------+--------+---------+----------|\n' '| ETH/BTC | 2 | 15.00 | 30.00 | 0.60000000 |' ' 15.00 | 0:20:00 | 2 | 0 | 0 |\n' '| TOTAL | 2 | 15.00 | 30.00 | 0.60000000 |' ' 15.00 | 0:20:00 | 2 | 0 | 0 |') pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC', max_open_trades=2, results=results) assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str
def test_text_table_bt_results(): results = pd.DataFrame({ 'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'], 'profit_ratio': [0.1, 0.2, -0.05], 'profit_abs': [0.2, 0.4, -0.1], 'trade_duration': [10, 30, 20], }) result_str = ( '| Pair | Buys | Avg Profit % | Cum Profit % | Tot Profit BTC | Tot Profit % |' ' Avg Duration | Win Draw Loss Win% |\n' '|---------+--------+----------------+----------------+------------------+----------------+' '----------------+-------------------------|\n' '| ETH/BTC | 3 | 8.33 | 25.00 | 0.50000000 | 12.50 |' ' 0:20:00 | 2 0 1 66.7 |\n' '| TOTAL | 3 | 8.33 | 25.00 | 0.50000000 | 12.50 |' ' 0:20:00 | 2 0 1 66.7 |') pair_results = generate_pair_metrics(['ETH/BTC'], stake_currency='BTC', starting_balance=4, results=results) assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str