修复 Gate K 线分页:单次不足 300 根时继续拉取至最新
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+8
-4
@@ -157,17 +157,21 @@ def fetch_ohlcv_for_hub(
|
||||
if since_ms is not None and int(since_ms) > 0:
|
||||
since = int(since_ms)
|
||||
guard = 0
|
||||
while len(collected) < want and guard < 20:
|
||||
prev_since = None
|
||||
while len(collected) < want and guard < 60:
|
||||
guard += 1
|
||||
req_limit = min(chunk_max, want - len(collected))
|
||||
batch = exchange.fetch_ohlcv(
|
||||
ex_sym, timeframe=tf, since=since, limit=min(chunk_max, want - len(collected))
|
||||
ex_sym, timeframe=tf, since=since, limit=req_limit
|
||||
)
|
||||
if not batch:
|
||||
break
|
||||
collected.extend(batch)
|
||||
since = int(batch[-1][0]) + 1
|
||||
if len(batch) < min(chunk_max, want - len(collected)):
|
||||
next_since = int(batch[-1][0]) + 1
|
||||
if prev_since is not None and next_since <= prev_since:
|
||||
break
|
||||
prev_since = since
|
||||
since = next_since
|
||||
else:
|
||||
batch = exchange.fetch_ohlcv(ex_sym, timeframe=tf, limit=want)
|
||||
collected = list(batch or [])
|
||||
|
||||
Reference in New Issue
Block a user