44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""把今天的候选池代码写进共享 Redis, 给择时决策系统的盘中强势扫描当覆盖面 (2026-09-09, 台账 004)。
|
||
|
|
|
||
|
|
**只写一份, 只写代码。** 不写分数、不写理由、不写价格 —— 那些是 PMS 的内部判断,
|
||
|
|
择时侧要的只是"今天该盯哪几十只"。
|
||
|
|
|
||
|
|
为什么走 Redis 不走接口: 两侧本来就连着同一台行情信号 Redis 的盘中库 (PMS 的信号消化
|
||
|
|
读它的盘中信号流, 择时侧写那条流), 不新增网络方向、不涉及鉴权; 失败模式也良性 ——
|
||
|
|
键没了就是择时侧本轮不扫, 它绝不会因此回退到全市场。反过来让择时侧调 PMS 的计划接口,
|
||
|
|
要新造一条"择时到 PMS"的调用方向, 还要处理会话票签。
|
||
|
|
|
||
|
|
写失败只记日志, **绝不影响扫描主流程** —— 这个键是给别人用的方便, 不是 PMS 自己的依赖。
|
||
|
|
"""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
import logging
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from app.services import signal_service
|
||
|
|
|
||
|
|
logger = logging.getLogger("pms.candpub")
|
||
|
|
|
||
|
|
KEY = "pms:candidates:{ymd}"
|
||
|
|
TTL_SEC = 2 * 24 * 3600
|
||
|
|
|
||
|
|
|
||
|
|
def publish(codes) -> bool:
|
||
|
|
"""写今天的候选代码列表。返回是否写成功。"""
|
||
|
|
try:
|
||
|
|
arr = sorted({str(c).strip().upper() for c in (codes or []) if c})
|
||
|
|
if not arr:
|
||
|
|
return False
|
||
|
|
key = KEY.format(ymd=datetime.now().strftime("%Y%m%d"))
|
||
|
|
payload = json.dumps({"ymd": datetime.now().strftime("%Y%m%d"), "codes": arr,
|
||
|
|
"at": datetime.now().isoformat(timespec="seconds"),
|
||
|
|
"n": len(arr)}, ensure_ascii=False)
|
||
|
|
from config.settings import settings
|
||
|
|
signal_service._client(settings.SIGNAL_REDIS_DB_INTRADAY).set(key, payload, ex=TTL_SEC)
|
||
|
|
return True
|
||
|
|
except Exception as e:
|
||
|
|
logger.warning("[候选池发布] 写共享键失败 (不影响扫描): %s", e)
|
||
|
|
return False
|