Route business quotes and K-lines to CTP; keep Sina only for market chart page.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -303,8 +303,7 @@ def fetch_market_klines(
|
||||
except Exception as exc:
|
||||
logger.debug("ctp kline fetch failed %s %s: %s", symbol, p, exc)
|
||||
|
||||
need_sina = force_remote or not prefer_ctp or not ctp_bars or len(ctp_bars) < MIN_CTP_KLINE_BARS
|
||||
|
||||
need_sina = not prefer_ctp or force_remote
|
||||
if ctp_bars and len(ctp_bars) >= MIN_CTP_KLINE_BARS:
|
||||
bars = ctp_bars
|
||||
source = "ctp"
|
||||
@@ -321,7 +320,7 @@ def fetch_market_klines(
|
||||
except Exception as exc:
|
||||
logger.warning("kline cache read failed %s %s: %s", chart_sym, p, exc)
|
||||
|
||||
if not bars or len(ctp_bars) < MIN_CTP_KLINE_BARS or not prefer_ctp:
|
||||
if need_sina and (not bars or len(ctp_bars) < MIN_CTP_KLINE_BARS or not prefer_ctp):
|
||||
remote_bars = fetch_sina_klines(symbol, p)
|
||||
if remote_bars:
|
||||
if prefer_ctp and ctp_bars and ctp_connected:
|
||||
@@ -498,7 +497,7 @@ def generate_review_kline_chart(
|
||||
plotted = False
|
||||
for idx, period in enumerate(valid_periods):
|
||||
ax = axes[idx, 0]
|
||||
bars = fetch_sina_klines(symbol, period)
|
||||
bars = fetch_market_klines(symbol, period, prefer_ctp=True).get("bars") or []
|
||||
bars = _select_bars(bars, cutoff, count)
|
||||
if not bars:
|
||||
ax.set_facecolor("#12121a")
|
||||
|
||||
@@ -43,15 +43,8 @@ def _has_ths_token() -> bool:
|
||||
def get_quote_source_label(*, ctp_connected: bool = False) -> str:
|
||||
"""界面展示用行情源说明。"""
|
||||
if ctp_connected:
|
||||
return "CTP 柜台(已连接)"
|
||||
source = _quote_source()
|
||||
if source == "sina":
|
||||
return "新浪(CTP 未连接时备用)"
|
||||
if source == "ths":
|
||||
return "同花顺 iFinD" if _has_ths_token() else "同花顺(未配置 token)"
|
||||
if _has_ths_token():
|
||||
return "同花顺优先,失败回退新浪"
|
||||
return "新浪(CTP 未连接时备用)"
|
||||
return "CTP 柜台"
|
||||
return "CTP 未连接"
|
||||
|
||||
|
||||
def _sina_headers() -> dict:
|
||||
|
||||
@@ -182,7 +182,7 @@ def register(deps) -> None:
|
||||
yield sse_format(
|
||||
"quote",
|
||||
build_market_quote_payload(
|
||||
symbol, market_code, sina_code, prefer_sina=True,
|
||||
symbol, market_code, sina_code, prefer_sina=False,
|
||||
),
|
||||
)
|
||||
while True:
|
||||
@@ -214,7 +214,7 @@ def register(deps) -> None:
|
||||
if not symbol and not market_code:
|
||||
return jsonify({"error": "请提供合约"}), 400
|
||||
return jsonify(build_market_quote_payload(
|
||||
symbol, market_code, sina_code, prefer_sina=True,
|
||||
symbol, market_code, sina_code, prefer_sina=False,
|
||||
))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user