fix: 品种推荐改为最大手数并补算旧缓存。
- 最大手数 = floor(权益×保证金上限%÷1手保证金) - 加载与 SSE 推送时实时补算,旧缓存缺字段时自动刷新 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -47,14 +47,14 @@ def assess_product_for_capital(
|
||||
"status_label": "暂无行情",
|
||||
"min_capital_one_lot": None,
|
||||
"margin_one_lot": None,
|
||||
"recommended_lots": 0,
|
||||
"max_lots": 0,
|
||||
"risk_one_lot_1pct": None,
|
||||
}
|
||||
|
||||
margin_one = p * mult * margin_rate
|
||||
min_capital = margin_one / (margin_pct / 100.0) if margin_pct > 0 else margin_one
|
||||
margin_budget = cap * margin_pct / 100.0 if cap > 0 else 0.0
|
||||
recommended_lots = int(math.floor(margin_budget / margin_one)) if margin_one > 0 and margin_budget > 0 else 0
|
||||
max_lots = int(math.floor(margin_budget / margin_one)) if margin_one > 0 and margin_budget > 0 else 0
|
||||
stop_dist = tick * default_stop_ticks
|
||||
risk_one_lot = stop_dist * mult
|
||||
risk_pct_1lot = (risk_one_lot / cap * 100) if cap > 0 else 999.0
|
||||
@@ -65,13 +65,13 @@ def assess_product_for_capital(
|
||||
fee_ths, p, p, 1.0, open_time="", close_time="", trading_mode=trading_mode,
|
||||
)
|
||||
|
||||
can_margin = recommended_lots >= 1
|
||||
can_margin = max_lots >= 1
|
||||
can_risk = cap > 0 and risk_one_lot <= cap * 0.01
|
||||
|
||||
if can_margin and can_risk:
|
||||
status, label = "ok", f"推荐 {recommended_lots} 手"
|
||||
status, label = "ok", f"最大 {max_lots} 手"
|
||||
elif can_margin:
|
||||
status, label = "margin_ok", f"可开 {recommended_lots} 手·止损偏宽"
|
||||
status, label = "margin_ok", f"最大 {max_lots} 手·止损偏宽"
|
||||
else:
|
||||
status, label = "blocked", "资金不足"
|
||||
|
||||
@@ -84,7 +84,7 @@ def assess_product_for_capital(
|
||||
"tick_size": tick,
|
||||
"margin_one_lot": round(margin_one, 2),
|
||||
"min_capital_one_lot": round(min_capital, 2),
|
||||
"recommended_lots": recommended_lots,
|
||||
"max_lots": max_lots,
|
||||
"margin_budget": round(margin_budget, 2),
|
||||
"max_margin_pct": margin_pct,
|
||||
"risk_one_lot_1pct": round(risk_one_lot, 2),
|
||||
@@ -123,5 +123,5 @@ def list_product_recommendations(
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
rows = list(pool.map(_one, PRODUCTS))
|
||||
order = {"ok": 0, "margin_ok": 1, "blocked": 2, "no_price": 3}
|
||||
rows.sort(key=lambda r: (order.get(r["status"], 9), -(r.get("recommended_lots") or 0)))
|
||||
rows.sort(key=lambda r: (order.get(r["status"], 9), -(r.get("max_lots") or 0)))
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user