refactor: rename fetch_ohlcv to download_archive_ohlcv

This commit is contained in:
xzmeng
2024-11-14 07:29:37 +08:00
parent 8baa0f7310
commit 660863392b
4 changed files with 19 additions and 13 deletions

View File

@@ -10,8 +10,8 @@ from pandas import DataFrame
from freqtrade.constants import DEFAULT_DATAFRAME_COLUMNS
from freqtrade.enums import CandleType, MarginMode, PriceType, TradingMode
from freqtrade.exceptions import DDosProtection, OperationalException, TemporaryError
from freqtrade.exchange import Exchange, binance_public_data
from freqtrade.exchange.binance_public_data import concat
from freqtrade.exchange import Exchange
from freqtrade.exchange.binance_public_data import concat, download_archive_ohlcv
from freqtrade.exchange.common import retrier
from freqtrade.exchange.exchange_types import FtHas, Tickers
from freqtrade.exchange.exchange_utils_timeframe import timeframe_to_msecs
@@ -172,7 +172,7 @@ class Binance(Exchange):
candle_type == CandleType.FUTURES and timeframe in ["1m", "3m", "5m", "15m", "30m"]
):
df = self.loop.run_until_complete(
binance_public_data.fetch_ohlcv(
download_archive_ohlcv(
candle_type=candle_type,
pair=pair,
timeframe=timeframe,

View File

@@ -35,7 +35,7 @@ class BadHttpStatus(Exception):
pass
async def fetch_ohlcv(
async def download_archive_ohlcv(
candle_type: CandleType,
pair: str,
timeframe: str,
@@ -86,7 +86,9 @@ async def fetch_ohlcv(
end = min(end, last_available_date)
if start >= end:
return DataFrame()
df = await _fetch_ohlcv(asset_type, symbol, pair, timeframe, start, end, stop_on_404)
df = await _download_archive_ohlcv(
asset_type, symbol, pair, timeframe, start, end, stop_on_404
)
logger.debug(
f"Downloaded data for {pair} from https://data.binance.vision with length {len(df)}."
)
@@ -108,7 +110,7 @@ def concat(dfs) -> DataFrame:
return pd.concat(dfs)
async def _fetch_ohlcv(
async def _download_archive_ohlcv(
asset_type: str,
symbol: str,
pair: str,

View File

@@ -763,7 +763,7 @@ def patch_ohlcv(mocker, start, archive_end, api_end, timeframe):
until = dt_from_ts(until_ms) if until_ms else api_end + timedelta(seconds=1)
return api_storage.loc[(api_storage["date"] >= since) & (api_storage["date"] < until)]
async def fetch_ohlcv(
async def download_archive_ohlcv(
candle_type,
pair,
timeframe,
@@ -787,7 +787,7 @@ def patch_ohlcv(mocker, start, archive_end, api_end, timeframe):
"freqtrade.exchange.Exchange.get_historic_ohlcv", side_effect=get_historic_ohlcv
)
archive_mock = mocker.patch(
"freqtrade.exchange.binance_public_data.fetch_ohlcv", side_effect=fetch_ohlcv
"freqtrade.exchange.binance.download_archive_ohlcv", side_effect=download_archive_ohlcv
)
return candle_mock, api_mock, archive_mock

View File

@@ -14,7 +14,7 @@ from freqtrade.enums import CandleType
from freqtrade.exchange.binance_public_data import (
BadHttpStatus,
Http404,
fetch_ohlcv,
download_archive_ohlcv,
get_daily_ohlcv,
zip_name,
)
@@ -196,7 +196,9 @@ def make_response_from_url(start_date, end_date):
),
],
)
async def test_fetch_ohlcv(mocker, candle_type, since, until, first_date, last_date, stop_on_404):
async def test_download_archive_ohlcv(
mocker, candle_type, since, until, first_date, last_date, stop_on_404
):
history_start = dt_utc(2020, 1, 1).date()
history_end = dt_utc(2020, 1, 3).date()
timeframe = "1h"
@@ -214,7 +216,9 @@ async def test_fetch_ohlcv(mocker, candle_type, since, until, first_date, last_d
)
markets = {"BTC/USDT": {"id": "BTCUSDT"}, "BTC/USDT:USDT": {"id": "BTCUSDT"}}
df = await fetch_ohlcv(candle_type, pair, timeframe, since_ms, until_ms, markets, stop_on_404)
df = await download_archive_ohlcv(
candle_type, pair, timeframe, since_ms, until_ms, markets, stop_on_404
)
if df.empty:
assert first_date is None and last_date is None
@@ -224,7 +228,7 @@ async def test_fetch_ohlcv(mocker, candle_type, since, until, first_date, last_d
assert df["date"].iloc[-1] == last_date
async def test_fetch_ohlcv_exc(mocker):
async def test_download_archive_ohlcv_exc(mocker):
timeframe = "1h"
pair = "BTC/USDT"
@@ -240,7 +244,7 @@ async def test_fetch_ohlcv_exc(mocker):
{"BTC/USDT": {"id": "BTCUSDT"}},
)
df = await fetch_ohlcv(CandleType.SPOT, pair, timeframe, since_ms, until_ms)
df = await download_archive_ohlcv(CandleType.SPOT, pair, timeframe, since_ms, until_ms)
assert df.empty