K线后台自动刷新并通过SSE推送到前端,移除轮询
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+9
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user