Update test for new trades handling
This commit is contained in:
@@ -2349,6 +2349,13 @@ def trades_history():
|
|||||||
[1565798399872, '1261aa81333', None, 'sell', 0.019626, 0.011, 0.00021588599999999999]]
|
[1565798399872, '1261aa81333', None, 'sell', 0.019626, 0.011, 0.00021588599999999999]]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def trades_history_df(trades_history):
|
||||||
|
trades = pd.DataFrame(trades_history, columns=constants.DEFAULT_TRADES_COLUMNS)
|
||||||
|
trades['timestamp'] = pd.to_datetime(trades['timestamp'], unit='ms', utc=True)
|
||||||
|
return trades
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def fetch_trades_result():
|
def fetch_trades_result():
|
||||||
return [{'info': {'a': 126181329,
|
return [{'info': {'a': 126181329,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from pathlib import Path
|
|||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freqtrade.configuration.timerange import TimeRange
|
from freqtrade.configuration.timerange import TimeRange
|
||||||
@@ -34,13 +35,13 @@ def test_ohlcv_to_dataframe(ohlcv_history_list, caplog):
|
|||||||
assert log_has('Converting candle (OHLCV) data to dataframe for pair UNITTEST/BTC.', caplog)
|
assert log_has('Converting candle (OHLCV) data to dataframe for pair UNITTEST/BTC.', caplog)
|
||||||
|
|
||||||
|
|
||||||
def test_trades_to_ohlcv(trades_history, caplog):
|
def test_trades_to_ohlcv(trades_history_df, caplog):
|
||||||
|
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
with pytest.raises(ValueError, match="Trade-list empty."):
|
with pytest.raises(ValueError, match="Trade-list empty."):
|
||||||
trades_to_ohlcv([], '1m')
|
trades_to_ohlcv(pd.DataFrame(columns=trades_history_df.columns), '1m')
|
||||||
|
|
||||||
df = trades_to_ohlcv(trades_history, '1m')
|
df = trades_to_ohlcv(trades_history_df, '1m')
|
||||||
assert not df.empty
|
assert not df.empty
|
||||||
assert len(df) == 1
|
assert len(df) == 1
|
||||||
assert 'open' in df.columns
|
assert 'open' in df.columns
|
||||||
@@ -297,13 +298,13 @@ def test_trim_dataframe(testdatadir) -> None:
|
|||||||
assert all(data_modify.iloc[0] == data.iloc[25])
|
assert all(data_modify.iloc[0] == data.iloc[25])
|
||||||
|
|
||||||
|
|
||||||
def test_trades_remove_duplicates(trades_history):
|
def test_trades_remove_duplicates(trades_history_df):
|
||||||
trades_history1 = trades_history * 3
|
trades_history1 = pd.concat([trades_history_df, trades_history_df, trades_history_df]
|
||||||
assert len(trades_history1) == len(trades_history) * 3
|
).reset_index(drop=True)
|
||||||
|
assert len(trades_history1) == len(trades_history_df) * 3
|
||||||
res = trades_remove_duplicates(trades_history1)
|
res = trades_remove_duplicates(trades_history1)
|
||||||
assert len(res) == len(trades_history)
|
assert len(res) == len(trades_history_df)
|
||||||
for i, t in enumerate(res):
|
assert res.equals(trades_history_df)
|
||||||
assert t == trades_history[i]
|
|
||||||
|
|
||||||
|
|
||||||
def test_trades_dict_to_list(fetch_trades_result):
|
def test_trades_dict_to_list(fetch_trades_result):
|
||||||
|
|||||||
Reference in New Issue
Block a user