From 9fc41b6a46fdd791b8d0123a298cfbe773aac231 Mon Sep 17 00:00:00 2001 From: dekun Date: Mon, 15 Jun 2026 11:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=AF=E5=8A=A8=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=9Aexpire=5Fold=5Fplans=20=E5=9C=A8=20init=5Fdb?= =?UTF-8?q?=20=E5=89=8D=E6=9C=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- app.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 46c8fe4..de83e51 100644 --- a/app.py +++ b/app.py @@ -43,6 +43,21 @@ KLINE_CUTOFFS = ["平仓时间", "开仓时间", "当前时间"] def today_str() -> str: return datetime.now(TZ).date().isoformat() + +def expire_old_plans(): + """当日结束后计划自动失效,保留历史。""" + today = today_str() + conn = get_db() + conn.execute( + "UPDATE order_plans SET status='expired' WHERE plan_date < ? AND status IN ('planned', 'active')", + (today,), + ) + conn.execute( + "UPDATE order_plans SET plan_date=date(created_at) WHERE plan_date IS NULL OR plan_date=''" + ) + conn.commit() + conn.close() + # —————————————— 设置读写 —————————————— def get_db(): @@ -211,23 +226,6 @@ def fetch_price(ths_code: str, market_code: str = "", sina_code: str = "") -> Op # —————————————— 监控逻辑 —————————————— -# —————————————— 开单计划(按日) —————————————— - -def expire_old_plans(): - """当日结束后计划自动失效,保留历史。""" - today = today_str() - conn = get_db() - conn.execute( - "UPDATE order_plans SET status='expired' WHERE plan_date < ? AND status IN ('planned', 'active')", - (today,), - ) - conn.execute( - "UPDATE order_plans SET plan_date=date(created_at) WHERE plan_date IS NULL OR plan_date=''" - ) - conn.commit() - conn.close() - - def check_order_plans(): expire_old_plans() today = today_str()