Add conversion function from fetch_trades to list

This commit is contained in:
Matthias
2020-03-31 20:12:01 +02:00
parent 8bfbbac748
commit 1659ddcc5d
4 changed files with 78 additions and 9 deletions

View File

@@ -1391,6 +1391,50 @@ def buy_order_fee():
}
@pytest.fixture
def fetch_trades_result():
return [{'info': {'a': 153942751,
'p': '0.02059000',
'q': '6.95500000',
'f': 170811204,
'l': 170811204,
'T': 1585670882666,
'm': True,
'M': True},
'timestamp': 1585670882666,
'datetime': '2020-03-31T16:08:02.666Z',
'symbol': 'ETH/BTC',
'id': '153942751',
'order': None,
'type': None,
'takerOrMaker': None,
'side': 'sell',
'price': 0.02059,
'amount': 6.955,
'cost': 0.14320345,
'fee': None},
{'info': {'a': 153942752,
'p': '0.02059100',
'q': '0.04900000',
'f': 170811205,
'l': 170811205,
'T': 1585670889154,
'm': False,
'M': True},
'timestamp': 1585670889154,
'datetime': '2020-03-31T16:08:09.154Z',
'symbol': 'ETH/BTC',
'id': '153942752',
'order': None,
'type': None,
'takerOrMaker': None,
'side': 'buy',
'price': 0.020591,
'amount': 0.049,
'cost': 0.001008959,
'fee': None}]
@pytest.fixture(scope="function")
def edge_conf(default_conf):
conf = deepcopy(default_conf)

View File

@@ -5,12 +5,10 @@ from freqtrade.configuration.timerange import TimeRange
from freqtrade.data.converter import (convert_ohlcv_format,
convert_trades_format,
ohlcv_fill_up_missing_data,
ohlcv_to_dataframe,
ohlcv_to_dataframe, trades_dict_to_list,
trim_dataframe)
from freqtrade.data.history import (get_timerange,
load_data,
load_pair_history,
validate_backtest_data)
from freqtrade.data.history import (get_timerange, load_data,
load_pair_history, validate_backtest_data)
from tests.conftest import log_has
from tests.data.test_history import _backup_file, _clean_test_file
@@ -197,6 +195,21 @@ def test_trim_dataframe(testdatadir) -> None:
assert all(data_modify.iloc[0] == data.iloc[25])
def test_trades_dict_to_list(mocker, fetch_trades_result):
res = trades_dict_to_list(fetch_trades_result)
assert isinstance(res, list)
assert isinstance(res[0], list)
for i, t in enumerate(res):
assert t[0] == fetch_trades_result[i]['timestamp']
assert t[1] == fetch_trades_result[i]['id']
assert t[2] == fetch_trades_result[i]['type']
assert t[3] == fetch_trades_result[i]['side']
assert t[4] == fetch_trades_result[i]['price']
assert t[5] == fetch_trades_result[i]['amount']
assert t[6] == fetch_trades_result[i]['cost']
def test_convert_trades_format(mocker, default_conf, testdatadir):
file = testdatadir / "XRP_ETH-trades.json.gz"
file_new = testdatadir / "XRP_ETH-trades.json"