日线口径对齐TDX自然日:定型线改为夜盘收盘(23:00/贵金属次日02:30);新增reset_daily_signals.py重置脚本
This commit is contained in:
@@ -17,8 +17,8 @@ abstract final class XlColors {
|
||||
static const ink = Color(0xFF2E2E2E); // 黛
|
||||
|
||||
// 功能色(K线/涨跌)
|
||||
static const rise = Color(0xFFBE3830); // 阳线红
|
||||
static const fall = Color(0xFF4E9A7A); // 阴线绿
|
||||
static const rise = Color(0xFFE02424); // 阳线红(通达信风格正红)
|
||||
static const fall = Color(0xFF00A800); // 阴线绿(通达信风格正绿)
|
||||
|
||||
// 表面(从设计稿取色)
|
||||
static const surface = Color(0xFF241816); // 暗漆(卡片/输入框)
|
||||
|
||||
+12
-4
@@ -111,7 +111,7 @@ def _judge(symbol: dict, interval: str, bars: list[dict], ind: dict, cutoff: str
|
||||
upto = _judged_upto(symbol_code, interval)
|
||||
# 已定型K:dt 的收盘时刻 <= cutoff
|
||||
period_min = {"15m": 15, "30m": 30, "60m": 60, "1d": 1440}[interval]
|
||||
closed = [b for b in bars if _close_time(b["dt"], period_min) <= cutoff]
|
||||
closed = [b for b in bars if _close_time(b["dt"], period_min, symbol_code) <= cutoff]
|
||||
if not closed:
|
||||
return 0
|
||||
last_dt = closed[-1]["dt"]
|
||||
@@ -149,11 +149,19 @@ def _judge(symbol: dict, interval: str, bars: list[dict], ind: dict, cutoff: str
|
||||
return len(new_ids)
|
||||
|
||||
|
||||
def _close_time(dt: str, period_min: int) -> str:
|
||||
# 夜盘跨零点到次日 02:30 收盘的品种(上期所贵金属);其余有夜盘品种 23:00 收
|
||||
NIGHT_TILL_0230 = {"AUL9", "AGL9"}
|
||||
|
||||
|
||||
def _close_time(dt: str, period_min: int, symbol_code: str = "") -> str:
|
||||
d = datetime.strptime(dt, "%Y-%m-%d %H:%M")
|
||||
if period_min == 1440:
|
||||
# 日线 K 的 dt 是交易日 00:00,收盘 = 当日 15:00(全部品种日盘均 15:00 收)
|
||||
return d.strftime("%Y-%m-%d") + " 15:00"
|
||||
# 日线对齐 TDX「自然日口径」:当日 K = 白盘 + 当晚夜盘,
|
||||
# 完整定型需等夜盘收盘(郑商所/大商所等 23:00;贵金属次日 02:30;
|
||||
# 无夜盘品种当日 23:00 前数值不变,只是判定顺延)。
|
||||
if symbol_code in NIGHT_TILL_0230:
|
||||
return (d + timedelta(days=1)).strftime("%Y-%m-%d") + " 02:30"
|
||||
return d.strftime("%Y-%m-%d") + " 23:00"
|
||||
return (d + timedelta(minutes=period_min)).strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"""日线口径对齐 TDX 后的一次性重置:清空日线 checkpoint 与旧口径日线信号,
|
||||
下一轮扫描会用完整口径(白盘+夜盘)重判。
|
||||
|
||||
用法(生产服务器项目 server/ 目录):
|
||||
.venv/bin/python scripts/reset_daily_signals.py # 预览(不写入)
|
||||
.venv/bin/python scripts/reset_daily_signals.py --apply # 实际执行
|
||||
|
||||
注意:分钟周期(15m/30m/60m)不受影响,不动。
|
||||
"""
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
from app.config import settings # noqa: E402 # noqa: E402
|
||||
|
||||
|
||||
def resolve_db() -> str:
|
||||
if os.environ.get("XL_DB_PATH"):
|
||||
return os.environ["XL_DB_PATH"]
|
||||
env_file = os.path.join(ROOT, ".env")
|
||||
if os.path.exists(env_file):
|
||||
with open(env_file, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if line.strip().startswith("XL_DB_PATH="):
|
||||
return line.split("=", 1)[1].strip().strip('"').strip("'")
|
||||
return os.path.join(ROOT, "data", "xuanlong.db")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
apply = "--apply" in sys.argv
|
||||
db = resolve_db()
|
||||
conn = sqlite3.connect(db)
|
||||
n_sig = conn.execute("SELECT COUNT(*) FROM signals WHERE interval='1d'").fetchone()[0]
|
||||
n_ck = conn.execute("SELECT COUNT(*) FROM scan_checkpoint WHERE interval='1d'").fetchone()[0]
|
||||
# 日线信号关联的通知一并清掉(避免指向被删信号的孤儿通知)
|
||||
n_notif = conn.execute(
|
||||
"SELECT COUNT(*) FROM notifications n JOIN signals s ON n.signal_id=s.id WHERE s.interval='1d'"
|
||||
).fetchone()[0]
|
||||
print(f"日线信号 {n_sig} 条、checkpoint {n_ck} 条、关联通知 {n_notif} 条")
|
||||
if not apply:
|
||||
print("预览模式,未写入。确认无误后加 --apply 执行。")
|
||||
conn.close()
|
||||
return
|
||||
conn.execute(
|
||||
"DELETE FROM notifications WHERE signal_id IN (SELECT id FROM signals WHERE interval='1d')"
|
||||
)
|
||||
conn.execute("DELETE FROM signals WHERE interval='1d'")
|
||||
conn.execute("DELETE FROM scan_checkpoint WHERE interval='1d'")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print("✓ 已重置。扫描器下一轮(15 分钟内)会用完整口径重判日线。")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user