refactor: rename asset_type to asset_type_url_segment

This commit is contained in:
xzmeng
2024-11-14 07:51:58 +08:00
parent 660863392b
commit bfdbf0248c
3 changed files with 25 additions and 21 deletions

View File

@@ -51,11 +51,11 @@ def make_daily_df(date, timeframe):
return df
def make_daily_zip(asset_type, symbol, timeframe, date) -> bytes:
def make_daily_zip(asset_type_url_segment, symbol, timeframe, date) -> bytes:
df = make_daily_df(date, timeframe)
if asset_type == "spot":
if asset_type_url_segment == "spot":
header = True
elif asset_type == "futures/um":
elif asset_type_url_segment == "futures/um":
header = None
else:
raise ValueError
@@ -85,8 +85,8 @@ class MockResponse:
def make_response_from_url(start_date, end_date):
def make_response(url):
pattern = (
r"https://data.binance.vision/data/(?P<asset_type>spot|futures/um)/daily/klines/"
r"(?P<symbol>.*?)/(?P<timeframe>.*?)/(?P=symbol)-(?P=timeframe)-"
r"https://data.binance.vision/data/(?P<asset_type_url_segment>spot|futures/um)"
r"/daily/klines/(?P<symbol>.*?)/(?P<timeframe>.*?)/(?P=symbol)-(?P=timeframe)-"
r"(?P<date>\d{4}-\d{2}-\d{2}).zip"
)
m = re.match(pattern, url)
@@ -97,7 +97,7 @@ def make_response_from_url(start_date, end_date):
if date < start_date or date > end_date:
return MockResponse(content="", status=404)
zip_file = make_daily_zip(m["asset_type"], m["symbol"], m["timeframe"], date)
zip_file = make_daily_zip(m["asset_type_url_segment"], m["symbol"], m["timeframe"], date)
return MockResponse(content=zip_file, status=200)
return make_response

View File

@@ -31,14 +31,14 @@ from freqtrade.util.datetime_helpers import dt_from_ts
class Check:
def __init__(self, asset_type, timeframe):
self.asset_type = asset_type
def __init__(self, asset_type_url_segment, timeframe):
self.asset_type_url_segment = asset_type_url_segment
self.timeframe = timeframe
self.klines_endpoint = "https://api.binance.com/api/v3/klines"
self.exchange_endpoint = "https://api.binance.com/api/v3/exchangeInfo"
self.mismatch = set()
if asset_type == "futures/um":
if asset_type_url_segment == "futures/um":
self.klines_endpoint = "https://fapi.binance.com/fapi/v1/klines"
self.exchange_endpoint = "https://fapi.binance.com/fapi/v1/exchangeInfo"
@@ -52,7 +52,9 @@ class Check:
first_kline_ts = first_kline[0]
date = dt_from_ts(first_kline_ts).date()
archive_url = zip_url(self.asset_type, symbol=symbol, timeframe=self.timeframe, date=date)
archive_url = zip_url(
self.asset_type_url_segment, symbol=symbol, timeframe=self.timeframe, date=date
)
async with self.session.get(
archive_url, params=dict(symbol=symbol, interval=self.timeframe, startTime=0)
) as resp: