Use variable for exchange mocks to shorten lines
This commit is contained in:
parent
78e5ec13bb
commit
bcdf4e0fe8
@ -24,7 +24,7 @@ from freqtrade.enums import RunMode
|
|||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.persistence.models import init_db
|
from freqtrade.persistence.models import init_db
|
||||||
from freqtrade.persistence.pairlock_middleware import PairLocks
|
from freqtrade.persistence.pairlock_middleware import PairLocks
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, create_mock_trades, get_args, log_has,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, create_mock_trades, get_args, log_has,
|
||||||
log_has_re, patch_exchange, patched_configuration_load_config_file)
|
log_has_re, patch_exchange, patched_configuration_load_config_file)
|
||||||
from tests.conftest_trades import MOCK_TRADE_COUNT
|
from tests.conftest_trades import MOCK_TRADE_COUNT
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
|||||||
assert re.search(r"^BLK/BTC$", captured.out, re.MULTILINE)
|
assert re.search(r"^BLK/BTC$", captured.out, re.MULTILINE)
|
||||||
assert re.search(r"^LTC/USD$", captured.out, re.MULTILINE)
|
assert re.search(r"^LTC/USD$", captured.out, re.MULTILINE)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(side_effect=ValueError))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(side_effect=ValueError))
|
||||||
# Test --one-column
|
# Test --one-column
|
||||||
args = [
|
args = [
|
||||||
"list-markets",
|
"list-markets",
|
||||||
@ -643,9 +643,7 @@ def test_download_data_keyboardInterrupt(mocker, markets):
|
|||||||
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(side_effect=KeyboardInterrupt))
|
MagicMock(side_effect=KeyboardInterrupt))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange", "binance",
|
"--exchange", "binance",
|
||||||
@ -664,9 +662,7 @@ def test_download_data_timerange(mocker, markets):
|
|||||||
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange", "binance",
|
"--exchange", "binance",
|
||||||
@ -715,9 +711,7 @@ def test_download_data_no_markets(mocker, caplog):
|
|||||||
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
||||||
patch_exchange(mocker, id='binance')
|
patch_exchange(mocker, id='binance')
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange", "binance",
|
"--exchange", "binance",
|
||||||
@ -733,9 +727,7 @@ def test_download_data_no_exchange(mocker, caplog):
|
|||||||
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
]
|
]
|
||||||
@ -751,9 +743,7 @@ def test_download_data_no_pairs(mocker):
|
|||||||
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange",
|
"--exchange",
|
||||||
@ -771,9 +761,7 @@ def test_download_data_all_pairs(mocker, markets):
|
|||||||
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange",
|
"--exchange",
|
||||||
@ -810,9 +798,7 @@ def test_download_data_trades(mocker, caplog):
|
|||||||
convert_mock = mocker.patch('freqtrade.commands.data_commands.convert_trades_to_ohlcv',
|
convert_mock = mocker.patch('freqtrade.commands.data_commands.convert_trades_to_ohlcv',
|
||||||
MagicMock(return_value=[]))
|
MagicMock(return_value=[]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange", "kraken",
|
"--exchange", "kraken",
|
||||||
@ -843,9 +829,7 @@ def test_download_data_trades(mocker, caplog):
|
|||||||
|
|
||||||
def test_download_data_data_invalid(mocker):
|
def test_download_data_data_invalid(mocker):
|
||||||
patch_exchange(mocker, id="kraken")
|
patch_exchange(mocker, id="kraken")
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
"--exchange", "kraken",
|
"--exchange", "kraken",
|
||||||
@ -862,9 +846,7 @@ def test_start_convert_trades(mocker, caplog):
|
|||||||
convert_mock = mocker.patch('freqtrade.commands.data_commands.convert_trades_to_ohlcv',
|
convert_mock = mocker.patch('freqtrade.commands.data_commands.convert_trades_to_ohlcv',
|
||||||
MagicMock(return_value=[]))
|
MagicMock(return_value=[]))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
args = [
|
args = [
|
||||||
"trades-to-ohlcv",
|
"trades-to-ohlcv",
|
||||||
"--exchange", "kraken",
|
"--exchange", "kraken",
|
||||||
|
@ -40,6 +40,7 @@ np.seterr(all='raise')
|
|||||||
|
|
||||||
CURRENT_TEST_STRATEGY = 'StrategyTestV3'
|
CURRENT_TEST_STRATEGY = 'StrategyTestV3'
|
||||||
TRADE_SIDES = ('long', 'short')
|
TRADE_SIDES = ('long', 'short')
|
||||||
|
EXMS = 'freqtrade.exchange.exchange.Exchange'
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
@ -145,19 +146,17 @@ def patch_exchange(
|
|||||||
mock_markets=True,
|
mock_markets=True,
|
||||||
mock_supported_modes=True
|
mock_supported_modes=True
|
||||||
) -> None:
|
) -> None:
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange._load_async_markets',
|
mocker.patch(f'{EXMS}._load_async_markets', return_value={})
|
||||||
MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}.validate_config', MagicMock())
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_config', MagicMock())
|
mocker.patch(f'{EXMS}.validate_timeframes', MagicMock())
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_timeframes', MagicMock())
|
mocker.patch(f'{EXMS}.id', PropertyMock(return_value=id))
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.id', PropertyMock(return_value=id))
|
mocker.patch(f'{EXMS}.name', PropertyMock(return_value=id.title()))
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.name', PropertyMock(return_value=id.title()))
|
mocker.patch(f'{EXMS}.precisionMode', PropertyMock(return_value=2))
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.precisionMode', PropertyMock(return_value=2))
|
|
||||||
|
|
||||||
if mock_markets:
|
if mock_markets:
|
||||||
if isinstance(mock_markets, bool):
|
if isinstance(mock_markets, bool):
|
||||||
mock_markets = get_markets()
|
mock_markets = get_markets()
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.markets',
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=mock_markets))
|
||||||
PropertyMock(return_value=mock_markets))
|
|
||||||
|
|
||||||
if mock_supported_modes:
|
if mock_supported_modes:
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
@ -171,11 +170,10 @@ def patch_exchange(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if api_mock:
|
if api_mock:
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange._init_ccxt',
|
mocker.patch(f'{EXMS}._init_ccxt', return_value=api_mock)
|
||||||
MagicMock(return_value=api_mock))
|
|
||||||
else:
|
else:
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange._init_ccxt', MagicMock())
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock())
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.timeframes', PropertyMock(
|
mocker.patch(f'{EXMS}.timeframes', PropertyMock(
|
||||||
return_value=['5m', '15m', '1h', '1d']))
|
return_value=['5m', '15m', '1h', '1d']))
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from freqtrade.data.dataprovider import DataProvider
|
|||||||
from freqtrade.enums import CandleType, RunMode
|
from freqtrade.enums import CandleType, RunMode
|
||||||
from freqtrade.exceptions import ExchangeError, OperationalException
|
from freqtrade.exceptions import ExchangeError, OperationalException
|
||||||
from freqtrade.plugins.pairlistmanager import PairListManager
|
from freqtrade.plugins.pairlistmanager import PairListManager
|
||||||
from tests.conftest import generate_test_data, get_patched_exchange
|
from tests.conftest import EXMS, generate_test_data, get_patched_exchange
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('candle_type', [
|
@pytest.mark.parametrize('candle_type', [
|
||||||
@ -223,7 +223,7 @@ def test_emit_df(mocker, default_conf, ohlcv_history):
|
|||||||
|
|
||||||
def test_refresh(mocker, default_conf):
|
def test_refresh(mocker, default_conf):
|
||||||
refresh_mock = MagicMock()
|
refresh_mock = MagicMock()
|
||||||
mocker.patch("freqtrade.exchange.Exchange.refresh_latest_ohlcv", refresh_mock)
|
mocker.patch(f"{EXMS}.refresh_latest_ohlcv", refresh_mock)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
timeframe = default_conf["timeframe"]
|
timeframe = default_conf["timeframe"]
|
||||||
@ -281,7 +281,7 @@ def test_market(mocker, default_conf, markets):
|
|||||||
|
|
||||||
def test_ticker(mocker, default_conf, tickers):
|
def test_ticker(mocker, default_conf, tickers):
|
||||||
ticker_mock = MagicMock(return_value=tickers()['ETH/BTC'])
|
ticker_mock = MagicMock(return_value=tickers()['ETH/BTC'])
|
||||||
mocker.patch("freqtrade.exchange.Exchange.fetch_ticker", ticker_mock)
|
mocker.patch(f"{EXMS}.fetch_ticker", ticker_mock)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
dp = DataProvider(default_conf, exchange)
|
dp = DataProvider(default_conf, exchange)
|
||||||
res = dp.ticker('ETH/BTC')
|
res = dp.ticker('ETH/BTC')
|
||||||
@ -290,7 +290,7 @@ def test_ticker(mocker, default_conf, tickers):
|
|||||||
assert res['symbol'] == 'ETH/BTC'
|
assert res['symbol'] == 'ETH/BTC'
|
||||||
|
|
||||||
ticker_mock = MagicMock(side_effect=ExchangeError('Pair not found'))
|
ticker_mock = MagicMock(side_effect=ExchangeError('Pair not found'))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.fetch_ticker", ticker_mock)
|
mocker.patch(f"{EXMS}.fetch_ticker", ticker_mock)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
dp = DataProvider(default_conf, exchange)
|
dp = DataProvider(default_conf, exchange)
|
||||||
res = dp.ticker('UNITTEST/BTC')
|
res = dp.ticker('UNITTEST/BTC')
|
||||||
|
@ -26,7 +26,7 @@ from freqtrade.enums import CandleType
|
|||||||
from freqtrade.exchange import timeframe_to_minutes
|
from freqtrade.exchange import timeframe_to_minutes
|
||||||
from freqtrade.misc import file_dump_json
|
from freqtrade.misc import file_dump_json
|
||||||
from freqtrade.resolvers import StrategyResolver
|
from freqtrade.resolvers import StrategyResolver
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, get_patched_exchange, log_has, log_has_re,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, get_patched_exchange, log_has, log_has_re,
|
||||||
patch_exchange)
|
patch_exchange)
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ def test_load_data_7min_timeframe(caplog, testdatadir) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_load_data_1min_timeframe(ohlcv_history, mocker, caplog, testdatadir) -> None:
|
def test_load_data_1min_timeframe(ohlcv_history, mocker, caplog, testdatadir) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history)
|
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history)
|
||||||
file = testdatadir / 'UNITTEST_BTC-1m.json'
|
file = testdatadir / 'UNITTEST_BTC-1m.json'
|
||||||
load_data(datadir=testdatadir, timeframe='1m', pairs=['UNITTEST/BTC'])
|
load_data(datadir=testdatadir, timeframe='1m', pairs=['UNITTEST/BTC'])
|
||||||
assert file.is_file()
|
assert file.is_file()
|
||||||
@ -77,7 +77,7 @@ def test_load_data_1min_timeframe(ohlcv_history, mocker, caplog, testdatadir) ->
|
|||||||
|
|
||||||
|
|
||||||
def test_load_data_mark(ohlcv_history, mocker, caplog, testdatadir) -> None:
|
def test_load_data_mark(ohlcv_history, mocker, caplog, testdatadir) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history)
|
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history)
|
||||||
file = testdatadir / 'futures/UNITTEST_USDT_USDT-1h-mark.json'
|
file = testdatadir / 'futures/UNITTEST_USDT_USDT-1h-mark.json'
|
||||||
load_data(datadir=testdatadir, timeframe='1h', pairs=['UNITTEST/BTC'], candle_type='mark')
|
load_data(datadir=testdatadir, timeframe='1h', pairs=['UNITTEST/BTC'], candle_type='mark')
|
||||||
assert file.is_file()
|
assert file.is_file()
|
||||||
@ -109,7 +109,7 @@ def test_load_data_with_new_pair_1min(ohlcv_history_list, mocker, caplog,
|
|||||||
Test load_pair_history() with 1 min timeframe
|
Test load_pair_history() with 1 min timeframe
|
||||||
"""
|
"""
|
||||||
tmpdir1 = Path(tmpdir)
|
tmpdir1 = Path(tmpdir)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history_list)
|
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
file = tmpdir1 / 'MEME_BTC-1m.json'
|
file = tmpdir1 / 'MEME_BTC-1m.json'
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ def test_download_pair_history(
|
|||||||
subdir,
|
subdir,
|
||||||
file_tail
|
file_tail
|
||||||
) -> None:
|
) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history_list)
|
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
tmpdir1 = Path(tmpdir)
|
tmpdir1 = Path(tmpdir)
|
||||||
file1_1 = tmpdir1 / f'{subdir}MEME_BTC-1m{file_tail}.json'
|
file1_1 = tmpdir1 / f'{subdir}MEME_BTC-1m{file_tail}.json'
|
||||||
@ -328,7 +328,7 @@ def test_download_pair_history2(mocker, default_conf, testdatadir) -> None:
|
|||||||
json_dump_mock = mocker.patch(
|
json_dump_mock = mocker.patch(
|
||||||
'freqtrade.data.history.jsondatahandler.JsonDataHandler.ohlcv_store',
|
'freqtrade.data.history.jsondatahandler.JsonDataHandler.ohlcv_store',
|
||||||
return_value=None)
|
return_value=None)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=tick)
|
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=tick)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
_download_pair_history(datadir=testdatadir, exchange=exchange, pair="UNITTEST/BTC",
|
_download_pair_history(datadir=testdatadir, exchange=exchange, pair="UNITTEST/BTC",
|
||||||
timeframe='1m', candle_type='spot')
|
timeframe='1m', candle_type='spot')
|
||||||
@ -340,7 +340,7 @@ def test_download_pair_history2(mocker, default_conf, testdatadir) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_download_backtesting_data_exception(mocker, caplog, default_conf, tmpdir) -> None:
|
def test_download_backtesting_data_exception(mocker, caplog, default_conf, tmpdir) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv',
|
mocker.patch(f'{EXMS}.get_historic_ohlcv',
|
||||||
side_effect=Exception('File Error'))
|
side_effect=Exception('File Error'))
|
||||||
tmpdir1 = Path(tmpdir)
|
tmpdir1 = Path(tmpdir)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
@ -506,9 +506,7 @@ def test_refresh_backtest_ohlcv_data(
|
|||||||
mocker, default_conf, markets, caplog, testdatadir, trademode, callcount):
|
mocker, default_conf, markets, caplog, testdatadir, trademode, callcount):
|
||||||
dl_mock = mocker.patch('freqtrade.data.history.history_utils._download_pair_history',
|
dl_mock = mocker.patch('freqtrade.data.history.history_utils._download_pair_history',
|
||||||
MagicMock())
|
MagicMock())
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||||
mocker.patch.object(Path, "unlink", MagicMock())
|
mocker.patch.object(Path, "unlink", MagicMock())
|
||||||
|
|
||||||
@ -531,9 +529,7 @@ def test_download_data_no_markets(mocker, default_conf, caplog, testdatadir):
|
|||||||
MagicMock())
|
MagicMock())
|
||||||
|
|
||||||
ex = get_patched_exchange(mocker, default_conf)
|
ex = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
|
|
||||||
)
|
|
||||||
timerange = TimeRange.parse_timerange("20190101-20190102")
|
timerange = TimeRange.parse_timerange("20190101-20190102")
|
||||||
unav_pairs = refresh_backtest_ohlcv_data(exchange=ex, pairs=["BTT/BTC", "LTC/USDT"],
|
unav_pairs = refresh_backtest_ohlcv_data(exchange=ex, pairs=["BTT/BTC", "LTC/USDT"],
|
||||||
timeframes=["1m", "5m"],
|
timeframes=["1m", "5m"],
|
||||||
@ -551,9 +547,7 @@ def test_download_data_no_markets(mocker, default_conf, caplog, testdatadir):
|
|||||||
def test_refresh_backtest_trades_data(mocker, default_conf, markets, caplog, testdatadir):
|
def test_refresh_backtest_trades_data(mocker, default_conf, markets, caplog, testdatadir):
|
||||||
dl_mock = mocker.patch('freqtrade.data.history.history_utils._download_trades_history',
|
dl_mock = mocker.patch('freqtrade.data.history.history_utils._download_trades_history',
|
||||||
MagicMock())
|
MagicMock())
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||||
mocker.patch.object(Path, "unlink", MagicMock())
|
mocker.patch.object(Path, "unlink", MagicMock())
|
||||||
|
|
||||||
@ -577,8 +571,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
|||||||
tmpdir) -> None:
|
tmpdir) -> None:
|
||||||
tmpdir1 = Path(tmpdir)
|
tmpdir1 = Path(tmpdir)
|
||||||
ght_mock = MagicMock(side_effect=lambda pair, *args, **kwargs: (pair, trades_history))
|
ght_mock = MagicMock(side_effect=lambda pair, *args, **kwargs: (pair, trades_history))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_trades',
|
mocker.patch(f'{EXMS}.get_historic_trades', ght_mock)
|
||||||
ght_mock)
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
file1 = tmpdir1 / 'ETH_BTC-trades.json.gz'
|
file1 = tmpdir1 / 'ETH_BTC-trades.json.gz'
|
||||||
data_handler = get_datahandler(tmpdir1, data_format='jsongz')
|
data_handler = get_datahandler(tmpdir1, data_format='jsongz')
|
||||||
@ -604,8 +597,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
|||||||
|
|
||||||
file1.unlink()
|
file1.unlink()
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_trades',
|
mocker.patch(f'{EXMS}.get_historic_trades', MagicMock(side_effect=ValueError))
|
||||||
MagicMock(side_effect=ValueError))
|
|
||||||
|
|
||||||
assert not _download_trades_history(data_handler=data_handler, exchange=exchange,
|
assert not _download_trades_history(data_handler=data_handler, exchange=exchange,
|
||||||
pair='ETH/BTC')
|
pair='ETH/BTC')
|
||||||
@ -615,8 +607,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
|||||||
copyfile(testdatadir / file2.name, file2)
|
copyfile(testdatadir / file2.name, file2)
|
||||||
|
|
||||||
ght_mock.reset_mock()
|
ght_mock.reset_mock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_historic_trades',
|
mocker.patch(f'{EXMS}.get_historic_trades', ght_mock)
|
||||||
ght_mock)
|
|
||||||
# Since before first start date
|
# Since before first start date
|
||||||
since_time = int(trades_history[0][0] // 1000) - 500
|
since_time = int(trades_history[0][0] // 1000) - 500
|
||||||
timerange = TimeRange('date', None, since_time, 0)
|
timerange = TimeRange('date', None, since_time, 0)
|
||||||
|
@ -14,7 +14,7 @@ from freqtrade.data.converter import ohlcv_to_dataframe
|
|||||||
from freqtrade.edge import Edge, PairInfo
|
from freqtrade.edge import Edge, PairInfo
|
||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from tests.conftest import get_patched_freqtradebot, log_has
|
from tests.conftest import EXMS, get_patched_freqtradebot, log_has
|
||||||
from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
|
from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
|
||||||
_get_frame_time_from_offset)
|
_get_frame_time_from_offset)
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ def mocked_load_data(datadir, pairs=[], timeframe='0m',
|
|||||||
|
|
||||||
def test_edge_process_downloaded_data(mocker, edge_conf):
|
def test_edge_process_downloaded_data(mocker, edge_conf):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.001))
|
mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.001))
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', MagicMock())
|
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', MagicMock())
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
||||||
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
||||||
@ -273,7 +273,7 @@ def test_edge_process_downloaded_data(mocker, edge_conf):
|
|||||||
|
|
||||||
def test_edge_process_no_data(mocker, edge_conf, caplog):
|
def test_edge_process_no_data(mocker, edge_conf, caplog):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.001))
|
mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.001))
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', MagicMock())
|
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', MagicMock())
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.load_data', MagicMock(return_value={}))
|
mocker.patch('freqtrade.edge.edge_positioning.load_data', MagicMock(return_value={}))
|
||||||
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
||||||
@ -286,7 +286,7 @@ def test_edge_process_no_data(mocker, edge_conf, caplog):
|
|||||||
|
|
||||||
def test_edge_process_no_trades(mocker, edge_conf, caplog):
|
def test_edge_process_no_trades(mocker, edge_conf, caplog):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', return_value=0.001)
|
mocker.patch(f'{EXMS}.get_fee', return_value=0.001)
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', )
|
mocker.patch('freqtrade.edge.edge_positioning.refresh_data', )
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
||||||
# Return empty
|
# Return empty
|
||||||
@ -303,7 +303,7 @@ def test_edge_process_no_pairs(mocker, edge_conf, caplog):
|
|||||||
mocker.patch('freqtrade.freqtradebot.validate_config_consistency')
|
mocker.patch('freqtrade.freqtradebot.validate_config_consistency')
|
||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', return_value=0.001)
|
fee_mock = mocker.patch(f'{EXMS}.get_fee', return_value=0.001)
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.refresh_data')
|
mocker.patch('freqtrade.edge.edge_positioning.refresh_data')
|
||||||
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
mocker.patch('freqtrade.edge.edge_positioning.load_data', mocked_load_data)
|
||||||
# Return empty
|
# Return empty
|
||||||
@ -319,7 +319,7 @@ def test_edge_process_no_pairs(mocker, edge_conf, caplog):
|
|||||||
|
|
||||||
def test_edge_init_error(mocker, edge_conf,):
|
def test_edge_init_error(mocker, edge_conf,):
|
||||||
edge_conf['stake_amount'] = 0.5
|
edge_conf['stake_amount'] = 0.5
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.001))
|
mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.001))
|
||||||
with pytest.raises(OperationalException, match='Edge works only with unlimited stake amount'):
|
with pytest.raises(OperationalException, match='Edge works only with unlimited stake amount'):
|
||||||
get_patched_freqtradebot(mocker, edge_conf)
|
get_patched_freqtradebot(mocker, edge_conf)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import pytest
|
|||||||
|
|
||||||
from freqtrade.enums import CandleType, MarginMode, TradingMode
|
from freqtrade.enums import CandleType, MarginMode, TradingMode
|
||||||
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
||||||
from tests.conftest import get_mock_coro, get_patched_exchange, log_has_re
|
from tests.conftest import EXMS, get_mock_coro, get_patched_exchange, log_has_re
|
||||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||||
|
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ def test_create_stoploss_order_binance(default_conf, mocker, limitratio, expecte
|
|||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
default_conf['trading_mode'] = trademode
|
default_conf['trading_mode'] = trademode
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ def test_create_stoploss_order_dry_run_binance(default_conf, mocker):
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
order_type = 'stop_loss_limit'
|
order_type = 'stop_loss_limit'
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
|
||||||
|
|
||||||
@ -600,7 +600,7 @@ def test_get_maintenance_ratio_and_amt_binance(
|
|||||||
mm_ratio,
|
mm_ratio,
|
||||||
amt,
|
amt,
|
||||||
):
|
):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
exchange._leverage_tiers = leverage_tiers
|
exchange._leverage_tiers = leverage_tiers
|
||||||
(result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value)
|
(result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import EXMS, get_patched_exchange
|
||||||
|
|
||||||
|
|
||||||
def test_get_trades_for_order(default_conf, mocker):
|
def test_get_trades_for_order(default_conf, mocker):
|
||||||
@ -9,7 +9,7 @@ def test_get_trades_for_order(default_conf, mocker):
|
|||||||
order_id = 'ABCD-ABCD'
|
order_id = 'ABCD-ABCD'
|
||||||
since = datetime(2018, 5, 5, 0, 0, 0)
|
since = datetime(2018, 5, 5, 0, 0, 0)
|
||||||
default_conf["dry_run"] = False
|
default_conf["dry_run"] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
|
|
||||||
api_mock.fetch_my_trades = MagicMock(return_value=[{'id': 'TTR67E-3PFBD-76IISV',
|
api_mock.fetch_my_trades = MagicMock(return_value=[{'id': 'TTR67E-3PFBD-76IISV',
|
||||||
|
@ -17,7 +17,7 @@ from freqtrade.enums import CandleType
|
|||||||
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_prev_date
|
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_prev_date
|
||||||
from freqtrade.exchange.exchange import Exchange, timeframe_to_msecs
|
from freqtrade.exchange.exchange import Exchange, timeframe_to_msecs
|
||||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||||
from tests.conftest import get_default_conf_usdt
|
from tests.conftest import EXMS, get_default_conf_usdt
|
||||||
|
|
||||||
|
|
||||||
EXCHANGE_FIXTURE_TYPE = Tuple[Exchange, str]
|
EXCHANGE_FIXTURE_TYPE = Tuple[Exchange, str]
|
||||||
@ -322,13 +322,12 @@ def exchange_futures(request, exchange_conf, class_mocker):
|
|||||||
|
|
||||||
class_mocker.patch(
|
class_mocker.patch(
|
||||||
'freqtrade.exchange.binance.Binance.fill_leverage_tiers')
|
'freqtrade.exchange.binance.Binance.fill_leverage_tiers')
|
||||||
class_mocker.patch('freqtrade.exchange.exchange.Exchange.fetch_trading_fees')
|
class_mocker.patch(f'{EXMS}.fetch_trading_fees')
|
||||||
class_mocker.patch('freqtrade.exchange.okx.Okx.additional_exchange_init')
|
class_mocker.patch('freqtrade.exchange.okx.Okx.additional_exchange_init')
|
||||||
class_mocker.patch('freqtrade.exchange.binance.Binance.additional_exchange_init')
|
class_mocker.patch('freqtrade.exchange.binance.Binance.additional_exchange_init')
|
||||||
class_mocker.patch('freqtrade.exchange.bybit.Bybit.additional_exchange_init')
|
class_mocker.patch('freqtrade.exchange.bybit.Bybit.additional_exchange_init')
|
||||||
class_mocker.patch('freqtrade.exchange.exchange.Exchange.load_cached_leverage_tiers',
|
class_mocker.patch(f'{EXMS}.load_cached_leverage_tiers', return_value=None)
|
||||||
return_value=None)
|
class_mocker.patch(f'{EXMS}.cache_leverage_tiers')
|
||||||
class_mocker.patch('freqtrade.exchange.exchange.Exchange.cache_leverage_tiers')
|
|
||||||
|
|
||||||
exchange = ExchangeResolver.load_exchange(
|
exchange = ExchangeResolver.load_exchange(
|
||||||
request.param, exchange_conf, validate=True, load_leverage_tiers=True)
|
request.param, exchange_conf, validate=True, load_leverage_tiers=True)
|
||||||
|
@ -22,8 +22,8 @@ from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_CO
|
|||||||
calculate_backoff, remove_credentials)
|
calculate_backoff, remove_credentials)
|
||||||
from freqtrade.exchange.exchange import amount_to_contract_precision
|
from freqtrade.exchange.exchange import amount_to_contract_precision
|
||||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||||
from tests.conftest import (generate_test_data_raw, get_mock_coro, get_patched_exchange, log_has,
|
from tests.conftest import (EXMS, generate_test_data_raw, get_mock_coro, get_patched_exchange,
|
||||||
log_has_re, num_log_has_re)
|
log_has, log_has_re, num_log_has_re)
|
||||||
|
|
||||||
|
|
||||||
# Make sure to always keep one exchange here which is NOT subclassed!!
|
# Make sure to always keep one exchange here which is NOT subclassed!!
|
||||||
@ -150,9 +150,9 @@ def test_remove_credentials(default_conf, caplog) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_init_ccxt_kwargs(default_conf, mocker, caplog):
|
def test_init_ccxt_kwargs(default_conf, mocker, caplog):
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
aei_mock = mocker.patch('freqtrade.exchange.Exchange.additional_exchange_init')
|
aei_mock = mocker.patch(f'{EXMS}.additional_exchange_init')
|
||||||
|
|
||||||
caplog.set_level(logging.INFO)
|
caplog.set_level(logging.INFO)
|
||||||
conf = copy.deepcopy(default_conf)
|
conf = copy.deepcopy(default_conf)
|
||||||
@ -218,12 +218,12 @@ def test_init_exception(default_conf, mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test_exchange_resolver(default_conf, mocker, caplog):
|
def test_exchange_resolver(default_conf, mocker, caplog):
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=MagicMock()))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=MagicMock()))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
|
|
||||||
exchange = ExchangeResolver.load_exchange('zaif', default_conf)
|
exchange = ExchangeResolver.load_exchange('zaif', default_conf)
|
||||||
assert isinstance(exchange, Exchange)
|
assert isinstance(exchange, Exchange)
|
||||||
@ -362,9 +362,8 @@ def test_price_to_precision(price, precision_mode, precision, expected):
|
|||||||
def test_price_get_one_pip(default_conf, mocker, price, precision_mode, precision, expected):
|
def test_price_get_one_pip(default_conf, mocker, price, precision_mode, precision, expected):
|
||||||
markets = PropertyMock(return_value={'ETH/BTC': {'precision': {'price': precision}}})
|
markets = PropertyMock(return_value={'ETH/BTC': {'precision': {'price': precision}}})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
mocker.patch(f'{EXMS}.markets', markets)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.precisionMode',
|
mocker.patch(f'{EXMS}.precisionMode', PropertyMock(return_value=precision_mode))
|
||||||
PropertyMock(return_value=precision_mode))
|
|
||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
assert pytest.approx(exchange.price_get_one_pip(pair, price)) == expected
|
assert pytest.approx(exchange.price_get_one_pip(pair, price)) == expected
|
||||||
|
|
||||||
@ -376,10 +375,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
|
markets = {'ETH/BTC': {'symbol': 'ETH/BTC'}}
|
||||||
|
|
||||||
# no pair found
|
# no pair found
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
with pytest.raises(ValueError, match=r'.*get market information.*'):
|
with pytest.raises(ValueError, match=r'.*get market information.*'):
|
||||||
exchange.get_min_pair_stake_amount('BNB/BTC', 1, stoploss)
|
exchange.get_min_pair_stake_amount('BNB/BTC', 1, stoploss)
|
||||||
|
|
||||||
@ -388,10 +384,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': None, 'max': None},
|
'cost': {'min': None, 'max': None},
|
||||||
'amount': {'min': None, 'max': None},
|
'amount': {'min': None, 'max': None},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||||
assert result is None
|
assert result is None
|
||||||
result = exchange.get_max_pair_stake_amount('ETH/BTC', 1)
|
result = exchange.get_max_pair_stake_amount('ETH/BTC', 1)
|
||||||
@ -402,10 +395,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': 2, 'max': 10000},
|
'cost': {'min': 2, 'max': 10000},
|
||||||
'amount': {'min': None, 'max': None},
|
'amount': {'min': None, 'max': None},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
# min
|
# min
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 1, stoploss)
|
||||||
expected_result = 2 * (1 + 0.05) / (1 - abs(stoploss))
|
expected_result = 2 * (1 + 0.05) / (1 - abs(stoploss))
|
||||||
@ -422,10 +412,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': None, 'max': None},
|
'cost': {'min': None, 'max': None},
|
||||||
'amount': {'min': 2, 'max': 10000},
|
'amount': {'min': 2, 'max': 10000},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
expected_result = 2 * 2 * (1 + 0.05) / (1 - abs(stoploss))
|
expected_result = 2 * 2 * (1 + 0.05) / (1 - abs(stoploss))
|
||||||
assert pytest.approx(result) == expected_result
|
assert pytest.approx(result) == expected_result
|
||||||
@ -441,10 +428,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': 2, 'max': None},
|
'cost': {'min': 2, 'max': None},
|
||||||
'amount': {'min': 2, 'max': None},
|
'amount': {'min': 2, 'max': None},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
expected_result = max(2, 2 * 2) * (1 + 0.05) / (1 - abs(stoploss))
|
expected_result = max(2, 2 * 2) * (1 + 0.05) / (1 - abs(stoploss))
|
||||||
assert pytest.approx(result) == expected_result
|
assert pytest.approx(result) == expected_result
|
||||||
@ -457,10 +441,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': 8, 'max': 10000},
|
'cost': {'min': 8, 'max': 10000},
|
||||||
'amount': {'min': 2, 'max': 500},
|
'amount': {'min': 2, 'max': 500},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, stoploss)
|
||||||
expected_result = max(8, 2 * 2) * (1 + 0.05) / (1 - abs(stoploss))
|
expected_result = max(8, 2 * 2) * (1 + 0.05) / (1 - abs(stoploss))
|
||||||
assert pytest.approx(result) == expected_result
|
assert pytest.approx(result) == expected_result
|
||||||
@ -496,10 +477,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
exchange = get_patched_exchange(mocker, default_conf, id="binance")
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Contract size 0.01
|
# Contract size 0.01
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1)
|
||||||
@ -509,10 +487,7 @@ def test__get_stake_amount_limit(mocker, default_conf) -> None:
|
|||||||
assert result == 10
|
assert result == 10
|
||||||
|
|
||||||
markets["ETH/BTC"]["contractSize"] = '10'
|
markets["ETH/BTC"]["contractSize"] = '10'
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
# With Leverage, Contract size 10
|
# With Leverage, Contract size 10
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 2, -1, 12.0)
|
||||||
assert pytest.approx(result) == (expected_result / 12) * 10.0
|
assert pytest.approx(result) == (expected_result / 12) * 10.0
|
||||||
@ -531,10 +506,7 @@ def test_get_min_pair_stake_amount_real_data(mocker, default_conf) -> None:
|
|||||||
'cost': {'min': 0.0001, 'max': 4000},
|
'cost': {'min': 0.0001, 'max': 4000},
|
||||||
'amount': {'min': 0.001, 'max': 10000},
|
'amount': {'min': 0.001, 'max': 10000},
|
||||||
}
|
}
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
'freqtrade.exchange.Exchange.markets',
|
|
||||||
PropertyMock(return_value=markets)
|
|
||||||
)
|
|
||||||
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss)
|
result = exchange.get_min_pair_stake_amount('ETH/BTC', 0.020405, stoploss)
|
||||||
expected_result = max(0.0001, 0.001 * 0.020405) * (1 + 0.05) / (1 - abs(stoploss))
|
expected_result = max(0.0001, 0.001 * 0.020405) * (1 + 0.05) / (1 - abs(stoploss))
|
||||||
assert round(result, 8) == round(expected_result, 8)
|
assert round(result, 8) == round(expected_result, 8)
|
||||||
@ -592,12 +564,12 @@ def test_set_sandbox_exception(default_conf, mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test__load_async_markets(default_conf, mocker, caplog):
|
def test__load_async_markets(default_conf, mocker, caplog):
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt')
|
mocker.patch(f'{EXMS}._init_ccxt')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets')
|
mocker.patch(f'{EXMS}._load_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
exchange = Exchange(default_conf)
|
exchange = Exchange(default_conf)
|
||||||
exchange._api_async.load_markets = get_mock_coro(None)
|
exchange._api_async.load_markets = get_mock_coro(None)
|
||||||
exchange._load_async_markets()
|
exchange._load_async_markets()
|
||||||
@ -614,19 +586,19 @@ def test__load_markets(default_conf, mocker, caplog):
|
|||||||
caplog.set_level(logging.INFO)
|
caplog.set_level(logging.INFO)
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.load_markets = MagicMock(side_effect=ccxt.BaseError("SomeError"))
|
api_mock.load_markets = MagicMock(side_effect=ccxt.BaseError("SomeError"))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
assert log_has('Unable to initialize markets.', caplog)
|
assert log_has('Unable to initialize markets.', caplog)
|
||||||
|
|
||||||
expected_return = {'ETH/BTC': 'available'}
|
expected_return = {'ETH/BTC': 'available'}
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.load_markets = MagicMock(return_value=expected_return)
|
api_mock.load_markets = MagicMock(return_value=expected_return)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
default_conf['exchange']['pair_whitelist'] = ['ETH/BTC']
|
default_conf['exchange']['pair_whitelist'] = ['ETH/BTC']
|
||||||
ex = Exchange(default_conf)
|
ex = Exchange(default_conf)
|
||||||
|
|
||||||
@ -684,11 +656,11 @@ def test_validate_stakecurrency(default_conf, stake_currency, mocker, caplog):
|
|||||||
'ETH/BTC': {'quote': 'BTC'}, 'LTC/BTC': {'quote': 'BTC'},
|
'ETH/BTC': {'quote': 'BTC'}, 'LTC/BTC': {'quote': 'BTC'},
|
||||||
'XRP/ETH': {'quote': 'ETH'}, 'NEO/USDT': {'quote': 'USDT'},
|
'XRP/ETH': {'quote': 'ETH'}, 'NEO/USDT': {'quote': 'USDT'},
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
@ -699,17 +671,17 @@ def test_validate_stakecurrency_error(default_conf, mocker, caplog):
|
|||||||
'ETH/BTC': {'quote': 'BTC'}, 'LTC/BTC': {'quote': 'BTC'},
|
'ETH/BTC': {'quote': 'BTC'}, 'LTC/BTC': {'quote': 'BTC'},
|
||||||
'XRP/ETH': {'quote': 'ETH'}, 'NEO/USDT': {'quote': 'USDT'},
|
'XRP/ETH': {'quote': 'ETH'}, 'NEO/USDT': {'quote': 'USDT'},
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'XRP is not available as stake on .*'
|
match=r'XRP is not available as stake on .*'
|
||||||
'Available currencies are: BTC, ETH, USDT'):
|
'Available currencies are: BTC, ETH, USDT'):
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
type(api_mock).load_markets = MagicMock(side_effect=ccxt.NetworkError('No connection.'))
|
type(api_mock).load_markets = MagicMock(side_effect=ccxt.NetworkError('No connection.'))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
|
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'Could not load markets, therefore cannot start\. Please.*'):
|
match=r'Could not load markets, therefore cannot start\. Please.*'):
|
||||||
@ -757,11 +729,11 @@ def test_validate_pairs(default_conf, mocker): # test exchange.validate_pairs d
|
|||||||
id_mock = PropertyMock(return_value='test_exchange')
|
id_mock = PropertyMock(return_value='test_exchange')
|
||||||
type(api_mock).id = id_mock
|
type(api_mock).id = id_mock
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
@ -770,10 +742,10 @@ def test_validate_pairs_not_available(default_conf, mocker):
|
|||||||
type(api_mock).markets = PropertyMock(return_value={
|
type(api_mock).markets = PropertyMock(return_value={
|
||||||
'XRP/BTC': {'inactive': True, 'base': 'XRP', 'quote': 'BTC'}
|
'XRP/BTC': {'inactive': True, 'base': 'XRP', 'quote': 'BTC'}
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
|
|
||||||
with pytest.raises(OperationalException, match=r'not available'):
|
with pytest.raises(OperationalException, match=r'not available'):
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
@ -782,19 +754,19 @@ def test_validate_pairs_not_available(default_conf, mocker):
|
|||||||
def test_validate_pairs_exception(default_conf, mocker, caplog):
|
def test_validate_pairs_exception(default_conf, mocker, caplog):
|
||||||
caplog.set_level(logging.INFO)
|
caplog.set_level(logging.INFO)
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', PropertyMock(return_value='Binance'))
|
mocker.patch(f'{EXMS}.name', PropertyMock(return_value='Binance'))
|
||||||
|
|
||||||
type(api_mock).markets = PropertyMock(return_value={})
|
type(api_mock).markets = PropertyMock(return_value={})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', api_mock)
|
mocker.patch(f'{EXMS}._init_ccxt', api_mock)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
|
|
||||||
with pytest.raises(OperationalException, match=r'Pair ETH/BTC is not available on Binance'):
|
with pytest.raises(OperationalException, match=r'Pair ETH/BTC is not available on Binance'):
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value={}))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={}))
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
assert log_has('Unable to validate pairs (assuming they are correct).', caplog)
|
assert log_has('Unable to validate pairs (assuming they are correct).', caplog)
|
||||||
|
|
||||||
@ -806,11 +778,11 @@ def test_validate_pairs_restricted(default_conf, mocker, caplog):
|
|||||||
'XRP/BTC': {'quote': 'BTC', 'info': {'prohibitedIn': ['US']}},
|
'XRP/BTC': {'quote': 'BTC', 'info': {'prohibitedIn': ['US']}},
|
||||||
'NEO/BTC': {'quote': 'BTC', 'info': 'TestString'}, # info can also be a string ...
|
'NEO/BTC': {'quote': 'BTC', 'info': 'TestString'}, # info can also be a string ...
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
|
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
assert log_has("Pair XRP/BTC is restricted for some users on this exchange."
|
assert log_has("Pair XRP/BTC is restricted for some users on this exchange."
|
||||||
@ -825,11 +797,11 @@ def test_validate_pairs_stakecompatibility(default_conf, mocker, caplog):
|
|||||||
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
||||||
'HELLO-WORLD': {'quote': 'BTC'},
|
'HELLO-WORLD': {'quote': 'BTC'},
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
|
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
@ -842,11 +814,11 @@ def test_validate_pairs_stakecompatibility_downloaddata(default_conf, mocker, ca
|
|||||||
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
||||||
'HELLO-WORLD': {'quote': 'BTC'},
|
'HELLO-WORLD': {'quote': 'BTC'},
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
|
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
assert type(api_mock).load_markets.call_count == 1
|
assert type(api_mock).load_markets.call_count == 1
|
||||||
@ -860,10 +832,10 @@ def test_validate_pairs_stakecompatibility_fail(default_conf, mocker, caplog):
|
|||||||
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
'XRP/BTC': {'quote': 'BTC'}, 'NEO/BTC': {'quote': 'BTC'},
|
||||||
'HELLO-WORLD': {'quote': 'USDT'},
|
'HELLO-WORLD': {'quote': 'USDT'},
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
|
|
||||||
with pytest.raises(OperationalException, match=r"Stake-currency 'BTC' not compatible with.*"):
|
with pytest.raises(OperationalException, match=r"Stake-currency 'BTC' not compatible with.*"):
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
@ -883,11 +855,11 @@ def test_validate_timeframes(default_conf, mocker, timeframe):
|
|||||||
'1h': '1h'})
|
'1h': '1h'})
|
||||||
type(api_mock).timeframes = timeframes
|
type(api_mock).timeframes = timeframes
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
@ -903,9 +875,9 @@ def test_validate_timeframes_failed(default_conf, mocker):
|
|||||||
'1h': '1h'})
|
'1h': '1h'})
|
||||||
type(api_mock).timeframes = timeframes
|
type(api_mock).timeframes = timeframes
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs', MagicMock())
|
mocker.patch(f'{EXMS}.validate_pairs', MagicMock())
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"Invalid timeframe '3m'. This exchange supports.*"):
|
match=r"Invalid timeframe '3m'. This exchange supports.*"):
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
@ -925,10 +897,10 @@ def test_validate_timeframes_emulated_ohlcv_1(default_conf, mocker):
|
|||||||
# delete timeframes so magicmock does not autocreate it
|
# delete timeframes so magicmock does not autocreate it
|
||||||
del api_mock.timeframes
|
del api_mock.timeframes
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'The ccxt library does not provide the list of timeframes '
|
match=r'The ccxt library does not provide the list of timeframes '
|
||||||
r'for the exchange .* and this exchange '
|
r'for the exchange .* and this exchange '
|
||||||
@ -945,11 +917,11 @@ def test_validate_timeframes_emulated_ohlcvi_2(default_conf, mocker):
|
|||||||
# delete timeframes so magicmock does not autocreate it
|
# delete timeframes so magicmock does not autocreate it
|
||||||
del api_mock.timeframes
|
del api_mock.timeframes
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets',
|
mocker.patch(f'{EXMS}._load_markets',
|
||||||
MagicMock(return_value={'timeframes': None}))
|
MagicMock(return_value={'timeframes': None}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs', MagicMock())
|
mocker.patch(f'{EXMS}.validate_pairs', MagicMock())
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'The ccxt library does not provide the list of timeframes '
|
match=r'The ccxt library does not provide the list of timeframes '
|
||||||
r'for the exchange .* and this exchange '
|
r'for the exchange .* and this exchange '
|
||||||
@ -969,12 +941,12 @@ def test_validate_timeframes_not_in_config(default_conf, mocker):
|
|||||||
'1h': '1h'})
|
'1h': '1h'})
|
||||||
type(api_mock).timeframes = timeframes
|
type(api_mock).timeframes = timeframes
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_required_startup_candles')
|
mocker.patch(f'{EXMS}.validate_required_startup_candles')
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
|
||||||
@ -985,13 +957,13 @@ def test_validate_pricing(default_conf, mocker):
|
|||||||
'fetchTicker': True,
|
'fetchTicker': True,
|
||||||
}
|
}
|
||||||
type(api_mock).has = PropertyMock(return_value=has)
|
type(api_mock).has = PropertyMock(return_value=has)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_margin_mode')
|
mocker.patch(f'{EXMS}.validate_trading_mode_and_margin_mode')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', 'Binance')
|
mocker.patch(f'{EXMS}.name', 'Binance')
|
||||||
ExchangeResolver.load_exchange('binance', default_conf)
|
ExchangeResolver.load_exchange('binance', default_conf)
|
||||||
has.update({'fetchTicker': False})
|
has.update({'fetchTicker': False})
|
||||||
with pytest.raises(OperationalException, match="Ticker pricing not available for .*"):
|
with pytest.raises(OperationalException, match="Ticker pricing not available for .*"):
|
||||||
@ -1020,13 +992,13 @@ def test_validate_ordertypes(default_conf, mocker):
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
|
|
||||||
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': True})
|
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': True})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', 'Bittrex')
|
mocker.patch(f'{EXMS}.name', 'Bittrex')
|
||||||
|
|
||||||
default_conf['order_types'] = {
|
default_conf['order_types'] = {
|
||||||
'entry': 'limit',
|
'entry': 'limit',
|
||||||
@ -1037,7 +1009,7 @@ def test_validate_ordertypes(default_conf, mocker):
|
|||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': False})
|
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': False})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
|
|
||||||
default_conf['order_types'] = {
|
default_conf['order_types'] = {
|
||||||
'entry': 'limit',
|
'entry': 'limit',
|
||||||
@ -1080,12 +1052,12 @@ def test_validate_ordertypes_stop_advanced(default_conf, mocker, exchange_name,
|
|||||||
default_conf['trading_mode'] = TradingMode.FUTURES
|
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': True})
|
type(api_mock).has = PropertyMock(return_value={'createMarketOrder': True})
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
default_conf['order_types'] = {
|
default_conf['order_types'] = {
|
||||||
'entry': 'limit',
|
'entry': 'limit',
|
||||||
'exit': 'limit',
|
'exit': 'limit',
|
||||||
@ -1103,12 +1075,12 @@ def test_validate_ordertypes_stop_advanced(default_conf, mocker, exchange_name,
|
|||||||
|
|
||||||
def test_validate_order_types_not_in_config(default_conf, mocker):
|
def test_validate_order_types_not_in_config(default_conf, mocker):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
mocker.patch(f'{EXMS}._init_ccxt', MagicMock(return_value=api_mock))
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
|
mocker.patch(f'{EXMS}._load_markets', MagicMock(return_value={}))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
|
|
||||||
conf = copy.deepcopy(default_conf)
|
conf = copy.deepcopy(default_conf)
|
||||||
Exchange(conf)
|
Exchange(conf)
|
||||||
@ -1116,14 +1088,14 @@ def test_validate_order_types_not_in_config(default_conf, mocker):
|
|||||||
|
|
||||||
def test_validate_required_startup_candles(default_conf, mocker, caplog):
|
def test_validate_required_startup_candles(default_conf, mocker, caplog):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', PropertyMock(return_value='Binance'))
|
mocker.patch(f'{EXMS}.name', PropertyMock(return_value='Binance'))
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', api_mock)
|
mocker.patch(f'{EXMS}._init_ccxt', api_mock)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets')
|
mocker.patch(f'{EXMS}._load_async_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
|
|
||||||
default_conf['startup_candle_count'] = 20
|
default_conf['startup_candle_count'] = 20
|
||||||
ex = Exchange(default_conf)
|
ex = Exchange(default_conf)
|
||||||
@ -1220,11 +1192,10 @@ def test_create_dry_run_order_fees(
|
|||||||
fee,
|
fee,
|
||||||
):
|
):
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.get_fee',
|
f'{EXMS}.get_fee',
|
||||||
side_effect=lambda symbol, taker_or_maker: 2.0 if taker_or_maker == 'taker' else 1.0
|
side_effect=lambda symbol, taker_or_maker: 2.0 if taker_or_maker == 'taker' else 1.0
|
||||||
)
|
)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed',
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=price_side == 'other')
|
||||||
return_value=price_side == 'other')
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
|
|
||||||
order = exchange.create_dry_run_order(
|
order = exchange.create_dry_run_order(
|
||||||
@ -1241,8 +1212,7 @@ def test_create_dry_run_order_fees(
|
|||||||
else:
|
else:
|
||||||
assert order['fee'] is None
|
assert order['fee'] is None
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed',
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=price_side != 'other')
|
||||||
return_value=price_side != 'other')
|
|
||||||
|
|
||||||
order1 = exchange.fetch_dry_run_order(order['id'])
|
order1 = exchange.fetch_dry_run_order(order['id'])
|
||||||
assert order1['fee']['rate'] == fee
|
assert order1['fee']['rate'] == fee
|
||||||
@ -1303,8 +1273,7 @@ def test_create_dry_run_order_limit_fill(default_conf, mocker, side, price, fill
|
|||||||
order_book_l2_usd.reset_mock()
|
order_book_l2_usd.reset_mock()
|
||||||
|
|
||||||
# Empty orderbook test
|
# Empty orderbook test
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book',
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', return_value={'asks': [], 'bids': []})
|
||||||
return_value={'asks': [], 'bids': []})
|
|
||||||
exchange._dry_run_open_orders[order['id']]['status'] = 'open'
|
exchange._dry_run_open_orders[order['id']]['status'] = 'open'
|
||||||
order_closed = exchange.fetch_dry_run_order(order['id'])
|
order_closed = exchange.fetch_dry_run_order(order['id'])
|
||||||
|
|
||||||
@ -1372,8 +1341,8 @@ def test_create_order(default_conf, mocker, side, ordertype, rate, marketprice,
|
|||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
exchange._set_leverage = MagicMock()
|
exchange._set_leverage = MagicMock()
|
||||||
exchange.set_margin_mode = MagicMock()
|
exchange.set_margin_mode = MagicMock()
|
||||||
@ -1452,8 +1421,8 @@ def test_buy_prod(default_conf, mocker, exchange_name):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type, side="buy",
|
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type, side="buy",
|
||||||
@ -1536,8 +1505,8 @@ def test_buy_considers_time_in_force(default_conf, mocker, exchange_name):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
order_type = 'limit'
|
order_type = 'limit'
|
||||||
@ -1602,8 +1571,8 @@ def test_sell_prod(default_conf, mocker, exchange_name):
|
|||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type,
|
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type,
|
||||||
@ -1675,8 +1644,8 @@ def test_sell_considers_time_in_force(default_conf, mocker, exchange_name):
|
|||||||
})
|
})
|
||||||
api_mock.options = {}
|
api_mock.options = {}
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
order_type = 'limit'
|
order_type = 'limit'
|
||||||
@ -1742,7 +1711,7 @@ def test_get_balances_prod(default_conf, mocker, exchange_name):
|
|||||||
|
|
||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
def test_fetch_positions(default_conf, mocker, exchange_name):
|
def test_fetch_positions(default_conf, mocker, exchange_name):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_trading_mode_and_margin_mode')
|
mocker.patch(f'{EXMS}.validate_trading_mode_and_margin_mode')
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.fetch_positions = MagicMock(return_value=[
|
api_mock.fetch_positions = MagicMock(return_value=[
|
||||||
{'symbol': 'ETH/USDT:USDT', 'leverage': 5},
|
{'symbol': 'ETH/USDT:USDT', 'leverage': 5},
|
||||||
@ -1798,7 +1767,7 @@ def test_fetch_trading_fees(default_conf, mocker):
|
|||||||
default_conf['trading_mode'] = TradingMode.FUTURES
|
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
api_mock.fetch_trading_fees = MagicMock(return_value=tick)
|
api_mock.fetch_trading_fees = MagicMock(return_value=tick)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
assert '1INCH/USDT:USDT' in exchange._trading_fees
|
assert '1INCH/USDT:USDT' in exchange._trading_fees
|
||||||
@ -1813,7 +1782,7 @@ def test_fetch_trading_fees(default_conf, mocker):
|
|||||||
api_mock.fetch_trading_fees = MagicMock(return_value={})
|
api_mock.fetch_trading_fees = MagicMock(return_value={})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
exchange.fetch_trading_fees()
|
exchange.fetch_trading_fees()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
assert exchange.fetch_trading_fees() == {}
|
assert exchange.fetch_trading_fees() == {}
|
||||||
|
|
||||||
|
|
||||||
@ -1833,7 +1802,7 @@ def test_fetch_bids_asks(default_conf, mocker):
|
|||||||
}
|
}
|
||||||
exchange_name = 'binance'
|
exchange_name = 'binance'
|
||||||
api_mock.fetch_bids_asks = MagicMock(return_value=tick)
|
api_mock.fetch_bids_asks = MagicMock(return_value=tick)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
# retrieve original ticker
|
# retrieve original ticker
|
||||||
bidsasks = exchange.fetch_bids_asks()
|
bidsasks = exchange.fetch_bids_asks()
|
||||||
@ -1866,7 +1835,7 @@ def test_fetch_bids_asks(default_conf, mocker):
|
|||||||
api_mock.fetch_bids_asks = MagicMock(return_value={})
|
api_mock.fetch_bids_asks = MagicMock(return_value={})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
exchange.fetch_bids_asks()
|
exchange.fetch_bids_asks()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
assert exchange.fetch_bids_asks() == {}
|
assert exchange.fetch_bids_asks() == {}
|
||||||
|
|
||||||
|
|
||||||
@ -1885,7 +1854,7 @@ def test_get_tickers(default_conf, mocker, exchange_name):
|
|||||||
'last': 41,
|
'last': 41,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
api_mock.fetch_tickers = MagicMock(return_value=tick)
|
api_mock.fetch_tickers = MagicMock(return_value=tick)
|
||||||
api_mock.fetch_bids_asks = MagicMock(return_value={})
|
api_mock.fetch_bids_asks = MagicMock(return_value={})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
@ -1928,7 +1897,7 @@ def test_get_tickers(default_conf, mocker, exchange_name):
|
|||||||
api_mock.fetch_bids_asks.reset_mock()
|
api_mock.fetch_bids_asks.reset_mock()
|
||||||
default_conf['trading_mode'] = TradingMode.FUTURES
|
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
|
|
||||||
exchange.get_tickers()
|
exchange.get_tickers()
|
||||||
@ -1937,7 +1906,7 @@ def test_get_tickers(default_conf, mocker, exchange_name):
|
|||||||
|
|
||||||
api_mock.fetch_tickers.reset_mock()
|
api_mock.fetch_tickers.reset_mock()
|
||||||
api_mock.fetch_bids_asks.reset_mock()
|
api_mock.fetch_bids_asks.reset_mock()
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.exchange_has', return_value=False)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=False)
|
||||||
assert exchange.get_tickers() == {}
|
assert exchange.get_tickers() == {}
|
||||||
|
|
||||||
|
|
||||||
@ -2191,7 +2160,7 @@ def test_refresh_latest_ohlcv_cache(mocker, default_conf, candle_type, time_mach
|
|||||||
time_machine.move_to(start + timedelta(hours=99, minutes=30))
|
time_machine.move_to(start + timedelta(hours=99, minutes=30))
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.ohlcv_candle_limit", return_value=100)
|
mocker.patch(f"{EXMS}.ohlcv_candle_limit", return_value=100)
|
||||||
assert exchange._startup_candle_count == 0
|
assert exchange._startup_candle_count == 0
|
||||||
|
|
||||||
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
||||||
@ -2241,7 +2210,7 @@ def test_refresh_latest_ohlcv_cache(mocker, default_conf, candle_type, time_mach
|
|||||||
# New candle on exchange - return 100 candles - but skip one candle so we actually get 2 candles
|
# New candle on exchange - return 100 candles - but skip one candle so we actually get 2 candles
|
||||||
# in one go
|
# in one go
|
||||||
new_startdate = (start + timedelta(hours=2)).strftime('%Y-%m-%d %H:%M')
|
new_startdate = (start + timedelta(hours=2)).strftime('%Y-%m-%d %H:%M')
|
||||||
# mocker.patch("freqtrade.exchange.Exchange.ohlcv_candle_limit", return_value=100)
|
# mocker.patch(f"{EXMS}.ohlcv_candle_limit", return_value=100)
|
||||||
ohlcv = generate_test_data_raw('1h', 100, new_startdate)
|
ohlcv = generate_test_data_raw('1h', 100, new_startdate)
|
||||||
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
exchange._api_async.fetch_ohlcv = get_mock_coro(ohlcv)
|
||||||
res = exchange.refresh_latest_ohlcv(pairs)
|
res = exchange.refresh_latest_ohlcv(pairs)
|
||||||
@ -2342,7 +2311,7 @@ async def test__async_kucoin_get_candle_history(default_conf, mocker, caplog):
|
|||||||
"symbol=ETH-BTC&type=5min&startAt=1640268735&endAt=1640418735"
|
"symbol=ETH-BTC&type=5min&startAt=1640268735&endAt=1640418735"
|
||||||
"429 Too Many Requests" '{"code":"429000","msg":"Too Many Requests"}'))
|
"429 Too Many Requests" '{"code":"429000","msg":"Too Many Requests"}'))
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kucoin")
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kucoin")
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', PropertyMock(return_value='KuCoin'))
|
mocker.patch(f'{EXMS}.name', PropertyMock(return_value='KuCoin'))
|
||||||
|
|
||||||
msg = "Kucoin 429 error, avoid triggering DDosProtection backoff delay"
|
msg = "Kucoin 429 error, avoid triggering DDosProtection backoff delay"
|
||||||
assert not num_log_has_re(msg, caplog)
|
assert not num_log_has_re(msg, caplog)
|
||||||
@ -2500,8 +2469,7 @@ def test_get_entry_rate(mocker, default_conf, caplog, side, ask, bid,
|
|||||||
default_conf['entry_pricing']['price_last_balance'] = last_ab
|
default_conf['entry_pricing']['price_last_balance'] = last_ab
|
||||||
default_conf['entry_pricing']['price_side'] = side
|
default_conf['entry_pricing']['price_side'] = side
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'ask': ask, 'last': last, 'bid': bid})
|
||||||
return_value={'ask': ask, 'last': last, 'bid': bid})
|
|
||||||
|
|
||||||
assert exchange.get_rate('ETH/BTC', side="entry", is_short=False, refresh=True) == expected
|
assert exchange.get_rate('ETH/BTC', side="entry", is_short=False, refresh=True) == expected
|
||||||
assert not log_has("Using cached entry rate for ETH/BTC.", caplog)
|
assert not log_has("Using cached entry rate for ETH/BTC.", caplog)
|
||||||
@ -2522,8 +2490,7 @@ def test_get_exit_rate(default_conf, mocker, caplog, side, bid, ask,
|
|||||||
default_conf['exit_pricing']['price_side'] = side
|
default_conf['exit_pricing']['price_side'] = side
|
||||||
if last_ab is not None:
|
if last_ab is not None:
|
||||||
default_conf['exit_pricing']['price_last_balance'] = last_ab
|
default_conf['exit_pricing']['price_last_balance'] = last_ab
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'ask': ask, 'bid': bid, 'last': last})
|
||||||
return_value={'ask': ask, 'bid': bid, 'last': last})
|
|
||||||
pair = "ETH/BTC"
|
pair = "ETH/BTC"
|
||||||
|
|
||||||
# Test regular mode
|
# Test regular mode
|
||||||
@ -2556,8 +2523,7 @@ def test_get_ticker_rate_error(mocker, entry, default_conf, caplog, side, is_sho
|
|||||||
default_conf['exit_pricing']['price_side'] = side
|
default_conf['exit_pricing']['price_side'] = side
|
||||||
default_conf['exit_pricing']['price_last_balance'] = last_ab
|
default_conf['exit_pricing']['price_last_balance'] = last_ab
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'ask': ask, 'last': last, 'bid': bid})
|
||||||
return_value={'ask': ask, 'last': last, 'bid': bid})
|
|
||||||
|
|
||||||
with pytest.raises(PricingError):
|
with pytest.raises(PricingError):
|
||||||
exchange.get_rate('ETH/BTC', refresh=True, side=entry, is_short=is_short)
|
exchange.get_rate('ETH/BTC', refresh=True, side=entry, is_short=is_short)
|
||||||
@ -2581,7 +2547,7 @@ def test_get_exit_rate_orderbook(
|
|||||||
default_conf['exit_pricing']['use_order_book'] = True
|
default_conf['exit_pricing']['use_order_book'] = True
|
||||||
default_conf['exit_pricing']['order_book_top'] = 1
|
default_conf['exit_pricing']['order_book_top'] = 1
|
||||||
pair = "ETH/BTC"
|
pair = "ETH/BTC"
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book', order_book_l2)
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', order_book_l2)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
rate = exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
rate = exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
||||||
assert not log_has("Using cached exit rate for ETH/BTC.", caplog)
|
assert not log_has("Using cached exit rate for ETH/BTC.", caplog)
|
||||||
@ -2599,8 +2565,7 @@ def test_get_exit_rate_orderbook_exception(default_conf, mocker, caplog):
|
|||||||
default_conf['exit_pricing']['order_book_top'] = 1
|
default_conf['exit_pricing']['order_book_top'] = 1
|
||||||
pair = "ETH/BTC"
|
pair = "ETH/BTC"
|
||||||
# Test What happens if the exchange returns an empty orderbook.
|
# Test What happens if the exchange returns an empty orderbook.
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book',
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', return_value={'bids': [[]], 'asks': [[]]})
|
||||||
return_value={'bids': [[]], 'asks': [[]]})
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
with pytest.raises(PricingError):
|
with pytest.raises(PricingError):
|
||||||
exchange.get_rate(pair, refresh=True, side="exit", is_short=False)
|
exchange.get_rate(pair, refresh=True, side="exit", is_short=False)
|
||||||
@ -2614,8 +2579,7 @@ def test_get_exit_rate_exception(default_conf, mocker, is_short):
|
|||||||
# Ticker on one side can be empty in certain circumstances.
|
# Ticker on one side can be empty in certain circumstances.
|
||||||
default_conf['exit_pricing']['price_side'] = 'ask'
|
default_conf['exit_pricing']['price_side'] = 'ask'
|
||||||
pair = "ETH/BTC"
|
pair = "ETH/BTC"
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'ask': None, 'bid': 0.12, 'last': None})
|
||||||
return_value={'ask': None, 'bid': 0.12, 'last': None})
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
with pytest.raises(PricingError, match=r"Exit-Rate for ETH/BTC was empty."):
|
with pytest.raises(PricingError, match=r"Exit-Rate for ETH/BTC was empty."):
|
||||||
exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
||||||
@ -2623,8 +2587,7 @@ def test_get_exit_rate_exception(default_conf, mocker, is_short):
|
|||||||
exchange._config['exit_pricing']['price_side'] = 'bid'
|
exchange._config['exit_pricing']['price_side'] = 'bid'
|
||||||
assert exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short) == 0.12
|
assert exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short) == 0.12
|
||||||
# Reverse sides
|
# Reverse sides
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'ask': 0.13, 'bid': None, 'last': None})
|
||||||
return_value={'ask': 0.13, 'bid': None, 'last': None})
|
|
||||||
with pytest.raises(PricingError, match=r"Exit-Rate for ETH/BTC was empty."):
|
with pytest.raises(PricingError, match=r"Exit-Rate for ETH/BTC was empty."):
|
||||||
exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
exchange.get_rate(pair, refresh=True, side="exit", is_short=is_short)
|
||||||
|
|
||||||
@ -2990,7 +2953,7 @@ async def test__async_get_trade_history_time_empty(default_conf, mocker, caplog,
|
|||||||
|
|
||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
def test_get_historic_trades(default_conf, mocker, caplog, exchange_name, trades_history):
|
def test_get_historic_trades(default_conf, mocker, caplog, exchange_name, trades_history):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
|
|
||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
@ -3012,7 +2975,7 @@ def test_get_historic_trades(default_conf, mocker, caplog, exchange_name, trades
|
|||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
def test_get_historic_trades_notsupported(default_conf, mocker, caplog, exchange_name,
|
def test_get_historic_trades_notsupported(default_conf, mocker, caplog, exchange_name,
|
||||||
trades_history):
|
trades_history):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=False)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=False)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
|
|
||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
@ -3028,7 +2991,7 @@ def test_get_historic_trades_notsupported(default_conf, mocker, caplog, exchange
|
|||||||
def test_cancel_order_dry_run(default_conf, mocker, exchange_name):
|
def test_cancel_order_dry_run(default_conf, mocker, exchange_name):
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=True)
|
||||||
assert exchange.cancel_order(order_id='123', pair='TKN/BTC') == {}
|
assert exchange.cancel_order(order_id='123', pair='TKN/BTC') == {}
|
||||||
assert exchange.cancel_stoploss_order(order_id='123', pair='TKN/BTC') == {}
|
assert exchange.cancel_stoploss_order(order_id='123', pair='TKN/BTC') == {}
|
||||||
|
|
||||||
@ -3156,24 +3119,24 @@ def test_cancel_stoploss_order(default_conf, mocker, exchange_name):
|
|||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
def test_cancel_stoploss_order_with_result(default_conf, mocker, exchange_name):
|
def test_cancel_stoploss_order_with_result(default_conf, mocker, exchange_name):
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', return_value={'for': 123})
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', return_value={'for': 123})
|
||||||
mocker.patch('freqtrade.exchange.Gate.fetch_stoploss_order', return_value={'for': 123})
|
mocker.patch('freqtrade.exchange.Gate.fetch_stoploss_order', return_value={'for': 123})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
|
|
||||||
res = {'fee': {}, 'status': 'canceled', 'amount': 1234}
|
res = {'fee': {}, 'status': 'canceled', 'amount': 1234}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', return_value=res)
|
mocker.patch(f'{EXMS}.cancel_stoploss_order', return_value=res)
|
||||||
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', return_value=res)
|
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', return_value=res)
|
||||||
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
||||||
assert co == res
|
assert co == res
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', return_value='canceled')
|
mocker.patch(f'{EXMS}.cancel_stoploss_order', return_value='canceled')
|
||||||
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', return_value='canceled')
|
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', return_value='canceled')
|
||||||
# Fall back to fetch_stoploss_order
|
# Fall back to fetch_stoploss_order
|
||||||
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
||||||
assert co == {'for': 123}
|
assert co == {'for': 123}
|
||||||
|
|
||||||
exc = InvalidOrderException("")
|
exc = InvalidOrderException("")
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', side_effect=exc)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', side_effect=exc)
|
||||||
mocker.patch('freqtrade.exchange.Gate.fetch_stoploss_order', side_effect=exc)
|
mocker.patch('freqtrade.exchange.Gate.fetch_stoploss_order', side_effect=exc)
|
||||||
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
co = exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=555)
|
||||||
assert co['amount'] == 555
|
assert co['amount'] == 555
|
||||||
@ -3181,7 +3144,7 @@ def test_cancel_stoploss_order_with_result(default_conf, mocker, exchange_name):
|
|||||||
|
|
||||||
with pytest.raises(InvalidOrderException):
|
with pytest.raises(InvalidOrderException):
|
||||||
exc = InvalidOrderException("Did not find order")
|
exc = InvalidOrderException("Did not find order")
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', side_effect=exc)
|
mocker.patch(f'{EXMS}.cancel_stoploss_order', side_effect=exc)
|
||||||
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', side_effect=exc)
|
mocker.patch('freqtrade.exchange.Gate.cancel_stoploss_order', side_effect=exc)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=123)
|
exchange.cancel_stoploss_order_with_result(order_id='_', pair='TKN/BTC', amount=123)
|
||||||
@ -3315,7 +3278,7 @@ def test_get_trades_for_order(default_conf, mocker, exchange_name, trading_mode,
|
|||||||
default_conf["dry_run"] = False
|
default_conf["dry_run"] = False
|
||||||
default_conf["trading_mode"] = trading_mode
|
default_conf["trading_mode"] = trading_mode
|
||||||
default_conf["margin_mode"] = 'isolated'
|
default_conf["margin_mode"] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
|
|
||||||
api_mock.fetch_my_trades = MagicMock(return_value=[{'id': 'TTR67E-3PFBD-76IISV',
|
api_mock.fetch_my_trades = MagicMock(return_value=[{'id': 'TTR67E-3PFBD-76IISV',
|
||||||
@ -3358,7 +3321,7 @@ def test_get_trades_for_order(default_conf, mocker, exchange_name, trading_mode,
|
|||||||
'get_trades_for_order', 'fetch_my_trades',
|
'get_trades_for_order', 'fetch_my_trades',
|
||||||
order_id=order_id, pair='ETH/USDT:USDT', since=since)
|
order_id=order_id, pair='ETH/USDT:USDT', since=since)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=False))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=False))
|
||||||
assert exchange.get_trades_for_order(order_id, 'ETH/USDT:USDT', since) == []
|
assert exchange.get_trades_for_order(order_id, 'ETH/USDT:USDT', since) == []
|
||||||
|
|
||||||
|
|
||||||
@ -3550,7 +3513,7 @@ def test_get_markets(default_conf, mocker, markets_static,
|
|||||||
|
|
||||||
def test_get_markets_error(default_conf, mocker):
|
def test_get_markets_error(default_conf, mocker):
|
||||||
ex = get_patched_exchange(mocker, default_conf)
|
ex = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=None))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=None))
|
||||||
with pytest.raises(OperationalException, match="Markets were not loaded."):
|
with pytest.raises(OperationalException, match="Markets were not loaded."):
|
||||||
ex.get_markets('LTC', 'USDT', True, False)
|
ex.get_markets('LTC', 'USDT', True, False)
|
||||||
|
|
||||||
@ -3695,7 +3658,7 @@ def test_market_is_tradable(
|
|||||||
quote, spot, margin, futures, trademode, add_dict, exchange, expected_result
|
quote, spot, margin, futures, trademode, add_dict, exchange, expected_result
|
||||||
) -> None:
|
) -> None:
|
||||||
default_conf['trading_mode'] = trademode
|
default_conf['trading_mode'] = trademode
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_margin_mode')
|
mocker.patch(f'{EXMS}.validate_trading_mode_and_margin_mode')
|
||||||
ex = get_patched_exchange(mocker, default_conf, id=exchange)
|
ex = get_patched_exchange(mocker, default_conf, id=exchange)
|
||||||
market = {
|
market = {
|
||||||
'symbol': market_symbol,
|
'symbol': market_symbol,
|
||||||
@ -3740,7 +3703,7 @@ def test_order_has_fee(order, expected) -> None:
|
|||||||
(0.34, 'USDT', 0.01)),
|
(0.34, 'USDT', 0.01)),
|
||||||
])
|
])
|
||||||
def test_extract_cost_curr_rate(mocker, default_conf, order, expected) -> None:
|
def test_extract_cost_curr_rate(mocker, default_conf, order, expected) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.calculate_fee_rate', MagicMock(return_value=0.01))
|
mocker.patch(f'{EXMS}.calculate_fee_rate', MagicMock(return_value=0.01))
|
||||||
ex = get_patched_exchange(mocker, default_conf)
|
ex = get_patched_exchange(mocker, default_conf)
|
||||||
assert ex.extract_cost_curr_rate(order['fee'], order['symbol'], cost=20, amount=1) == expected
|
assert ex.extract_cost_curr_rate(order['fee'], order['symbol'], cost=20, amount=1) == expected
|
||||||
|
|
||||||
@ -3785,7 +3748,7 @@ def test_extract_cost_curr_rate(mocker, default_conf, order, expected) -> None:
|
|||||||
'fee': {'currency': None, 'cost': 0.005}}, None, None),
|
'fee': {'currency': None, 'cost': 0.005}}, None, None),
|
||||||
])
|
])
|
||||||
def test_calculate_fee_rate(mocker, default_conf, order, expected, unknown_fee_rate) -> None:
|
def test_calculate_fee_rate(mocker, default_conf, order, expected, unknown_fee_rate) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value={'last': 0.081})
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'last': 0.081})
|
||||||
if unknown_fee_rate:
|
if unknown_fee_rate:
|
||||||
default_conf['exchange']['unknown_fee_rate'] = unknown_fee_rate
|
default_conf['exchange']['unknown_fee_rate'] = unknown_fee_rate
|
||||||
|
|
||||||
@ -3857,7 +3820,7 @@ def test__get_funding_fees_from_exchange(default_conf, mocker, exchange_name):
|
|||||||
])
|
])
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchFundingHistory': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchFundingHistory': True})
|
||||||
|
|
||||||
# mocker.patch('freqtrade.exchange.Exchange.get_funding_fees', lambda pair, since: y)
|
# mocker.patch(f'{EXMS}.get_funding_fees', lambda pair, since: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
date_time = datetime.strptime("2021-09-01T00:00:01.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
date_time = datetime.strptime("2021-09-01T00:00:01.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
unix_time = int(date_time.timestamp())
|
unix_time = int(date_time.timestamp())
|
||||||
@ -4257,8 +4220,7 @@ def test__fetch_and_calculate_funding_fees(
|
|||||||
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
||||||
|
|
||||||
ex = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
ex = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.timeframes', PropertyMock(
|
mocker.patch(f'{EXMS}.timeframes', PropertyMock(return_value=['1h', '4h', '8h']))
|
||||||
return_value=['1h', '4h', '8h']))
|
|
||||||
funding_fees = ex._fetch_and_calculate_funding_fees(
|
funding_fees = ex._fetch_and_calculate_funding_fees(
|
||||||
pair='ADA/USDT', amount=amount, is_short=True, open_date=d1, close_date=d2)
|
pair='ADA/USDT', amount=amount, is_short=True, open_date=d1, close_date=d2)
|
||||||
assert pytest.approx(funding_fees) == expected_fees
|
assert pytest.approx(funding_fees) == expected_fees
|
||||||
@ -4268,7 +4230,7 @@ def test__fetch_and_calculate_funding_fees(
|
|||||||
assert pytest.approx(funding_fees) == -expected_fees
|
assert pytest.approx(funding_fees) == -expected_fees
|
||||||
|
|
||||||
# Return empty "refresh_latest"
|
# Return empty "refresh_latest"
|
||||||
mocker.patch("freqtrade.exchange.Exchange.refresh_latest_ohlcv", return_value={})
|
mocker.patch(f"{EXMS}.refresh_latest_ohlcv", return_value={})
|
||||||
ex = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
ex = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
||||||
with pytest.raises(ExchangeError, match="Could not find funding rates."):
|
with pytest.raises(ExchangeError, match="Could not find funding rates."):
|
||||||
ex._fetch_and_calculate_funding_fees(
|
ex._fetch_and_calculate_funding_fees(
|
||||||
@ -4294,7 +4256,7 @@ def test__fetch_and_calculate_funding_fees_datetime_called(
|
|||||||
return_value=funding_rate_history_octohourly)
|
return_value=funding_rate_history_octohourly)
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchOHLCV': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchOHLCV': True})
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.timeframes', PropertyMock(return_value=['4h', '8h']))
|
mocker.patch(f'{EXMS}.timeframes', PropertyMock(return_value=['4h', '8h']))
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange)
|
||||||
d1 = datetime.strptime("2021-09-01 00:00:00 +0000", '%Y-%m-%d %H:%M:%S %z')
|
d1 = datetime.strptime("2021-09-01 00:00:00 +0000", '%Y-%m-%d %H:%M:%S %z')
|
||||||
|
|
||||||
@ -4317,7 +4279,7 @@ def test__get_contract_size(mocker, default_conf, pair, expected_size, trading_m
|
|||||||
default_conf['trading_mode'] = trading_mode
|
default_conf['trading_mode'] = trading_mode
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', {
|
mocker.patch(f'{EXMS}.markets', {
|
||||||
'LTC/USD': {
|
'LTC/USD': {
|
||||||
'symbol': 'LTC/USD',
|
'symbol': 'LTC/USD',
|
||||||
'contractSize': None,
|
'contractSize': None,
|
||||||
@ -4353,7 +4315,7 @@ def test__order_contracts_to_amount(
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = trading_mode
|
default_conf['trading_mode'] = trading_mode
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
mocker.patch(f'{EXMS}.markets', markets)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
|
||||||
orders = [
|
orders = [
|
||||||
@ -4475,7 +4437,7 @@ def test__trades_contracts_to_amount(
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = trading_mode
|
default_conf['trading_mode'] = trading_mode
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
mocker.patch(f'{EXMS}.markets', markets)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
|
||||||
trades = [
|
trades = [
|
||||||
@ -4511,7 +4473,7 @@ def test__amount_to_contracts(
|
|||||||
default_conf['trading_mode'] = 'spot'
|
default_conf['trading_mode'] = 'spot'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', {
|
mocker.patch(f'{EXMS}.markets', {
|
||||||
'LTC/USD': {
|
'LTC/USD': {
|
||||||
'symbol': 'LTC/USD',
|
'symbol': 'LTC/USD',
|
||||||
'contractSize': None,
|
'contractSize': None,
|
||||||
@ -4769,7 +4731,7 @@ def test_get_max_pair_stake_amount(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
mocker.patch(f'{EXMS}.markets', markets)
|
||||||
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0) == 20000
|
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0) == 20000
|
||||||
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0, 5) == 4000
|
assert exchange.get_max_pair_stake_amount('XRP/USDT:USDT', 2.0, 5) == 4000
|
||||||
assert exchange.get_max_pair_stake_amount('LTC/USDT:USDT', 2.0) == float('inf')
|
assert exchange.get_max_pair_stake_amount('LTC/USDT:USDT', 2.0) == float('inf')
|
||||||
@ -4779,7 +4741,7 @@ def test_get_max_pair_stake_amount(
|
|||||||
|
|
||||||
default_conf['trading_mode'] = 'spot'
|
default_conf['trading_mode'] = 'spot'
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', markets)
|
mocker.patch(f'{EXMS}.markets', markets)
|
||||||
assert exchange.get_max_pair_stake_amount('BTC/USDT', 2.0) == 20000
|
assert exchange.get_max_pair_stake_amount('BTC/USDT', 2.0) == 20000
|
||||||
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500
|
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500
|
||||||
|
|
||||||
@ -4790,7 +4752,7 @@ def test_load_leverage_tiers(mocker, default_conf, leverage_tiers, exchange_name
|
|||||||
api_mock.fetch_leverage_tiers = MagicMock()
|
api_mock.fetch_leverage_tiers = MagicMock()
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_margin_mode')
|
mocker.patch(f'{EXMS}.validate_trading_mode_and_margin_mode')
|
||||||
|
|
||||||
api_mock.fetch_leverage_tiers = MagicMock(return_value={
|
api_mock.fetch_leverage_tiers = MagicMock(return_value={
|
||||||
'ADA/USDT:USDT': [
|
'ADA/USDT:USDT': [
|
||||||
@ -4943,7 +4905,7 @@ def test_get_maintenance_ratio_and_amt_exceptions(mocker, default_conf, leverage
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
|
||||||
exchange._leverage_tiers = leverage_tiers
|
exchange._leverage_tiers = leverage_tiers
|
||||||
@ -4980,7 +4942,7 @@ def test_get_maintenance_ratio_and_amt(
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
exchange._leverage_tiers = leverage_tiers
|
exchange._leverage_tiers = leverage_tiers
|
||||||
exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt)
|
exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt)
|
||||||
@ -5019,7 +4981,7 @@ def test_get_max_leverage_futures(default_conf, mocker, leverage_tiers):
|
|||||||
@pytest.mark.parametrize("exchange_name", ['bittrex', 'binance', 'kraken', 'gate', 'okx', 'bybit'])
|
@pytest.mark.parametrize("exchange_name", ['bittrex', 'binance', 'kraken', 'gate', 'okx', 'bybit'])
|
||||||
def test__get_params(mocker, default_conf, exchange_name):
|
def test__get_params(mocker, default_conf, exchange_name):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
exchange._params = {'test': True}
|
exchange._params = {'test': True}
|
||||||
|
|
||||||
@ -5324,8 +5286,8 @@ def test_stoploss_contract_size(mocker, default_conf, contract_size, order_amoun
|
|||||||
'symbol': 'ETH/BTC',
|
'symbol': 'ETH/BTC',
|
||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
exchange.get_contract_size = MagicMock(return_value=contract_size)
|
exchange.get_contract_size = MagicMock(return_value=contract_size)
|
||||||
|
@ -7,18 +7,18 @@ from freqtrade.enums import MarginMode, TradingMode
|
|||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.exchange import Gate
|
from freqtrade.exchange import Gate
|
||||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import EXMS, get_patched_exchange
|
||||||
|
|
||||||
|
|
||||||
def test_validate_order_types_gate(default_conf, mocker):
|
def test_validate_order_types_gate(default_conf, mocker):
|
||||||
default_conf['exchange']['name'] = 'gate'
|
default_conf['exchange']['name'] = 'gate'
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt')
|
mocker.patch(f'{EXMS}._init_ccxt')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets', return_value={})
|
mocker.patch(f'{EXMS}._load_markets', return_value={})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pairs')
|
mocker.patch(f'{EXMS}.validate_pairs')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes')
|
mocker.patch(f'{EXMS}.validate_timeframes')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_stakecurrency')
|
mocker.patch(f'{EXMS}.validate_stakecurrency')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_pricing')
|
mocker.patch(f'{EXMS}.validate_pricing')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.name', 'Gate')
|
mocker.patch(f'{EXMS}.name', 'Gate')
|
||||||
exch = ExchangeResolver.load_exchange('gate', default_conf, True)
|
exch = ExchangeResolver.load_exchange('gate', default_conf, True)
|
||||||
assert isinstance(exch, Gate)
|
assert isinstance(exch, Gate)
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ def test_stoploss_adjust_gate(mocker, default_conf, sl1, sl2, sl3, side):
|
|||||||
('maker', 0.0, 0.0),
|
('maker', 0.0, 0.0),
|
||||||
])
|
])
|
||||||
def test_fetch_my_trades_gate(mocker, default_conf, takerormaker, rate, cost):
|
def test_fetch_my_trades_gate(mocker, default_conf, takerormaker, rate, cost):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
tick = {'ETH/USDT:USDT': {
|
tick = {'ETH/USDT:USDT': {
|
||||||
'info': {'user_id': '',
|
'info': {'user_id': '',
|
||||||
'taker_fee': '0.0018',
|
'taker_fee': '0.0018',
|
||||||
|
@ -5,7 +5,7 @@ import ccxt
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import EXMS, get_patched_exchange
|
||||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||||
|
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ def test_create_stoploss_order_huobi(default_conf, mocker, limitratio, expected,
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'huobi')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'huobi')
|
||||||
|
|
||||||
@ -79,8 +79,8 @@ def test_create_stoploss_order_dry_run_huobi(default_conf, mocker):
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
order_type = 'stop-limit'
|
order_type = 'stop-limit'
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'huobi')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'huobi')
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import ccxt
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.exceptions import DependencyException, InvalidOrderException
|
from freqtrade.exceptions import DependencyException, InvalidOrderException
|
||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import EXMS, get_patched_exchange
|
||||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||||
|
|
||||||
|
|
||||||
@ -28,8 +28,8 @@ def test_buy_kraken_trading_agreement(default_conf, mocker):
|
|||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kraken")
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kraken")
|
||||||
|
|
||||||
order = exchange.create_order(
|
order = exchange.create_order(
|
||||||
@ -68,8 +68,8 @@ def test_sell_kraken_trading_agreement(default_conf, mocker):
|
|||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kraken")
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kraken")
|
||||||
|
|
||||||
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type,
|
order = exchange.create_order(pair='ETH/BTC', ordertype=order_type,
|
||||||
@ -191,8 +191,8 @@ def test_create_stoploss_order_kraken(default_conf, mocker, ordertype, side, adj
|
|||||||
})
|
})
|
||||||
|
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kraken')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kraken')
|
||||||
|
|
||||||
@ -262,8 +262,8 @@ def test_create_stoploss_order_kraken(default_conf, mocker, ordertype, side, adj
|
|||||||
def test_create_stoploss_order_dry_run_kraken(default_conf, mocker, side):
|
def test_create_stoploss_order_dry_run_kraken(default_conf, mocker, side):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kraken')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kraken')
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import ccxt
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
|
||||||
from tests.conftest import get_patched_exchange
|
from tests.conftest import EXMS, get_patched_exchange
|
||||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||||
|
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ def test_create_stoploss_order_kucoin(default_conf, mocker, limitratio, expected
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kucoin')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kucoin')
|
||||||
if order_type == 'limit':
|
if order_type == 'limit':
|
||||||
@ -87,8 +87,8 @@ def test_stoploss_order_dry_run_kucoin(default_conf, mocker):
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
order_type = 'market'
|
order_type = 'market'
|
||||||
default_conf['dry_run'] = True
|
default_conf['dry_run'] = True
|
||||||
mocker.patch('freqtrade.exchange.Exchange.amount_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.amount_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kucoin')
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'kucoin')
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from freqtrade.freqai.utils import download_all_data_for_training, get_required_
|
|||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.plugins.pairlistmanager import PairListManager
|
from freqtrade.plugins.pairlistmanager import PairListManager
|
||||||
from tests.conftest import create_mock_trades, get_patched_exchange, log_has_re
|
from tests.conftest import EXMS, create_mock_trades, get_patched_exchange, log_has_re
|
||||||
from tests.freqai.conftest import get_patched_freqai_strategy, make_rl_config
|
from tests.freqai.conftest import get_patched_freqai_strategy, make_rl_config
|
||||||
|
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ def test_get_state_info(mocker, freqai_conf, dp_exists, caplog, tickers):
|
|||||||
strategy = get_patched_freqai_strategy(mocker, freqai_conf)
|
strategy = get_patched_freqai_strategy(mocker, freqai_conf)
|
||||||
exchange = get_patched_exchange(mocker, freqai_conf)
|
exchange = get_patched_exchange(mocker, freqai_conf)
|
||||||
ticker_mock = MagicMock(return_value=tickers()['ETH/BTC'])
|
ticker_mock = MagicMock(return_value=tickers()['ETH/BTC'])
|
||||||
mocker.patch("freqtrade.exchange.Exchange.fetch_ticker", ticker_mock)
|
mocker.patch(f"{EXMS}.fetch_ticker", ticker_mock)
|
||||||
strategy.dp = DataProvider(freqai_conf, exchange)
|
strategy.dp = DataProvider(freqai_conf, exchange)
|
||||||
|
|
||||||
if not dp_exists:
|
if not dp_exists:
|
||||||
|
@ -8,7 +8,7 @@ from freqtrade.data.history import get_timerange
|
|||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType
|
||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from freqtrade.persistence.trade_model import LocalTrade
|
from freqtrade.persistence.trade_model import LocalTrade
|
||||||
from tests.conftest import patch_exchange
|
from tests.conftest import EXMS, patch_exchange
|
||||||
from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
|
from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
|
||||||
_get_frame_time_from_offset, tests_timeframe)
|
_get_frame_time_from_offset, tests_timeframe)
|
||||||
|
|
||||||
@ -921,9 +921,9 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data: BTContainer)
|
|||||||
default_conf["use_exit_signal"] = data.use_exit_signal
|
default_conf["use_exit_signal"] = data.use_exit_signal
|
||||||
default_conf["max_open_trades"] = 10
|
default_conf["max_open_trades"] = 10
|
||||||
|
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_fee", return_value=0.0)
|
mocker.patch(f"{EXMS}.get_fee", return_value=0.0)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch("freqtrade.exchange.Binance.get_max_leverage", return_value=100)
|
mocker.patch("freqtrade.exchange.Binance.get_max_leverage", return_value=100)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
frame = _build_backtest_dataframe(data.data)
|
frame = _build_backtest_dataframe(data.data)
|
||||||
|
@ -26,8 +26,8 @@ from freqtrade.optimize.backtest_caching import get_strategy_run_id
|
|||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from freqtrade.persistence import LocalTrade, Trade
|
from freqtrade.persistence import LocalTrade, Trade
|
||||||
from freqtrade.resolvers import StrategyResolver
|
from freqtrade.resolvers import StrategyResolver
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, get_args, log_has, log_has_re, patch_exchange,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, get_args, log_has, log_has_re,
|
||||||
patched_configuration_load_config_file)
|
patch_exchange, patched_configuration_load_config_file)
|
||||||
|
|
||||||
|
|
||||||
ORDER_TYPES = [
|
ORDER_TYPES = [
|
||||||
@ -245,7 +245,7 @@ def test_setup_optimize_configuration_stake_amount(mocker, default_conf, caplog)
|
|||||||
|
|
||||||
def test_start(mocker, fee, default_conf, caplog) -> None:
|
def test_start(mocker, fee, default_conf, caplog) -> None:
|
||||||
start_mock = MagicMock()
|
start_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting.start', start_mock)
|
mocker.patch('freqtrade.optimize.backtesting.Backtesting.start', start_mock)
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
@ -269,7 +269,7 @@ def test_backtesting_init(mocker, default_conf, order_types) -> None:
|
|||||||
"""
|
"""
|
||||||
default_conf["order_types"] = order_types
|
default_conf["order_types"] = order_types
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
get_fee = mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5))
|
get_fee = mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.5))
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
assert backtesting.config == default_conf
|
assert backtesting.config == default_conf
|
||||||
@ -290,7 +290,7 @@ def test_backtesting_init_no_timeframe(mocker, default_conf, caplog) -> None:
|
|||||||
default_conf['strategy_list'] = [CURRENT_TEST_STRATEGY,
|
default_conf['strategy_list'] = [CURRENT_TEST_STRATEGY,
|
||||||
'HyperoptableStrategy']
|
'HyperoptableStrategy']
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5))
|
mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.5))
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"Timeframe needs to be set in either configuration"):
|
match=r"Timeframe needs to be set in either configuration"):
|
||||||
Backtesting(default_conf)
|
Backtesting(default_conf)
|
||||||
@ -300,7 +300,7 @@ def test_data_with_fee(default_conf, mocker) -> None:
|
|||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf['fee'] = 0.1234
|
default_conf['fee'] = 0.1234
|
||||||
|
|
||||||
fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5))
|
fee_mock = mocker.patch(f'{EXMS}.get_fee', MagicMock(return_value=0.5))
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
assert backtesting.fee == 0.1234
|
assert backtesting.fee == 0.1234
|
||||||
@ -404,7 +404,7 @@ def test_backtesting_start_no_data(default_conf, mocker, caplog, testdatadir) ->
|
|||||||
|
|
||||||
|
|
||||||
def test_backtesting_no_pair_left(default_conf, mocker, caplog, testdatadir) -> None:
|
def test_backtesting_no_pair_left(default_conf, mocker, caplog, testdatadir) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.data.history.history_utils.load_pair_history',
|
mocker.patch('freqtrade.data.history.history_utils.load_pair_history',
|
||||||
MagicMock(return_value=pd.DataFrame()))
|
MagicMock(return_value=pd.DataFrame()))
|
||||||
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
||||||
@ -436,9 +436,9 @@ def test_backtesting_no_pair_left(default_conf, mocker, caplog, testdatadir) ->
|
|||||||
|
|
||||||
|
|
||||||
def test_backtesting_pairlist_list(default_conf, mocker, caplog, testdatadir, tickers) -> None:
|
def test_backtesting_pairlist_list(default_conf, mocker, caplog, testdatadir, tickers) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_tickers', tickers)
|
mocker.patch(f'{EXMS}.get_tickers', tickers)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.price_to_precision', lambda s, x, y: y)
|
mocker.patch(f'{EXMS}.price_to_precision', lambda s, x, y: y)
|
||||||
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest')
|
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest')
|
||||||
@ -474,9 +474,9 @@ def test_backtesting_pairlist_list(default_conf, mocker, caplog, testdatadir, ti
|
|||||||
|
|
||||||
def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
|
def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f'{EXMS}.get_max_pair_stake_amount', return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf['stake_amount'] = 'unlimited'
|
default_conf['stake_amount'] = 'unlimited'
|
||||||
default_conf['max_open_trades'] = 2
|
default_conf['max_open_trades'] = 2
|
||||||
@ -525,7 +525,7 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
|
|||||||
assert trade.stake_amount == 495
|
assert trade.stake_amount == 495
|
||||||
assert trade.is_short is True
|
assert trade.is_short is True
|
||||||
|
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=300.0)
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=300.0)
|
||||||
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.stake_amount == 300.0
|
assert trade.stake_amount == 300.0
|
||||||
@ -533,10 +533,10 @@ def test_backtest__enter_trade(default_conf, fee, mocker) -> None:
|
|||||||
|
|
||||||
def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
||||||
default_conf_usdt['use_exit_signal'] = False
|
default_conf_usdt['use_exit_signal'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_leverage", return_value=100)
|
mocker.patch(f"{EXMS}.get_max_leverage", return_value=100)
|
||||||
mocker.patch("freqtrade.optimize.backtesting.price_to_precision", lambda p, *args: p)
|
mocker.patch("freqtrade.optimize.backtesting.price_to_precision", lambda p, *args: p)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf_usdt['stake_amount'] = 300
|
default_conf_usdt['stake_amount'] = 300
|
||||||
@ -564,7 +564,7 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
backtesting.strategy.leverage = MagicMock(return_value=5.0)
|
backtesting.strategy.leverage = MagicMock(return_value=5.0)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_maintenance_ratio_and_amt",
|
mocker.patch(f"{EXMS}.get_maintenance_ratio_and_amt",
|
||||||
return_value=(0.01, 0.01))
|
return_value=(0.01, 0.01))
|
||||||
|
|
||||||
# leverage = 5
|
# leverage = 5
|
||||||
@ -601,7 +601,7 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
|||||||
assert pytest.approx(trade.liquidation_price) == 0.11787191
|
assert pytest.approx(trade.liquidation_price) == 0.11787191
|
||||||
|
|
||||||
# Stake-amount too high!
|
# Stake-amount too high!
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=600.0)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=600.0)
|
||||||
|
|
||||||
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
trade = backtesting._enter_trade(pair, row=row, direction='long')
|
||||||
assert trade is None
|
assert trade is None
|
||||||
@ -616,9 +616,9 @@ def test_backtest__enter_trade_futures(default_conf_usdt, fee, mocker) -> None:
|
|||||||
|
|
||||||
def test_backtest__check_trade_exit(default_conf, fee, mocker) -> None:
|
def test_backtest__check_trade_exit(default_conf, fee, mocker) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf['timeframe_detail'] = '1m'
|
default_conf['timeframe_detail'] = '1m'
|
||||||
default_conf['max_open_trades'] = 2
|
default_conf['max_open_trades'] = 2
|
||||||
@ -681,9 +681,9 @@ def test_backtest_one(default_conf, fee, mocker, testdatadir) -> None:
|
|||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
default_conf['max_open_trades'] = 10
|
default_conf['max_open_trades'] = 10
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
@ -766,9 +766,9 @@ def test_backtest_one(default_conf, fee, mocker, testdatadir) -> None:
|
|||||||
@pytest.mark.parametrize('use_detail', [True, False])
|
@pytest.mark.parametrize('use_detail', [True, False])
|
||||||
def test_backtest_one_detail(default_conf_usdt, fee, mocker, testdatadir, use_detail) -> None:
|
def test_backtest_one_detail(default_conf_usdt, fee, mocker, testdatadir, use_detail) -> None:
|
||||||
default_conf_usdt['use_exit_signal'] = False
|
default_conf_usdt['use_exit_signal'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
if use_detail:
|
if use_detail:
|
||||||
default_conf_usdt['timeframe_detail'] = '1m'
|
default_conf_usdt['timeframe_detail'] = '1m'
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
@ -854,12 +854,12 @@ def test_backtest_one_detail_futures(
|
|||||||
default_conf_usdt['margin_mode'] = 'isolated'
|
default_conf_usdt['margin_mode'] = 'isolated'
|
||||||
default_conf_usdt['candle_type_def'] = CandleType.FUTURES
|
default_conf_usdt['candle_type_def'] = CandleType.FUTURES
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
|
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
|
||||||
PropertyMock(return_value=['XRP/USDT:USDT']))
|
PropertyMock(return_value=['XRP/USDT:USDT']))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_maintenance_ratio_and_amt",
|
mocker.patch(f"{EXMS}.get_maintenance_ratio_and_amt",
|
||||||
return_value=(0.01, 0.01))
|
return_value=(0.01, 0.01))
|
||||||
default_conf_usdt['timeframe'] = '1h'
|
default_conf_usdt['timeframe'] = '1h'
|
||||||
if use_detail:
|
if use_detail:
|
||||||
@ -945,12 +945,12 @@ def test_backtest_one_detail_futures_funding_fees(
|
|||||||
default_conf_usdt['minimal_roi'] = {'0': 1}
|
default_conf_usdt['minimal_roi'] = {'0': 1}
|
||||||
default_conf_usdt['dry_run_wallet'] = 100000
|
default_conf_usdt['dry_run_wallet'] = 100000
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
|
mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist',
|
||||||
PropertyMock(return_value=['XRP/USDT:USDT']))
|
PropertyMock(return_value=['XRP/USDT:USDT']))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_maintenance_ratio_and_amt",
|
mocker.patch(f"{EXMS}.get_maintenance_ratio_and_amt",
|
||||||
return_value=(0.01, 0.01))
|
return_value=(0.01, 0.01))
|
||||||
default_conf_usdt['timeframe'] = '1h'
|
default_conf_usdt['timeframe'] = '1h'
|
||||||
if use_detail:
|
if use_detail:
|
||||||
@ -1010,9 +1010,9 @@ def test_backtest_timedout_entry_orders(default_conf, fee, mocker, testdatadir)
|
|||||||
default_conf['startup_candle_count'] = 0
|
default_conf['startup_candle_count'] = 0
|
||||||
# Cancel unfilled order after 4 minutes on 5m timeframe.
|
# Cancel unfilled order after 4 minutes on 5m timeframe.
|
||||||
default_conf["unfilledtimeout"] = {"entry": 4}
|
default_conf["unfilledtimeout"] = {"entry": 4}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf['max_open_trades'] = 1
|
default_conf['max_open_trades'] = 1
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
@ -1035,9 +1035,9 @@ def test_backtest_timedout_entry_orders(default_conf, fee, mocker, testdatadir)
|
|||||||
def test_backtest_1min_timeframe(default_conf, fee, mocker, testdatadir) -> None:
|
def test_backtest_1min_timeframe(default_conf, fee, mocker, testdatadir) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
default_conf['max_open_trades'] = 1
|
default_conf['max_open_trades'] = 1
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
@ -1061,9 +1061,9 @@ def test_backtest_trim_no_data_left(default_conf, fee, mocker, testdatadir) -> N
|
|||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
default_conf['max_open_trades'] = 10
|
default_conf['max_open_trades'] = 10
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
@ -1105,9 +1105,9 @@ def test_processed(default_conf, mocker, testdatadir) -> None:
|
|||||||
def test_backtest_dataprovider_analyzed_df(default_conf, fee, mocker, testdatadir) -> None:
|
def test_backtest_dataprovider_analyzed_df(default_conf, fee, mocker, testdatadir) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
default_conf['max_open_trades'] = 10
|
default_conf['max_open_trades'] = 10
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=100000)
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=100000)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
backtesting._set_strategy(backtesting.strategylist[0])
|
backtesting._set_strategy(backtesting.strategylist[0])
|
||||||
@ -1155,9 +1155,9 @@ def test_backtest_pricecontours_protections(default_conf, fee, mocker, testdatad
|
|||||||
default_conf['enable_protections'] = True
|
default_conf['enable_protections'] = True
|
||||||
default_conf['timeframe'] = '1m'
|
default_conf['timeframe'] = '1m'
|
||||||
default_conf['max_open_trades'] = 1
|
default_conf['max_open_trades'] = 1
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
tests = [
|
tests = [
|
||||||
['sine', 9],
|
['sine', 9],
|
||||||
['raise', 10],
|
['raise', 10],
|
||||||
@ -1203,9 +1203,9 @@ def test_backtest_pricecontours(default_conf, fee, mocker, testdatadir,
|
|||||||
default_conf['protections'] = protections
|
default_conf['protections'] = protections
|
||||||
default_conf['enable_protections'] = True
|
default_conf['enable_protections'] = True
|
||||||
|
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
# While entry-signals are unrealistic, running backtesting
|
# While entry-signals are unrealistic, running backtesting
|
||||||
# over and over again should not cause different results
|
# over and over again should not cause different results
|
||||||
|
|
||||||
@ -1262,9 +1262,9 @@ def test_backtest_only_sell(mocker, default_conf, testdatadir):
|
|||||||
|
|
||||||
|
|
||||||
def test_backtest_alternate_buy_sell(default_conf, fee, mocker, testdatadir):
|
def test_backtest_alternate_buy_sell(default_conf, fee, mocker, testdatadir):
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
default_conf['max_open_trades'] = 10
|
default_conf['max_open_trades'] = 10
|
||||||
backtest_conf = _make_backtest_conf(mocker, conf=default_conf,
|
backtest_conf = _make_backtest_conf(mocker, conf=default_conf,
|
||||||
pair='UNITTEST/BTC', datadir=testdatadir)
|
pair='UNITTEST/BTC', datadir=testdatadir)
|
||||||
@ -1310,9 +1310,9 @@ def test_backtest_multi_pair(default_conf, fee, mocker, tres, pair, testdatadir)
|
|||||||
dataframe['exit_short'] = 0
|
dataframe['exit_short'] = 0
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
|
|
||||||
pairs = ['ADA/BTC', 'DASH/BTC', 'ETH/BTC', 'LTC/BTC', 'NXT/BTC']
|
pairs = ['ADA/BTC', 'DASH/BTC', 'ETH/BTC', 'LTC/BTC', 'NXT/BTC']
|
||||||
|
@ -12,17 +12,17 @@ from freqtrade.data import history
|
|||||||
from freqtrade.data.history import get_timerange
|
from freqtrade.data.history import get_timerange
|
||||||
from freqtrade.enums import ExitType
|
from freqtrade.enums import ExitType
|
||||||
from freqtrade.optimize.backtesting import Backtesting
|
from freqtrade.optimize.backtesting import Backtesting
|
||||||
from tests.conftest import patch_exchange
|
from tests.conftest import EXMS, patch_exchange
|
||||||
|
|
||||||
|
|
||||||
def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> None:
|
def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
default_conf['max_open_trades'] = 10
|
default_conf['max_open_trades'] = 10
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch('freqtrade.optimize.backtesting.amount_to_contract_precision',
|
mocker.patch('freqtrade.optimize.backtesting.amount_to_contract_precision',
|
||||||
lambda x, *args, **kwargs: round(x, 8))
|
lambda x, *args, **kwargs: round(x, 8))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=0.00001)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=0.00001)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf.update({
|
default_conf.update({
|
||||||
"stake_amount": 100.0,
|
"stake_amount": 100.0,
|
||||||
@ -99,10 +99,10 @@ def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) ->
|
|||||||
])
|
])
|
||||||
def test_backtest_position_adjustment_detailed(default_conf, fee, mocker, leverage) -> None:
|
def test_backtest_position_adjustment_detailed(default_conf, fee, mocker, leverage) -> None:
|
||||||
default_conf['use_exit_signal'] = False
|
default_conf['use_exit_signal'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_min_pair_stake_amount", return_value=10)
|
mocker.patch(f"{EXMS}.get_min_pair_stake_amount", return_value=10)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_pair_stake_amount", return_value=float('inf'))
|
mocker.patch(f"{EXMS}.get_max_pair_stake_amount", return_value=float('inf'))
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_leverage", return_value=10)
|
mocker.patch(f"{EXMS}.get_max_leverage", return_value=10)
|
||||||
|
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
default_conf.update({
|
default_conf.update({
|
||||||
|
@ -6,7 +6,7 @@ from unittest.mock import MagicMock
|
|||||||
from freqtrade.commands.optimize_commands import setup_optimize_configuration, start_edge
|
from freqtrade.commands.optimize_commands import setup_optimize_configuration, start_edge
|
||||||
from freqtrade.enums import RunMode
|
from freqtrade.enums import RunMode
|
||||||
from freqtrade.optimize.edge_cli import EdgeCli
|
from freqtrade.optimize.edge_cli import EdgeCli
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, get_args, log_has, patch_exchange,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, get_args, log_has, patch_exchange,
|
||||||
patched_configuration_load_config_file)
|
patched_configuration_load_config_file)
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ def test_setup_edge_configuration_with_arguments(mocker, edge_conf, caplog) -> N
|
|||||||
|
|
||||||
def test_start(mocker, fee, edge_conf, caplog) -> None:
|
def test_start(mocker, fee, edge_conf, caplog) -> None:
|
||||||
start_mock = MagicMock()
|
start_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.optimize.edge_cli.EdgeCli.start', start_mock)
|
mocker.patch('freqtrade.optimize.edge_cli.EdgeCli.start', start_mock)
|
||||||
patched_configuration_load_config_file(mocker, edge_conf)
|
patched_configuration_load_config_file(mocker, edge_conf)
|
||||||
@ -101,7 +101,7 @@ def test_edge_init_fee(mocker, edge_conf) -> None:
|
|||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
edge_conf['fee'] = 0.1234
|
edge_conf['fee'] = 0.1234
|
||||||
edge_conf['stake_amount'] = 20
|
edge_conf['stake_amount'] = 20
|
||||||
fee_mock = mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5))
|
fee_mock = mocker.patch(f'{EXMS}.get_fee', return_value=0.5)
|
||||||
edge_cli = EdgeCli(edge_conf)
|
edge_cli = EdgeCli(edge_conf)
|
||||||
assert edge_cli.edge.fee == 0.1234
|
assert edge_cli.edge.fee == 0.1234
|
||||||
assert fee_mock.call_count == 0
|
assert fee_mock.call_count == 0
|
||||||
|
@ -20,7 +20,7 @@ from freqtrade.optimize.hyperopt_tools import HyperoptTools
|
|||||||
from freqtrade.optimize.optimize_reports import generate_strategy_stats
|
from freqtrade.optimize.optimize_reports import generate_strategy_stats
|
||||||
from freqtrade.optimize.space import SKDecimal
|
from freqtrade.optimize.space import SKDecimal
|
||||||
from freqtrade.strategy import IntParameter
|
from freqtrade.strategy import IntParameter
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, get_args, get_markets, log_has, log_has_re,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, get_args, get_markets, log_has, log_has_re,
|
||||||
patch_exchange, patched_configuration_load_config_file)
|
patch_exchange, patched_configuration_load_config_file)
|
||||||
|
|
||||||
|
|
||||||
@ -859,7 +859,7 @@ def test_simplified_interface_failed(mocker, hyperopt_conf, space) -> None:
|
|||||||
|
|
||||||
def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
# No hyperopt needed
|
# No hyperopt needed
|
||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
@ -897,10 +897,10 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.validate_config', MagicMock())
|
mocker.patch(f'{EXMS}.validate_config', MagicMock())
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._load_markets')
|
mocker.patch(f'{EXMS}._load_markets')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets',
|
mocker.patch(f'{EXMS}.markets',
|
||||||
PropertyMock(return_value=get_markets()))
|
PropertyMock(return_value=get_markets()))
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
# No hyperopt needed
|
# No hyperopt needed
|
||||||
@ -938,7 +938,7 @@ def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmpdir,
|
|||||||
|
|
||||||
def test_in_strategy_auto_hyperopt_per_epoch(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
def test_in_strategy_auto_hyperopt_per_epoch(mocker, hyperopt_conf, tmpdir, fee) -> None:
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
|
|
||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
@ -996,7 +996,7 @@ def test_stake_amount_unlimited_max_open_trades(mocker, hyperopt_conf, tmpdir, f
|
|||||||
# This test is to ensure that unlimited max_open_trades are ignored for the backtesting
|
# This test is to ensure that unlimited max_open_trades are ignored for the backtesting
|
||||||
# if we have an unlimited stake amount
|
# if we have an unlimited stake amount
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
'strategy': 'HyperoptableStrategy',
|
'strategy': 'HyperoptableStrategy',
|
||||||
@ -1024,7 +1024,7 @@ def test_max_open_trades_dump(mocker, hyperopt_conf, tmpdir, fee, capsys) -> Non
|
|||||||
# This test is to ensure that after hyperopting, max_open_trades is never
|
# This test is to ensure that after hyperopting, max_open_trades is never
|
||||||
# saved as inf in the output json params
|
# saved as inf in the output json params
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
'strategy': 'HyperoptableStrategy',
|
'strategy': 'HyperoptableStrategy',
|
||||||
@ -1070,7 +1070,7 @@ def test_max_open_trades_consistency(mocker, hyperopt_conf, tmpdir, fee) -> None
|
|||||||
# This test is to ensure that max_open_trades is the same across all functions needing it
|
# This test is to ensure that max_open_trades is the same across all functions needing it
|
||||||
# after it has been changed from the hyperopt
|
# after it has been changed from the hyperopt
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', return_value=0)
|
mocker.patch(f'{EXMS}.get_fee', return_value=0)
|
||||||
|
|
||||||
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
|
||||||
hyperopt_conf.update({
|
hyperopt_conf.update({
|
||||||
|
@ -18,8 +18,8 @@ from freqtrade.persistence import Trade
|
|||||||
from freqtrade.plugins.pairlist.pairlist_helpers import dynamic_expand_pairlist, expand_pairlist
|
from freqtrade.plugins.pairlist.pairlist_helpers import dynamic_expand_pairlist, expand_pairlist
|
||||||
from freqtrade.plugins.pairlistmanager import PairListManager
|
from freqtrade.plugins.pairlistmanager import PairListManager
|
||||||
from freqtrade.resolvers import PairListResolver
|
from freqtrade.resolvers import PairListResolver
|
||||||
from tests.conftest import (create_mock_trades_usdt, get_patched_exchange, get_patched_freqtradebot,
|
from tests.conftest import (EXMS, create_mock_trades_usdt, get_patched_exchange,
|
||||||
log_has, log_has_re, num_log_has)
|
get_patched_freqtradebot, log_has, log_has_re, num_log_has)
|
||||||
|
|
||||||
|
|
||||||
# Exclude RemotePairList from tests.
|
# Exclude RemotePairList from tests.
|
||||||
@ -139,7 +139,7 @@ def test_log_cached(mocker, static_pl_conf, markets, tickers):
|
|||||||
|
|
||||||
def test_load_pairlist_noexist(mocker, markets, default_conf):
|
def test_load_pairlist_noexist(mocker, markets, default_conf):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"Impossible to load Pairlist 'NonexistingPairList'. "
|
match=r"Impossible to load Pairlist 'NonexistingPairList'. "
|
||||||
@ -150,7 +150,7 @@ def test_load_pairlist_noexist(mocker, markets, default_conf):
|
|||||||
|
|
||||||
def test_load_pairlist_verify_multi(mocker, markets_static, default_conf):
|
def test_load_pairlist_verify_multi(mocker, markets_static, default_conf):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets_static))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets_static))
|
||||||
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
plm = PairListManager(freqtrade.exchange, default_conf, MagicMock())
|
||||||
# Call different versions one after the other, should always consider what was passed in
|
# Call different versions one after the other, should always consider what was passed in
|
||||||
# and have no side-effects (therefore the same check multiple times)
|
# and have no side-effects (therefore the same check multiple times)
|
||||||
@ -166,7 +166,7 @@ def test_refresh_market_pair_not_in_whitelist(mocker, markets, static_pl_conf):
|
|||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
freqtrade = get_patched_freqtradebot(mocker, static_pl_conf)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
# List ordered by BaseVolume
|
# List ordered by BaseVolume
|
||||||
whitelist = ['ETH/BTC', 'TKN/BTC']
|
whitelist = ['ETH/BTC', 'TKN/BTC']
|
||||||
@ -324,7 +324,7 @@ def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):
|
|||||||
exchange_has=MagicMock(return_value=True),
|
exchange_has=MagicMock(return_value=True),
|
||||||
)
|
)
|
||||||
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets_empty))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets_empty))
|
||||||
|
|
||||||
# argument: use the whitelist dynamically by exchange-volume
|
# argument: use the whitelist dynamically by exchange-volume
|
||||||
whitelist = []
|
whitelist = []
|
||||||
@ -523,7 +523,7 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t
|
|||||||
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_vola,
|
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_vola,
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
@ -649,7 +649,7 @@ def test_VolumePairList_range(mocker, whitelist_conf, shitcoinmarkets, tickers,
|
|||||||
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_volume,
|
('HOT/BTC', '1d', CandleType.SPOT): ohlcv_history_high_volume,
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
if volumefilter_result == 'default_refresh_too_short':
|
if volumefilter_result == 'default_refresh_too_short':
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
@ -702,7 +702,7 @@ def test_PrecisionFilter_error(mocker, whitelist_conf) -> None:
|
|||||||
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PrecisionFilter"}]
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PrecisionFilter"}]
|
||||||
del whitelist_conf['stoploss']
|
del whitelist_conf['stoploss']
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"PrecisionFilter can only work with stoploss defined\..*"):
|
match=r"PrecisionFilter can only work with stoploss defined\..*"):
|
||||||
@ -713,7 +713,7 @@ def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
|
|||||||
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
|
||||||
if hasattr(Trade, 'query'):
|
if hasattr(Trade, 'query'):
|
||||||
del Trade.query
|
del Trade.query
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
exchange = get_patched_exchange(mocker, whitelist_conf)
|
exchange = get_patched_exchange(mocker, whitelist_conf)
|
||||||
pm = PairListManager(exchange, whitelist_conf, MagicMock())
|
pm = PairListManager(exchange, whitelist_conf, MagicMock())
|
||||||
pm.refresh_pairlist()
|
pm.refresh_pairlist()
|
||||||
@ -755,7 +755,7 @@ def test_PerformanceFilter_lookback(mocker, default_conf_usdt, fee, caplog) -> N
|
|||||||
{"method": "StaticPairList"},
|
{"method": "StaticPairList"},
|
||||||
{"method": "PerformanceFilter", "minutes": 60, "min_profit": 0.01}
|
{"method": "PerformanceFilter", "minutes": 60, "min_profit": 0.01}
|
||||||
]
|
]
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
||||||
pm = PairListManager(exchange, default_conf_usdt)
|
pm = PairListManager(exchange, default_conf_usdt)
|
||||||
pm.refresh_pairlist()
|
pm.refresh_pairlist()
|
||||||
@ -781,7 +781,7 @@ def test_PerformanceFilter_keep_mid_order(mocker, default_conf_usdt, fee, caplog
|
|||||||
{"method": "StaticPairList", "allow_inactive": True},
|
{"method": "StaticPairList", "allow_inactive": True},
|
||||||
{"method": "PerformanceFilter", "minutes": 60, }
|
{"method": "PerformanceFilter", "minutes": 60, }
|
||||||
]
|
]
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
exchange = get_patched_exchange(mocker, default_conf_usdt)
|
||||||
pm = PairListManager(exchange, default_conf_usdt)
|
pm = PairListManager(exchange, default_conf_usdt)
|
||||||
pm.refresh_pairlist()
|
pm.refresh_pairlist()
|
||||||
@ -881,7 +881,7 @@ def test__whitelist_for_active_markets(mocker, whitelist_conf, markets, pairlist
|
|||||||
def test__whitelist_for_active_markets_empty(mocker, whitelist_conf, pairlist, tickers):
|
def test__whitelist_for_active_markets_empty(mocker, whitelist_conf, pairlist, tickers):
|
||||||
whitelist_conf['pairlists'][0]['method'] = pairlist
|
whitelist_conf['pairlists'][0]['method'] = pairlist
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', return_value=True)
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtrade = get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
@ -897,7 +897,7 @@ def test__whitelist_for_active_markets_empty(mocker, whitelist_conf, pairlist, t
|
|||||||
def test_volumepairlist_invalid_sortvalue(mocker, whitelist_conf):
|
def test_volumepairlist_invalid_sortvalue(mocker, whitelist_conf):
|
||||||
whitelist_conf['pairlists'][0].update({"sort_key": "asdf"})
|
whitelist_conf['pairlists'][0].update({"sort_key": "asdf"})
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"key asdf not in .*"):
|
match=r"key asdf not in .*"):
|
||||||
get_patched_freqtradebot(mocker, whitelist_conf)
|
get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
@ -1000,14 +1000,14 @@ def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, o
|
|||||||
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
||||||
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history.iloc[[0]],
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history.iloc[[0]],
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data)
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
||||||
freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
assert len(freqtrade.pairlists.whitelist) == 3
|
assert len(freqtrade.pairlists.whitelist) == 3
|
||||||
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
||||||
|
|
||||||
# Move to next day
|
# Move to next day
|
||||||
t.move_to("2021-09-02 01:00:00 +00:00")
|
t.move_to("2021-09-02 01:00:00 +00:00")
|
||||||
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data)
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
||||||
freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
assert len(freqtrade.pairlists.whitelist) == 3
|
assert len(freqtrade.pairlists.whitelist) == 3
|
||||||
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
assert freqtrade.exchange.refresh_latest_ohlcv.call_count == 1
|
||||||
@ -1021,7 +1021,7 @@ def test_agefilter_caching(mocker, markets, whitelist_conf_agefilter, tickers, o
|
|||||||
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
('LTC/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
||||||
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
('XRP/BTC', '1d', CandleType.SPOT): ohlcv_history,
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', return_value=ohlcv_data)
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', return_value=ohlcv_data)
|
||||||
freqtrade.pairlists.refresh_pairlist()
|
freqtrade.pairlists.refresh_pairlist()
|
||||||
assert len(freqtrade.pairlists.whitelist) == 4
|
assert len(freqtrade.pairlists.whitelist) == 4
|
||||||
# Called once (only for XRP/BTC)
|
# Called once (only for XRP/BTC)
|
||||||
@ -1033,7 +1033,7 @@ def test_OffsetFilter_error(mocker, whitelist_conf) -> None:
|
|||||||
[{"method": "StaticPairList"}, {"method": "OffsetFilter", "offset": -1}]
|
[{"method": "StaticPairList"}, {"method": "OffsetFilter", "offset": -1}]
|
||||||
)
|
)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'OffsetFilter requires offset to be >= 0'):
|
match=r'OffsetFilter requires offset to be >= 0'):
|
||||||
@ -1214,7 +1214,7 @@ def test_pricefilter_desc(mocker, whitelist_conf, markets, pairlistconfig,
|
|||||||
|
|
||||||
|
|
||||||
def test_pairlistmanager_no_pairlist(mocker, whitelist_conf):
|
def test_pairlistmanager_no_pairlist(mocker, whitelist_conf):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
whitelist_conf['pairlists'] = []
|
whitelist_conf['pairlists'] = []
|
||||||
|
|
||||||
@ -1266,7 +1266,7 @@ def test_performance_filter(mocker, whitelist_conf, pairlists, pair_allowlist, o
|
|||||||
allowlist_conf['pairlists'] = pairlists
|
allowlist_conf['pairlists'] = pairlists
|
||||||
allowlist_conf['exchange']['pair_whitelist'] = pair_allowlist
|
allowlist_conf['exchange']['pair_whitelist'] = pair_allowlist
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
freqtrade = get_patched_freqtradebot(mocker, allowlist_conf)
|
freqtrade = get_patched_freqtradebot(mocker, allowlist_conf)
|
||||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
@ -1371,7 +1371,7 @@ def test_expand_pairlist_keep_invalid(wildcardlist, pairs, expected):
|
|||||||
|
|
||||||
|
|
||||||
def test_ProducerPairlist_no_emc(mocker, whitelist_conf):
|
def test_ProducerPairlist_no_emc(mocker, whitelist_conf):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
|
|
||||||
whitelist_conf['pairlists'] = [
|
whitelist_conf['pairlists'] = [
|
||||||
{
|
{
|
||||||
@ -1388,7 +1388,7 @@ def test_ProducerPairlist_no_emc(mocker, whitelist_conf):
|
|||||||
|
|
||||||
|
|
||||||
def test_ProducerPairlist(mocker, whitelist_conf, markets):
|
def test_ProducerPairlist(mocker, whitelist_conf, markets):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
markets=PropertyMock(return_value=markets),
|
markets=PropertyMock(return_value=markets),
|
||||||
exchange_has=MagicMock(return_value=True),
|
exchange_has=MagicMock(return_value=True),
|
||||||
|
@ -12,8 +12,8 @@ from freqtrade.persistence import Trade
|
|||||||
from freqtrade.persistence.pairlock_middleware import PairLocks
|
from freqtrade.persistence.pairlock_middleware import PairLocks
|
||||||
from freqtrade.rpc import RPC, RPCException
|
from freqtrade.rpc import RPC, RPCException
|
||||||
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
||||||
from tests.conftest import (create_mock_trades, create_mock_trades_usdt, get_patched_freqtradebot,
|
from tests.conftest import (EXMS, create_mock_trades, create_mock_trades_usdt,
|
||||||
patch_get_signal)
|
get_patched_freqtradebot, patch_get_signal)
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
||||||
@ -169,7 +169,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||||||
response = deepcopy(gen_response)
|
response = deepcopy(gen_response)
|
||||||
assert results[0] == response
|
assert results[0] == response
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate',
|
mocker.patch(f'{EXMS}.get_rate',
|
||||||
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
||||||
results = rpc._rpc_trade_status()
|
results = rpc._rpc_trade_status()
|
||||||
assert isnan(results[0]['profit_ratio'])
|
assert isnan(results[0]['profit_ratio'])
|
||||||
@ -209,7 +209,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
freqtradebot.state = State.RUNNING
|
freqtradebot.state = State.RUNNING
|
||||||
with pytest.raises(RPCException, match=r'.*no active trade*'):
|
with pytest.raises(RPCException, match=r'.*no active trade*'):
|
||||||
rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=False)
|
||||||
freqtradebot.enter_positions()
|
freqtradebot.enter_positions()
|
||||||
|
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
@ -220,7 +220,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
assert '0.00' == result[0][3]
|
assert '0.00' == result[0][3]
|
||||||
assert isnan(fiat_profit_sum)
|
assert isnan(fiat_profit_sum)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=True)
|
||||||
freqtradebot.process()
|
freqtradebot.process()
|
||||||
|
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
@ -231,7 +231,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
assert '-0.41%' == result[0][3]
|
assert '-0.41%' == result[0][3]
|
||||||
assert isnan(fiat_profit_sum)
|
assert isnan(fiat_profit_sum)
|
||||||
|
|
||||||
# Test with fiatconvert
|
# Test with fiat convert
|
||||||
rpc._fiat_converter = CryptoToFiatConverter()
|
rpc._fiat_converter = CryptoToFiatConverter()
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
assert "Since" in headers
|
assert "Since" in headers
|
||||||
@ -251,7 +251,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||||||
# 3 on top of the initial one.
|
# 3 on top of the initial one.
|
||||||
assert result[0][4] == '1/4'
|
assert result[0][4] == '1/4'
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate',
|
mocker.patch(f'{EXMS}.get_rate',
|
||||||
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
||||||
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
|
||||||
assert 'instantly' == result[0][2]
|
assert 'instantly' == result[0][2]
|
||||||
@ -367,15 +367,13 @@ def test_rpc_delete_trade(mocker, default_conf, fee, markets, caplog, is_short):
|
|||||||
assert stoploss_mock.call_count == 1
|
assert stoploss_mock.call_count == 1
|
||||||
assert res['cancel_order_count'] == 2
|
assert res['cancel_order_count'] == 2
|
||||||
|
|
||||||
stoploss_mock = mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order',
|
stoploss_mock = mocker.patch(f'{EXMS}.cancel_stoploss_order', side_effect=InvalidOrderException)
|
||||||
side_effect=InvalidOrderException)
|
|
||||||
|
|
||||||
res = rpc._rpc_delete('3')
|
res = rpc._rpc_delete('3')
|
||||||
assert stoploss_mock.call_count == 1
|
assert stoploss_mock.call_count == 1
|
||||||
stoploss_mock.reset_mock()
|
stoploss_mock.reset_mock()
|
||||||
|
|
||||||
cancel_mock = mocker.patch('freqtrade.exchange.Exchange.cancel_order',
|
cancel_mock = mocker.patch(f'{EXMS}.cancel_order', side_effect=InvalidOrderException)
|
||||||
side_effect=InvalidOrderException)
|
|
||||||
|
|
||||||
res = rpc._rpc_delete('4')
|
res = rpc._rpc_delete('4')
|
||||||
assert cancel_mock.call_count == 1
|
assert cancel_mock.call_count == 1
|
||||||
@ -423,7 +421,7 @@ def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None:
|
|||||||
assert stats['best_rate'] == 10.0
|
assert stats['best_rate'] == 10.0
|
||||||
|
|
||||||
# Test non-available pair
|
# Test non-available pair
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate',
|
mocker.patch(f'{EXMS}.get_rate',
|
||||||
MagicMock(side_effect=ExchangeError("Pair 'XRP/USDT' not available")))
|
MagicMock(side_effect=ExchangeError("Pair 'XRP/USDT' not available")))
|
||||||
stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency)
|
stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency)
|
||||||
assert stats['trade_count'] == 7
|
assert stats['trade_count'] == 7
|
||||||
@ -708,15 +706,14 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
|
|||||||
|
|
||||||
freqtradebot.state = State.RUNNING
|
freqtradebot.state = State.RUNNING
|
||||||
assert cancel_order_mock.call_count == 0
|
assert cancel_order_mock.call_count == 0
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', MagicMock(return_value=False))
|
||||||
'freqtrade.exchange.Exchange._dry_is_price_crossed', MagicMock(return_value=False))
|
|
||||||
freqtradebot.enter_positions()
|
freqtradebot.enter_positions()
|
||||||
# make an limit-buy open trade
|
# make an limit-buy open trade
|
||||||
trade = Trade.query.filter(Trade.id == '3').first()
|
trade = Trade.query.filter(Trade.id == '3').first()
|
||||||
filled_amount = trade.amount / 2
|
filled_amount = trade.amount / 2
|
||||||
# Fetch order - it's open first, and closed after cancel_order is called.
|
# Fetch order - it's open first, and closed after cancel_order is called.
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_order',
|
f'{EXMS}.fetch_order',
|
||||||
side_effect=[{
|
side_effect=[{
|
||||||
'id': trade.orders[0].order_id,
|
'id': trade.orders[0].order_id,
|
||||||
'status': 'open',
|
'status': 'open',
|
||||||
@ -738,7 +735,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
|
|||||||
assert pytest.approx(trade.amount) == filled_amount
|
assert pytest.approx(trade.amount) == filled_amount
|
||||||
|
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_order',
|
f'{EXMS}.fetch_order',
|
||||||
return_value={
|
return_value={
|
||||||
'status': 'open',
|
'status': 'open',
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -752,7 +749,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
|
|||||||
amount = trade.amount
|
amount = trade.amount
|
||||||
# make an limit-buy open trade, if there is no 'filled', don't sell it
|
# make an limit-buy open trade, if there is no 'filled', don't sell it
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_order',
|
f'{EXMS}.fetch_order',
|
||||||
return_value={
|
return_value={
|
||||||
'status': 'open',
|
'status': 'open',
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -770,7 +767,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
|
|||||||
|
|
||||||
# make an limit-sell open trade
|
# make an limit-sell open trade
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_order',
|
f'{EXMS}.fetch_order',
|
||||||
return_value={
|
return_value={
|
||||||
'status': 'open',
|
'status': 'open',
|
||||||
'type': 'limit',
|
'type': 'limit',
|
||||||
@ -1138,7 +1135,7 @@ def test_rpc_whitelist_dynamic(mocker, default_conf) -> None:
|
|||||||
default_conf['pairlists'] = [{'method': 'VolumePairList',
|
default_conf['pairlists'] = [{'method': 'VolumePairList',
|
||||||
'number_assets': 4,
|
'number_assets': 4,
|
||||||
}]
|
}]
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
@ -24,7 +24,7 @@ from freqtrade.rpc import RPC
|
|||||||
from freqtrade.rpc.api_server import ApiServer
|
from freqtrade.rpc.api_server import ApiServer
|
||||||
from freqtrade.rpc.api_server.api_auth import create_token, get_user_from_token
|
from freqtrade.rpc.api_server.api_auth import create_token, get_user_from_token
|
||||||
from freqtrade.rpc.api_server.uvicorn_threaded import UvicornServer
|
from freqtrade.rpc.api_server.uvicorn_threaded import UvicornServer
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, create_mock_trades, get_mock_coro,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, create_mock_trades, get_mock_coro,
|
||||||
get_patched_freqtradebot, log_has, log_has_re, patch_get_signal)
|
get_patched_freqtradebot, log_has, log_has_re, patch_get_signal)
|
||||||
|
|
||||||
|
|
||||||
@ -473,9 +473,9 @@ def test_api_balance(botclient, mocker, rpc_balance, tickers):
|
|||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
|
|
||||||
ftbot.config['dry_run'] = False
|
ftbot.config['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
mocker.patch(f'{EXMS}.get_balances', return_value=rpc_balance)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_tickers', tickers)
|
mocker.patch(f'{EXMS}.get_tickers', tickers)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
|
mocker.patch(f'{EXMS}.get_valid_pair_combination',
|
||||||
side_effect=lambda a, b: f"{a}/{b}")
|
side_effect=lambda a, b: f"{a}/{b}")
|
||||||
ftbot.wallets.update()
|
ftbot.wallets.update()
|
||||||
|
|
||||||
@ -731,15 +731,13 @@ def test_api_delete_open_order(botclient, mocker, fee, markets, ticker, is_short
|
|||||||
assert_response(rc, 502)
|
assert_response(rc, 502)
|
||||||
assert 'No open order for trade_id' in rc.json()['error']
|
assert 'No open order for trade_id' in rc.json()['error']
|
||||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order', side_effect=ExchangeError)
|
||||||
side_effect=ExchangeError)
|
|
||||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||||
assert_response(rc, 502)
|
assert_response(rc, 502)
|
||||||
assert 'Order not found.' in rc.json()['error']
|
assert 'Order not found.' in rc.json()['error']
|
||||||
|
|
||||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order', return_value=trade.orders[-1].to_ccxt_object())
|
||||||
return_value=trade.orders[-1].to_ccxt_object())
|
|
||||||
|
|
||||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
@ -1068,7 +1066,7 @@ def test_api_status(botclient, mocker, ticker, fee, markets, is_short,
|
|||||||
'orders': [ANY],
|
'orders': [ANY],
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate',
|
mocker.patch(f'{EXMS}.get_rate',
|
||||||
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/status")
|
rc = client_get(client, f"{BASE_URI}/status")
|
||||||
@ -1631,7 +1629,7 @@ def test_sysinfo(botclient):
|
|||||||
|
|
||||||
def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir):
|
def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch(f'{EXMS}.get_fee', fee)
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/backtest")
|
rc = client_get(client, f"{BASE_URI}/backtest")
|
||||||
# Backtest prevented in default mode
|
# Backtest prevented in default mode
|
||||||
|
@ -30,9 +30,9 @@ from freqtrade.persistence.models import Order
|
|||||||
from freqtrade.rpc import RPC
|
from freqtrade.rpc import RPC
|
||||||
from freqtrade.rpc.rpc import RPCException
|
from freqtrade.rpc.rpc import RPCException
|
||||||
from freqtrade.rpc.telegram import Telegram, authorized_only
|
from freqtrade.rpc.telegram import Telegram, authorized_only
|
||||||
from tests.conftest import (CURRENT_TEST_STRATEGY, create_mock_trades, create_mock_trades_usdt,
|
from tests.conftest import (CURRENT_TEST_STRATEGY, EXMS, create_mock_trades,
|
||||||
get_patched_freqtradebot, log_has, log_has_re, patch_exchange,
|
create_mock_trades_usdt, get_patched_freqtradebot, log_has, log_has_re,
|
||||||
patch_get_signal, patch_whitelist)
|
patch_exchange, patch_get_signal, patch_whitelist)
|
||||||
|
|
||||||
|
|
||||||
class DummyCls(Telegram):
|
class DummyCls(Telegram):
|
||||||
@ -706,7 +706,7 @@ def test_profit_handle(default_conf_usdt, update, ticker_usdt, ticker_sell_up, f
|
|||||||
msg_mock.reset_mock()
|
msg_mock.reset_mock()
|
||||||
|
|
||||||
# Update the ticker with a market going up
|
# Update the ticker with a market going up
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', ticker_sell_up)
|
mocker.patch(f'{EXMS}.fetch_ticker', ticker_sell_up)
|
||||||
# Simulate fulfilled LIMIT_SELL order for trade
|
# Simulate fulfilled LIMIT_SELL order for trade
|
||||||
oobj = Order.parse_from_ccxt_object(
|
oobj = Order.parse_from_ccxt_object(
|
||||||
limit_sell_order_usdt, limit_sell_order_usdt['symbol'], 'sell')
|
limit_sell_order_usdt, limit_sell_order_usdt['symbol'], 'sell')
|
||||||
@ -764,10 +764,9 @@ def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) ->
|
|||||||
|
|
||||||
def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tickers) -> None:
|
def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tickers) -> None:
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
|
mocker.patch(f'{EXMS}.get_balances', return_value=rpc_balance)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_tickers', tickers)
|
mocker.patch(f'{EXMS}.get_tickers', tickers)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
|
mocker.patch(f'{EXMS}.get_valid_pair_combination', side_effect=lambda a, b: f"{a}/{b}")
|
||||||
side_effect=lambda a, b: f"{a}/{b}")
|
|
||||||
|
|
||||||
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
@ -790,7 +789,7 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick
|
|||||||
|
|
||||||
def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
|
def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={})
|
mocker.patch(f'{EXMS}.get_balances', return_value={})
|
||||||
|
|
||||||
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
@ -803,7 +802,7 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None:
|
def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={})
|
mocker.patch(f'{EXMS}.get_balances', return_value={})
|
||||||
|
|
||||||
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
@ -949,7 +948,7 @@ def test_telegram_forceexit_handle(default_conf, update, ticker, fee,
|
|||||||
assert trade
|
assert trade
|
||||||
|
|
||||||
# Increase the price and sell it
|
# Increase the price and sell it
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', ticker_sell_up)
|
mocker.patch(f'{EXMS}.fetch_ticker', ticker_sell_up)
|
||||||
|
|
||||||
# /forceexit 1
|
# /forceexit 1
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
@ -1492,7 +1491,7 @@ def test_whitelist_static(default_conf, update, mocker) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_whitelist_dynamic(default_conf, update, mocker) -> None:
|
def test_whitelist_dynamic(default_conf, update, mocker) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', return_value=True)
|
||||||
default_conf['pairlists'] = [{'method': 'VolumePairList',
|
default_conf['pairlists'] = [{'method': 'VolumePairList',
|
||||||
'number_assets': 4
|
'number_assets': 4
|
||||||
}]
|
}]
|
||||||
@ -1707,8 +1706,7 @@ def test_telegram_delete_open_order(mocker, update, default_conf, fee, is_short,
|
|||||||
msg_mock.reset_mock()
|
msg_mock.reset_mock()
|
||||||
|
|
||||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order', return_value=trade.orders[-1].to_ccxt_object())
|
||||||
return_value=trade.orders[-1].to_ccxt_object())
|
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
context.args = [6]
|
context.args = [6]
|
||||||
telegram._cancel_open_order(update=update, context=context)
|
telegram._cancel_open_order(update=update, context=context)
|
||||||
|
@ -22,9 +22,10 @@ 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, create_mock_trades_usdt, get_patched_freqtradebot,
|
from tests.conftest import (EXMS, create_mock_trades, create_mock_trades_usdt,
|
||||||
get_patched_worker, log_has, log_has_re, patch_edge, patch_exchange,
|
get_patched_freqtradebot, get_patched_worker, log_has, log_has_re,
|
||||||
patch_get_signal, patch_wallet, patch_whitelist)
|
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,
|
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)
|
||||||
@ -46,7 +47,7 @@ def patch_RPCManager(mocker) -> MagicMock:
|
|||||||
|
|
||||||
|
|
||||||
def test_freqtradebot_state(mocker, default_conf_usdt, markets) -> None:
|
def test_freqtradebot_state(mocker, default_conf_usdt, markets) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
assert freqtrade.state is State.RUNNING
|
assert freqtrade.state is State.RUNNING
|
||||||
|
|
||||||
@ -862,8 +863,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
|||||||
order['cost'] = 300
|
order['cost'] = 300
|
||||||
order['id'] = '444'
|
order['id'] = '444'
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=order))
|
||||||
MagicMock(return_value=order))
|
|
||||||
assert freqtrade.execute_entry(pair, stake_amount, is_short=is_short)
|
assert freqtrade.execute_entry(pair, stake_amount, is_short=is_short)
|
||||||
trade = Trade.query.all()[2]
|
trade = Trade.query.all()[2]
|
||||||
trade.is_short = is_short
|
trade.is_short = is_short
|
||||||
@ -881,8 +881,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
|||||||
order['average'] = 0.5
|
order['average'] = 0.5
|
||||||
order['cost'] = 10.0
|
order['cost'] = 10.0
|
||||||
order['id'] = '555'
|
order['id'] = '555'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=order))
|
||||||
MagicMock(return_value=order))
|
|
||||||
assert freqtrade.execute_entry(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[3]
|
trade = Trade.query.all()[3]
|
||||||
trade.is_short = is_short
|
trade.is_short = is_short
|
||||||
@ -919,19 +918,18 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
|
|||||||
order['average'] = 0.5
|
order['average'] = 0.5
|
||||||
order['cost'] = 0.0
|
order['cost'] = 0.0
|
||||||
order['id'] = '66'
|
order['id'] = '66'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=order))
|
||||||
MagicMock(return_value=order))
|
|
||||||
assert not freqtrade.execute_entry(pair, stake_amount)
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
||||||
assert freqtrade.strategy.leverage.call_count == 0 if trading_mode == 'spot' else 2
|
assert freqtrade.strategy.leverage.call_count == 0 if trading_mode == 'spot' else 2
|
||||||
|
|
||||||
# Fail to get price...
|
# Fail to get price...
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate', MagicMock(return_value=0.0))
|
mocker.patch(f'{EXMS}.get_rate', MagicMock(return_value=0.0))
|
||||||
|
|
||||||
with pytest.raises(PricingError, match="Could not determine entry price."):
|
with pytest.raises(PricingError, match="Could not determine entry price."):
|
||||||
freqtrade.execute_entry(pair, stake_amount, is_short=is_short)
|
freqtrade.execute_entry(pair, stake_amount, is_short=is_short)
|
||||||
|
|
||||||
# In case of custom entry price
|
# In case of custom entry price
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate', return_value=0.50)
|
mocker.patch(f'{EXMS}.get_rate', return_value=0.50)
|
||||||
order['status'] = 'open'
|
order['status'] = 'open'
|
||||||
order['id'] = '5566'
|
order['id'] = '5566'
|
||||||
freqtrade.strategy.custom_entry_price = lambda **kwargs: 0.508
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: 0.508
|
||||||
@ -1066,11 +1064,11 @@ def test_add_stoploss_on_exchange(mocker, default_conf_usdt, limit_order, is_sho
|
|||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
order = limit_order[entry_side(is_short)]
|
order = limit_order[entry_side(is_short)]
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=order)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
|
|
||||||
stoploss = MagicMock(return_value={'id': 13434334})
|
stoploss = MagicMock(return_value={'id': 13434334})
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
||||||
@ -1135,7 +1133,7 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
trade.stoploss_order_id = "100"
|
trade.stoploss_order_id = "100"
|
||||||
|
|
||||||
hanging_stoploss_order = MagicMock(return_value={'status': 'open'})
|
hanging_stoploss_order = MagicMock(return_value={'status': 'open'})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', hanging_stoploss_order)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', hanging_stoploss_order)
|
||||||
|
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
||||||
assert trade.stoploss_order_id == "100"
|
assert trade.stoploss_order_id == "100"
|
||||||
@ -1148,7 +1146,7 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
trade.stoploss_order_id = "100"
|
trade.stoploss_order_id = "100"
|
||||||
|
|
||||||
canceled_stoploss_order = MagicMock(return_value={'status': 'canceled'})
|
canceled_stoploss_order = MagicMock(return_value={'status': 'canceled'})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', canceled_stoploss_order)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', canceled_stoploss_order)
|
||||||
stoploss.reset_mock()
|
stoploss.reset_mock()
|
||||||
|
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
||||||
@ -1183,17 +1181,14 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
'average': 2,
|
'average': 2,
|
||||||
'amount': enter_order['amount'],
|
'amount': enter_order['amount'],
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', stoploss_order_hit)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', stoploss_order_hit)
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is True
|
assert freqtrade.handle_stoploss_on_exchange(trade) is True
|
||||||
assert log_has_re(r'STOP_LOSS_LIMIT is hit for Trade\(id=1, .*\)\.', caplog)
|
assert log_has_re(r'STOP_LOSS_LIMIT is hit for Trade\(id=1, .*\)\.', caplog)
|
||||||
assert trade.stoploss_order_id is None
|
assert trade.stoploss_order_id is None
|
||||||
assert trade.is_open is False
|
assert trade.is_open is False
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
mocker.patch(
|
mocker.patch(f'{EXMS}.create_stoploss', side_effect=ExchangeError())
|
||||||
'freqtrade.exchange.Exchange.create_stoploss',
|
|
||||||
side_effect=ExchangeError()
|
|
||||||
)
|
|
||||||
trade.is_open = True
|
trade.is_open = True
|
||||||
freqtrade.handle_stoploss_on_exchange(trade)
|
freqtrade.handle_stoploss_on_exchange(trade)
|
||||||
assert log_has('Unable to place a stoploss order on exchange.', caplog)
|
assert log_has('Unable to place a stoploss order on exchange.', caplog)
|
||||||
@ -1203,9 +1198,8 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
# It should try to add stoploss order
|
# It should try to add stoploss order
|
||||||
trade.stoploss_order_id = 100
|
trade.stoploss_order_id = 100
|
||||||
stoploss.reset_mock()
|
stoploss.reset_mock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order',
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', side_effect=InvalidOrderException())
|
||||||
side_effect=InvalidOrderException())
|
mocker.patch(f'{EXMS}.create_stoploss', stoploss)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_stoploss', stoploss)
|
|
||||||
freqtrade.handle_stoploss_on_exchange(trade)
|
freqtrade.handle_stoploss_on_exchange(trade)
|
||||||
assert stoploss.call_count == 1
|
assert stoploss.call_count == 1
|
||||||
|
|
||||||
@ -1214,8 +1208,8 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
trade.stoploss_order_id = None
|
trade.stoploss_order_id = None
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
stoploss.reset_mock()
|
stoploss.reset_mock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order')
|
mocker.patch(f'{EXMS}.fetch_order')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_stoploss', stoploss)
|
mocker.patch(f'{EXMS}.create_stoploss', stoploss)
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
||||||
assert stoploss.call_count == 0
|
assert stoploss.call_count == 0
|
||||||
|
|
||||||
@ -1237,10 +1231,10 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_
|
|||||||
freqtrade.config['trailing_stop'] = True
|
freqtrade.config['trailing_stop'] = True
|
||||||
stoploss = MagicMock(side_effect=InvalidOrderException())
|
stoploss = MagicMock(side_effect=InvalidOrderException())
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order_with_result',
|
mocker.patch(f'{EXMS}.cancel_stoploss_order_with_result',
|
||||||
side_effect=InvalidOrderException())
|
side_effect=InvalidOrderException())
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', stoploss_order_cancelled)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', stoploss_order_cancelled)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_stoploss', stoploss)
|
mocker.patch(f'{EXMS}.create_stoploss', stoploss)
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
||||||
assert trade.stoploss_order_id is None
|
assert trade.stoploss_order_id is None
|
||||||
assert trade.is_open is False
|
assert trade.is_open is False
|
||||||
@ -1269,7 +1263,7 @@ def test_handle_sle_cancel_cant_recreate(mocker, default_conf_usdt, fee, caplog,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
fetch_stoploss_order=MagicMock(return_value={'status': 'canceled', 'id': 100}),
|
fetch_stoploss_order=MagicMock(return_value={'status': 'canceled', 'id': 100}),
|
||||||
create_stoploss=MagicMock(side_effect=ExchangeError()),
|
create_stoploss=MagicMock(side_effect=ExchangeError()),
|
||||||
)
|
)
|
||||||
@ -1313,7 +1307,7 @@ def test_create_stoploss_order_invalid_order(
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
fetch_order=MagicMock(return_value={'status': 'canceled'}),
|
fetch_order=MagicMock(return_value={'status': 'canceled'}),
|
||||||
create_stoploss=MagicMock(side_effect=InvalidOrderException()),
|
create_stoploss=MagicMock(side_effect=InvalidOrderException()),
|
||||||
)
|
)
|
||||||
@ -1366,7 +1360,7 @@ def test_create_stoploss_order_insufficient_funds(
|
|||||||
fetch_order=MagicMock(return_value={'status': 'canceled'}),
|
fetch_order=MagicMock(return_value={'status': 'canceled'}),
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
create_stoploss=MagicMock(side_effect=InsufficientFundsError()),
|
create_stoploss=MagicMock(side_effect=InsufficientFundsError()),
|
||||||
)
|
)
|
||||||
patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short)
|
patch_get_signal(freqtrade, enter_short=is_short, enter_long=not is_short)
|
||||||
@ -1416,7 +1410,7 @@ def test_handle_stoploss_on_exchange_trailing(
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
create_stoploss=stoploss,
|
create_stoploss=stoploss,
|
||||||
stoploss_adjust=MagicMock(return_value=True),
|
stoploss_adjust=MagicMock(return_value=True),
|
||||||
)
|
)
|
||||||
@ -1459,7 +1453,7 @@ def test_handle_stoploss_on_exchange_trailing(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Binance.fetch_stoploss_order', stoploss_order_hanging)
|
mocker.patch('freqtrade.exchange.binance.Binance.fetch_stoploss_order', stoploss_order_hanging)
|
||||||
|
|
||||||
# stoploss initially at 5%
|
# stoploss initially at 5%
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
@ -1467,7 +1461,7 @@ def test_handle_stoploss_on_exchange_trailing(
|
|||||||
|
|
||||||
# price jumped 2x
|
# price jumped 2x
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': bid[0],
|
'bid': bid[0],
|
||||||
'ask': ask[0],
|
'ask': ask[0],
|
||||||
@ -1477,8 +1471,8 @@ def test_handle_stoploss_on_exchange_trailing(
|
|||||||
|
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
stoploss_order_mock = MagicMock(return_value={'id': 'so1'})
|
stoploss_order_mock = MagicMock(return_value={'id': 'so1'})
|
||||||
mocker.patch('freqtrade.exchange.Binance.cancel_stoploss_order', cancel_order_mock)
|
mocker.patch('freqtrade.exchange.binance.Binance.cancel_stoploss_order', cancel_order_mock)
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss_order_mock)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss_order_mock)
|
||||||
|
|
||||||
# stoploss should not be updated as the interval is 60 seconds
|
# stoploss should not be updated as the interval is 60 seconds
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
@ -1506,7 +1500,7 @@ def test_handle_stoploss_on_exchange_trailing(
|
|||||||
|
|
||||||
# price fell below stoploss, so dry-run sells trade.
|
# price fell below stoploss, so dry-run sells trade.
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': bid[1],
|
'bid': bid[1],
|
||||||
'ask': ask[1],
|
'ask': ask[1],
|
||||||
@ -1541,7 +1535,7 @@ def test_handle_stoploss_on_exchange_trailing_error(
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
create_stoploss=stoploss,
|
create_stoploss=stoploss,
|
||||||
stoploss_adjust=MagicMock(return_value=True),
|
stoploss_adjust=MagicMock(return_value=True),
|
||||||
)
|
)
|
||||||
@ -1579,9 +1573,9 @@ def test_handle_stoploss_on_exchange_trailing_error(
|
|||||||
'stopPrice': '0.1'
|
'stopPrice': '0.1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Binance.cancel_stoploss_order',
|
mocker.patch('freqtrade.exchange.binance.Binance.cancel_stoploss_order',
|
||||||
side_effect=InvalidOrderException())
|
side_effect=InvalidOrderException())
|
||||||
mocker.patch('freqtrade.exchange.Binance.fetch_stoploss_order',
|
mocker.patch('freqtrade.exchange.binance.Binance.fetch_stoploss_order',
|
||||||
return_value=stoploss_order_hanging)
|
return_value=stoploss_order_hanging)
|
||||||
freqtrade.handle_trailing_stoploss_on_exchange(trade, stoploss_order_hanging)
|
freqtrade.handle_trailing_stoploss_on_exchange(trade, stoploss_order_hanging)
|
||||||
assert log_has_re(r"Could not cancel stoploss order abcd for pair ETH/USDT.*", caplog)
|
assert log_has_re(r"Could not cancel stoploss order abcd for pair ETH/USDT.*", caplog)
|
||||||
@ -1610,7 +1604,7 @@ def test_stoploss_on_exchange_price_rounding(
|
|||||||
stoploss_mock = MagicMock(return_value={'id': '13434334'})
|
stoploss_mock = MagicMock(return_value={'id': '13434334'})
|
||||||
adjust_mock = MagicMock(return_value=False)
|
adjust_mock = MagicMock(return_value=False)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
create_stoploss=stoploss_mock,
|
create_stoploss=stoploss_mock,
|
||||||
stoploss_adjust=adjust_mock,
|
stoploss_adjust=adjust_mock,
|
||||||
price_to_precision=price_mock,
|
price_to_precision=price_mock,
|
||||||
@ -1649,7 +1643,7 @@ def test_handle_stoploss_on_exchange_custom_stop(
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Binance',
|
'freqtrade.exchange.binance.Binance',
|
||||||
create_stoploss=stoploss,
|
create_stoploss=stoploss,
|
||||||
stoploss_adjust=MagicMock(return_value=True),
|
stoploss_adjust=MagicMock(return_value=True),
|
||||||
)
|
)
|
||||||
@ -1692,14 +1686,14 @@ def test_handle_stoploss_on_exchange_custom_stop(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Binance.fetch_stoploss_order', stoploss_order_hanging)
|
mocker.patch('freqtrade.exchange.binance.Binance.fetch_stoploss_order', stoploss_order_hanging)
|
||||||
|
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
assert freqtrade.handle_stoploss_on_exchange(trade) is False
|
||||||
|
|
||||||
# price jumped 2x
|
# price jumped 2x
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': 4.38 if not is_short else 1.9 / 2,
|
'bid': 4.38 if not is_short else 1.9 / 2,
|
||||||
'ask': 4.4 if not is_short else 2.2 / 2,
|
'ask': 4.4 if not is_short else 2.2 / 2,
|
||||||
@ -1709,8 +1703,8 @@ def test_handle_stoploss_on_exchange_custom_stop(
|
|||||||
|
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
stoploss_order_mock = MagicMock(return_value={'id': 'so1'})
|
stoploss_order_mock = MagicMock(return_value={'id': 'so1'})
|
||||||
mocker.patch('freqtrade.exchange.Binance.cancel_stoploss_order', cancel_order_mock)
|
mocker.patch('freqtrade.exchange.binance.Binance.cancel_stoploss_order', cancel_order_mock)
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss_order_mock)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss_order_mock)
|
||||||
|
|
||||||
# stoploss should not be updated as the interval is 60 seconds
|
# stoploss should not be updated as the interval is 60 seconds
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
@ -1740,7 +1734,7 @@ def test_handle_stoploss_on_exchange_custom_stop(
|
|||||||
|
|
||||||
# price fell below stoploss, so dry-run sells trade.
|
# price fell below stoploss, so dry-run sells trade.
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': 4.17,
|
'bid': 4.17,
|
||||||
'ask': 4.19,
|
'ask': 4.19,
|
||||||
@ -1817,7 +1811,7 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, limit_orde
|
|||||||
'stopPrice': '2.178'
|
'stopPrice': '2.178'
|
||||||
})
|
})
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', stoploss_order_hanging)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', stoploss_order_hanging)
|
||||||
|
|
||||||
# stoploss initially at 20% as edge dictated it.
|
# stoploss initially at 20% as edge dictated it.
|
||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
@ -1826,11 +1820,11 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, limit_orde
|
|||||||
|
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
stoploss_order_mock = MagicMock()
|
stoploss_order_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order', cancel_order_mock)
|
mocker.patch(f'{EXMS}.cancel_stoploss_order', cancel_order_mock)
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss_order_mock)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss_order_mock)
|
||||||
|
|
||||||
# price goes down 5%
|
# price goes down 5%
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', MagicMock(return_value={
|
mocker.patch(f'{EXMS}.fetch_ticker', MagicMock(return_value={
|
||||||
'bid': 2.19 * 0.95,
|
'bid': 2.19 * 0.95,
|
||||||
'ask': 2.2 * 0.95,
|
'ask': 2.2 * 0.95,
|
||||||
'last': 2.19 * 0.95
|
'last': 2.19 * 0.95
|
||||||
@ -1845,7 +1839,7 @@ def test_tsl_on_exchange_compatible_with_edge(mocker, edge_conf, fee, limit_orde
|
|||||||
cancel_order_mock.assert_not_called()
|
cancel_order_mock.assert_not_called()
|
||||||
|
|
||||||
# price jumped 2x
|
# price jumped 2x
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', MagicMock(return_value={
|
mocker.patch(f'{EXMS}.fetch_ticker', MagicMock(return_value={
|
||||||
'bid': 4.38,
|
'bid': 4.38,
|
||||||
'ask': 4.4,
|
'ask': 4.4,
|
||||||
'last': 4.38
|
'last': 4.38
|
||||||
@ -1895,9 +1889,8 @@ def test_exit_positions(mocker, default_conf_usdt, limit_order, is_short, caplog
|
|||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
|
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order', return_value=limit_order[entry_side(is_short)])
|
||||||
return_value=limit_order[entry_side(is_short)])
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
|
||||||
|
|
||||||
# TODO: should not be magicmock
|
# TODO: should not be magicmock
|
||||||
trade = MagicMock()
|
trade = MagicMock()
|
||||||
@ -1921,7 +1914,7 @@ def test_exit_positions(mocker, default_conf_usdt, limit_order, is_short, caplog
|
|||||||
def test_exit_positions_exception(mocker, default_conf_usdt, limit_order, caplog, is_short) -> None:
|
def test_exit_positions_exception(mocker, default_conf_usdt, limit_order, caplog, is_short) -> None:
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
order = limit_order[entry_side(is_short)]
|
order = limit_order[entry_side(is_short)]
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=order)
|
||||||
|
|
||||||
# TODO: should not be magicmock
|
# TODO: should not be magicmock
|
||||||
trade = MagicMock()
|
trade = MagicMock()
|
||||||
@ -1947,8 +1940,8 @@ def test_update_trade_state(mocker, default_conf_usdt, limit_order, is_short, ca
|
|||||||
order = limit_order[entry_side(is_short)]
|
order = limit_order[entry_side(is_short)]
|
||||||
|
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_trade', MagicMock(return_value=True))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=order)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', return_value=0.0)
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', return_value=0.0)
|
||||||
order_id = order['id']
|
order_id = order['id']
|
||||||
|
|
||||||
@ -1999,7 +1992,7 @@ def test_update_trade_state(mocker, default_conf_usdt, limit_order, is_short, ca
|
|||||||
limit_buy_order_usdt_new['status'] = 'canceled'
|
limit_buy_order_usdt_new['status'] = 'canceled'
|
||||||
|
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', side_effect=ValueError)
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.get_real_amount', side_effect=ValueError)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=limit_buy_order_usdt_new)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=limit_buy_order_usdt_new)
|
||||||
res = freqtrade.update_trade_state(trade, order_id)
|
res = freqtrade.update_trade_state(trade, order_id)
|
||||||
# Cancelled empty
|
# Cancelled empty
|
||||||
assert res is True
|
assert res is True
|
||||||
@ -2018,9 +2011,9 @@ def test_update_trade_state_withorderdict(
|
|||||||
trades_for_order[0]['amount'] = initial_amount
|
trades_for_order[0]['amount'] = initial_amount
|
||||||
order_id = "oid_123456"
|
order_id = "oid_123456"
|
||||||
order['id'] = order_id
|
order['id'] = order_id
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
# fetch_order should not be called!!
|
# fetch_order should not be called!!
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', MagicMock(side_effect=ValueError))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(side_effect=ValueError))
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
amount = sum(x['amount'] for x in trades_for_order)
|
amount = sum(x['amount'] for x in trades_for_order)
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
@ -2062,7 +2055,7 @@ def test_update_trade_state_exception(mocker, default_conf_usdt, is_short, limit
|
|||||||
caplog) -> None:
|
caplog) -> None:
|
||||||
order = limit_order[entry_side(is_short)]
|
order = limit_order[entry_side(is_short)]
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=order)
|
||||||
|
|
||||||
# TODO: should not be magicmock
|
# TODO: should not be magicmock
|
||||||
trade = MagicMock()
|
trade = MagicMock()
|
||||||
@ -2080,8 +2073,7 @@ def test_update_trade_state_exception(mocker, default_conf_usdt, is_short, limit
|
|||||||
|
|
||||||
def test_update_trade_state_orderexception(mocker, default_conf_usdt, caplog) -> None:
|
def test_update_trade_state_orderexception(mocker, default_conf_usdt, caplog) -> None:
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(side_effect=InvalidOrderException))
|
||||||
MagicMock(side_effect=InvalidOrderException))
|
|
||||||
|
|
||||||
# TODO: should not be magicmock
|
# TODO: should not be magicmock
|
||||||
trade = MagicMock()
|
trade = MagicMock()
|
||||||
@ -2101,9 +2093,9 @@ def test_update_trade_state_sell(
|
|||||||
buy_order = limit_order[entry_side(is_short)]
|
buy_order = limit_order[entry_side(is_short)]
|
||||||
open_order = limit_order_open[exit_side(is_short)]
|
open_order = limit_order_open[exit_side(is_short)]
|
||||||
l_order = limit_order[exit_side(is_short)]
|
l_order = limit_order[exit_side(is_short)]
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
# fetch_order should not be called!!
|
# fetch_order should not be called!!
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', MagicMock(side_effect=ValueError))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(side_effect=ValueError))
|
||||||
wallet_mock = MagicMock()
|
wallet_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.wallets.Wallets.update', wallet_mock)
|
mocker.patch('freqtrade.wallets.Wallets.update', wallet_mock)
|
||||||
|
|
||||||
@ -2685,7 +2677,7 @@ def test_manage_open_orders_exit_usercustom(
|
|||||||
rpc_mock = patch_RPCManager(mocker)
|
rpc_mock = patch_RPCManager(mocker)
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_min_pair_stake_amount', return_value=0.0)
|
mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=0.0)
|
||||||
et_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit')
|
et_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit')
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -3013,7 +3005,7 @@ def test_handle_cancel_enter(mocker, caplog, default_conf_usdt, limit_order, is_
|
|||||||
del cancel_buy_order['filled']
|
del cancel_buy_order['filled']
|
||||||
|
|
||||||
cancel_order_mock = MagicMock(return_value=cancel_buy_order)
|
cancel_order_mock = MagicMock(return_value=cancel_buy_order)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_order_with_result', cancel_order_mock)
|
mocker.patch(f'{EXMS}.cancel_order_with_result', cancel_order_mock)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
freqtrade._notify_enter_cancel = MagicMock()
|
freqtrade._notify_enter_cancel = MagicMock()
|
||||||
@ -3044,11 +3036,11 @@ def test_handle_cancel_enter(mocker, caplog, default_conf_usdt, limit_order, is_
|
|||||||
# Order remained open for some reason (cancel failed)
|
# Order remained open for some reason (cancel failed)
|
||||||
cancel_buy_order['status'] = 'open'
|
cancel_buy_order['status'] = 'open'
|
||||||
cancel_order_mock = MagicMock(return_value=cancel_buy_order)
|
cancel_order_mock = MagicMock(return_value=cancel_buy_order)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_order_with_result', cancel_order_mock)
|
mocker.patch(f'{EXMS}.cancel_order_with_result', cancel_order_mock)
|
||||||
assert not freqtrade.handle_cancel_enter(trade, l_order, reason)
|
assert not freqtrade.handle_cancel_enter(trade, l_order, reason)
|
||||||
assert log_has_re(r"Order .* for .* not cancelled.", caplog)
|
assert log_has_re(r"Order .* for .* not cancelled.", caplog)
|
||||||
# min_pair_stake empty should not crash
|
# min_pair_stake empty should not crash
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_min_pair_stake_amount', return_value=None)
|
mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=None)
|
||||||
assert not freqtrade.handle_cancel_enter(trade, limit_order[entry_side(is_short)], reason)
|
assert not freqtrade.handle_cancel_enter(trade, limit_order[entry_side(is_short)], reason)
|
||||||
|
|
||||||
|
|
||||||
@ -3060,9 +3052,9 @@ def test_handle_cancel_enter_exchanges(mocker, caplog, default_conf_usdt, is_sho
|
|||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
cancel_order_mock = mocker.patch(
|
cancel_order_mock = mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.cancel_order_with_result',
|
f'{EXMS}.cancel_order_with_result',
|
||||||
return_value=limit_buy_order_canceled_empty)
|
return_value=limit_buy_order_canceled_empty)
|
||||||
nofiy_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot._notify_enter_cancel')
|
notify_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot._notify_enter_cancel')
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
|
|
||||||
reason = CANCEL_REASON['TIMEOUT']
|
reason = CANCEL_REASON['TIMEOUT']
|
||||||
@ -3077,7 +3069,7 @@ def test_handle_cancel_enter_exchanges(mocker, caplog, default_conf_usdt, is_sho
|
|||||||
r'Removing .* from database\.',
|
r'Removing .* from database\.',
|
||||||
caplog
|
caplog
|
||||||
)
|
)
|
||||||
assert nofiy_mock.call_count == 1
|
assert notify_mock.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("is_short", [False, True])
|
@pytest.mark.parametrize("is_short", [False, True])
|
||||||
@ -3114,7 +3106,7 @@ def test_handle_cancel_enter_corder_empty(mocker, default_conf_usdt, limit_order
|
|||||||
l_order['filled'] = 1.0
|
l_order['filled'] = 1.0
|
||||||
order = deepcopy(l_order)
|
order = deepcopy(l_order)
|
||||||
order['status'] = 'canceled'
|
order['status'] = 'canceled'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=order)
|
||||||
assert not freqtrade.handle_cancel_enter(trade, l_order, reason)
|
assert not freqtrade.handle_cancel_enter(trade, l_order, reason)
|
||||||
assert cancel_order_mock.call_count == 1
|
assert cancel_order_mock.call_count == 1
|
||||||
|
|
||||||
@ -3127,8 +3119,8 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
cancel_order=cancel_order_mock,
|
cancel_order=cancel_order_mock,
|
||||||
)
|
)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate', return_value=0.245441)
|
mocker.patch(f'{EXMS}.get_rate', return_value=0.245441)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_min_pair_stake_amount', return_value=0.2)
|
mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=0.2)
|
||||||
|
|
||||||
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_order_fee')
|
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_order_fee')
|
||||||
|
|
||||||
@ -3230,9 +3222,8 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None:
|
|||||||
def test_handle_cancel_exit_cancel_exception(mocker, default_conf_usdt) -> None:
|
def test_handle_cancel_exit_cancel_exception(mocker, default_conf_usdt) -> None:
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_min_pair_stake_amount', return_value=0.0)
|
mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=0.0)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_order_with_result',
|
mocker.patch(f'{EXMS}.cancel_order_with_result', side_effect=InvalidOrderException())
|
||||||
side_effect=InvalidOrderException())
|
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
|
|
||||||
@ -3555,8 +3546,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run(
|
|||||||
def test_execute_trade_exit_sloe_cancel_exception(
|
def test_execute_trade_exit_sloe_cancel_exception(
|
||||||
mocker, default_conf_usdt, ticker_usdt, fee, caplog) -> None:
|
mocker, default_conf_usdt, ticker_usdt, fee, caplog) -> None:
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order',
|
mocker.patch(f'{EXMS}.cancel_stoploss_order', side_effect=InvalidOrderException())
|
||||||
side_effect=InvalidOrderException())
|
|
||||||
mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock(return_value=300))
|
mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock(return_value=300))
|
||||||
create_order_mock = MagicMock(side_effect=[
|
create_order_mock = MagicMock(side_effect=[
|
||||||
{'id': '12345554'},
|
{'id': '12345554'},
|
||||||
@ -3668,7 +3658,7 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss)
|
||||||
|
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
||||||
@ -3707,7 +3697,7 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(
|
|||||||
"fee": None,
|
"fee": None,
|
||||||
"trades": None
|
"trades": None
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_stoploss_order', stoploss_executed)
|
mocker.patch(f'{EXMS}.fetch_stoploss_order', stoploss_executed)
|
||||||
|
|
||||||
freqtrade.exit_positions(trades)
|
freqtrade.exit_positions(trades)
|
||||||
assert trade.stoploss_order_id is None
|
assert trade.stoploss_order_id is None
|
||||||
@ -4127,7 +4117,7 @@ def test_trailing_stop_loss(default_conf_usdt, limit_order_open,
|
|||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
|
|
||||||
# Raise praise into profits
|
# Raise praise into profits
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': 2.0 * val1,
|
'bid': 2.0 * val1,
|
||||||
'ask': 2.0 * val1,
|
'ask': 2.0 * val1,
|
||||||
@ -4138,7 +4128,7 @@ def test_trailing_stop_loss(default_conf_usdt, limit_order_open,
|
|||||||
assert freqtrade.handle_trade(trade) is False
|
assert freqtrade.handle_trade(trade) is False
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
# Price fell
|
# Price fell
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': 2.0 * val2,
|
'bid': 2.0 * val2,
|
||||||
'ask': 2.0 * val2,
|
'ask': 2.0 * val2,
|
||||||
@ -4208,7 +4198,7 @@ def test_trailing_stop_loss_positive(
|
|||||||
|
|
||||||
# Raise ticker_usdt above buy price
|
# Raise ticker_usdt above buy price
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + (-0.06 if is_short else 0.06),
|
'bid': enter_price + (-0.06 if is_short else 0.06),
|
||||||
'ask': enter_price + (-0.06 if is_short else 0.06),
|
'ask': enter_price + (-0.06 if is_short else 0.06),
|
||||||
@ -4230,7 +4220,7 @@ def test_trailing_stop_loss_positive(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + (-0.135 if is_short else 0.125),
|
'bid': enter_price + (-0.135 if is_short else 0.125),
|
||||||
'ask': enter_price + (-0.135 if is_short else 0.125),
|
'ask': enter_price + (-0.135 if is_short else 0.125),
|
||||||
@ -4246,7 +4236,7 @@ def test_trailing_stop_loss_positive(
|
|||||||
assert log_has("ETH/USDT - Adjusting stoploss...", caplog)
|
assert log_has("ETH/USDT - Adjusting stoploss...", caplog)
|
||||||
|
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_ticker',
|
f'{EXMS}.fetch_ticker',
|
||||||
MagicMock(return_value={
|
MagicMock(return_value={
|
||||||
'bid': enter_price + (-0.02 if is_short else 0.02),
|
'bid': enter_price + (-0.02 if is_short else 0.02),
|
||||||
'ask': enter_price + (-0.02 if is_short else 0.02),
|
'ask': enter_price + (-0.02 if is_short else 0.02),
|
||||||
@ -4312,7 +4302,7 @@ def test_disable_ignore_roi_if_entry_signal(default_conf_usdt, limit_order, limi
|
|||||||
|
|
||||||
def test_get_real_amount_quote(default_conf_usdt, trades_for_order, buy_order_fee, fee, caplog,
|
def test_get_real_amount_quote(default_conf_usdt, trades_for_order, buy_order_fee, fee, caplog,
|
||||||
mocker):
|
mocker):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
amount = sum(x['amount'] for x in trades_for_order)
|
amount = sum(x['amount'] for x in trades_for_order)
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/ETH',
|
pair='LTC/ETH',
|
||||||
@ -4338,7 +4328,7 @@ def test_get_real_amount_quote(default_conf_usdt, trades_for_order, buy_order_fe
|
|||||||
|
|
||||||
def test_get_real_amount_quote_dust(default_conf_usdt, trades_for_order, buy_order_fee, fee,
|
def test_get_real_amount_quote_dust(default_conf_usdt, trades_for_order, buy_order_fee, fee,
|
||||||
caplog, mocker):
|
caplog, mocker):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
walletmock = mocker.patch('freqtrade.wallets.Wallets.update')
|
walletmock = mocker.patch('freqtrade.wallets.Wallets.update')
|
||||||
mocker.patch('freqtrade.wallets.Wallets.get_free', return_value=8.1122)
|
mocker.patch('freqtrade.wallets.Wallets.get_free', return_value=8.1122)
|
||||||
amount = sum(x['amount'] for x in trades_for_order)
|
amount = sum(x['amount'] for x in trades_for_order)
|
||||||
@ -4363,7 +4353,7 @@ def test_get_real_amount_quote_dust(default_conf_usdt, trades_for_order, buy_ord
|
|||||||
|
|
||||||
|
|
||||||
def test_get_real_amount_no_trade(default_conf_usdt, buy_order_fee, caplog, mocker, fee):
|
def test_get_real_amount_no_trade(default_conf_usdt, buy_order_fee, caplog, mocker, fee):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
|
|
||||||
amount = buy_order_fee['amount']
|
amount = buy_order_fee['amount']
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
@ -4417,7 +4407,7 @@ def test_get_real_amount(
|
|||||||
buy_order['fee'] = fee_par
|
buy_order['fee'] = fee_par
|
||||||
trades_for_order[0]['fee'] = fee_par
|
trades_for_order[0]['fee'] = fee_par
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
amount = sum(x['amount'] for x in trades_for_order)
|
amount = sum(x['amount'] for x in trades_for_order)
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/ETH',
|
pair='LTC/ETH',
|
||||||
@ -4431,7 +4421,7 @@ def test_get_real_amount(
|
|||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
|
|
||||||
if not use_ticker_usdt_rate:
|
if not use_ticker_usdt_rate:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', side_effect=ExchangeError)
|
mocker.patch(f'{EXMS}.fetch_ticker', side_effect=ExchangeError)
|
||||||
|
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
order_obj = Order.parse_from_ccxt_object(buy_order_fee, 'LTC/ETH', 'buy')
|
order_obj = Order.parse_from_ccxt_object(buy_order_fee, 'LTC/ETH', 'buy')
|
||||||
@ -4463,7 +4453,7 @@ def test_get_real_amount_multi(
|
|||||||
if fee_currency:
|
if fee_currency:
|
||||||
trades_for_order[0]['fee']['currency'] = fee_currency
|
trades_for_order[0]['fee']['currency'] = fee_currency
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
amount = float(sum(x['amount'] for x in trades_for_order))
|
amount = float(sum(x['amount'] for x in trades_for_order))
|
||||||
default_conf_usdt['stake_currency'] = "ETH"
|
default_conf_usdt['stake_currency'] = "ETH"
|
||||||
|
|
||||||
@ -4480,8 +4470,8 @@ def test_get_real_amount_multi(
|
|||||||
# Fake markets entry to enable fee parsing
|
# Fake markets entry to enable fee parsing
|
||||||
markets['BNB/ETH'] = markets['ETH/USDT']
|
markets['BNB/ETH'] = markets['ETH/USDT']
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker',
|
mocker.patch(f'{EXMS}.fetch_ticker',
|
||||||
return_value={'ask': 0.19, 'last': 0.2})
|
return_value={'ask': 0.19, 'last': 0.2})
|
||||||
|
|
||||||
# Amount is reduced by "fee"
|
# Amount is reduced by "fee"
|
||||||
@ -4510,7 +4500,7 @@ def test_get_real_amount_invalid_order(default_conf_usdt, trades_for_order, buy_
|
|||||||
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
||||||
limit_buy_order_usdt['fee'] = {'cost': 0.004}
|
limit_buy_order_usdt['fee'] = {'cost': 0.004}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
amount = float(sum(x['amount'] for x in trades_for_order))
|
amount = float(sum(x['amount'] for x in trades_for_order))
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/ETH',
|
pair='LTC/ETH',
|
||||||
@ -4531,9 +4521,9 @@ def test_get_real_amount_invalid_order(default_conf_usdt, trades_for_order, buy_
|
|||||||
def test_get_real_amount_fees_order(default_conf_usdt, market_buy_order_usdt_doublefee,
|
def test_get_real_amount_fees_order(default_conf_usdt, market_buy_order_usdt_doublefee,
|
||||||
fee, mocker):
|
fee, mocker):
|
||||||
|
|
||||||
tfo_mock = mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=[])
|
tfo_mock = mocker.patch(f'{EXMS}.get_trades_for_order', return_value=[])
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination', return_value='BNB/USDT')
|
mocker.patch(f'{EXMS}.get_valid_pair_combination', return_value='BNB/USDT')
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value={'last': 200})
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value={'last': 200})
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/USDT',
|
pair='LTC/USDT',
|
||||||
amount=30.0,
|
amount=30.0,
|
||||||
@ -4559,7 +4549,7 @@ def test_get_real_amount_wrong_amount(default_conf_usdt, trades_for_order, buy_o
|
|||||||
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
||||||
limit_buy_order_usdt['amount'] = limit_buy_order_usdt['amount'] - 0.001
|
limit_buy_order_usdt['amount'] = limit_buy_order_usdt['amount'] - 0.001
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
amount = float(sum(x['amount'] for x in trades_for_order))
|
amount = float(sum(x['amount'] for x in trades_for_order))
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/ETH',
|
pair='LTC/ETH',
|
||||||
@ -4584,7 +4574,7 @@ def test_get_real_amount_wrong_amount_rounding(default_conf_usdt, trades_for_ord
|
|||||||
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
limit_buy_order_usdt = deepcopy(buy_order_fee)
|
||||||
trades_for_order[0]['amount'] = trades_for_order[0]['amount'] + 1e-15
|
trades_for_order[0]['amount'] = trades_for_order[0]['amount'] + 1e-15
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades_for_order)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades_for_order)
|
||||||
amount = float(sum(x['amount'] for x in trades_for_order))
|
amount = float(sum(x['amount'] for x in trades_for_order))
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='LTC/ETH',
|
pair='LTC/ETH',
|
||||||
@ -4664,7 +4654,7 @@ def test_get_real_amount_in_point(default_conf_usdt, buy_order_fee, fee, mocker,
|
|||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_trades_for_order', return_value=trades)
|
mocker.patch(f'{EXMS}.get_trades_for_order', return_value=trades)
|
||||||
amount = float(sum(x['amount'] for x in trades))
|
amount = float(sum(x['amount'] for x in trades))
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair='CEL/USDT',
|
pair='CEL/USDT',
|
||||||
@ -4746,7 +4736,7 @@ def test_order_book_depth_of_market(
|
|||||||
default_conf_usdt['entry_pricing']['check_depth_of_market']['bids_to_ask_delta'] = delta
|
default_conf_usdt['entry_pricing']['check_depth_of_market']['bids_to_ask_delta'] = delta
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book', order_book_l2)
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', order_book_l2)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
fetch_ticker=ticker_usdt,
|
fetch_ticker=ticker_usdt,
|
||||||
@ -4843,7 +4833,7 @@ def test_order_book_exit_pricing(
|
|||||||
"""
|
"""
|
||||||
test order book ask strategy
|
test order book ask strategy
|
||||||
"""
|
"""
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book', order_book_l2)
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', order_book_l2)
|
||||||
default_conf_usdt['exchange']['name'] = 'binance'
|
default_conf_usdt['exchange']['name'] = 'binance'
|
||||||
default_conf_usdt['exit_pricing']['use_order_book'] = True
|
default_conf_usdt['exit_pricing']['use_order_book'] = True
|
||||||
default_conf_usdt['exit_pricing']['order_book_top'] = 1
|
default_conf_usdt['exit_pricing']['order_book_top'] = 1
|
||||||
@ -4884,8 +4874,7 @@ def test_order_book_exit_pricing(
|
|||||||
assert freqtrade.handle_trade(trade) is True
|
assert freqtrade.handle_trade(trade) is True
|
||||||
assert trade.close_rate_requested == order_book_l2.return_value['asks'][0][0]
|
assert trade.close_rate_requested == order_book_l2.return_value['asks'][0][0]
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_l2_order_book',
|
mocker.patch(f'{EXMS}.fetch_l2_order_book', return_value={'bids': [[]], 'asks': [[]]})
|
||||||
return_value={'bids': [[]], 'asks': [[]]})
|
|
||||||
with pytest.raises(PricingError):
|
with pytest.raises(PricingError):
|
||||||
freqtrade.handle_trade(trade)
|
freqtrade.handle_trade(trade)
|
||||||
assert log_has_re(
|
assert log_has_re(
|
||||||
@ -4897,14 +4886,14 @@ def test_startup_state(default_conf_usdt, mocker):
|
|||||||
default_conf_usdt['pairlist'] = {'method': 'VolumePairList',
|
default_conf_usdt['pairlist'] = {'method': 'VolumePairList',
|
||||||
'config': {'number_assets': 20}
|
'config': {'number_assets': 20}
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
worker = get_patched_worker(mocker, default_conf_usdt)
|
worker = get_patched_worker(mocker, default_conf_usdt)
|
||||||
assert worker.freqtrade.state is State.RUNNING
|
assert worker.freqtrade.state is State.RUNNING
|
||||||
|
|
||||||
|
|
||||||
def test_startup_trade_reinit(default_conf_usdt, edge_conf, mocker):
|
def test_startup_trade_reinit(default_conf_usdt, edge_conf, mocker):
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
reinit_mock = MagicMock()
|
reinit_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.persistence.Trade.stoploss_reinitialization', reinit_mock)
|
mocker.patch('freqtrade.persistence.Trade.stoploss_reinitialization', reinit_mock)
|
||||||
|
|
||||||
@ -4961,7 +4950,7 @@ def test_cancel_all_open_orders(mocker, default_conf_usdt, fee, limit_order, lim
|
|||||||
is_short, buy_calls, sell_calls):
|
is_short, buy_calls, sell_calls):
|
||||||
default_conf_usdt['cancel_open_orders_on_exit'] = True
|
default_conf_usdt['cancel_open_orders_on_exit'] = True
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.exchange.Exchange.fetch_order',
|
f'{EXMS}.fetch_order',
|
||||||
side_effect=[
|
side_effect=[
|
||||||
ExchangeError(),
|
ExchangeError(),
|
||||||
limit_order[exit_side(is_short)],
|
limit_order[exit_side(is_short)],
|
||||||
@ -5017,17 +5006,17 @@ def test_startup_update_open_orders(mocker, default_conf_usdt, fee, caplog, is_s
|
|||||||
matching_buy_order.update({
|
matching_buy_order.update({
|
||||||
'status': 'closed',
|
'status': 'closed',
|
||||||
})
|
})
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=matching_buy_order)
|
mocker.patch(f'{EXMS}.fetch_order', return_value=matching_buy_order)
|
||||||
freqtrade.startup_update_open_orders()
|
freqtrade.startup_update_open_orders()
|
||||||
# Only stoploss and sell orders are kept open
|
# Only stoploss and sell orders are kept open
|
||||||
assert len(Order.get_open_orders()) == 2
|
assert len(Order.get_open_orders()) == 2
|
||||||
|
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', side_effect=ExchangeError)
|
mocker.patch(f'{EXMS}.fetch_order', side_effect=ExchangeError)
|
||||||
freqtrade.startup_update_open_orders()
|
freqtrade.startup_update_open_orders()
|
||||||
assert log_has_re(r"Error updating Order .*", caplog)
|
assert log_has_re(r"Error updating Order .*", caplog)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', side_effect=InvalidOrderException)
|
mocker.patch(f'{EXMS}.fetch_order', side_effect=InvalidOrderException)
|
||||||
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_order')
|
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_order')
|
||||||
# Orders which are no longer found after X days should be assumed as canceled.
|
# Orders which are no longer found after X days should be assumed as canceled.
|
||||||
freqtrade.startup_update_open_orders()
|
freqtrade.startup_update_open_orders()
|
||||||
@ -5072,7 +5061,7 @@ def test_update_trades_without_assigned_fees(mocker, default_conf_usdt, fee, is_
|
|||||||
'currency': order['symbol'].split('/')[0]}})
|
'currency': order['symbol'].split('/')[0]}})
|
||||||
return order
|
return order
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
side_effect=[
|
side_effect=[
|
||||||
patch_with_fee(mock_order_2_sell(is_short=is_short)),
|
patch_with_fee(mock_order_2_sell(is_short=is_short)),
|
||||||
patch_with_fee(mock_order_3_sell(is_short=is_short)),
|
patch_with_fee(mock_order_3_sell(is_short=is_short)),
|
||||||
@ -5132,8 +5121,7 @@ def test_reupdate_enter_order_fees(mocker, default_conf_usdt, fee, caplog, is_sh
|
|||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mock_uts = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_trade_state')
|
mock_uts = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_trade_state')
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order', return_value={'status': 'open'})
|
||||||
return_value={'status': 'open'})
|
|
||||||
create_mock_trades(fee, is_short)
|
create_mock_trades(fee, is_short)
|
||||||
trades = Trade.get_trades().all()
|
trades = Trade.get_trades().all()
|
||||||
|
|
||||||
@ -5173,7 +5161,7 @@ def test_handle_insufficient_funds(mocker, default_conf_usdt, fee, is_short, cap
|
|||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
mock_uts = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_trade_state')
|
mock_uts = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.update_trade_state')
|
||||||
|
|
||||||
mock_fo = mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
mock_fo = mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
return_value={'status': 'open'})
|
return_value={'status': 'open'})
|
||||||
|
|
||||||
def reset_open_orders(trade):
|
def reset_open_orders(trade):
|
||||||
@ -5259,7 +5247,7 @@ def test_handle_insufficient_funds(mocker, default_conf_usdt, fee, is_short, cap
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
# Test error case
|
# Test error case
|
||||||
mock_fo = mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
mock_fo = mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
side_effect=ExchangeError())
|
side_effect=ExchangeError())
|
||||||
order = mock_order_5_stoploss(is_short=is_short)
|
order = mock_order_5_stoploss(is_short=is_short)
|
||||||
|
|
||||||
@ -5439,8 +5427,7 @@ def test_update_funding_fees(
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv',
|
mocker.patch(f'{EXMS}.refresh_latest_ohlcv', side_effect=refresh_latest_ohlcv_mock)
|
||||||
side_effect=refresh_latest_ohlcv_mock)
|
|
||||||
|
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -5467,7 +5454,7 @@ def test_update_funding_fees(
|
|||||||
assert len(trades) == 3
|
assert len(trades) == 3
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
assert pytest.approx(trade.funding_fees) == 0
|
assert pytest.approx(trade.funding_fees) == 0
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order', return_value=open_exit_order)
|
mocker.patch(f'{EXMS}.create_order', return_value=open_exit_order)
|
||||||
time_machine.move_to("2021-09-01 08:00:00 +00:00")
|
time_machine.move_to("2021-09-01 08:00:00 +00:00")
|
||||||
if schedule_off:
|
if schedule_off:
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
@ -5497,7 +5484,7 @@ def test_update_funding_fees(
|
|||||||
|
|
||||||
|
|
||||||
def test_update_funding_fees_error(mocker, default_conf, caplog):
|
def test_update_funding_fees_error(mocker, default_conf, caplog):
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_funding_fees', side_effect=ExchangeError())
|
mocker.patch(f'{EXMS}.get_funding_fees', side_effect=ExchangeError())
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
@ -5551,9 +5538,8 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '650',
|
'id': '650',
|
||||||
'order_id': '650'
|
'order_id': '650'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_successful_buy_order))
|
||||||
MagicMock(return_value=closed_successful_buy_order))
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_successful_buy_order))
|
MagicMock(return_value=closed_successful_buy_order))
|
||||||
assert freqtrade.execute_entry(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
# Should create an closed trade with an no open order id
|
# Should create an closed trade with an no open order id
|
||||||
@ -5603,10 +5589,8 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '651',
|
'id': '651',
|
||||||
'order_id': '651'
|
'order_id': '651'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=open_dca_order_1))
|
||||||
MagicMock(return_value=open_dca_order_1))
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order', MagicMock(return_value=open_dca_order_1))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=open_dca_order_1))
|
|
||||||
assert freqtrade.execute_entry(pair, stake_amount, trade=trade)
|
assert freqtrade.execute_entry(pair, stake_amount, trade=trade)
|
||||||
|
|
||||||
orders = Order.query.all()
|
orders = Order.query.all()
|
||||||
@ -5637,9 +5621,9 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
|
|
||||||
# Assume it does nothing since order is still open
|
# Assume it does nothing since order is still open
|
||||||
fetch_order_mm = MagicMock(side_effect=make_sure_its_651)
|
fetch_order_mm = MagicMock(side_effect=make_sure_its_651)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order', fetch_order_mm)
|
mocker.patch(f'{EXMS}.create_order', fetch_order_mm)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', fetch_order_mm)
|
mocker.patch(f'{EXMS}.fetch_order', fetch_order_mm)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order', fetch_order_mm)
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order', fetch_order_mm)
|
||||||
freqtrade.update_trades_without_assigned_fees()
|
freqtrade.update_trades_without_assigned_fees()
|
||||||
|
|
||||||
orders = Order.query.all()
|
orders = Order.query.all()
|
||||||
@ -5679,11 +5663,9 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'datetime': arrow.utcnow().isoformat(),
|
'datetime': arrow.utcnow().isoformat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_dca_order_1))
|
||||||
MagicMock(return_value=closed_dca_order_1))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(return_value=closed_dca_order_1))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
MagicMock(return_value=closed_dca_order_1))
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_dca_order_1))
|
MagicMock(return_value=closed_dca_order_1))
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
|
|
||||||
@ -5723,11 +5705,9 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '652',
|
'id': '652',
|
||||||
'order_id': '652'
|
'order_id': '652'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_dca_order_2))
|
||||||
MagicMock(return_value=closed_dca_order_2))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(return_value=closed_dca_order_2))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
MagicMock(return_value=closed_dca_order_2))
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_dca_order_2))
|
MagicMock(return_value=closed_dca_order_2))
|
||||||
assert freqtrade.execute_entry(pair, stake_amount, trade=trade)
|
assert freqtrade.execute_entry(pair, stake_amount, trade=trade)
|
||||||
|
|
||||||
@ -5761,11 +5741,9 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '653',
|
'id': '653',
|
||||||
'order_id': '653'
|
'order_id': '653'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
assert freqtrade.execute_trade_exit(trade=trade, limit=8,
|
assert freqtrade.execute_trade_exit(trade=trade, limit=8,
|
||||||
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
||||||
@ -5839,9 +5817,8 @@ def test_position_adjust2(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '600',
|
'id': '600',
|
||||||
'order_id': '600'
|
'order_id': '600'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_successful_buy_order))
|
||||||
MagicMock(return_value=closed_successful_buy_order))
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_successful_buy_order))
|
MagicMock(return_value=closed_successful_buy_order))
|
||||||
assert freqtrade.execute_entry(pair, amount)
|
assert freqtrade.execute_entry(pair, amount)
|
||||||
# Should create an closed trade with an no open order id
|
# Should create an closed trade with an no open order id
|
||||||
@ -5894,11 +5871,9 @@ def test_position_adjust2(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '601',
|
'id': '601',
|
||||||
'order_id': '601'
|
'order_id': '601'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_sell_dca_order_1))
|
MagicMock(return_value=closed_sell_dca_order_1))
|
||||||
assert freqtrade.execute_trade_exit(trade=trade, limit=ask,
|
assert freqtrade.execute_trade_exit(trade=trade, limit=ask,
|
||||||
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
||||||
@ -5940,11 +5915,9 @@ def test_position_adjust2(mocker, default_conf_usdt, fee) -> None:
|
|||||||
'id': '602',
|
'id': '602',
|
||||||
'order_id': '602'
|
'order_id': '602'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_sell_dca_order_2))
|
||||||
MagicMock(return_value=closed_sell_dca_order_2))
|
mocker.patch(f'{EXMS}.fetch_order', MagicMock(return_value=closed_sell_dca_order_2))
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
MagicMock(return_value=closed_sell_dca_order_2))
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_sell_dca_order_2))
|
MagicMock(return_value=closed_sell_dca_order_2))
|
||||||
assert freqtrade.execute_trade_exit(trade=trade, limit=ask,
|
assert freqtrade.execute_trade_exit(trade=trade, limit=ask,
|
||||||
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
exit_check=ExitCheckTuple(exit_type=ExitType.PARTIAL_EXIT),
|
||||||
@ -6034,9 +6007,8 @@ def test_position_adjust3(mocker, default_conf_usdt, fee, data) -> None:
|
|||||||
'id': f'60{idx}',
|
'id': f'60{idx}',
|
||||||
'order_id': f'60{idx}'
|
'order_id': f'60{idx}'
|
||||||
}
|
}
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch(f'{EXMS}.create_order', MagicMock(return_value=closed_successful_order))
|
||||||
MagicMock(return_value=closed_successful_order))
|
mocker.patch(f'{EXMS}.fetch_order_or_stoploss_order',
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order_or_stoploss_order',
|
|
||||||
MagicMock(return_value=closed_successful_order))
|
MagicMock(return_value=closed_successful_order))
|
||||||
if order[0] == 'buy':
|
if order[0] == 'buy':
|
||||||
assert freqtrade.execute_entry(pair, amount, trade=trade)
|
assert freqtrade.execute_entry(pair, amount, trade=trade)
|
||||||
|
@ -6,7 +6,7 @@ from freqtrade.enums import ExitCheckTuple, ExitType, TradingMode
|
|||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.persistence.models import Order
|
from freqtrade.persistence.models import Order
|
||||||
from freqtrade.rpc.rpc import RPC
|
from freqtrade.rpc.rpc import RPC
|
||||||
from tests.conftest import get_patched_freqtradebot, log_has_re, patch_get_signal
|
from tests.conftest import EXMS, get_patched_freqtradebot, log_has_re, patch_get_signal
|
||||||
|
|
||||||
|
|
||||||
def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
||||||
@ -56,7 +56,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
|
|||||||
[ExitCheckTuple(exit_type=ExitType.EXIT_SIGNAL)]]
|
[ExitCheckTuple(exit_type=ExitType.EXIT_SIGNAL)]]
|
||||||
)
|
)
|
||||||
cancel_order_mock = MagicMock()
|
cancel_order_mock = MagicMock()
|
||||||
mocker.patch('freqtrade.exchange.Binance.create_stoploss', stoploss)
|
mocker.patch('freqtrade.exchange.binance.Binance.create_stoploss', stoploss)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
fetch_ticker=ticker,
|
fetch_ticker=ticker,
|
||||||
@ -239,7 +239,7 @@ def test_dca_buying(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
|
|||||||
# Reduce bid amount
|
# Reduce bid amount
|
||||||
ticker_usdt_modif = ticker_usdt.return_value
|
ticker_usdt_modif = ticker_usdt.return_value
|
||||||
ticker_usdt_modif['bid'] = ticker_usdt_modif['bid'] * 0.995
|
ticker_usdt_modif['bid'] = ticker_usdt_modif['bid'] * 0.995
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value=ticker_usdt_modif)
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value=ticker_usdt_modif)
|
||||||
|
|
||||||
# additional buy order
|
# additional buy order
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
@ -311,7 +311,7 @@ def test_dca_short(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
|
|||||||
# Reduce bid amount
|
# Reduce bid amount
|
||||||
ticker_usdt_modif = ticker_usdt.return_value
|
ticker_usdt_modif = ticker_usdt.return_value
|
||||||
ticker_usdt_modif['ask'] = ticker_usdt_modif['ask'] * 1.004
|
ticker_usdt_modif['ask'] = ticker_usdt_modif['ask'] * 1.004
|
||||||
mocker.patch('freqtrade.exchange.Exchange.fetch_ticker', return_value=ticker_usdt_modif)
|
mocker.patch(f'{EXMS}.fetch_ticker', return_value=ticker_usdt_modif)
|
||||||
|
|
||||||
# additional buy order
|
# additional buy order
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
@ -367,10 +367,10 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker)
|
|||||||
amount_to_precision=lambda s, x, y: y,
|
amount_to_precision=lambda s, x, y: y,
|
||||||
price_to_precision=lambda s, x, y: y,
|
price_to_precision=lambda s, x, y: y,
|
||||||
)
|
)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=False)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_leverage", return_value=10)
|
mocker.patch(f"{EXMS}.get_max_leverage", return_value=10)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_funding_fees", return_value=0)
|
mocker.patch(f"{EXMS}.get_funding_fees", return_value=0)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_maintenance_ratio_and_amt", return_value=(0, 0))
|
mocker.patch(f"{EXMS}.get_maintenance_ratio_and_amt", return_value=(0, 0))
|
||||||
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.custom_entry_price = lambda **kwargs: ticker_usdt['ask'] * 0.96
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: ticker_usdt['ask'] * 0.96
|
||||||
@ -413,7 +413,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker)
|
|||||||
assert trade.initial_stop_loss_pct is None
|
assert trade.initial_stop_loss_pct is None
|
||||||
|
|
||||||
# Fill order
|
# Fill order
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=True)
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
trade = Trade.get_trades().first()
|
trade = Trade.get_trades().first()
|
||||||
assert len(trade.orders) == 2
|
assert len(trade.orders) == 2
|
||||||
@ -428,7 +428,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker)
|
|||||||
|
|
||||||
# 2nd order - not filling
|
# 2nd order - not filling
|
||||||
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=120)
|
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=120)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=False)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=False)
|
||||||
|
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
trade = Trade.get_trades().first()
|
trade = Trade.get_trades().first()
|
||||||
@ -452,7 +452,7 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker)
|
|||||||
|
|
||||||
# Fill DCA order
|
# Fill DCA order
|
||||||
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=None)
|
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=None)
|
||||||
mocker.patch('freqtrade.exchange.Exchange._dry_is_price_crossed', return_value=True)
|
mocker.patch(f'{EXMS}._dry_is_price_crossed', return_value=True)
|
||||||
freqtrade.strategy.adjust_entry_price = MagicMock(side_effect=ValueError)
|
freqtrade.strategy.adjust_entry_price = MagicMock(side_effect=ValueError)
|
||||||
|
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
@ -484,7 +484,7 @@ def test_dca_exiting(default_conf_usdt, ticker_usdt, fee, mocker, caplog, levera
|
|||||||
price_to_precision=lambda s, x, y: y,
|
price_to_precision=lambda s, x, y: y,
|
||||||
get_min_pair_stake_amount=MagicMock(return_value=10),
|
get_min_pair_stake_amount=MagicMock(return_value=10),
|
||||||
)
|
)
|
||||||
mocker.patch("freqtrade.exchange.Exchange.get_max_leverage", return_value=10)
|
mocker.patch(f"{EXMS}.get_max_leverage", return_value=10)
|
||||||
|
|
||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
freqtrade.strategy.leverage = MagicMock(return_value=leverage)
|
freqtrade.strategy.leverage = MagicMock(return_value=leverage)
|
||||||
@ -532,8 +532,7 @@ def test_dca_exiting(default_conf_usdt, ticker_usdt, fee, mocker, caplog, levera
|
|||||||
assert trade.is_open
|
assert trade.is_open
|
||||||
|
|
||||||
# use amount that would trunc to 0.0 once selling
|
# use amount that would trunc to 0.0 once selling
|
||||||
mocker.patch("freqtrade.exchange.Exchange.amount_to_contract_precision",
|
mocker.patch(f"{EXMS}.amount_to_contract_precision", lambda s, p, v: round(v, 1))
|
||||||
lambda s, p, v: round(v, 1))
|
|
||||||
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=-0.01)
|
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=-0.01)
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
trade = Trade.get_trades().first()
|
trade = Trade.get_trades().first()
|
||||||
|
@ -8,11 +8,11 @@ import time_machine
|
|||||||
from freqtrade.data.dataprovider import DataProvider
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
from freqtrade.enums import State
|
from freqtrade.enums import State
|
||||||
from freqtrade.worker import Worker
|
from freqtrade.worker import Worker
|
||||||
from tests.conftest import get_patched_worker, log_has, log_has_re
|
from tests.conftest import EXMS, get_patched_worker, log_has, log_has_re
|
||||||
|
|
||||||
|
|
||||||
def test_worker_state(mocker, default_conf, markets) -> None:
|
def test_worker_state(mocker, default_conf, markets) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value=markets))
|
||||||
worker = get_patched_worker(mocker, default_conf)
|
worker = get_patched_worker(mocker, default_conf)
|
||||||
assert worker.freqtrade.state is State.RUNNING
|
assert worker.freqtrade.state is State.RUNNING
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user