feat: 品种推荐与下单显示主力合约
推荐列表展示当前主力代码;下单品种支持中文/代码搜索并按交易所分组选择主力合约。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -79,18 +79,22 @@ def assess_product_for_capital(
|
||||
|
||||
def list_product_recommendations(
|
||||
capital: float,
|
||||
price_fn: Callable[[str], Optional[float]],
|
||||
quote_fn: Callable[[str], Optional[dict]],
|
||||
*,
|
||||
max_position_pct: float = 50.0,
|
||||
) -> list[dict]:
|
||||
"""扫描全部品种并排序:推荐 > 可开 > 不足。"""
|
||||
"""扫描全部品种并排序:推荐 > 可开 > 不足。quote_fn(品种代码) -> {price, ths_code, ...}"""
|
||||
|
||||
def _one(product: dict) -> dict:
|
||||
ths = product["ths"]
|
||||
main_code = price_fn(ths)
|
||||
return assess_product_for_capital(
|
||||
product, capital, main_code, max_position_pct=max_position_pct
|
||||
quote = quote_fn(ths) or {}
|
||||
price = quote.get("price")
|
||||
row = assess_product_for_capital(
|
||||
product, capital, price, max_position_pct=max_position_pct
|
||||
)
|
||||
main_code = (quote.get("ths_code") or "").strip()
|
||||
row["main_code"] = main_code
|
||||
return row
|
||||
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
rows = list(pool.map(_one, PRODUCTS))
|
||||
|
||||
Reference in New Issue
Block a user