ui: 手续费/设置布局优化,行情优先 CTP

手续费数据源与本地倍率并列双列;设置页去掉参考资金、缩小改密表单;CTP 连接时订阅柜台 tick 作为行情源。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 13:04:11 +08:00
parent 9d4aea60f0
commit eaca3d43ec
5 changed files with 204 additions and 105 deletions
+24 -16
View File
@@ -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"),