mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
Adjust tests for new arguments
This commit is contained in:
@@ -261,11 +261,11 @@ def test_datahandler_trades_not_supported(datahandler, testdatadir, ):
|
||||
def test_jsondatahandler_trades_load(testdatadir, caplog):
|
||||
dh = JsonGzDataHandler(testdatadir)
|
||||
logmsg = "Old trades format detected - converting"
|
||||
dh.trades_load('XRP/ETH')
|
||||
dh.trades_load('XRP/ETH', TradingMode.SPOT)
|
||||
assert not log_has(logmsg, caplog)
|
||||
|
||||
# Test conversation is happening
|
||||
dh.trades_load('XRP/OLD')
|
||||
dh.trades_load('XRP/OLD', TradingMode.SPOT)
|
||||
assert log_has(logmsg, caplog)
|
||||
|
||||
|
||||
@@ -300,16 +300,16 @@ def test_datahandler_trades_get_pairs(testdatadir, datahandler, expected):
|
||||
|
||||
def test_hdf5datahandler_trades_load(testdatadir):
|
||||
dh = get_datahandler(testdatadir, 'hdf5')
|
||||
trades = dh.trades_load('XRP/ETH')
|
||||
trades = dh.trades_load('XRP/ETH', TradingMode.SPOT)
|
||||
assert isinstance(trades, DataFrame)
|
||||
|
||||
trades1 = dh.trades_load('UNITTEST/NONEXIST')
|
||||
trades1 = dh.trades_load('UNITTEST/NONEXIST', TradingMode.SPOT)
|
||||
assert isinstance(trades1, DataFrame)
|
||||
assert trades1.empty
|
||||
# data goes from 2019-10-11 - 2019-10-13
|
||||
timerange = TimeRange.parse_timerange('20191011-20191012')
|
||||
|
||||
trades2 = dh._trades_load('XRP/ETH', timerange)
|
||||
trades2 = dh._trades_load('XRP/ETH', TradingMode.SPOT, timerange)
|
||||
assert len(trades) > len(trades2)
|
||||
# Check that ID is None (If it's nan, it's wrong)
|
||||
assert trades2.iloc[0]['type'] is None
|
||||
@@ -451,13 +451,13 @@ def test_hdf5datahandler_ohlcv_purge(mocker, testdatadir):
|
||||
@pytest.mark.parametrize('datahandler', ['jsongz', 'hdf5', 'feather', 'parquet'])
|
||||
def test_datahandler_trades_load(testdatadir, datahandler):
|
||||
dh = get_datahandler(testdatadir, datahandler)
|
||||
trades = dh.trades_load('XRP/ETH')
|
||||
trades = dh.trades_load('XRP/ETH', TradingMode.SPOT)
|
||||
assert isinstance(trades, DataFrame)
|
||||
assert trades.iloc[0]['timestamp'] == 1570752011620
|
||||
assert trades.iloc[0]['date'] == Timestamp('2019-10-11 00:00:11.620000+0000')
|
||||
assert trades.iloc[-1]['cost'] == 0.1986231
|
||||
|
||||
trades1 = dh.trades_load('UNITTEST/NONEXIST')
|
||||
trades1 = dh.trades_load('UNITTEST/NONEXIST', TradingMode.SPOT)
|
||||
assert isinstance(trades, DataFrame)
|
||||
assert trades1.empty
|
||||
|
||||
@@ -465,15 +465,15 @@ def test_datahandler_trades_load(testdatadir, datahandler):
|
||||
@pytest.mark.parametrize('datahandler', ['jsongz', 'hdf5', 'feather', 'parquet'])
|
||||
def test_datahandler_trades_store(testdatadir, tmp_path, datahandler):
|
||||
dh = get_datahandler(testdatadir, datahandler)
|
||||
trades = dh.trades_load('XRP/ETH')
|
||||
trades = dh.trades_load('XRP/ETH', TradingMode.SPOT)
|
||||
|
||||
dh1 = get_datahandler(tmp_path, datahandler)
|
||||
dh1.trades_store('XRP/NEW', trades)
|
||||
dh1.trades_store('XRP/NEW', trades, TradingMode.SPOT)
|
||||
|
||||
file = tmp_path / f'XRP_NEW-trades.{dh1._get_file_extension()}'
|
||||
assert file.is_file()
|
||||
# Load trades back
|
||||
trades_new = dh1.trades_load('XRP/NEW')
|
||||
trades_new = dh1.trades_load('XRP/NEW', TradingMode.SPOT)
|
||||
assert_frame_equal(trades, trades_new, check_exact=True)
|
||||
assert len(trades_new) == len(trades)
|
||||
|
||||
@@ -483,11 +483,11 @@ def test_datahandler_trades_purge(mocker, testdatadir, datahandler):
|
||||
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
||||
unlinkmock = mocker.patch.object(Path, "unlink", MagicMock())
|
||||
dh = get_datahandler(testdatadir, datahandler)
|
||||
assert not dh.trades_purge('UNITTEST/NONEXIST')
|
||||
assert not dh.trades_purge('UNITTEST/NONEXIST', TradingMode.SPOT)
|
||||
assert unlinkmock.call_count == 0
|
||||
|
||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||
assert dh.trades_purge('UNITTEST/NONEXIST')
|
||||
assert dh.trades_purge('UNITTEST/NONEXIST', TradingMode.SPOT)
|
||||
assert unlinkmock.call_count == 1
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from freqtrade.data.history.history_utils import (_download_pair_history, _downl
|
||||
validate_backtest_data)
|
||||
from freqtrade.data.history.idatahandler import get_datahandler
|
||||
from freqtrade.data.history.jsondatahandler import JsonDataHandler, JsonGzDataHandler
|
||||
from freqtrade.enums import CandleType
|
||||
from freqtrade.enums import CandleType, TradingMode
|
||||
from freqtrade.exchange import timeframe_to_minutes
|
||||
from freqtrade.misc import file_dump_json
|
||||
from freqtrade.resolvers import StrategyResolver
|
||||
@@ -168,21 +168,21 @@ def test_json_pair_data_filename(pair, timeframe, expected_result, candle_type):
|
||||
assert fn == Path(expected_result + '.gz')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pair,expected_result", [
|
||||
("ETH/BTC", 'freqtrade/hello/world/ETH_BTC-trades.json'),
|
||||
("ETH/USDT:USDT", 'freqtrade/hello/world/futures/ETH_USDT_USDT-trades.json'),
|
||||
("Fabric Token/ETH", 'freqtrade/hello/world/Fabric_Token_ETH-trades.json'),
|
||||
("ETHH20", 'freqtrade/hello/world/ETHH20-trades.json'),
|
||||
(".XBTBON2H", 'freqtrade/hello/world/_XBTBON2H-trades.json'),
|
||||
("ETHUSD.d", 'freqtrade/hello/world/ETHUSD_d-trades.json'),
|
||||
("ACC_OLD_BTC", 'freqtrade/hello/world/ACC_OLD_BTC-trades.json'),
|
||||
@pytest.mark.parametrize("pair,trading_mode,expected_result", [
|
||||
("ETH/BTC", '', 'freqtrade/hello/world/ETH_BTC-trades.json'),
|
||||
("ETH/USDT:USDT", 'futures', 'freqtrade/hello/world/futures/ETH_USDT_USDT-trades.json'),
|
||||
("Fabric Token/ETH", '', 'freqtrade/hello/world/Fabric_Token_ETH-trades.json'),
|
||||
("ETHH20", '', 'freqtrade/hello/world/ETHH20-trades.json'),
|
||||
(".XBTBON2H", '', 'freqtrade/hello/world/_XBTBON2H-trades.json'),
|
||||
("ETHUSD.d", '', 'freqtrade/hello/world/ETHUSD_d-trades.json'),
|
||||
("ACC_OLD_BTC", '', 'freqtrade/hello/world/ACC_OLD_BTC-trades.json'),
|
||||
])
|
||||
def test_json_pair_trades_filename(pair, expected_result):
|
||||
fn = JsonDataHandler._pair_trades_filename(Path('freqtrade/hello/world'), pair)
|
||||
def test_json_pair_trades_filename(pair, trading_mode, expected_result):
|
||||
fn = JsonDataHandler._pair_trades_filename(Path('freqtrade/hello/world'), pair, trading_mode)
|
||||
assert isinstance(fn, Path)
|
||||
assert fn == Path(expected_result)
|
||||
|
||||
fn = JsonGzDataHandler._pair_trades_filename(Path('freqtrade/hello/world'), pair)
|
||||
fn = JsonGzDataHandler._pair_trades_filename(Path('freqtrade/hello/world'), pair, trading_mode)
|
||||
assert isinstance(fn, Path)
|
||||
assert fn == Path(expected_result + '.gz')
|
||||
|
||||
@@ -560,7 +560,8 @@ def test_refresh_backtest_trades_data(mocker, default_conf, markets, caplog, tes
|
||||
unavailable_pairs = refresh_backtest_trades_data(exchange=ex,
|
||||
pairs=["ETH/BTC", "XRP/BTC", "XRP/ETH"],
|
||||
datadir=testdatadir,
|
||||
timerange=timerange, erase=True
|
||||
timerange=timerange, erase=True,
|
||||
trading_mode=TradingMode.SPOT,
|
||||
)
|
||||
|
||||
assert dl_mock.call_count == 2
|
||||
@@ -585,7 +586,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
||||
assert not file1.is_file()
|
||||
|
||||
assert _download_trades_history(data_handler=data_handler, exchange=exchange,
|
||||
pair='ETH/BTC')
|
||||
pair='ETH/BTC', trading_mode=TradingMode.SPOT)
|
||||
assert log_has("Current Amount of trades: 0", caplog)
|
||||
assert log_has("New Amount of trades: 6", caplog)
|
||||
assert ght_mock.call_count == 1
|
||||
@@ -598,8 +599,9 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
||||
since_time = int(trades_history[-3][0] // 1000)
|
||||
since_time2 = int(trades_history[-1][0] // 1000)
|
||||
timerange = TimeRange('date', None, since_time, 0)
|
||||
assert _download_trades_history(data_handler=data_handler, exchange=exchange,
|
||||
pair='ETH/BTC', timerange=timerange)
|
||||
assert _download_trades_history(
|
||||
data_handler=data_handler, exchange=exchange, pair='ETH/BTC',
|
||||
timerange=timerange, trading_mode=TradingMode.SPOT)
|
||||
|
||||
assert ght_mock.call_count == 1
|
||||
# Check this in seconds - since we had to convert to seconds above too.
|
||||
@@ -612,7 +614,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
||||
caplog.clear()
|
||||
|
||||
assert not _download_trades_history(data_handler=data_handler, exchange=exchange,
|
||||
pair='ETH/BTC')
|
||||
pair='ETH/BTC', trading_mode=TradingMode.SPOT)
|
||||
assert log_has_re('Failed to download historic trades for pair: "ETH/BTC".*', caplog)
|
||||
|
||||
file2 = tmp_path / 'XRP_ETH-trades.json.gz'
|
||||
@@ -624,8 +626,9 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
|
||||
since_time = int(trades_history[0][0] // 1000) - 500
|
||||
timerange = TimeRange('date', None, since_time, 0)
|
||||
|
||||
assert _download_trades_history(data_handler=data_handler, exchange=exchange,
|
||||
pair='XRP/ETH', timerange=timerange)
|
||||
assert _download_trades_history(
|
||||
data_handler=data_handler, exchange=exchange, pair='XRP/ETH',
|
||||
timerange=timerange, trading_mode=TradingMode.SPOT)
|
||||
|
||||
assert ght_mock.call_count == 1
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
|
||||
from freqtrade.data.converter.trade_converter_kraken import import_kraken_trades_from_csv
|
||||
from freqtrade.data.history.idatahandler import get_datahandler
|
||||
from freqtrade.enums import TradingMode
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from tests.conftest import EXMS, log_has, log_has_re, patch_exchange
|
||||
|
||||
@@ -40,7 +41,7 @@ def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_co
|
||||
assert dstfile.is_file()
|
||||
|
||||
dh = get_datahandler(tmp_path, 'feather')
|
||||
trades = dh.trades_load('BCH_EUR')
|
||||
trades = dh.trades_load('BCH_EUR', TradingMode.SPOT)
|
||||
assert len(trades) == 340
|
||||
|
||||
assert trades['date'].min().to_pydatetime() == datetime(2023, 1, 1, 0, 3, 56,
|
||||
|
||||
Reference in New Issue
Block a user