This commit is contained in:
aaron 2025-09-18 23:11:03 +08:00
parent ca52f20c85
commit c8066cf432
4 changed files with 137 additions and 6 deletions

View File

@ -26,11 +26,11 @@ RUN pip install --no-cache-dir -r requirements.txt
# 复制项目文件
COPY . .
# 创建数据目录
RUN mkdir -p /app/data
# 创建必要的目录
RUN mkdir -p /app/data /app/logs /app/config
# 设置权限
RUN chmod +x start_web.py
RUN chmod +x start_web.py scripts/init_container.sh
# 暴露端口
EXPOSE 8080
@ -39,5 +39,8 @@ EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/api/stats || exit 1
# 设置入口点
ENTRYPOINT ["/app/scripts/init_container.sh"]
# 启动命令
CMD ["python", "start_web.py"]

View File

@ -34,7 +34,8 @@ services:
environment:
- PYTHONPATH=/app
# 运行数据采集脚本
command: python scripts/data_collector.py
entrypoint: ["/app/scripts/init_container.sh"]
command: ["python", "scripts/data_collector.py"]
restart: unless-stopped
depends_on:
- trading-web

View File

@ -35,16 +35,18 @@ def run_strategy():
data_fetcher = ADataFetcher()
# 初始化通知管理器
notification_manager = NotificationManager(config)
notification_config = config.get('notification', {})
notification_manager = NotificationManager(notification_config)
# 初始化数据库管理器
db_manager = DatabaseManager()
# 初始化策略
strategy_config = config.get('strategy', {}).get('kline_pattern', {})
strategy = KLinePatternStrategy(
data_fetcher=data_fetcher,
notification_manager=notification_manager,
config=config,
config=strategy_config,
db_manager=db_manager
)

125
scripts/init_container.sh Normal file
View File

@ -0,0 +1,125 @@
#!/bin/bash
# 容器初始化脚本
# 确保配置文件存在
CONFIG_DIR="/app/config"
CONFIG_FILE="$CONFIG_DIR/config.yaml"
# 创建配置目录(如果不存在)
mkdir -p $CONFIG_DIR
# 如果配置文件不存在,创建默认配置文件
if [ ! -f "$CONFIG_FILE" ]; then
echo "创建默认配置文件: $CONFIG_FILE"
cat > "$CONFIG_FILE" << 'EOF'
# A股量化交易配置文件
trading:
# 交易时间配置
trading_hours:
start: "09:30:00"
end: "15:00:00"
lunch_break_start: "11:30:00"
lunch_break_end: "13:00:00"
# 股票池配置
stock_pool:
# 默认关注的指数成分股
index_codes: ["000001.SZ", "000300.SZ", "000905.SZ"] # 上证指数、沪深300、中证500
# 排除的股票代码
exclude_codes: []
# 风险控制
risk_management:
max_position_per_stock: 0.05 # 单股最大仓位比例
max_total_position: 0.9 # 最大总仓位比例
stop_loss_ratio: 0.05 # 止损比例
take_profit_ratio: 0.15 # 止盈比例
# 数据配置
data:
# 数据源配置
sources:
primary: "adata"
# 数据更新频率
update_frequency:
realtime: "1min" # 实时数据更新频率
daily: "after_close" # 日线数据更新时机
# 数据存储
storage:
path: "data/"
format: "parquet" # 数据存储格式
# 策略配置
strategy:
# 技术指标参数
indicators:
ma_periods: [5, 10, 20, 50] # 移动平均线周期
rsi_period: 14 # RSI周期
macd_params: [12, 26, 9] # MACD参数
# 选股条件
selection_criteria:
min_market_cap: 1000000000 # 最小市值(元)
max_pe_ratio: 30 # 最大市盈率
min_volume_ratio: 1.5 # 最小成交量比率
# K线形态策略配置
kline_pattern:
enabled: true # 是否启用K线形态策略
min_entity_ratio: 0.55 # 前两根阳线实体最小占振幅比例55%
final_yang_min_ratio: 0.40 # 最后阳线实体最小占振幅比例40%
timeframes: ["1h", "daily", "weekly"] # 支持的时间周期
scan_stocks_count: 100 # Docker环境默认扫描股票数量
analysis_days: 60 # 分析的历史天数
# 回踩监控配置
pullback_tolerance: 0.02 # 回踩容忍度2%),价格接近阴线最高点的阈值
monitor_days: 30 # 监控回踩的天数信号触发后30天内监控
# 监控配置
monitor:
# 实时监控
realtime:
enabled: true
refresh_interval: 60 # 刷新间隔(秒)
# 报警配置
alerts:
price_change_threshold: 0.05 # 价格变动报警阈值
volume_spike_threshold: 3.0 # 成交量异常报警阈值
# 日志配置
logging:
level: "INFO"
format: "{time:YYYY-MM-DD HH:mm:ss} | {level} | {name} | {message}"
rotation: "1 day"
retention: "30 days"
file_path: "logs/trading.log"
# 通知配置
notification:
# 钉钉机器人配置
dingtalk:
enabled: false # Docker环境默认关闭通知
webhook_url: "" # 钉钉机器人webhook地址
secret: "" # 加签密钥
at_all: false # 是否@所有人
at_mobiles: [] # @指定手机号列表
# 其他通知方式
email:
enabled: false # 邮件通知(预留)
wechat:
enabled: false # 微信通知(预留)
EOF
echo "默认配置文件已创建"
else
echo "配置文件已存在: $CONFIG_FILE"
fi
# 执行传入的命令
exec "$@"