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:
@@ -11,7 +11,7 @@ _legacy = os.path.join(_ROOT, "_legacy")
|
||||
if _legacy not in sys.path:
|
||||
sys.path.insert(0, _legacy)
|
||||
|
||||
from modules.core.paths import ROOT, UPLOADS_DIR, DB_PATH, ensure_runtime_dirs, resolve_env_file
|
||||
from modules.core.paths import ROOT, UPLOADS_DIR, DB_PATH, KLINE_DB_PATH, ensure_runtime_dirs, resolve_env_file
|
||||
from locale_fix import ensure_process_locale
|
||||
|
||||
ensure_process_locale()
|
||||
@@ -60,7 +60,7 @@ from stats_engine import (
|
||||
load_stats_cache,
|
||||
refresh_stats_cache,
|
||||
)
|
||||
from kline_store import ensure_kline_tables
|
||||
from kline_store import connect_kline_db, ensure_kline_tables
|
||||
from kline_stream import kline_hub, sse_format
|
||||
from kline_chart import generate_review_kline_chart, fetch_market_klines, MARKET_PERIODS
|
||||
from market import (
|
||||
@@ -456,7 +456,6 @@ def init_db():
|
||||
if not is_schema_migration_error(exc):
|
||||
raise
|
||||
rollback_if_postgres(conn)
|
||||
ensure_kline_tables(conn)
|
||||
init_strategy_tables(conn)
|
||||
from risk.account_risk_lib import ensure_account_risk_schema
|
||||
from recommend_store import ensure_recommend_tables
|
||||
@@ -761,7 +760,6 @@ def check_order_plans():
|
||||
|
||||
|
||||
def check_key_monitors():
|
||||
from db_conn import DB_PATH
|
||||
from key_monitor_lib import run_key_monitor_check
|
||||
from trading_context import get_trading_mode
|
||||
|
||||
@@ -770,7 +768,7 @@ def check_key_monitors():
|
||||
execute_fn = getattr(app, "_execute_key_breakout", None)
|
||||
run_key_monitor_check(
|
||||
conn,
|
||||
db_path=DB_PATH,
|
||||
db_path=KLINE_DB_PATH,
|
||||
get_trading_mode_fn=lambda: get_trading_mode(get_setting),
|
||||
send_wechat=send_wechat_msg,
|
||||
execute_breakout_fn=execute_fn,
|
||||
@@ -799,11 +797,20 @@ def background_task():
|
||||
|
||||
def start_background_threads():
|
||||
from trading_context import get_trading_mode
|
||||
from modules.market.kline_seed import start_small_account_kline_seed
|
||||
|
||||
try:
|
||||
kconn = connect_kline_db(KLINE_DB_PATH)
|
||||
ensure_kline_tables(kconn)
|
||||
kconn.close()
|
||||
except Exception as exc:
|
||||
app.logger.warning("kline db init: %s", exc)
|
||||
start_small_account_kline_seed(db_path=KLINE_DB_PATH)
|
||||
|
||||
threading.Thread(target=background_task, daemon=True).start()
|
||||
threading.Thread(
|
||||
target=lambda: kline_hub.worker_loop(
|
||||
DB_PATH,
|
||||
KLINE_DB_PATH,
|
||||
lambda sym, mc, sc: build_market_quote_payload(
|
||||
sym, mc, sc, prefer_sina=False,
|
||||
),
|
||||
@@ -849,6 +856,7 @@ if os.getenv("QIHUO_INIT_ONLY") != "1":
|
||||
start_background_threads=start_background_threads,
|
||||
tz=TZ,
|
||||
db_path=DB_PATH,
|
||||
kline_db_path=KLINE_DB_PATH,
|
||||
upload_dir=UPLOAD_DIR,
|
||||
open_types=OPEN_TYPES,
|
||||
exit_triggers=EXIT_TRIGGERS,
|
||||
|
||||
Reference in New Issue
Block a user