Add test for precision backpopulation

This commit is contained in:
Matthias 2022-08-16 10:59:43 +02:00
parent 15a1c59a91
commit fa89368c02
5 changed files with 41 additions and 16 deletions

View File

@ -852,7 +852,7 @@ class Backtesting:
# interest_rate=interest_rate,
amount_precision=self.exchange.get_precision_amount(pair),
price_precision=self.exchange.get_precision_price(pair),
precision_mode=self.self.precision_mode,
precision_mode=self.precision_mode,
orders=[],
)

View File

@ -81,7 +81,7 @@ def mock_trade_usdt_1(fee, is_short: bool):
def mock_order_usdt_2(is_short: bool):
return {
'id': f'1235_{direc(is_short)}',
'symbol': 'ETC/USDT',
'symbol': 'NEO/USDT',
'status': 'closed',
'side': entry_side(is_short),
'type': 'limit',
@ -95,7 +95,7 @@ def mock_order_usdt_2(is_short: bool):
def mock_order_usdt_2_exit(is_short: bool):
return {
'id': f'12366_{direc(is_short)}',
'symbol': 'ETC/USDT',
'symbol': 'NEO/USDT',
'status': 'closed',
'side': exit_side(is_short),
'type': 'limit',
@ -111,7 +111,7 @@ def mock_trade_usdt_2(fee, is_short: bool):
Closed trade...
"""
trade = Trade(
pair='ETC/USDT',
pair='NEO/USDT',
stake_amount=200.0,
amount=100.0,
amount_requested=100.0,
@ -132,10 +132,10 @@ def mock_trade_usdt_2(fee, is_short: bool):
close_date=datetime.now(tz=timezone.utc) - timedelta(minutes=2),
is_short=is_short,
)
o = Order.parse_from_ccxt_object(mock_order_usdt_2(is_short), 'ETC/USDT', entry_side(is_short))
o = Order.parse_from_ccxt_object(mock_order_usdt_2(is_short), 'NEO/USDT', entry_side(is_short))
trade.orders.append(o)
o = Order.parse_from_ccxt_object(
mock_order_usdt_2_exit(is_short), 'ETC/USDT', exit_side(is_short))
mock_order_usdt_2_exit(is_short), 'NEO/USDT', exit_side(is_short))
trade.orders.append(o)
return trade
@ -205,7 +205,7 @@ def mock_trade_usdt_3(fee, is_short: bool):
def mock_order_usdt_4(is_short: bool):
return {
'id': f'prod_buy_12345_{direc(is_short)}',
'symbol': 'ETC/USDT',
'symbol': 'NEO/USDT',
'status': 'open',
'side': entry_side(is_short),
'type': 'limit',
@ -221,7 +221,7 @@ def mock_trade_usdt_4(fee, is_short: bool):
Simulate prod entry
"""
trade = Trade(
pair='ETC/USDT',
pair='NEO/USDT',
stake_amount=20.0,
amount=10.0,
amount_requested=10.01,
@ -236,7 +236,7 @@ def mock_trade_usdt_4(fee, is_short: bool):
timeframe=5,
is_short=is_short,
)
o = Order.parse_from_ccxt_object(mock_order_usdt_4(is_short), 'ETC/USDT', entry_side(is_short))
o = Order.parse_from_ccxt_object(mock_order_usdt_4(is_short), 'NEO/USDT', entry_side(is_short))
trade.orders.append(o)
return trade

View File

@ -735,7 +735,7 @@ def test_PerformanceFilter_lookback(mocker, default_conf_usdt, fee, caplog) -> N
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
create_mock_trades_usdt(fee)
pm.refresh_pairlist()
assert pm.whitelist == ['XRP/USDT']
assert pm.whitelist == ['XRP/USDT', 'NEO/USDT']
assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
# Move to "outside" of lookback window, so original sorting is restored.
@ -762,8 +762,8 @@ def test_PerformanceFilter_keep_mid_order(mocker, default_conf_usdt, fee, caplog
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
create_mock_trades_usdt(fee)
pm.refresh_pairlist()
assert pm.whitelist == ['XRP/USDT', 'ETC/USDT', 'ETH/USDT', 'LTC/USDT',
'NEO/USDT', 'TKN/USDT', 'ADA/USDT', ]
assert pm.whitelist == ['XRP/USDT', 'NEO/USDT', 'ETH/USDT', 'LTC/USDT',
'TKN/USDT', 'ADA/USDT', 'ETC/USDT', ]
# assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
# Move to "outside" of lookback window, so original sorting is restored.

View File

@ -830,7 +830,7 @@ def test_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None:
res = rpc._rpc_performance()
assert len(res) == 3
assert res[0]['pair'] == 'ETC/USDT'
assert res[0]['pair'] == 'NEO/USDT'
assert res[0]['count'] == 1
assert res[0]['profit_pct'] == 5.0

View File

@ -23,9 +23,9 @@ from freqtrade.persistence import Order, PairLocks, Trade
from freqtrade.persistence.models import PairLock
from freqtrade.plugins.protections.iprotection import ProtectionReturn
from freqtrade.worker import Worker
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, get_patched_worker,
log_has, log_has_re, patch_edge, patch_exchange, patch_get_signal,
patch_wallet, patch_whitelist)
from tests.conftest import (create_mock_trades, create_mock_trades_usdt, get_patched_freqtradebot,
get_patched_worker, log_has, log_has_re, patch_edge, patch_exchange,
patch_get_signal, patch_wallet, patch_whitelist)
from tests.conftest_trades import (MOCK_TRADE_COUNT, entry_side, exit_side, mock_order_1,
mock_order_2, mock_order_2_sell, mock_order_3, mock_order_3_sell,
mock_order_4, mock_order_5_stoploss, mock_order_6_sell)
@ -4888,6 +4888,31 @@ def test_startup_update_open_orders(mocker, default_conf_usdt, fee, caplog, is_s
assert hto_mock.call_args_list[1][0][0]['status'] == 'canceled'
@pytest.mark.usefixtures("init_persistence")
def test_startup_backpopulate_precision(mocker, default_conf_usdt, fee, caplog):
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
create_mock_trades_usdt(fee)
trades = Trade.get_trades().all()
trades[-1].exchange = 'some_other_exchange'
for trade in trades:
assert trade.price_precision is None
assert trade.amount_precision is None
assert trade.precision_mode is None
freqtrade.startup_backpopulate_precision()
trades = Trade.get_trades().all()
for trade in trades:
if trade.exchange == 'some_other_exchange':
assert trade.price_precision is None
assert trade.amount_precision is None
assert trade.precision_mode is None
else:
assert trade.price_precision is not None
assert trade.amount_precision is not None
assert trade.precision_mode is not None
@pytest.mark.usefixtures("init_persistence")
@pytest.mark.parametrize("is_short", [False, True])
def test_update_closed_trades_without_assigned_fees(mocker, default_conf_usdt, fee, is_short):