def test_download_data_all_pairs(mocker, markets):

    mocker.patch.object(Path, "exists", MagicMock(return_value=False))

    dl_mock = mocker.patch(
        'freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
        MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
    patch_exchange(mocker)
    mocker.patch('freqtrade.exchange.Exchange.markets',
                 PropertyMock(return_value=markets))
    args = ["download-data", "--exchange", "binance", "--pairs", ".*/USDT"]
    pargs = get_args(args)
    pargs['config'] = None
    start_download_data(pargs)
    expected = set(['ETH/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT'])
    assert set(dl_mock.call_args_list[0][1]['pairs']) == expected
    assert dl_mock.call_count == 1

    dl_mock.reset_mock()
    args = [
        "download-data",
        "--exchange",
        "binance",
        "--pairs",
        ".*/USDT",
        "--include-inactive-pairs",
    ]
    pargs = get_args(args)
    pargs['config'] = None
    start_download_data(pargs)
    expected = set(
        ['ETH/USDT', 'LTC/USDT', 'XRP/USDT', 'NEO/USDT', 'TKN/USDT'])
    assert set(dl_mock.call_args_list[0][1]['pairs']) == expected
Beispiel #2
0
def test_download_data_trades(mocker, caplog):
    dl_mock = mocker.patch(
        'freqtrade.commands.data_commands.refresh_backtest_trades_data',
        MagicMock(return_value=[]))
    convert_mock = mocker.patch(
        'freqtrade.commands.data_commands.convert_trades_to_ohlcv',
        MagicMock(return_value=[]))
    patch_exchange(mocker)
    mocker.patch('freqtrade.exchange.Exchange.markets',
                 PropertyMock(return_value={}))
    args = [
        "download-data", "--exchange", "kraken", "--pairs", "ETH/BTC",
        "XRP/BTC", "--days", "20", "--dl-trades"
    ]
    pargs = get_args(args)
    pargs['config'] = None
    start_download_data(pargs)
    assert dl_mock.call_args[1]['timerange'].starttype == "date"
    assert dl_mock.call_count == 1
    assert convert_mock.call_count == 1
    args = [
        "download-data", "--exchange", "kraken", "--pairs", "ETH/BTC",
        "XRP/BTC", "--days", "20", "--trading-mode", "futures", "--dl-trades"
    ]
    with pytest.raises(OperationalException,
                       match="Trade download not supported for futures."):
        pargs = get_args(args)
        pargs['config'] = None
        start_download_data(pargs)
Beispiel #3
0
def test_download_data_no_exchange(mocker, caplog):
    mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
                 MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
    patch_exchange(mocker)
    mocker.patch(
        'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
    )
    args = [
        "download-data",
    ]
    pargs = get_args(args)
    pargs['config'] = None
    with pytest.raises(OperationalException,
                       match=r"This command requires a configured exchange.*"):
        start_download_data(pargs)
Beispiel #4
0
def test_download_data_no_markets(mocker, caplog):
    dl_mock = mocker.patch(
        'freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
        MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
    patch_exchange(mocker, id='binance')
    mocker.patch('freqtrade.exchange.Exchange.markets',
                 PropertyMock(return_value={}))
    args = [
        "download-data", "--exchange", "binance", "--pairs", "ETH/BTC",
        "XRP/BTC", "--days", "20"
    ]
    start_download_data(get_args(args))
    assert dl_mock.call_args[1]['timerange'].starttype == "date"
    assert log_has(
        "Pairs [ETH/BTC,XRP/BTC] not available on exchange Binance.", caplog)
Beispiel #5
0
def test_download_data_keyboardInterrupt(mocker, caplog, markets):
    dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
                           MagicMock(side_effect=KeyboardInterrupt))
    patch_exchange(mocker)
    mocker.patch(
        'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
    )
    args = [
        "download-data",
        "--exchange", "binance",
        "--pairs", "ETH/BTC", "XRP/BTC",
    ]
    with pytest.raises(SystemExit):
        start_download_data(get_args(args))

    assert dl_mock.call_count == 1
Beispiel #6
0
def test_download_data_trades(mocker, caplog):
    dl_mock = mocker.patch(
        'freqtrade.commands.data_commands.refresh_backtest_trades_data',
        MagicMock(return_value=[]))
    convert_mock = mocker.patch(
        'freqtrade.commands.data_commands.convert_trades_to_ohlcv',
        MagicMock(return_value=[]))
    patch_exchange(mocker)
    mocker.patch('freqtrade.exchange.Exchange.markets',
                 PropertyMock(return_value={}))
    args = [
        "download-data", "--exchange", "kraken", "--pairs", "ETH/BTC",
        "XRP/BTC", "--days", "20", "--dl-trades"
    ]
    start_download_data(get_args(args))
    assert dl_mock.call_args[1]['timerange'].starttype == "date"
    assert dl_mock.call_count == 1
    assert convert_mock.call_count == 1
Beispiel #7
0
def test_download_data_no_pairs(mocker, caplog):

    mocker.patch.object(Path, "exists", MagicMock(return_value=False))

    mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
                 MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
    patch_exchange(mocker)
    mocker.patch(
        'freqtrade.exchange.Exchange.markets', PropertyMock(return_value={})
    )
    args = [
        "download-data",
        "--exchange",
        "binance",
    ]
    pargs = get_args(args)
    pargs['config'] = None
    with pytest.raises(OperationalException,
                       match=r"Downloading data requires a list of pairs\..*"):
        start_download_data(pargs)
Beispiel #8
0
def test_download_data_timerange(mocker, caplog, markets):
    dl_mock = mocker.patch('freqtrade.commands.data_commands.refresh_backtest_ohlcv_data',
                           MagicMock(return_value=["ETH/BTC", "XRP/BTC"]))
    patch_exchange(mocker)
    mocker.patch(
        'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
    )
    args = [
        "download-data",
        "--exchange", "binance",
        "--pairs", "ETH/BTC", "XRP/BTC",
        "--days", "20",
        "--timerange", "20200101-"
    ]
    with pytest.raises(OperationalException,
                       match=r"--days and --timerange are mutually.*"):
        start_download_data(get_args(args))
    assert dl_mock.call_count == 0

    args = [
        "download-data",
        "--exchange", "binance",
        "--pairs", "ETH/BTC", "XRP/BTC",
        "--days", "20",
    ]
    start_download_data(get_args(args))
    assert dl_mock.call_count == 1
    # 20days ago
    days_ago = arrow.get(arrow.now().shift(days=-20).date()).int_timestamp
    assert dl_mock.call_args_list[0][1]['timerange'].startts == days_ago

    dl_mock.reset_mock()
    args = [
        "download-data",
        "--exchange", "binance",
        "--pairs", "ETH/BTC", "XRP/BTC",
        "--timerange", "20200101-"
    ]
    start_download_data(get_args(args))
    assert dl_mock.call_count == 1

    assert dl_mock.call_args_list[0][1]['timerange'].startts == arrow.Arrow(
        2020, 1, 1).int_timestamp