2b5a32ca1e
新增模块: - fund_flow_analyzer.py: 主力资金流向分析(P0, ±20) - market_sentiment.py: 市场情绪指标(P1, ±10) - external_factors.py: 北向资金/美股/大宗商品/汇率(P2-P4,P7) - news_analyzer.py: 公告/并购/政策面LLM分析(P5-P6) - score_engine.py: 综合评分引擎,整合技术面+外部因素 路由更新: - analysis.py: deep_analyze接入综合评分,根据最终评级修正买卖建议 - market.py: 新增4个外部因素API端点 - trades.py: 交易路由更新 算法文档重构: - 章节重排: 技术面(二三)→外部因素(四)→买卖决策(五)→数据源(六)→性能(七) - 架构图更新为五层,标注章节对应 - 5.1/5.2标注纯技术面,5.3整合外部因素修正推荐
95 lines
2.4 KiB
Python
95 lines
2.4 KiB
Python
"""
|
||
股票投资分析系统 - 主应用入口
|
||
"""
|
||
from flask import Flask, render_template, jsonify
|
||
from flask_cors import CORS
|
||
from config import Config
|
||
|
||
# 初始化配置
|
||
Config.init_app()
|
||
|
||
# 创建Flask应用
|
||
app = Flask(__name__, template_folder='templates', static_folder='static')
|
||
app.config['SECRET_KEY'] = Config.SECRET_KEY
|
||
CORS(app, supports_credentials=True)
|
||
|
||
# 初始化数据库连接池
|
||
from db import init_db_pool
|
||
init_db_pool()
|
||
|
||
# 注册路由蓝图
|
||
from routes.auth import bp as auth_bp
|
||
from routes.trades import bp as trades_bp
|
||
from routes.watchlist import bp as watchlist_bp
|
||
from routes.analysis import bp as analysis_bp
|
||
from routes.market import bp as market_bp
|
||
from routes.sim_trade import bp as sim_trade_bp
|
||
from routes.admin import bp as admin_bp
|
||
from routes.smart_trade import bp as smart_trade_bp
|
||
|
||
app.register_blueprint(auth_bp)
|
||
app.register_blueprint(trades_bp)
|
||
app.register_blueprint(watchlist_bp)
|
||
app.register_blueprint(analysis_bp)
|
||
app.register_blueprint(market_bp)
|
||
app.register_blueprint(sim_trade_bp)
|
||
app.register_blueprint(admin_bp)
|
||
app.register_blueprint(smart_trade_bp)
|
||
|
||
|
||
# ========== 基础路由 ==========
|
||
|
||
@app.route('/')
|
||
def index():
|
||
"""首页"""
|
||
return render_template('index.html')
|
||
|
||
|
||
@app.route('/api/health', methods=['GET'])
|
||
def health():
|
||
"""健康检查"""
|
||
return jsonify({'status': 'ok', 'message': '服务运行正常'})
|
||
|
||
|
||
# ========== 静态文件安全 ==========
|
||
|
||
@app.route('/robots.txt')
|
||
def robots():
|
||
return "User-agent: *\nDisallow: /api/\nDisallow: /admin\n", 200, {'Content-Type': 'text/plain'}
|
||
|
||
|
||
@app.route('/.env')
|
||
def block_env():
|
||
from flask import abort
|
||
abort(404)
|
||
|
||
|
||
# ========== 启动 ==========
|
||
|
||
_scheduler_started = False
|
||
|
||
|
||
def _start_scheduler_once():
|
||
"""确保调度器只启动一次(兼容 gunicorn preload + Flask dev reloader)"""
|
||
global _scheduler_started
|
||
if _scheduler_started:
|
||
return
|
||
_scheduler_started = True
|
||
from services.scheduler import start_scheduler
|
||
start_scheduler()
|
||
|
||
|
||
if __name__ == '__main__':
|
||
print("=" * 60)
|
||
print("股票投资分析系统启动")
|
||
print("=" * 60)
|
||
print(f"Web界面: http://localhost:{Config.PORT}")
|
||
print(f"API地址: http://localhost:{Config.PORT}/api/")
|
||
print(f"健康检查: http://localhost:{Config.PORT}/api/health")
|
||
print("=" * 60)
|
||
|
||
_start_scheduler_once()
|
||
app.run(debug=True, host='0.0.0.0', port=Config.PORT)
|
||
else:
|
||
_start_scheduler_once()
|