fix: 修复6个数据和代码问题
1. 修复 _generate_plain_summary position key 不匹配 (20d→d20, pct→range_pct) 2. 修复 mairui_api.py 日期解析不一致及 float(None) 崩溃风险 3. 修复 fund_flow_analyzer.py 麦蕊回退数据 close_price=0 导致量价背离误判 4. 修复 db_get_fund_flow_history 缺少完整字段和日期过滤 5. 修复 scheduler.py 连接池泄漏 (conn.close() → put_db(conn)) 6. 修复多处北交所股票代码映射缺失 (8/9开头→bj)
This commit is contained in:
@@ -101,7 +101,7 @@ def is_trading_time():
|
||||
|
||||
def get_all_users():
|
||||
"""获取所有启用自动交易的用户"""
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
conn = get_db()
|
||||
@@ -121,7 +121,7 @@ def get_all_users():
|
||||
print(f"[定时任务] 获取用户列表失败: {e}")
|
||||
return []
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
# 自定义股票列表(100只精选股票)
|
||||
@@ -168,7 +168,7 @@ def execute_auto_trade_for_user(user_id, trade_quantity=1000, scan_date=None):
|
||||
|
||||
scan_date: 使用哪天的扫描数据, None则自动选择最近可用的
|
||||
"""
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
print(f"[定时任务] 开始为用户{user_id}执行策略交易(统一推荐算法)...")
|
||||
@@ -407,7 +407,7 @@ def execute_auto_trade_for_user(user_id, trade_quantity=1000, scan_date=None):
|
||||
traceback.print_exc()
|
||||
return {'error': str(e)}
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def _get_latest_price(stock_code):
|
||||
@@ -417,7 +417,7 @@ def _get_latest_price(stock_code):
|
||||
|
||||
def update_positions_price_for_user(user_id):
|
||||
"""更新用户持仓的当前价格(收盘时调用)— 使用腾讯财经API"""
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
conn = get_db()
|
||||
@@ -443,6 +443,8 @@ def update_positions_price_for_user(user_id):
|
||||
for c in codes:
|
||||
if c.startswith('6'):
|
||||
tencent_codes.append(f'sh{c}')
|
||||
elif c.startswith('8') or c.startswith('9'):
|
||||
tencent_codes.append(f'bj{c}')
|
||||
else:
|
||||
tencent_codes.append(f'sz{c}')
|
||||
_r = _req.get(f'http://qt.gtimg.cn/q={",".join(tencent_codes)}',
|
||||
@@ -492,7 +494,7 @@ def update_positions_price_for_user(user_id):
|
||||
conn.rollback()
|
||||
print(f"[定时任务] 更新用户{user_id}持仓价格失败: {e}")
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
def job_morning_trade():
|
||||
@@ -514,11 +516,11 @@ def job_morning_trade():
|
||||
# 尝试使用智能引擎
|
||||
try:
|
||||
from services.smart_trade_engine import execute_smart_trade
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
conn = get_db()
|
||||
if conn:
|
||||
result = execute_smart_trade(conn, user_id, scan_date=None)
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
if result.get('success'):
|
||||
print(f"[定时任务] 用户{user_id} 智能引擎执行成功 "
|
||||
f"(算法:{result.get('algo','?')}, 信号:{result.get('signals',0)})")
|
||||
@@ -553,11 +555,11 @@ def job_afternoon_trade():
|
||||
# 尝试使用智能引擎
|
||||
try:
|
||||
from services.smart_trade_engine import execute_smart_trade
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
conn = get_db()
|
||||
if conn:
|
||||
result = execute_smart_trade(conn, user_id, scan_date=today)
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
if result.get('success'):
|
||||
print(f"[定时任务] 用户{user_id} 午后智能引擎执行成功")
|
||||
continue
|
||||
@@ -645,7 +647,7 @@ def trigger_afternoon_trade():
|
||||
|
||||
def trigger_closing_update():
|
||||
"""手动触发收盘更新(仅更新持仓价格)"""
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
if not is_trading_day():
|
||||
print("[定时任务] 今天不是交易日,跳过")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user