feat(hub): background chart poll with SSE for positions and market watch
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+9
-2
@@ -286,10 +286,11 @@ def resolve_chart_bars(
|
||||
*,
|
||||
db_path: Path | None = None,
|
||||
force_refresh: bool = False,
|
||||
tail_refresh: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
按需:先读库,不足则 remote_fetch(symbol, timeframe, since_ms, limit) 补齐并写库。
|
||||
无后台定时任务;每次调用时顺带 purge 15 天前数据。
|
||||
tail_refresh=True 时即使库内「够新」也增量拉取尾部 K 线(未收盘 K 的 OHLC 更新)。
|
||||
"""
|
||||
init_db(db_path)
|
||||
purged = purge_retention(db_path)
|
||||
@@ -317,6 +318,10 @@ def resolve_chart_bars(
|
||||
period_ms = TIMEFRAME_MS[tf]
|
||||
newest_ok = newest_db is not None and int(newest_db) >= int(last_closed) - period_ms
|
||||
need_fetch = force_refresh or len(db_rows) < need or not newest_ok
|
||||
tail_only = False
|
||||
if tail_refresh and db_rows and not force_refresh and not need_fetch:
|
||||
need_fetch = True
|
||||
tail_only = True
|
||||
|
||||
fetched = 0
|
||||
price_tick: Optional[float] = None
|
||||
@@ -324,8 +329,10 @@ def resolve_chart_bars(
|
||||
|
||||
if need_fetch:
|
||||
since = fetch_start_ms
|
||||
if tail_only and newest_db is not None:
|
||||
since = max(0, int(newest_db) - period_ms * 3)
|
||||
# 仅当库内根数已够且缺口在尾部时做增量拉取;否则全量回看,避免 Gate from>to
|
||||
if (
|
||||
elif (
|
||||
db_rows
|
||||
and not force_refresh
|
||||
and newest_ok
|
||||
|
||||
Reference in New Issue
Block a user