Merge pull request #5273 from freqtrade/fix/profit_calc
fix calculation logic for /profit
This commit is contained in:
@@ -677,12 +677,16 @@ def test_api_profit(botclient, mocker, ticker, fee, markets):
|
||||
'profit_all_ratio_mean': -0.6641100666666667,
|
||||
'profit_all_percent_sum': -398.47,
|
||||
'profit_all_ratio_sum': -3.9846604,
|
||||
'profit_all_percent': -4.41,
|
||||
'profit_all_ratio': -0.044063014216106644,
|
||||
'profit_closed_coin': 0.00073913,
|
||||
'profit_closed_fiat': 9.124559849999999,
|
||||
'profit_closed_ratio_mean': 0.0075,
|
||||
'profit_closed_percent_mean': 0.75,
|
||||
'profit_closed_ratio_sum': 0.015,
|
||||
'profit_closed_percent_sum': 1.5,
|
||||
'profit_closed_ratio': 7.391275897987988e-07,
|
||||
'profit_closed_percent': 0.0,
|
||||
'trade_count': 6,
|
||||
'closed_trade_count': 2,
|
||||
'winning_trades': 2,
|
||||
|
@@ -452,7 +452,8 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'No closed trade' in msg_mock.call_args_list[-1][0][0]
|
||||
assert '*ROI:* All trades' in msg_mock.call_args_list[-1][0][0]
|
||||
assert ('∙ `-0.00000500 BTC (-0.50%) (-0.5 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
mocker.patch('freqtrade.wallets.Wallets.get_starting_balance', return_value=0.01)
|
||||
assert ('∙ `-0.00000500 BTC (-0.50%) (-0.0 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
in msg_mock.call_args_list[-1][0][0])
|
||||
msg_mock.reset_mock()
|
||||
|
||||
@@ -466,11 +467,11 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
|
||||
telegram._profit(update=update, context=MagicMock())
|
||||
assert msg_mock.call_count == 1
|
||||
assert '*ROI:* Closed trades' in msg_mock.call_args_list[-1][0][0]
|
||||
assert ('∙ `0.00006217 BTC (6.20%) (6.2 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
assert ('∙ `0.00006217 BTC (6.20%) (0.62 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
in msg_mock.call_args_list[-1][0][0])
|
||||
assert '∙ `0.933 USD`' in msg_mock.call_args_list[-1][0][0]
|
||||
assert '*ROI:* All trades' in msg_mock.call_args_list[-1][0][0]
|
||||
assert ('∙ `0.00006217 BTC (6.20%) (6.2 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
assert ('∙ `0.00006217 BTC (6.20%) (0.62 \N{GREEK CAPITAL LETTER SIGMA}%)`'
|
||||
in msg_mock.call_args_list[-1][0][0])
|
||||
assert '∙ `0.933 USD`' in msg_mock.call_args_list[-1][0][0]
|
||||
|
||||
|
@@ -197,3 +197,30 @@ def test__validate_stake_amount(mocker, default_conf,
|
||||
return_value=max_stake_amount)
|
||||
res = freqtrade.wallets._validate_stake_amount('XRP/USDT', stake_amount, min_stake_amount)
|
||||
assert res == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('available_capital,closed_profit,open_stakes,free,expected', [
|
||||
(None, 10, 100, 910, 1000),
|
||||
(None, 0, 0, 2500, 2500),
|
||||
(None, 500, 0, 2500, 2000),
|
||||
(None, 500, 0, 2500, 2000),
|
||||
(None, -70, 0, 1930, 2000),
|
||||
# Only available balance matters when it's set.
|
||||
(100, 0, 0, 0, 100),
|
||||
(1000, 0, 2, 5, 1000),
|
||||
(1235, 2250, 2, 5, 1235),
|
||||
(1235, -2250, 2, 5, 1235),
|
||||
])
|
||||
def test_get_starting_balance(mocker, default_conf, available_capital, closed_profit,
|
||||
open_stakes, free, expected):
|
||||
if available_capital:
|
||||
default_conf['available_capital'] = available_capital
|
||||
mocker.patch("freqtrade.persistence.models.Trade.get_total_closed_profit",
|
||||
return_value=closed_profit)
|
||||
mocker.patch("freqtrade.persistence.models.Trade.total_open_trades_stakes",
|
||||
return_value=open_stakes)
|
||||
mocker.patch("freqtrade.wallets.Wallets.get_free", return_value=free)
|
||||
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
|
||||
assert freqtrade.wallets.get_starting_balance() == expected
|
||||
|
Reference in New Issue
Block a user