update watchlist
This commit is contained in:
51
app.py
51
app.py
@@ -5487,31 +5487,7 @@ def add_to_watchlist():
|
|||||||
return jsonify({'success': True, 'data': {'id': item.id}})
|
return jsonify({'success': True, 'data': {'id': item.id}})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/account/watchlist/<string:stock_code>', methods=['DELETE'])
|
# 注意:/realtime 路由必须在 /<stock_code> 之前定义,否则会被错误匹配
|
||||||
def remove_from_watchlist(stock_code):
|
|
||||||
"""从自选股移除"""
|
|
||||||
if 'user_id' not in session:
|
|
||||||
return jsonify({'success': False, 'error': '未登录'}), 401
|
|
||||||
|
|
||||||
code6, _ = _normalize_stock_input(stock_code)
|
|
||||||
candidates = []
|
|
||||||
if code6:
|
|
||||||
candidates = [code6, f"{code6}.SH", f"{code6}.SZ"]
|
|
||||||
# 包含原始传入(以兼容历史)
|
|
||||||
if stock_code not in candidates:
|
|
||||||
candidates.append(stock_code)
|
|
||||||
|
|
||||||
item = Watchlist.query.filter(
|
|
||||||
Watchlist.user_id == session['user_id'],
|
|
||||||
Watchlist.stock_code.in_(candidates)
|
|
||||||
).first()
|
|
||||||
if not item:
|
|
||||||
return jsonify({'success': False, 'error': '未找到自选项'}), 404
|
|
||||||
db.session.delete(item)
|
|
||||||
db.session.commit()
|
|
||||||
return jsonify({'success': True})
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/account/watchlist/realtime', methods=['GET'])
|
@app.route('/api/account/watchlist/realtime', methods=['GET'])
|
||||||
def get_watchlist_realtime():
|
def get_watchlist_realtime():
|
||||||
"""获取自选股实时行情数据(基于分钟线)- 优化为批量查询"""
|
"""获取自选股实时行情数据(基于分钟线)- 优化为批量查询"""
|
||||||
@@ -5675,6 +5651,31 @@ def get_watchlist_realtime():
|
|||||||
return jsonify({'success': False, 'error': '获取实时行情失败'}), 500
|
return jsonify({'success': False, 'error': '获取实时行情失败'}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/account/watchlist/<string:stock_code>', methods=['DELETE'])
|
||||||
|
def remove_from_watchlist(stock_code):
|
||||||
|
"""从自选股移除"""
|
||||||
|
if 'user_id' not in session:
|
||||||
|
return jsonify({'success': False, 'error': '未登录'}), 401
|
||||||
|
|
||||||
|
code6, _ = _normalize_stock_input(stock_code)
|
||||||
|
candidates = []
|
||||||
|
if code6:
|
||||||
|
candidates = [code6, f"{code6}.SH", f"{code6}.SZ"]
|
||||||
|
# 包含原始传入(以兼容历史)
|
||||||
|
if stock_code not in candidates:
|
||||||
|
candidates.append(stock_code)
|
||||||
|
|
||||||
|
item = Watchlist.query.filter(
|
||||||
|
Watchlist.user_id == session['user_id'],
|
||||||
|
Watchlist.stock_code.in_(candidates)
|
||||||
|
).first()
|
||||||
|
if not item:
|
||||||
|
return jsonify({'success': False, 'error': '未找到自选项'}), 404
|
||||||
|
db.session.delete(item)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({'success': True})
|
||||||
|
|
||||||
|
|
||||||
# 投资计划和复盘相关的模型
|
# 投资计划和复盘相关的模型
|
||||||
class InvestmentPlan(db.Model):
|
class InvestmentPlan(db.Model):
|
||||||
__tablename__ = 'investment_plans'
|
__tablename__ = 'investment_plans'
|
||||||
|
|||||||
Reference in New Issue
Block a user