freqtrade_origin/tests/data/test_trade_converter_kraken.py

59 lines
2.4 KiB
Python
Raw Normal View History

from datetime import datetime, timezone
from shutil import copytree
from unittest.mock import PropertyMock
2023-09-25 17:48:09 +00:00
import pytest
from freqtrade.data.converter.trade_converter_kraken import import_kraken_trades_from_csv
from freqtrade.data.history.idatahandler import get_datahandler
2023-09-25 17:48:09 +00:00
from freqtrade.exceptions import OperationalException
from tests.conftest import EXMS, log_has, log_has_re, patch_exchange
2023-11-05 15:18:28 +00:00
def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_conf_usdt, mocker):
2023-09-25 17:48:09 +00:00
with pytest.raises(OperationalException, match="This function is only for the kraken exchange"):
import_kraken_trades_from_csv(default_conf_usdt, 'feather')
default_conf_usdt['exchange']['name'] = 'kraken'
patch_exchange(mocker, id='kraken')
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={
'BCH/EUR': {'symbol': 'BCH/EUR', 'id': 'BCHEUR', 'altname': 'BCHEUR'},
}))
2023-11-05 15:18:28 +00:00
dstfile = tmp_path / 'BCH_EUR-trades.feather'
assert not dstfile.is_file()
2023-11-05 15:18:28 +00:00
default_conf_usdt['datadir'] = tmp_path
# There's 2 files in this tree, containing a total of 2 days.
# tests/testdata/kraken/
# └── trades_csv
# ├── BCHEUR.csv <-- 2023-01-01
# └── incremental_q2
# └── BCHEUR.csv <-- 2023-01-02
2023-11-05 15:18:28 +00:00
copytree(testdatadir / 'kraken/trades_csv', tmp_path / 'trades_csv')
import_kraken_trades_from_csv(default_conf_usdt, 'feather')
assert log_has("Found csv files for BCHEUR.", caplog)
assert log_has("Converting pairs: BCH/EUR.", caplog)
assert log_has_re(r"BCH/EUR: 340 trades.* 2023-01-01.* 2023-01-02.*", caplog)
assert dstfile.is_file()
2023-11-05 15:18:28 +00:00
dh = get_datahandler(tmp_path, 'feather')
trades = dh.trades_load('BCH_EUR')
assert len(trades) == 340
assert trades['date'].min().to_pydatetime() == datetime(2023, 1, 1, 0, 3, 56,
tzinfo=timezone.utc)
assert trades['date'].max().to_pydatetime() == datetime(2023, 1, 2, 23, 17, 3,
tzinfo=timezone.utc)
# ID is not filled
assert len(trades.loc[trades['id'] != '']) == 0
caplog.clear()
default_conf_usdt['pairs'] = ['XRP/EUR']
# Filtered to non-existing pair
import_kraken_trades_from_csv(default_conf_usdt, 'feather')
assert log_has("Found csv files for BCHEUR.", caplog)
assert log_has("No data found for pairs XRP/EUR.", caplog)