K线后台自动刷新并通过SSE推送到前端,移除轮询

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 17:33:31 +08:00
parent b804bd19a7
commit 65992eb35e
5 changed files with 327 additions and 134 deletions
+9 -4
View File
@@ -215,7 +215,12 @@ def bars_to_api(bars: list) -> list[dict]:
return result
def fetch_market_klines(symbol: str, period: str, db_path: Optional[str] = None) -> dict:
def fetch_market_klines(
symbol: str,
period: str,
db_path: Optional[str] = None,
force_remote: bool = False,
) -> dict:
chart_sym = ths_to_sina_chart_symbol(symbol)
p = (period or "15m").lower()
if p == "timeshare":
@@ -227,7 +232,7 @@ def fetch_market_klines(symbol: str, period: str, db_path: Optional[str] = None)
source = "remote"
cached_at = None
if db_path and chart_sym:
if db_path and chart_sym and not force_remote:
try:
conn = sqlite3.connect(db_path)
cached = get_cached_entry(conn, chart_sym, p)
@@ -239,7 +244,7 @@ def fetch_market_klines(symbol: str, period: str, db_path: Optional[str] = None)
except Exception as exc:
logger.warning("kline cache read failed %s %s: %s", chart_sym, p, exc)
if not bars:
if force_remote or not bars:
remote_bars = fetch_sina_klines(symbol, p)
if remote_bars:
bars = remote_bars
@@ -257,7 +262,7 @@ def fetch_market_klines(symbol: str, period: str, db_path: Optional[str] = None)
cached_at = meta[0] if meta else None
except Exception as exc:
logger.warning("kline cache write failed %s %s: %s", chart_sym, p, exc)
elif db_path and chart_sym:
elif not bars and db_path and chart_sym:
try:
conn = sqlite3.connect(db_path)
cached = get_cached_entry(conn, chart_sym, p)