diff --git a/install_trading.py b/install_trading.py index e923b6a..17d439c 100644 --- a/install_trading.py +++ b/install_trading.py @@ -28,7 +28,16 @@ from position_sizing import ( calc_order_tick_metrics, normalize_sizing_mode, ) -from product_recommend import assert_product_allowed_for_capital, is_small_account, SMALL_ACCOUNT_SCOPE_LABEL +from product_recommend import ( + assert_product_allowed_for_capital, + is_small_account, + small_account_scope_hint, + SMALL_ACCOUNT_SCOPE_LABEL, +) +from recommend_store import ( + recommend_payload, + refresh_recommend_cache, +) from recommend_stream import recommend_hub, schedule_recommend_refresh, start_recommend_worker from position_stream import position_hub, start_position_worker from ctp_settings import is_ctp_auto_connect_enabled @@ -1643,7 +1652,7 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se recommend_updated_at=rec_cache.get("updated_at"), night_session=is_night_trading_session(), small_account_scope=is_small_account(capital), - small_account_scope_label=SMALL_ACCOUNT_SCOPE_LABEL, + small_account_scope_hint=small_account_scope_hint(), product_categories=PRODUCT_CATEGORIES, ) finally: diff --git a/product_recommend.py b/product_recommend.py index 32327d2..eaae3d3 100644 --- a/product_recommend.py +++ b/product_recommend.py @@ -18,12 +18,22 @@ from symbols import PRODUCTS, product_category, product_has_night_session logger = logging.getLogger(__name__) -# 权益低于该值时,仅允许下列品种(可开仓列表、品种下拉、开仓报单) -SMALL_ACCOUNT_CAPITAL_MAX = 100_000.0 +# 权益不超过该值时,仅允许下列品种(可开仓列表、品种下拉、开仓报单) +SMALL_ACCOUNT_CAPITAL_MAX = 200_000.0 SMALL_ACCOUNT_PRODUCT_THS = frozenset({"c", "m", "MA", "rb"}) SMALL_ACCOUNT_SCOPE_LABEL = "玉米、豆粕、甲醇、螺纹钢" +def small_account_scope_hint() -> str: + wan = int(SMALL_ACCOUNT_CAPITAL_MAX // 10_000) + return f"权益 {wan} 万以下仅显示并可交易:{SMALL_ACCOUNT_SCOPE_LABEL}" + + +def small_account_scope_status_label() -> str: + wan = int(SMALL_ACCOUNT_CAPITAL_MAX // 10_000) + return f"权益{wan}万以下限{SMALL_ACCOUNT_SCOPE_LABEL}" + + def normalize_product_ths(ths: str) -> str: import re s = (ths or "").strip() @@ -56,7 +66,8 @@ def assert_product_allowed_for_capital(ths: str, capital: float) -> Optional[str return None if product_in_small_account_whitelist(ths): return None - return f"权益 10 万以下仅可交易:{SMALL_ACCOUNT_SCOPE_LABEL}" + wan = int(SMALL_ACCOUNT_CAPITAL_MAX // 10_000) + return f"权益 {wan} 万以下仅可交易:{SMALL_ACCOUNT_SCOPE_LABEL}" def filter_products_for_capital(products: list[dict], capital: float) -> list[dict]: @@ -115,7 +126,7 @@ def assess_product_for_capital( "mult": spec["mult"], "tick_size": tick, "status": "blocked", - "status_label": f"10万以下限{SMALL_ACCOUNT_SCOPE_LABEL}", + "status_label": small_account_scope_status_label(), "min_capital_one_lot": None, "margin_one_lot": None, "max_lots": 0, diff --git a/scripts/deploy_fix_recommend_import.py b/scripts/deploy_fix_recommend_import.py new file mode 100644 index 0000000..f8e486f --- /dev/null +++ b/scripts/deploy_fix_recommend_import.py @@ -0,0 +1,19 @@ +"""Fix recommend_payload import and deploy 200k scope.""" +import paramiko, sys +from pathlib import Path +sys.stdout.reconfigure(encoding="utf-8", errors="replace") +root = Path(__file__).resolve().parents[1] +files = ["product_recommend.py", "install_trading.py", "templates/trade.html"] +c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +c.connect("192.168.8.21", username="root", password="woaini88", timeout=15) +sftp = c.open_sftp() +for rel in files: + sftp.put(str(root / rel), f"/opt/qihuo/{rel.replace(chr(92), '/')}") + print("uploaded", rel) +sftp.close() +_, o, e = c.exec_command("cd /opt/qihuo && pm2 restart qihuo && sleep 2 && /opt/qihuo/venv/bin/python -c \"from recommend_store import recommend_payload; from install_trading import install_trading; print('import ok')\"") +print(o.read().decode("utf-8", errors="replace")) +print(e.read().decode("utf-8", errors="replace")) +_, o, e = c.exec_command("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:6600/login") +print("login status", o.read().decode()) +c.close() diff --git a/templates/trade.html b/templates/trade.html index 42ec54d..cc8110b 100644 --- a/templates/trade.html +++ b/templates/trade.html @@ -133,7 +133,7 @@

最大手数 = floor(权益 × 保证金上限 {{ max_margin_pct }}% ÷ 1手保证金);当前权益 {{ '%.2f'|format(capital) }} 元。 {% if sizing_mode == 'fixed' %}仅显示最大手数 ≥ {{ fixed_lots }} 手的品种。{% endif %} - {% if small_account_scope %}权益 10 万以下仅显示并可交易:{{ small_account_scope_label }}。{% endif %} + {% if small_account_scope %}{{ small_account_scope_hint }}。{% endif %} {% if night_session %}当前为夜盘时段,品种下拉与下表仅显示有夜盘品种;带「夜盘」标记。{% elif not small_account_scope %}有夜盘交易的品种带「夜盘」标记。{% endif %} 保证金优先读取 CTP 柜台合约信息。 {% if recommend_updated_at %}每日后台更新 · 最近 {{ recommend_updated_at }}{% else %}等待今日后台刷新…{% endif %}