freqtrade_origin/tests/data/test_trade_converter_kraken.py

67 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 import get_datahandler
2024-03-02 12:17:45 +00:00
from freqtrade.enums import TradingMode
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"):
2024-05-12 13:38:09 +00:00
import_kraken_trades_from_csv(default_conf_usdt, "feather")
2023-09-25 17:48:09 +00:00
2024-05-12 13:38:09 +00:00
default_conf_usdt["exchange"]["name"] = "kraken"
patch_exchange(mocker, exchange="kraken")
2024-05-12 13:38:09 +00:00
mocker.patch(
f"{EXMS}.markets",
PropertyMock(
return_value={
"BCH/EUR": {"symbol": "BCH/EUR", "id": "BCHEUR", "altname": "BCHEUR"},
}
),
)
dstfile = tmp_path / "BCH_EUR-trades.feather"
assert not dstfile.is_file()
2024-05-12 13:38:09 +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
2024-05-12 13:38:09 +00:00
copytree(testdatadir / "kraken/trades_csv", tmp_path / "trades_csv")
2024-05-12 13:38:09 +00:00
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()
2024-05-12 13:38:09 +00:00
dh = get_datahandler(tmp_path, "feather")
trades = dh.trades_load("BCH_EUR", TradingMode.SPOT)
assert len(trades) == 340
2024-05-12 13:38:09 +00:00
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
2024-05-12 13:38:09 +00:00
assert len(trades.loc[trades["id"] != ""]) == 0
caplog.clear()
2024-05-12 13:38:09 +00:00
default_conf_usdt["pairs"] = ["XRP/EUR"]
# Filtered to non-existing pair
2024-05-12 13:38:09 +00:00
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)