diff --git a/app.py b/app.py index 8306a58..4f5b62c 100644 --- a/app.py +++ b/app.py @@ -428,7 +428,7 @@ def build_market_quote_payload( if codes: market_code = codes.get("market_code", "") or market_code sina_code = codes.get("sina_code", "") or sina_code - price = market_get_price(market_code, sina_code) + price = fetch_price(symbol, market_code, sina_code) name = symbol codes = ths_to_codes(symbol) if codes: @@ -477,7 +477,20 @@ def resolve_market_codes(ths_code: str, market_code: str = "", sina_code: str = def fetch_price(ths_code: str, market_code: str = "", sina_code: str = "") -> Optional[float]: - mc, sc = resolve_market_codes(ths_code, market_code, sina_code) + sym = (ths_code or "").strip() + if sym: + try: + from vnpy_bridge import ctp_status, ctp_get_tick_price + from trading_context import get_trading_mode + + mode = get_trading_mode(get_setting) + if ctp_status(mode).get("connected"): + p = ctp_get_tick_price(mode, sym) + if p and p > 0: + return p + except Exception: + pass + mc, sc = resolve_market_codes(sym, market_code, sina_code) if not mc and not sc: return None return market_get_price(mc, sc) @@ -1578,17 +1591,6 @@ def settings(): webhook = request.form.get("wechat_webhook", "").strip() set_setting("wechat_webhook", webhook) flash("企业微信配置已保存") - elif action == "capital": - raw = request.form.get("live_capital", "").strip() - try: - val = float(raw) - if val < 0: - flash("实盘资金不能为负数") - else: - set_setting("live_capital", str(val)) - flash("参考资金已保存(CTP 已连接时以 SimNow/柜台权益为准)") - except ValueError: - flash("请输入有效的实盘资金金额") elif action == "trading": mode = request.form.get("trading_mode", "simulation").strip() if mode not in ("simulation", "live"): @@ -1627,13 +1629,19 @@ def settings(): webhook = get_setting("wechat_webhook") username = get_setting("admin_username") - live_capital = get_setting("live_capital", "0") + ctp_st = {} + try: + from vnpy_bridge import ctp_status + from trading_context import get_trading_mode + + ctp_st = ctp_status(get_trading_mode(get_setting)) + except Exception: + pass return render_template( "settings.html", webhook=webhook, username=username, - live_capital=live_capital, - quote_label=get_quote_source_label(), + quote_label=get_quote_source_label(ctp_connected=bool(ctp_st.get("connected"))), trading_mode=get_setting("trading_mode", "simulation"), position_sizing_mode=get_setting("position_sizing_mode", "risk"), risk_percent=get_setting("risk_percent", "1"), diff --git a/market.py b/market.py index 524112e..798b991 100644 --- a/market.py +++ b/market.py @@ -35,16 +35,18 @@ def _has_ths_token() -> bool: return bool(_get_refresh_token()) -def get_quote_source_label() -> str: +def get_quote_source_label(*, ctp_connected: bool = False) -> str: """界面展示用行情源说明。""" + if ctp_connected: + return "CTP 柜台(已连接)" source = _quote_source() if source == "sina": - return "新浪(免费)" + return "新浪(CTP 未连接时备用)" if source == "ths": - return "同花顺 iFinD" if _has_ths_token() else "同花顺(未配置 token,无法使用)" + return "同花顺 iFinD" if _has_ths_token() else "同花顺(未配置 token)" if _has_ths_token(): return "同花顺优先,失败回退新浪" - return "新浪(免费)" + return "新浪(CTP 未连接时备用)" def _sina_headers() -> dict: diff --git a/templates/fees.html b/templates/fees.html index 81008af..29d0b08 100644 --- a/templates/fees.html +++ b/templates/fees.html @@ -1,54 +1,64 @@ {% extends "base.html" %} {% block title %}手续费配置 - 国内期货监控系统{% endblock %} +{% block extra_css %} + +{% endblock %} {% block content %} -
- 默认使用 CTP 柜台 查询到的开仓/平仓费率(连接 CTP 后自动同步,与 SimNow/期货公司一致)。 - 离线或未连接时可改用本地表估算。 -
-