mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-16 12:51:14 +00:00
test: add test for get_daily_trades
This commit is contained in:
@@ -411,8 +411,12 @@ async def get_daily_trades(
|
|||||||
# based on ccxt parseTrade logic.
|
# based on ccxt parseTrade logic.
|
||||||
df["side"] = np.where(df["is_buyer_maker"], "sell", "buy")
|
df["side"] = np.where(df["is_buyer_maker"], "sell", "buy")
|
||||||
df["type"] = None
|
df["type"] = None
|
||||||
if header is None:
|
# Convert timestamp to ms
|
||||||
df["timestamp"] = df["timestamp"] // 1000
|
df["timestamp"] = np.where(
|
||||||
|
df["timestamp"] > 10000000000000,
|
||||||
|
df["timestamp"] // 1000,
|
||||||
|
df["timestamp"],
|
||||||
|
)
|
||||||
return df[DEFAULT_TRADES_COLUMNS].to_records(index=False).tolist()
|
return df[DEFAULT_TRADES_COLUMNS].to_records(index=False).tolist()
|
||||||
elif resp.status == 404:
|
elif resp.status == 404:
|
||||||
logger.debug(f"Failed to download {url}")
|
logger.debug(f"Failed to download {url}")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from freqtrade.exchange.binance_public_data import (
|
|||||||
download_archive_ohlcv,
|
download_archive_ohlcv,
|
||||||
download_archive_trades,
|
download_archive_trades,
|
||||||
get_daily_ohlcv,
|
get_daily_ohlcv,
|
||||||
|
get_daily_trades,
|
||||||
)
|
)
|
||||||
from freqtrade.util.datetime_helpers import dt_ts, dt_utc
|
from freqtrade.util.datetime_helpers import dt_ts, dt_utc
|
||||||
|
|
||||||
@@ -372,3 +373,61 @@ async def test_binance_vision_trades_zip_url():
|
|||||||
url == "https://data.binance.vision/data/futures/um/daily/aggTrades/"
|
url == "https://data.binance.vision/data/futures/um/daily/aggTrades/"
|
||||||
"BTCUSDT/BTCUSDT-aggTrades-2023-10-28.zip"
|
"BTCUSDT/BTCUSDT-aggTrades-2023-10-28.zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_daily_trades(mocker, testdatadir):
|
||||||
|
symbol = "PEPEUSDT"
|
||||||
|
symbol_futures = "APEUSDT"
|
||||||
|
date = dt_utc(2024, 10, 28).date()
|
||||||
|
first_date = 1729987202368
|
||||||
|
last_date = 1730073596350
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
spot_path = (
|
||||||
|
testdatadir / "binance/binance_public_data/spot-PEPEUSDT-aggTrades-2024-10-27.zip"
|
||||||
|
)
|
||||||
|
get = mocker.patch(
|
||||||
|
"freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get",
|
||||||
|
return_value=MockResponse(spot_path.read_bytes(), 200),
|
||||||
|
)
|
||||||
|
res = await get_daily_trades(symbol, CandleType.SPOT, date, session)
|
||||||
|
assert get.call_count == 1
|
||||||
|
assert res[0][0] == first_date
|
||||||
|
assert res[-1][0] == last_date
|
||||||
|
|
||||||
|
futures_path = (
|
||||||
|
testdatadir / "binance/binance_public_data/futures-APEUSDT-aggTrades-2024-10-18.zip"
|
||||||
|
)
|
||||||
|
get = mocker.patch(
|
||||||
|
"freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get",
|
||||||
|
return_value=MockResponse(futures_path.read_bytes(), 200),
|
||||||
|
)
|
||||||
|
res_fut = await get_daily_trades(symbol_futures, CandleType.FUTURES, date, session)
|
||||||
|
assert get.call_count == 1
|
||||||
|
assert res_fut[0][0] == 1729209603958
|
||||||
|
assert res_fut[-1][0] == 1729295981272
|
||||||
|
|
||||||
|
get = mocker.patch(
|
||||||
|
"freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get",
|
||||||
|
return_value=MockResponse(b"", 404),
|
||||||
|
)
|
||||||
|
with pytest.raises(Http404):
|
||||||
|
await get_daily_trades(symbol, CandleType.SPOT, date, session, retry_delay=0)
|
||||||
|
assert get.call_count == 1
|
||||||
|
|
||||||
|
get = mocker.patch(
|
||||||
|
"freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get",
|
||||||
|
return_value=MockResponse(b"", 500),
|
||||||
|
)
|
||||||
|
mocker.patch("asyncio.sleep")
|
||||||
|
with pytest.raises(BadHttpStatus):
|
||||||
|
await get_daily_trades(symbol, CandleType.SPOT, date, session)
|
||||||
|
assert get.call_count == 4 # 1 + 3 default retries
|
||||||
|
|
||||||
|
get = mocker.patch(
|
||||||
|
"freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get",
|
||||||
|
return_value=MockResponse(b"nop", 200),
|
||||||
|
)
|
||||||
|
with pytest.raises(zipfile.BadZipFile):
|
||||||
|
await get_daily_trades(symbol, CandleType.SPOT, date, session)
|
||||||
|
assert get.call_count == 4 # 1 + 3 default retries
|
||||||
|
|||||||
BIN
tests/testdata/binance/binance_public_data/futures-APEUSDT-aggTrades-2024-10-18.zip
vendored
Normal file
BIN
tests/testdata/binance/binance_public_data/futures-APEUSDT-aggTrades-2024-10-18.zip
vendored
Normal file
Binary file not shown.
BIN
tests/testdata/binance/binance_public_data/spot-PEPEUSDT-aggTrades-2024-10-27.zip
vendored
Normal file
BIN
tests/testdata/binance/binance_public_data/spot-PEPEUSDT-aggTrades-2024-10-27.zip
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user