fix: 修复连接池泄漏(conn.close改为put_db) + put_db处理已关闭连接 + 添加日线同步cron
This commit is contained in:
@@ -29,7 +29,7 @@ def init_user_config(user_id):
|
||||
cur.execute("SELECT * FROM sim_config WHERE user_id = %s", (user_id,))
|
||||
return cur.fetchone()
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/config', methods=['GET'])
|
||||
@@ -82,7 +82,7 @@ def update_config():
|
||||
conn.rollback()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/trades', methods=['GET'])
|
||||
@@ -114,7 +114,7 @@ def get_trades():
|
||||
trades = cur.fetchall()
|
||||
return jsonify({'success': True, 'trades': trades})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/positions', methods=['GET'])
|
||||
@@ -140,7 +140,7 @@ def get_positions():
|
||||
positions = cur.fetchall()
|
||||
return jsonify({'success': True, 'positions': positions})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/stats', methods=['GET'])
|
||||
@@ -261,7 +261,7 @@ def get_stats():
|
||||
'history': list(reversed(history)) if history else []
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/execute', methods=['POST'])
|
||||
@@ -381,7 +381,7 @@ def execute_trade():
|
||||
traceback.print_exc()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/auto_execute', methods=['POST'])
|
||||
@@ -532,7 +532,7 @@ def auto_execute():
|
||||
traceback.print_exc()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/update_prices', methods=['POST'])
|
||||
@@ -588,7 +588,7 @@ def update_prices():
|
||||
conn.rollback()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/reset', methods=['POST'])
|
||||
@@ -612,7 +612,7 @@ def reset_simulation():
|
||||
conn.rollback()
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/trigger_trade', methods=['POST'])
|
||||
@@ -628,7 +628,7 @@ def trigger_trade():
|
||||
conn = get_db()
|
||||
if conn:
|
||||
result = execute_smart_trade(conn, user_id, scan_date=None)
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
if result.get('success'):
|
||||
results = result.get('results', [])
|
||||
buy_count = len([r for r in results if r['type'] == 'buy'])
|
||||
@@ -651,7 +651,7 @@ def trigger_trade():
|
||||
cur.execute("SELECT trade_quantity FROM sim_config WHERE user_id = %s", (user_id,))
|
||||
config = cur.fetchone()
|
||||
trade_quantity = config['trade_quantity'] if config else 1000
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
else:
|
||||
trade_quantity = 1000
|
||||
|
||||
@@ -730,4 +730,4 @@ def get_today_trades():
|
||||
}
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
Reference in New Issue
Block a user