Merge branch 'freqtrade:develop' into strategy_utils

This commit is contained in:
hippocritical
2023-03-05 12:30:26 +01:00
committed by GitHub
10 changed files with 64 additions and 19 deletions

View File

@@ -463,7 +463,9 @@ class TestCCXTExchange():
if exchangename == 'gate':
# TODO: Gate is unstable here at the moment, ignoring the limit partially.
return
for val in [1, 2, 5, 25, 100]:
for val in [1, 2, 5, 25, 50, 100]:
if val > 50 and exchangename == 'bybit':
continue
l2 = exch.fetch_l2_order_book(pair, val)
if not l2_limit_range or val in l2_limit_range:
if val > 50:

View File

@@ -1362,6 +1362,7 @@ def test_to_json(fee):
'trade_duration': None,
'trade_duration_s': None,
'realized_profit': 0.0,
'realized_profit_ratio': None,
'close_profit': None,
'close_profit_pct': None,
'close_profit_abs': None,
@@ -1438,6 +1439,7 @@ def test_to_json(fee):
'initial_stop_loss_pct': None,
'initial_stop_loss_ratio': None,
'realized_profit': 0.0,
'realized_profit_ratio': None,
'close_profit': None,
'close_profit_pct': None,
'close_profit_abs': None,

View File

@@ -76,6 +76,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'stoploss_entry_dist_ratio': -0.10376381,
'open_order': None,
'realized_profit': 0.0,
'realized_profit_ratio': None,
'total_profit_abs': -4.09e-06,
'total_profit_fiat': ANY,
'exchange': 'binance',

View File

@@ -1013,6 +1013,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short,
'total_profit_abs': ANY,
'total_profit_fiat': ANY,
'realized_profit': 0.0,
'realized_profit_ratio': None,
'current_rate': current_rate,
'open_date': ANY,
'open_timestamp': ANY,
@@ -1243,6 +1244,7 @@ def test_api_force_entry(botclient, mocker, fee, endpoint):
'profit_abs': None,
'profit_fiat': None,
'realized_profit': 0.0,
'realized_profit_ratio': None,
'fee_close': 0.0025,
'fee_close_cost': None,
'fee_close_currency': None,

View File

@@ -2012,7 +2012,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
'sub_trade': True,
})
assert msg_mock.call_args[0][0] == (
'\N{WARNING SIGN} *Binance (dry):* Exiting KEY/ETH (#1)\n'
'\N{WARNING SIGN} *Binance (dry):* Partially exiting KEY/ETH (#1)\n'
'*Unrealized Sub Profit:* `-57.41% (loss: -0.05746268 ETH / -24.812 USD)`\n'
'*Cumulative Profit:* (`-0.15746268 ETH / -24.812 USD`)\n'
'*Enter Tag:* `buy_signal1`\n'

View File

@@ -169,6 +169,36 @@ def test_stoploss_from_open(side, profitrange):
assert pytest.approx(stop_price) == expected_stop_price
@pytest.mark.parametrize("side,rel_stop,curr_profit,leverage,expected", [
# profit range for long is [-1, inf] while for shorts is [-inf, 1]
("long", 0, -1, 1, 1),
("long", 0, 0.1, 1, 0.09090909),
("long", -0.1, 0.1, 1, 0.18181818),
("long", 0.1, 0.2, 1, 0.08333333),
("long", 0.1, 0.5, 1, 0.266666666),
("long", 0.1, 5, 1, 0.816666666), # 500% profit, set stoploss to 10% above open price
("short", 0, 0.1, 1, 0.1111111),
("short", -0.1, 0.1, 1, 0.2222222),
("short", 0.1, 0.2, 1, 0.125),
("short", 0.1, 1, 1, 1),
])
def test_stoploss_from_open_leverage(side, rel_stop, curr_profit, leverage, expected):
stoploss = stoploss_from_open(rel_stop, curr_profit, side == 'short')
assert pytest.approx(stoploss) == expected
open_rate = 100
if stoploss != 1:
if side == 'long':
current_rate = open_rate * (1 + curr_profit)
stop = current_rate * (1 - stoploss)
assert pytest.approx(stop) == open_rate * (1 + rel_stop)
else:
current_rate = open_rate * (1 - curr_profit)
stop = current_rate * (1 + stoploss)
assert pytest.approx(stop) == open_rate * (1 - rel_stop)
def test_stoploss_from_absolute():
assert pytest.approx(stoploss_from_absolute(90, 100)) == 1 - (90 / 100)
assert pytest.approx(stoploss_from_absolute(90, 100)) == 0.1