From fa1e0af19f330ba080d0736a1317f382d1d30dda Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 29 Nov 2024 06:46:55 +0100 Subject: [PATCH] chore: remove direct exchange connection --- freqtrade/exchange/binance_public_data.py | 10 +++------- tests/exchange/test_binance_public_data.py | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/freqtrade/exchange/binance_public_data.py b/freqtrade/exchange/binance_public_data.py index b6bce37da..e956300ee 100644 --- a/freqtrade/exchange/binance_public_data.py +++ b/freqtrade/exchange/binance_public_data.py @@ -39,9 +39,10 @@ async def download_archive_ohlcv( candle_type: CandleType, pair: str, timeframe: str, + *, since_ms: int, until_ms: int | None, - markets: dict[str, Any] | None = None, + markets: dict[str, Any], stop_on_404: bool = True, ) -> DataFrame: """ @@ -70,12 +71,7 @@ async def download_archive_ohlcv( else: raise ValueError(f"Unsupported CandleType: {candle_type}") - if markets: - symbol = markets[pair]["id"] - else: - binance = ccxt.binance() - binance.load_markets() - symbol = binance.markets[pair]["id"] + symbol = markets[pair]["id"] start = dt_from_ts(since_ms) end = dt_from_ts(until_ms) if until_ms else dt_now() diff --git a/tests/exchange/test_binance_public_data.py b/tests/exchange/test_binance_public_data.py index 5f066d75e..16d803176 100644 --- a/tests/exchange/test_binance_public_data.py +++ b/tests/exchange/test_binance_public_data.py @@ -243,7 +243,13 @@ async def test_download_archive_ohlcv( markets = {"BTC/USDT": {"id": "BTCUSDT"}, "BTC/USDT:USDT": {"id": "BTCUSDT"}} df = await download_archive_ohlcv( - candle_type, pair, timeframe, since_ms, until_ms, markets, stop_on_404 + candle_type, + pair, + timeframe, + since_ms=since_ms, + until_ms=until_ms, + markets=markets, + stop_on_404=stop_on_404, ) if df.empty: @@ -254,23 +260,21 @@ async def test_download_archive_ohlcv( assert df["date"].iloc[-1] == last_date -async def test_download_archive_ohlcv_exc(mocker): +async def test_download_archive_ohlcv_exception(mocker): timeframe = "1h" pair = "BTC/USDT" since_ms = dt_ts(dt_utc(2020, 1, 1)) until_ms = dt_ts(dt_utc(2020, 1, 2)) + markets = {"BTC/USDT": {"id": "BTCUSDT"}, "BTC/USDT:USDT": {"id": "BTCUSDT"}} mocker.patch( "freqtrade.exchange.binance_public_data.aiohttp.ClientSession.get", side_effect=RuntimeError ) - mocker.patch("freqtrade.exchange.binance_public_data.ccxt.binance") - mocker.patch( - "freqtrade.exchange.binance_public_data.ccxt.binance.markets", - {"BTC/USDT": {"id": "BTCUSDT"}}, - ) - df = await download_archive_ohlcv(CandleType.SPOT, pair, timeframe, since_ms, until_ms) + df = await download_archive_ohlcv( + CandleType.SPOT, pair, timeframe, since_ms=since_ms, until_ms=until_ms, markets=markets + ) assert df.empty