修复 OKX K 线无 since 时只拉 300 根的问题,并加入行情快捷键

- fetch_ohlcv_for_hub:无 since 时按目标根数分页拉取(OKX/Gate 单次约 300)

- hub_kline_store 全量补拉传 fetch_start_ms

- 行情区:数字键切换周期、Ctrl+空格全屏、Esc 退出全屏

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-02 14:51:37 +08:00
parent 16927444d7
commit bfffc7d984
6 changed files with 241 additions and 26 deletions
+20 -18
View File
@@ -189,29 +189,31 @@ def fetch_ohlcv_for_hub(
ex_sym = normalize_exchange_symbol(sym)
want = max(1, min(int(limit or bar_limit_for_timeframe(tf)), 1500))
chunk_max = 300
period = TIMEFRAME_MS[tf]
collected: list = []
if since_ms is not None and int(since_ms) > 0:
since = int(since_ms)
guard = 0
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=req_limit
)
if not batch:
break
collected.extend(batch)
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 [])
# OKX/Gate 等无 since 时单次常被限制在 ~300 根,须从目标起点分页向前拉
since = max(0, int(time.time() * 1000) - want * period)
guard = 0
prev_since = None
while len(collected) < want and guard < 80:
guard += 1
req_limit = min(chunk_max, want - len(collected))
batch = exchange.fetch_ohlcv(
ex_sym, timeframe=tf, since=since, limit=req_limit
)
if not batch:
break
collected.extend(batch)
next_since = int(batch[-1][0]) + period
if prev_since is not None and next_since <= prev_since:
break
prev_since = since
since = next_since
bars = _bars_to_dicts(collected)
if not bars: