default_conf is function-scoped fixture, no need to deepcopy it
This commit is contained in:
parent
67d1693901
commit
8b8d3f3b75
@ -1,7 +1,6 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103, bad-continuation, global-statement
|
# pragma pylint: disable=missing-docstring, C0103, bad-continuation, global-statement
|
||||||
# pragma pylint: disable=protected-access
|
# pragma pylint: disable=protected-access
|
||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from random import randint
|
from random import randint
|
||||||
from unittest.mock import MagicMock, PropertyMock
|
from unittest.mock import MagicMock, PropertyMock
|
||||||
@ -78,12 +77,11 @@ def test_validate_pairs_not_compatible(default_conf, mocker):
|
|||||||
api_mock.load_markets = MagicMock(return_value={
|
api_mock.load_markets = MagicMock(return_value={
|
||||||
'ETH/BTC': '', 'TKN/BTC': '', 'TRST/BTC': '', 'SWT/BTC': '', 'BCC/BTC': ''
|
'ETH/BTC': '', 'TKN/BTC': '', 'TRST/BTC': '', 'SWT/BTC': '', 'BCC/BTC': ''
|
||||||
})
|
})
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_currency'] = 'ETH'
|
||||||
conf['stake_currency'] = 'ETH'
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
|
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
|
||||||
with pytest.raises(OperationalException, match=r'not compatible'):
|
with pytest.raises(OperationalException, match=r'not compatible'):
|
||||||
Exchange(conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_validate_pairs_exception(default_conf, mocker, caplog):
|
def test_validate_pairs_exception(default_conf, mocker, caplog):
|
||||||
@ -108,8 +106,7 @@ def test_validate_pairs_exception(default_conf, mocker, caplog):
|
|||||||
|
|
||||||
def test_validate_pairs_stake_exception(default_conf, mocker, caplog):
|
def test_validate_pairs_stake_exception(default_conf, mocker, caplog):
|
||||||
caplog.set_level(logging.INFO)
|
caplog.set_level(logging.INFO)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_currency'] = 'ETH'
|
||||||
conf['stake_currency'] = 'ETH'
|
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.name = MagicMock(return_value='binance')
|
api_mock.name = MagicMock(return_value='binance')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', api_mock)
|
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', api_mock)
|
||||||
@ -119,7 +116,7 @@ def test_validate_pairs_stake_exception(default_conf, mocker, caplog):
|
|||||||
OperationalException,
|
OperationalException,
|
||||||
match=r'Pair ETH/BTC not compatible with stake_currency: ETH'
|
match=r'Pair ETH/BTC not compatible with stake_currency: ETH'
|
||||||
):
|
):
|
||||||
Exchange(conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_validate_timeframes(default_conf, mocker):
|
def test_validate_timeframes(default_conf, mocker):
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
from copy import deepcopy
|
|
||||||
from typing import List
|
from typing import List
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
@ -270,11 +269,10 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
|
|
||||||
|
|
||||||
def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None:
|
def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
||||||
conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
|
||||||
|
|
||||||
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
||||||
read_data=json.dumps(conf)
|
read_data=json.dumps(default_conf)
|
||||||
))
|
))
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
@ -422,15 +420,14 @@ def test_backtesting_start(default_conf, mocker, caplog) -> None:
|
|||||||
get_timeframe=get_timeframe,
|
get_timeframe=get_timeframe,
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
||||||
conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
default_conf['ticker_interval'] = 1
|
||||||
conf['ticker_interval'] = 1
|
default_conf['live'] = False
|
||||||
conf['live'] = False
|
default_conf['datadir'] = None
|
||||||
conf['datadir'] = None
|
default_conf['export'] = None
|
||||||
conf['export'] = None
|
default_conf['timerange'] = '-100'
|
||||||
conf['timerange'] = '-100'
|
|
||||||
|
|
||||||
backtesting = Backtesting(conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting.start()
|
backtesting.start()
|
||||||
# check the logs, that will contain the backtest result
|
# check the logs, that will contain the backtest result
|
||||||
exists = [
|
exists = [
|
||||||
@ -458,15 +455,14 @@ def test_backtesting_start_no_data(default_conf, mocker, caplog) -> None:
|
|||||||
get_timeframe=get_timeframe,
|
get_timeframe=get_timeframe,
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
||||||
conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
default_conf['ticker_interval'] = "1m"
|
||||||
conf['ticker_interval'] = "1m"
|
default_conf['live'] = False
|
||||||
conf['live'] = False
|
default_conf['datadir'] = None
|
||||||
conf['datadir'] = None
|
default_conf['export'] = None
|
||||||
conf['export'] = None
|
default_conf['timerange'] = '20180101-20180102'
|
||||||
conf['timerange'] = '20180101-20180102'
|
|
||||||
|
|
||||||
backtesting = Backtesting(conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting.start()
|
backtesting.start()
|
||||||
# check the logs, that will contain the backtest result
|
# check the logs, that will contain the backtest result
|
||||||
|
|
||||||
@ -680,15 +676,14 @@ def test_backtest_record(default_conf, fee, mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test_backtest_start_live(default_conf, mocker, caplog):
|
def test_backtest_start_live(default_conf, mocker, caplog):
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
||||||
conf['exchange']['pair_whitelist'] = ['UNITTEST/BTC']
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_ticker_history',
|
mocker.patch('freqtrade.exchange.Exchange.get_ticker_history',
|
||||||
new=lambda s, n, i: _load_pair_as_ticks(n, i))
|
new=lambda s, n, i: _load_pair_as_ticks(n, i))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest', MagicMock())
|
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest', MagicMock())
|
||||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting._generate_text_table', MagicMock())
|
mocker.patch('freqtrade.optimize.backtesting.Backtesting._generate_text_table', MagicMock())
|
||||||
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
||||||
read_data=json.dumps(conf)
|
read_data=json.dumps(default_conf)
|
||||||
))
|
))
|
||||||
|
|
||||||
args = MagicMock()
|
args = MagicMock()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212,C0103
|
# pragma pylint: disable=missing-docstring,W0212,C0103
|
||||||
import os
|
import os
|
||||||
from copy import deepcopy
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@ -164,13 +163,12 @@ def test_start_calls_optimizer(mocker, default_conf, caplog) -> None:
|
|||||||
)
|
)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'config': 'config.json.example'})
|
||||||
conf.update({'config': 'config.json.example'})
|
default_conf.update({'epochs': 1})
|
||||||
conf.update({'epochs': 1})
|
default_conf.update({'timerange': None})
|
||||||
conf.update({'timerange': None})
|
default_conf.update({'spaces': 'all'})
|
||||||
conf.update({'spaces': 'all'})
|
|
||||||
|
|
||||||
hyperopt = Hyperopt(conf)
|
hyperopt = Hyperopt(default_conf)
|
||||||
hyperopt.tickerdata_to_dataframe = MagicMock()
|
hyperopt.tickerdata_to_dataframe = MagicMock()
|
||||||
|
|
||||||
hyperopt.start()
|
hyperopt.start()
|
||||||
@ -254,10 +252,9 @@ def test_buy_strategy_generator(hyperopt) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_generate_optimizer(mocker, default_conf) -> None:
|
def test_generate_optimizer(mocker, default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'config': 'config.json.example'})
|
||||||
conf.update({'config': 'config.json.example'})
|
default_conf.update({'timerange': None})
|
||||||
conf.update({'timerange': None})
|
default_conf.update({'spaces': 'all'})
|
||||||
conf.update({'spaces': 'all'})
|
|
||||||
|
|
||||||
trades = [
|
trades = [
|
||||||
('POWR/BTC', 0.023117, 0.000233, 100)
|
('POWR/BTC', 0.023117, 0.000233, 100)
|
||||||
@ -297,6 +294,6 @@ def test_generate_optimizer(mocker, default_conf) -> None:
|
|||||||
'params': optimizer_param
|
'params': optimizer_param
|
||||||
}
|
}
|
||||||
|
|
||||||
hyperopt = Hyperopt(conf)
|
hyperopt = Hyperopt(default_conf)
|
||||||
generate_optimizer_value = hyperopt.generate_optimizer(list(optimizer_param.values()))
|
generate_optimizer_value = hyperopt.generate_optimizer(list(optimizer_param.values()))
|
||||||
assert generate_optimizer_value == response_expected
|
assert generate_optimizer_value == response_expected
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from freqtrade.rpc import RPCMessageType, RPCManager
|
from freqtrade.rpc import RPCMessageType, RPCManager
|
||||||
@ -9,18 +8,16 @@ from freqtrade.tests.conftest import log_has, get_patched_freqtradebot
|
|||||||
|
|
||||||
|
|
||||||
def test__init__(mocker, default_conf) -> None:
|
def test__init__(mocker, default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
|
||||||
|
|
||||||
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, conf))
|
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, default_conf))
|
||||||
assert rpc_manager.registered_modules == []
|
assert rpc_manager.registered_modules == []
|
||||||
|
|
||||||
|
|
||||||
def test_init_telegram_disabled(mocker, default_conf, caplog) -> None:
|
def test_init_telegram_disabled(mocker, default_conf, caplog) -> None:
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, default_conf))
|
||||||
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, conf))
|
|
||||||
|
|
||||||
assert not log_has('Enabling rpc.telegram ...', caplog.record_tuples)
|
assert not log_has('Enabling rpc.telegram ...', caplog.record_tuples)
|
||||||
assert rpc_manager.registered_modules == []
|
assert rpc_manager.registered_modules == []
|
||||||
@ -40,10 +37,9 @@ def test_init_telegram_enabled(mocker, default_conf, caplog) -> None:
|
|||||||
def test_cleanup_telegram_disabled(mocker, default_conf, caplog) -> None:
|
def test_cleanup_telegram_disabled(mocker, default_conf, caplog) -> None:
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.cleanup', MagicMock())
|
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.cleanup', MagicMock())
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
rpc_manager = RPCManager(freqtradebot)
|
rpc_manager = RPCManager(freqtradebot)
|
||||||
rpc_manager.cleanup()
|
rpc_manager.cleanup()
|
||||||
|
|
||||||
@ -70,10 +66,9 @@ def test_cleanup_telegram_enabled(mocker, default_conf, caplog) -> None:
|
|||||||
|
|
||||||
def test_send_msg_telegram_disabled(mocker, default_conf, caplog) -> None:
|
def test_send_msg_telegram_disabled(mocker, default_conf, caplog) -> None:
|
||||||
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
|
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
rpc_manager = RPCManager(freqtradebot)
|
rpc_manager = RPCManager(freqtradebot)
|
||||||
rpc_manager.send_msg({
|
rpc_manager.send_msg({
|
||||||
'type': RPCMessageType.STATUS_NOTIFICATION,
|
'type': RPCMessageType.STATUS_NOTIFICATION,
|
||||||
@ -101,10 +96,9 @@ def test_send_msg_telegram_enabled(mocker, default_conf, caplog) -> None:
|
|||||||
|
|
||||||
def test_init_webhook_disabled(mocker, default_conf, caplog) -> None:
|
def test_init_webhook_disabled(mocker, default_conf, caplog) -> None:
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
default_conf['webhook'] = {'enabled': False}
|
||||||
conf['webhook'] = {'enabled': False}
|
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, default_conf))
|
||||||
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, conf))
|
|
||||||
|
|
||||||
assert not log_has('Enabling rpc.webhook ...', caplog.record_tuples)
|
assert not log_has('Enabling rpc.webhook ...', caplog.record_tuples)
|
||||||
assert rpc_manager.registered_modules == []
|
assert rpc_manager.registered_modules == []
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
# pragma pylint: disable=too-many-lines, too-many-arguments
|
# pragma pylint: disable=too-many-lines, too-many-arguments
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from copy import deepcopy
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from random import randint
|
from random import randint
|
||||||
from unittest.mock import MagicMock, ANY
|
from unittest.mock import MagicMock, ANY
|
||||||
@ -96,9 +95,8 @@ def test_authorized_only(default_conf, mocker, caplog) -> None:
|
|||||||
update = Update(randint(1, 100))
|
update = Update(randint(1, 100))
|
||||||
update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
|
update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
bot = FreqtradeBot(default_conf)
|
||||||
bot = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(bot, (True, False))
|
patch_get_signal(bot, (True, False))
|
||||||
dummy = DummyCls(bot)
|
dummy = DummyCls(bot)
|
||||||
dummy.dummy_handler(bot=MagicMock(), update=update)
|
dummy.dummy_handler(bot=MagicMock(), update=update)
|
||||||
@ -124,9 +122,8 @@ def test_authorized_only_unauthorized(default_conf, mocker, caplog) -> None:
|
|||||||
update = Update(randint(1, 100))
|
update = Update(randint(1, 100))
|
||||||
update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
|
update.message = Message(randint(1, 100), 0, datetime.utcnow(), chat)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
bot = FreqtradeBot(default_conf)
|
||||||
bot = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(bot, (True, False))
|
patch_get_signal(bot, (True, False))
|
||||||
dummy = DummyCls(bot)
|
dummy = DummyCls(bot)
|
||||||
dummy.dummy_handler(bot=MagicMock(), update=update)
|
dummy.dummy_handler(bot=MagicMock(), update=update)
|
||||||
@ -152,10 +149,9 @@ def test_authorized_only_exception(default_conf, mocker, caplog) -> None:
|
|||||||
update = Update(randint(1, 100))
|
update = Update(randint(1, 100))
|
||||||
update.message = Message(randint(1, 100), 0, datetime.utcnow(), Chat(0, 0))
|
update.message = Message(randint(1, 100), 0, datetime.utcnow(), Chat(0, 0))
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
|
||||||
|
|
||||||
bot = FreqtradeBot(conf)
|
bot = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(bot, (True, False))
|
patch_get_signal(bot, (True, False))
|
||||||
dummy = DummyCls(bot)
|
dummy = DummyCls(bot)
|
||||||
|
|
||||||
@ -177,9 +173,8 @@ def test_authorized_only_exception(default_conf, mocker, caplog) -> None:
|
|||||||
|
|
||||||
def test_status(default_conf, update, mocker, fee, ticker, markets) -> None:
|
def test_status(default_conf, update, mocker, fee, ticker, markets) -> None:
|
||||||
update.message.chat.id = 123
|
update.message.chat.id = 123
|
||||||
conf = deepcopy(default_conf)
|
default_conf['telegram']['enabled'] = False
|
||||||
conf['telegram']['enabled'] = False
|
default_conf['telegram']['chat_id'] = 123
|
||||||
conf['telegram']['chat_id'] = 123
|
|
||||||
|
|
||||||
patch_coinmarketcap(mocker)
|
patch_coinmarketcap(mocker)
|
||||||
|
|
||||||
@ -214,7 +209,7 @@ def test_status(default_conf, update, mocker, fee, ticker, markets) -> None:
|
|||||||
)
|
)
|
||||||
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
||||||
|
|
||||||
freqtradebot = FreqtradeBot(conf)
|
freqtradebot = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtradebot, (True, False))
|
patch_get_signal(freqtradebot, (True, False))
|
||||||
telegram = Telegram(freqtradebot)
|
telegram = Telegram(freqtradebot)
|
||||||
|
|
||||||
@ -294,9 +289,8 @@ def test_status_table_handle(default_conf, update, ticker, fee, markets, mocker)
|
|||||||
)
|
)
|
||||||
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_amount'] = 15.0
|
||||||
conf['stake_amount'] = 15.0
|
freqtradebot = FreqtradeBot(default_conf)
|
||||||
freqtradebot = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtradebot, (True, False))
|
patch_get_signal(freqtradebot, (True, False))
|
||||||
|
|
||||||
telegram = Telegram(freqtradebot)
|
telegram = Telegram(freqtradebot)
|
||||||
@ -1181,9 +1175,8 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
|
|||||||
def test__send_msg(default_conf, mocker) -> None:
|
def test__send_msg(default_conf, mocker) -> None:
|
||||||
patch_coinmarketcap(mocker)
|
patch_coinmarketcap(mocker)
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
bot = MagicMock()
|
bot = MagicMock()
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
telegram = Telegram(freqtradebot)
|
telegram = Telegram(freqtradebot)
|
||||||
|
|
||||||
telegram._config['telegram']['enabled'] = True
|
telegram._config['telegram']['enabled'] = True
|
||||||
@ -1194,10 +1187,9 @@ def test__send_msg(default_conf, mocker) -> None:
|
|||||||
def test__send_msg_network_error(default_conf, mocker, caplog) -> None:
|
def test__send_msg_network_error(default_conf, mocker, caplog) -> None:
|
||||||
patch_coinmarketcap(mocker)
|
patch_coinmarketcap(mocker)
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
bot = MagicMock()
|
bot = MagicMock()
|
||||||
bot.send_message = MagicMock(side_effect=NetworkError('Oh snap'))
|
bot.send_message = MagicMock(side_effect=NetworkError('Oh snap'))
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
telegram = Telegram(freqtradebot)
|
telegram = Telegram(freqtradebot)
|
||||||
|
|
||||||
telegram._config['telegram']['enabled'] = True
|
telegram._config['telegram']['enabled'] = True
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
from copy import deepcopy
|
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
@ -18,30 +17,27 @@ from freqtrade.tests.conftest import log_has
|
|||||||
|
|
||||||
|
|
||||||
def test_load_config_invalid_pair(default_conf) -> None:
|
def test_load_config_invalid_pair(default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_whitelist'].append('ETH-BTC')
|
||||||
conf['exchange']['pair_whitelist'].append('ETH-BTC')
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError, match=r'.*does not match.*'):
|
with pytest.raises(ValidationError, match=r'.*does not match.*'):
|
||||||
configuration = Configuration(Namespace())
|
configuration = Configuration(Namespace())
|
||||||
configuration._validate_config(conf)
|
configuration._validate_config(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_missing_attributes(default_conf) -> None:
|
def test_load_config_missing_attributes(default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf.pop('exchange')
|
||||||
conf.pop('exchange')
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError, match=r'.*\'exchange\' is a required property.*'):
|
with pytest.raises(ValidationError, match=r'.*\'exchange\' is a required property.*'):
|
||||||
configuration = Configuration(Namespace())
|
configuration = Configuration(Namespace())
|
||||||
configuration._validate_config(conf)
|
configuration._validate_config(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_incorrect_stake_amount(default_conf) -> None:
|
def test_load_config_incorrect_stake_amount(default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_amount'] = 'fake'
|
||||||
conf['stake_amount'] = 'fake'
|
|
||||||
|
|
||||||
with pytest.raises(ValidationError, match=r'.*\'fake\' does not match \'unlimited\'.*'):
|
with pytest.raises(ValidationError, match=r'.*\'fake\' does not match \'unlimited\'.*'):
|
||||||
configuration = Configuration(Namespace())
|
configuration = Configuration(Namespace())
|
||||||
configuration._validate_config(conf)
|
configuration._validate_config(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_file(default_conf, mocker, caplog) -> None:
|
def test_load_config_file(default_conf, mocker, caplog) -> None:
|
||||||
@ -58,10 +54,9 @@ def test_load_config_file(default_conf, mocker, caplog) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None:
|
def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['max_open_trades'] = 0
|
||||||
conf['max_open_trades'] = 0
|
|
||||||
file_mock = mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
file_mock = mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
||||||
read_data=json.dumps(conf)
|
read_data=json.dumps(default_conf)
|
||||||
))
|
))
|
||||||
|
|
||||||
Configuration(Namespace())._load_config_file('somefile')
|
Configuration(Namespace())._load_config_file('somefile')
|
||||||
@ -152,13 +147,12 @@ def test_load_config_with_params(default_conf, mocker) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_load_custom_strategy(default_conf, mocker) -> None:
|
def test_load_custom_strategy(default_conf, mocker) -> None:
|
||||||
custom_conf = deepcopy(default_conf)
|
default_conf.update({
|
||||||
custom_conf.update({
|
|
||||||
'strategy': 'CustomStrategy',
|
'strategy': 'CustomStrategy',
|
||||||
'strategy_path': '/tmp/strategies',
|
'strategy_path': '/tmp/strategies',
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
|
||||||
read_data=json.dumps(custom_conf)
|
read_data=json.dumps(default_conf)
|
||||||
))
|
))
|
||||||
|
|
||||||
args = Arguments([], '').get_parsed_arg()
|
args = Arguments([], '').get_parsed_arg()
|
||||||
@ -323,26 +317,25 @@ def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_check_exchange(default_conf) -> None:
|
def test_check_exchange(default_conf) -> None:
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
configuration = Configuration(Namespace())
|
configuration = Configuration(Namespace())
|
||||||
|
|
||||||
# Test a valid exchange
|
# Test a valid exchange
|
||||||
conf.get('exchange').update({'name': 'BITTREX'})
|
default_conf.get('exchange').update({'name': 'BITTREX'})
|
||||||
assert configuration.check_exchange(conf)
|
assert configuration.check_exchange(default_conf)
|
||||||
|
|
||||||
# Test a valid exchange
|
# Test a valid exchange
|
||||||
conf.get('exchange').update({'name': 'binance'})
|
default_conf.get('exchange').update({'name': 'binance'})
|
||||||
assert configuration.check_exchange(conf)
|
assert configuration.check_exchange(default_conf)
|
||||||
|
|
||||||
# Test a invalid exchange
|
# Test a invalid exchange
|
||||||
conf.get('exchange').update({'name': 'unknown_exchange'})
|
default_conf.get('exchange').update({'name': 'unknown_exchange'})
|
||||||
configuration.config = conf
|
configuration.config = default_conf
|
||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
OperationalException,
|
OperationalException,
|
||||||
match=r'.*Exchange "unknown_exchange" not supported.*'
|
match=r'.*Exchange "unknown_exchange" not supported.*'
|
||||||
):
|
):
|
||||||
configuration.check_exchange(conf)
|
configuration.check_exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None:
|
def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None:
|
||||||
|
@ -63,9 +63,8 @@ def test_freqtradebot(mocker, default_conf) -> None:
|
|||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
assert freqtrade.state is State.RUNNING
|
assert freqtrade.state is State.RUNNING
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf.pop('initial_state')
|
||||||
conf.pop('initial_state')
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
assert freqtrade.state is State.STOPPED
|
assert freqtrade.state is State.STOPPED
|
||||||
|
|
||||||
|
|
||||||
@ -442,14 +441,13 @@ def test_create_trade_minimal_amount(default_conf, ticker, limit_buy_order,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_amount'] = 0.0005
|
||||||
conf['stake_amount'] = 0.0005
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
rate, amount = buy_mock.call_args[0][1], buy_mock.call_args[0][2]
|
rate, amount = buy_mock.call_args[0][1], buy_mock.call_args[0][2]
|
||||||
assert rate * amount >= conf['stake_amount']
|
assert rate * amount >= default_conf['stake_amount']
|
||||||
|
|
||||||
|
|
||||||
def test_create_trade_too_small_stake_amount(default_conf, ticker, limit_buy_order,
|
def test_create_trade_too_small_stake_amount(default_conf, ticker, limit_buy_order,
|
||||||
@ -465,9 +463,8 @@ def test_create_trade_too_small_stake_amount(default_conf, ticker, limit_buy_ord
|
|||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['stake_amount'] = 0.000000005
|
||||||
conf['stake_amount'] = 0.000000005
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
result = freqtrade.create_trade()
|
result = freqtrade.create_trade()
|
||||||
@ -486,11 +483,10 @@ def test_create_trade_limit_reached(default_conf, ticker, limit_buy_order,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['max_open_trades'] = 0
|
||||||
conf['max_open_trades'] = 0
|
default_conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
||||||
conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
|
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
assert freqtrade.create_trade() is False
|
assert freqtrade.create_trade() is False
|
||||||
@ -508,10 +504,9 @@ def test_create_trade_no_pairs(default_conf, ticker, limit_buy_order, fee, marke
|
|||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_whitelist'] = ["ETH/BTC"]
|
||||||
conf['exchange']['pair_whitelist'] = ["ETH/BTC"]
|
default_conf['exchange']['pair_blacklist'] = ["ETH/BTC"]
|
||||||
conf['exchange']['pair_blacklist'] = ["ETH/BTC"]
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -531,11 +526,9 @@ def test_create_trade_no_pairs_after_blacklist(default_conf, ticker,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
default_conf['exchange']['pair_whitelist'] = ["ETH/BTC"]
|
||||||
conf = deepcopy(default_conf)
|
default_conf['exchange']['pair_blacklist'] = ["ETH/BTC"]
|
||||||
conf['exchange']['pair_whitelist'] = ["ETH/BTC"]
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
conf['exchange']['pair_blacklist'] = ["ETH/BTC"]
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -545,8 +538,7 @@ def test_create_trade_no_pairs_after_blacklist(default_conf, ticker,
|
|||||||
|
|
||||||
|
|
||||||
def test_create_trade_no_signal(default_conf, fee, mocker) -> None:
|
def test_create_trade_no_signal(default_conf, fee, mocker) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf['dry_run'] = True
|
||||||
conf['dry_run'] = True
|
|
||||||
|
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
@ -556,10 +548,8 @@ def test_create_trade_no_signal(default_conf, fee, mocker) -> None:
|
|||||||
get_balance=MagicMock(return_value=20),
|
get_balance=MagicMock(return_value=20),
|
||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
|
default_conf['stake_amount'] = 10
|
||||||
conf = deepcopy(default_conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
conf['stake_amount'] = 10
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade, value=(False, False))
|
patch_get_signal(freqtrade, value=(False, False))
|
||||||
|
|
||||||
Trade.query = MagicMock()
|
Trade.query = MagicMock()
|
||||||
@ -813,8 +803,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order,
|
|||||||
|
|
||||||
def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order,
|
def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order,
|
||||||
fee, markets, mocker) -> None:
|
fee, markets, mocker) -> None:
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'experimental': {'use_sell_signal': True}})
|
||||||
conf.update({'experimental': {'use_sell_signal': True}})
|
|
||||||
|
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
@ -826,7 +815,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order,
|
|||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade, value=(True, True))
|
patch_get_signal(freqtrade, value=(True, True))
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
|
|
||||||
@ -870,8 +859,7 @@ def test_handle_overlpapping_signals(default_conf, ticker, limit_buy_order,
|
|||||||
def test_handle_trade_roi(default_conf, ticker, limit_buy_order,
|
def test_handle_trade_roi(default_conf, ticker, limit_buy_order,
|
||||||
fee, mocker, markets, caplog) -> None:
|
fee, mocker, markets, caplog) -> None:
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'experimental': {'use_sell_signal': True}})
|
||||||
conf.update({'experimental': {'use_sell_signal': True}})
|
|
||||||
|
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
@ -883,7 +871,7 @@ def test_handle_trade_roi(default_conf, ticker, limit_buy_order,
|
|||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade, value=(True, False))
|
patch_get_signal(freqtrade, value=(True, False))
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
||||||
|
|
||||||
@ -905,9 +893,7 @@ def test_handle_trade_roi(default_conf, ticker, limit_buy_order,
|
|||||||
def test_handle_trade_experimental(
|
def test_handle_trade_experimental(
|
||||||
default_conf, ticker, limit_buy_order, fee, mocker, markets, caplog) -> None:
|
default_conf, ticker, limit_buy_order, fee, mocker, markets, caplog) -> None:
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'experimental': {'use_sell_signal': True}})
|
||||||
conf.update({'experimental': {'use_sell_signal': True}})
|
|
||||||
|
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -918,7 +904,7 @@ def test_handle_trade_experimental(
|
|||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -1360,12 +1346,11 @@ def test_sell_profit_only_enable_profit(default_conf, limit_buy_order,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['experimental'] = {
|
||||||
conf['experimental'] = {
|
|
||||||
'use_sell_signal': True,
|
'use_sell_signal': True,
|
||||||
'sell_profit_only': True,
|
'sell_profit_only': True,
|
||||||
}
|
}
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
|
|
||||||
@ -1393,12 +1378,11 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['experimental'] = {
|
||||||
conf['experimental'] = {
|
|
||||||
'use_sell_signal': True,
|
'use_sell_signal': True,
|
||||||
'sell_profit_only': False,
|
'sell_profit_only': False,
|
||||||
}
|
}
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -1424,12 +1408,11 @@ def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, fee, market
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
conf = deepcopy(default_conf)
|
default_conf['experimental'] = {
|
||||||
conf['experimental'] = {
|
|
||||||
'use_sell_signal': True,
|
'use_sell_signal': True,
|
||||||
'sell_profit_only': True,
|
'sell_profit_only': True,
|
||||||
}
|
}
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.stop_loss_reached = \
|
freqtrade.strategy.stop_loss_reached = \
|
||||||
lambda current_rate, trade, current_time, current_profit: SellCheckTuple(
|
lambda current_rate, trade, current_time, current_profit: SellCheckTuple(
|
||||||
@ -1456,14 +1439,12 @@ def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, fee, marke
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
default_conf['experimental'] = {
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
conf['experimental'] = {
|
|
||||||
'use_sell_signal': True,
|
'use_sell_signal': True,
|
||||||
'sell_profit_only': False,
|
'sell_profit_only': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
|
|
||||||
@ -1490,13 +1471,10 @@ def test_ignore_roi_if_buy_signal(default_conf, limit_buy_order, fee, markets, m
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
default_conf['experimental'] = {
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
conf['experimental'] = {
|
|
||||||
'ignore_roi_if_buy_signal': True
|
'ignore_roi_if_buy_signal': True
|
||||||
}
|
}
|
||||||
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
||||||
|
|
||||||
@ -1527,11 +1505,8 @@ def test_trailing_stop_loss(default_conf, limit_buy_order, fee, markets, caplog,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets,
|
get_markets=markets,
|
||||||
)
|
)
|
||||||
|
default_conf['trailing_stop'] = True
|
||||||
conf = deepcopy(default_conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
conf['trailing_stop'] = True
|
|
||||||
print(limit_buy_order)
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
|
|
||||||
@ -1564,11 +1539,9 @@ def test_trailing_stop_loss_positive(default_conf, limit_buy_order, fee, markets
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets,
|
get_markets=markets,
|
||||||
)
|
)
|
||||||
|
default_conf['trailing_stop'] = True
|
||||||
conf = deepcopy(default_conf)
|
default_conf['trailing_stop_positive'] = 0.01
|
||||||
conf['trailing_stop'] = True
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
conf['trailing_stop_positive'] = 0.01
|
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -1625,11 +1598,10 @@ def test_trailing_stop_loss_offset(default_conf, limit_buy_order, fee,
|
|||||||
get_markets=markets,
|
get_markets=markets,
|
||||||
)
|
)
|
||||||
|
|
||||||
conf = deepcopy(default_conf)
|
default_conf['trailing_stop'] = True
|
||||||
conf['trailing_stop'] = True
|
default_conf['trailing_stop_positive'] = 0.01
|
||||||
conf['trailing_stop_positive'] = 0.01
|
default_conf['trailing_stop_positive_offset'] = 0.011
|
||||||
conf['trailing_stop_positive_offset'] = 0.011
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: False
|
||||||
freqtrade.create_trade()
|
freqtrade.create_trade()
|
||||||
@ -1685,13 +1657,10 @@ def test_disable_ignore_roi_if_buy_signal(default_conf, limit_buy_order,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
get_markets=markets
|
get_markets=markets
|
||||||
)
|
)
|
||||||
|
default_conf['experimental'] = {
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
conf['experimental'] = {
|
|
||||||
'ignore_roi_if_buy_signal': False
|
'ignore_roi_if_buy_signal': False
|
||||||
}
|
}
|
||||||
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
freqtrade = FreqtradeBot(conf)
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
freqtrade.strategy.min_roi_reached = lambda trade, current_profit, current_time: True
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
from copy import deepcopy
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -23,46 +22,40 @@ def test_init_create_session(default_conf):
|
|||||||
|
|
||||||
|
|
||||||
def test_init_custom_db_url(default_conf, mocker):
|
def test_init_custom_db_url(default_conf, mocker):
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
|
|
||||||
# Update path to a value other than default, but still in-memory
|
# Update path to a value other than default, but still in-memory
|
||||||
conf.update({'db_url': 'sqlite:///tmp/freqtrade2_test.sqlite'})
|
default_conf.update({'db_url': 'sqlite:///tmp/freqtrade2_test.sqlite'})
|
||||||
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
||||||
|
|
||||||
init(conf)
|
init(default_conf)
|
||||||
assert create_engine_mock.call_count == 1
|
assert create_engine_mock.call_count == 1
|
||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tmp/freqtrade2_test.sqlite'
|
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tmp/freqtrade2_test.sqlite'
|
||||||
|
|
||||||
|
|
||||||
def test_init_invalid_db_url(default_conf):
|
def test_init_invalid_db_url(default_conf):
|
||||||
conf = deepcopy(default_conf)
|
|
||||||
|
|
||||||
# Update path to a value other than default, but still in-memory
|
# Update path to a value other than default, but still in-memory
|
||||||
conf.update({'db_url': 'unknown:///some.url'})
|
default_conf.update({'db_url': 'unknown:///some.url'})
|
||||||
with pytest.raises(OperationalException, match=r'.*no valid database URL*'):
|
with pytest.raises(OperationalException, match=r'.*no valid database URL*'):
|
||||||
init(conf)
|
init(default_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_init_prod_db(default_conf, mocker):
|
def test_init_prod_db(default_conf, mocker):
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'dry_run': False})
|
||||||
conf.update({'dry_run': False})
|
default_conf.update({'db_url': constants.DEFAULT_DB_PROD_URL})
|
||||||
conf.update({'db_url': constants.DEFAULT_DB_PROD_URL})
|
|
||||||
|
|
||||||
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
||||||
|
|
||||||
init(conf)
|
init(default_conf)
|
||||||
assert create_engine_mock.call_count == 1
|
assert create_engine_mock.call_count == 1
|
||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite'
|
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite'
|
||||||
|
|
||||||
|
|
||||||
def test_init_dryrun_db(default_conf, mocker):
|
def test_init_dryrun_db(default_conf, mocker):
|
||||||
conf = deepcopy(default_conf)
|
default_conf.update({'dry_run': True})
|
||||||
conf.update({'dry_run': True})
|
default_conf.update({'db_url': constants.DEFAULT_DB_DRYRUN_URL})
|
||||||
conf.update({'db_url': constants.DEFAULT_DB_DRYRUN_URL})
|
|
||||||
|
|
||||||
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock())
|
||||||
|
|
||||||
init(conf)
|
init(default_conf)
|
||||||
assert create_engine_mock.call_count == 1
|
assert create_engine_mock.call_count == 1
|
||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite://'
|
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite://'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user