refactor: 缠论引擎包化与 Web 分层(ECR-001)
将根目录引擎迁入 chanlun/ 并保留兼容 shim;拆分 TF_DF 与 web 服务; 前端模块化;strategies 改用 chanlun 导入;补充 ESS 文档与 golden 回归。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
"""交易对 / A股 / MACD 配置 API。"""
|
||||
from flask import Blueprint, jsonify, request
|
||||
from services.runtime import * # noqa: F403
|
||||
|
||||
bp = Blueprint("symbols", __name__)
|
||||
|
||||
@bp.route('/api/symbols')
|
||||
def get_symbols():
|
||||
"""获取可用交易对"""
|
||||
refresh_data_service_metadata()
|
||||
if SYMBOLS:
|
||||
return jsonify(SYMBOLS)
|
||||
try:
|
||||
markets = exchange.load_markets()
|
||||
# 合约交易对通常是以USDT结尾的永续合约
|
||||
symbols = [symbol for symbol in markets.keys() if '/USDT' in symbol and ':USDT' in symbol]
|
||||
return jsonify(symbols)
|
||||
except Exception as e:
|
||||
return jsonify(DEFAULT_SYMBOLS)
|
||||
|
||||
@bp.route('/api/a_stocks')
|
||||
def get_a_stocks():
|
||||
"""获取A股股票列表"""
|
||||
try:
|
||||
stock_list = china_stock.get_stock_list()
|
||||
return jsonify(stock_list)
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@bp.route('/api/popular_a_stocks')
|
||||
def get_popular_a_stocks():
|
||||
"""获取热门A股股票"""
|
||||
try:
|
||||
return jsonify(china_stock.get_popular_stocks())
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@bp.route('/api/sectors')
|
||||
def get_sectors():
|
||||
"""获取所有行业分类"""
|
||||
try:
|
||||
sectors = china_stock.get_all_sectors()
|
||||
return jsonify(sectors)
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@bp.route('/api/stocks_by_sector')
|
||||
def get_stocks_by_sector():
|
||||
"""根据行业获取股票"""
|
||||
try:
|
||||
sector = request.args.get('sector')
|
||||
if sector:
|
||||
stocks = china_stock.get_stock_by_sector(sector)
|
||||
return jsonify(stocks)
|
||||
else:
|
||||
# 返回所有行业的股票分组
|
||||
all_sectors = china_stock.get_stock_by_sector()
|
||||
return jsonify(all_sectors)
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@bp.route('/api/search_stock')
|
||||
def search_stock():
|
||||
"""搜索股票 - 增强版"""
|
||||
try:
|
||||
keyword = request.args.get('keyword', '')
|
||||
if not keyword:
|
||||
return jsonify({'error': '搜索关键词不能为空'})
|
||||
|
||||
results = china_stock.search_stock(keyword)
|
||||
return jsonify(results)
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
|
||||
@bp.route('/api/macd_config', methods=['GET', 'POST'])
|
||||
def macd_config():
|
||||
"""获取或设置MACD参数"""
|
||||
global macd_fast_period, macd_slow_period, macd_signal_period
|
||||
if request.method == 'GET':
|
||||
return jsonify({
|
||||
'fast': macd_fast_period,
|
||||
'slow': macd_slow_period,
|
||||
'signal': macd_signal_period
|
||||
})
|
||||
else:
|
||||
data = request.get_json(silent=True) or {}
|
||||
fast = data.get('fast')
|
||||
slow = data.get('slow')
|
||||
signal = data.get('signal')
|
||||
if fast is not None:
|
||||
macd_fast_period = int(fast)
|
||||
if slow is not None:
|
||||
macd_slow_period = int(slow)
|
||||
if signal is not None:
|
||||
macd_signal_period = int(signal)
|
||||
return jsonify({
|
||||
'fast': macd_fast_period,
|
||||
'slow': macd_slow_period,
|
||||
'signal': macd_signal_period
|
||||
})
|
||||
Reference in New Issue
Block a user