Add separate kline.db and pre-seed small-account four-product K-lines on startup.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-02 15:22:52 +08:00
parent 972ab5d08b
commit 5328673ce8
11 changed files with 215 additions and 33 deletions
+20 -1
View File
@@ -3,9 +3,10 @@
# 严禁用于:带单/代客理财、向他人推荐期货品种或买卖建议、融资配资等业务。
# 详见 LICENSE.zh-CN.txt 与 docs/软件购买与使用协议.md
"""K 线本地 SQLite 缓存。"""
"""K 线本地 SQLite 缓存(独立库 data/kline.db,与业务 futures.db 分离)"""
from __future__ import annotations
import os
import sqlite3
from datetime import datetime, timedelta
from typing import Optional
@@ -27,6 +28,24 @@ REFRESH_SECONDS = {
}
def connect_kline_db(path: Optional[str] = None) -> sqlite3.Connection:
"""K 线专用 SQLite(生产环境业务库可为 PostgreSQL,K 线仍走本地文件)。"""
from modules.core.paths import KLINE_DB_PATH
db_path = path or KLINE_DB_PATH
parent = os.path.dirname(db_path)
if parent:
os.makedirs(parent, exist_ok=True)
conn = sqlite3.connect(db_path, timeout=30, check_same_thread=False)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA busy_timeout=30000")
try:
conn.execute("PRAGMA journal_mode=WAL")
except sqlite3.OperationalError:
pass
return conn
def ensure_kline_tables(conn: sqlite3.Connection) -> None:
conn.execute(
"""CREATE TABLE IF NOT EXISTS kline_bars (