diff --git a/app.py b/app.py index a5caf38..c3341c9 100644 --- a/app.py +++ b/app.py @@ -24,7 +24,13 @@ from werkzeug.security import check_password_hash, generate_password_hash from functools import wraps -from symbols import search_symbols, ths_to_codes, list_main_contracts_grouped, refresh_main_index +from symbols import ( + search_symbols, + ths_to_codes, + list_main_contracts_grouped, + list_recommended_symbols_grouped, + refresh_main_index, +) from contract_specs import calc_position_metrics from fee_specs import ( calc_fee_breakdown, @@ -742,6 +748,26 @@ def api_symbols_mains(): return jsonify(list_main_contracts_grouped()) +@app.route("/api/symbols/recommended") +@login_required +def api_symbols_recommended(): + """品种下拉:仅展示当前资金下推荐的品种(与下方品种推荐表一致)。""" + from recommend_store import recommend_payload + from trading_context import get_account_capital, get_max_margin_pct + + conn = get_db() + try: + capital = get_account_capital(conn, get_setting) + payload = recommend_payload( + conn, + live_capital=capital, + max_margin_pct=get_max_margin_pct(get_setting), + ) + return jsonify(list_recommended_symbols_grouped(payload.get("rows") or [])) + finally: + conn.close() + + @app.route("/api/key_prices") @login_required def api_key_prices(): diff --git a/static/js/symbol.js b/static/js/symbol.js index 6e37c78..3514688 100644 --- a/static/js/symbol.js +++ b/static/js/symbol.js @@ -1,8 +1,12 @@ (function () { function formatSub(item) { - return '同花顺 ' + item.ths_code + + var sub = '同花顺 ' + item.ths_code + (item.market_code ? ' · ' + item.market_code : '') + ' · ' + (item.exchange || ''); + if (item.max_lots != null && item.max_lots > 0) { + sub += ' · 最大 ' + item.max_lots + ' 手'; + } + return sub; } function formatInputLabel(item) { @@ -132,17 +136,23 @@ return; } if (mainsLoading) { - dropdown.innerHTML = '