Add test for precision backpopulation
This commit is contained in:
parent
15a1c59a91
commit
fa89368c02
@ -852,7 +852,7 @@ class Backtesting:
|
|||||||
# interest_rate=interest_rate,
|
# interest_rate=interest_rate,
|
||||||
amount_precision=self.exchange.get_precision_amount(pair),
|
amount_precision=self.exchange.get_precision_amount(pair),
|
||||||
price_precision=self.exchange.get_precision_price(pair),
|
price_precision=self.exchange.get_precision_price(pair),
|
||||||
precision_mode=self.self.precision_mode,
|
precision_mode=self.precision_mode,
|
||||||
orders=[],
|
orders=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def mock_trade_usdt_1(fee, is_short: bool):
|
|||||||
def mock_order_usdt_2(is_short: bool):
|
def mock_order_usdt_2(is_short: bool):
|
||||||
return {
|
return {
|
||||||
'id': f'1235_{direc(is_short)}',
|
'id': f'1235_{direc(is_short)}',
|
||||||
'symbol': 'ETC/USDT',
|
'symbol': 'NEO/USDT',
|
||||||
'status': 'closed',
|
'status': 'closed',
|
||||||
'side': entry_side(is_short),
|
'side': entry_side(is_short),
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -95,7 +95,7 @@ def mock_order_usdt_2(is_short: bool):
|
|||||||
def mock_order_usdt_2_exit(is_short: bool):
|
def mock_order_usdt_2_exit(is_short: bool):
|
||||||
return {
|
return {
|
||||||
'id': f'12366_{direc(is_short)}',
|
'id': f'12366_{direc(is_short)}',
|
||||||
'symbol': 'ETC/USDT',
|
'symbol': 'NEO/USDT',
|
||||||
'status': 'closed',
|
'status': 'closed',
|
||||||
'side': exit_side(is_short),
|
'side': exit_side(is_short),
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -111,7 +111,7 @@ def mock_trade_usdt_2(fee, is_short: bool):
|
|||||||
Closed trade...
|
Closed trade...
|
||||||
"""
|
"""
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='ETC/USDT',
|
pair='NEO/USDT',
|
||||||
stake_amount=200.0,
|
stake_amount=200.0,
|
||||||
amount=100.0,
|
amount=100.0,
|
||||||
amount_requested=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),
|
close_date=datetime.now(tz=timezone.utc) - timedelta(minutes=2),
|
||||||
is_short=is_short,
|
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)
|
trade.orders.append(o)
|
||||||
o = Order.parse_from_ccxt_object(
|
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)
|
trade.orders.append(o)
|
||||||
return trade
|
return trade
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ def mock_trade_usdt_3(fee, is_short: bool):
|
|||||||
def mock_order_usdt_4(is_short: bool):
|
def mock_order_usdt_4(is_short: bool):
|
||||||
return {
|
return {
|
||||||
'id': f'prod_buy_12345_{direc(is_short)}',
|
'id': f'prod_buy_12345_{direc(is_short)}',
|
||||||
'symbol': 'ETC/USDT',
|
'symbol': 'NEO/USDT',
|
||||||
'status': 'open',
|
'status': 'open',
|
||||||
'side': entry_side(is_short),
|
'side': entry_side(is_short),
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -221,7 +221,7 @@ def mock_trade_usdt_4(fee, is_short: bool):
|
|||||||
Simulate prod entry
|
Simulate prod entry
|
||||||
"""
|
"""
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='ETC/USDT',
|
pair='NEO/USDT',
|
||||||
stake_amount=20.0,
|
stake_amount=20.0,
|
||||||
amount=10.0,
|
amount=10.0,
|
||||||
amount_requested=10.01,
|
amount_requested=10.01,
|
||||||
@ -236,7 +236,7 @@ def mock_trade_usdt_4(fee, is_short: bool):
|
|||||||
timeframe=5,
|
timeframe=5,
|
||||||
is_short=is_short,
|
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)
|
trade.orders.append(o)
|
||||||
return trade
|
return trade
|
||||||
|
|
||||||
|
@ -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:
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
||||||
create_mock_trades_usdt(fee)
|
create_mock_trades_usdt(fee)
|
||||||
pm.refresh_pairlist()
|
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)
|
assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
|
||||||
|
|
||||||
# Move to "outside" of lookback window, so original sorting is restored.
|
# 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:
|
with time_machine.travel("2021-09-01 05:00:00 +00:00") as t:
|
||||||
create_mock_trades_usdt(fee)
|
create_mock_trades_usdt(fee)
|
||||||
pm.refresh_pairlist()
|
pm.refresh_pairlist()
|
||||||
assert pm.whitelist == ['XRP/USDT', 'ETC/USDT', 'ETH/USDT', 'LTC/USDT',
|
assert pm.whitelist == ['XRP/USDT', 'NEO/USDT', 'ETH/USDT', 'LTC/USDT',
|
||||||
'NEO/USDT', 'TKN/USDT', 'ADA/USDT', ]
|
'TKN/USDT', 'ADA/USDT', 'ETC/USDT', ]
|
||||||
# assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
|
# assert log_has_re(r'Removing pair .* since .* is below .*', caplog)
|
||||||
|
|
||||||
# Move to "outside" of lookback window, so original sorting is restored.
|
# Move to "outside" of lookback window, so original sorting is restored.
|
||||||
|
@ -830,7 +830,7 @@ def test_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None:
|
|||||||
|
|
||||||
res = rpc._rpc_performance()
|
res = rpc._rpc_performance()
|
||||||
assert len(res) == 3
|
assert len(res) == 3
|
||||||
assert res[0]['pair'] == 'ETC/USDT'
|
assert res[0]['pair'] == 'NEO/USDT'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert res[0]['profit_pct'] == 5.0
|
assert res[0]['profit_pct'] == 5.0
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ from freqtrade.persistence import Order, PairLocks, Trade
|
|||||||
from freqtrade.persistence.models import PairLock
|
from freqtrade.persistence.models import PairLock
|
||||||
from freqtrade.plugins.protections.iprotection import ProtectionReturn
|
from freqtrade.plugins.protections.iprotection import ProtectionReturn
|
||||||
from freqtrade.worker import Worker
|
from freqtrade.worker import Worker
|
||||||
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, get_patched_worker,
|
from tests.conftest import (create_mock_trades, create_mock_trades_usdt, get_patched_freqtradebot,
|
||||||
log_has, log_has_re, patch_edge, patch_exchange, patch_get_signal,
|
get_patched_worker, log_has, log_has_re, patch_edge, patch_exchange,
|
||||||
patch_wallet, patch_whitelist)
|
patch_get_signal, patch_wallet, patch_whitelist)
|
||||||
from tests.conftest_trades import (MOCK_TRADE_COUNT, entry_side, exit_side, mock_order_1,
|
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_2, mock_order_2_sell, mock_order_3, mock_order_3_sell,
|
||||||
mock_order_4, mock_order_5_stoploss, mock_order_6_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'
|
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.usefixtures("init_persistence")
|
||||||
@pytest.mark.parametrize("is_short", [False, True])
|
@pytest.mark.parametrize("is_short", [False, True])
|
||||||
def test_update_closed_trades_without_assigned_fees(mocker, default_conf_usdt, fee, is_short):
|
def test_update_closed_trades_without_assigned_fees(mocker, default_conf_usdt, fee, is_short):
|
||||||
|
Loading…
Reference in New Issue
Block a user