123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- module.exports = {
- apps: [
- {
- name: 'complete-trading-system',
- script: 'run-production.ts',
- interpreter: 'tsx',
- instances: 1,
- autorestart: true,
- watch: false,
- max_memory_restart: '1G',
- // 环境变量
- env: {
- NODE_ENV: 'development',
- LOG_LEVEL: 'info',
- HEALTH_CHECK_PORT: 3001,
- },
- env_production: {
- NODE_ENV: 'production',
- LOG_LEVEL: 'info',
- LOG_DIR: './logs',
- HEALTH_CHECK_PORT: 3001,
- ENABLE_HEALTH_API: 'true',
- ENABLE_STRUCTURED_LOGGING: 'true',
- },
- // 日志配置 - 对冲交易系统需要详细的日志记录
- log_file: './logs/pm2-combined.log',
- out_file: './logs/pm2-out.log',
- error_file: './logs/pm2-error.log',
- log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
- // 重启策略 - 对冲系统需要稳定运行
- min_uptime: '30s', // 最少运行30秒才认为启动成功
- max_restarts: 5, // 最大重启次数
- restart_delay: 5000, // 重启延迟5秒
- // 监控配置
- pmx: true,
- monitoring: {
- // 对冲交易关键指标监控
- custom_probes: [
- {
- name: 'Active Positions',
- agg_type: 'avg',
- },
- {
- name: 'Global Delta',
- agg_type: 'avg',
- },
- {
- name: 'Hedge Executions/min',
- agg_type: 'sum',
- },
- ],
- },
- // 进程配置
- exec_mode: 'fork', // 对冲系统使用fork模式,避免cluster模式的状态问题
- // 优雅关闭配置 - 确保对冲仓位安全关闭
- kill_timeout: 30000, // 30秒优雅关闭时间
- wait_ready: true, // 等待应用就绪信号
- listen_timeout: 10000, // 监听超时10秒
- // 健康检查配置
- health_check: {
- endpoint: 'http://localhost:3001/health',
- interval: 30000, // 30秒检查一次
- timeout: 10000, // 10秒超时
- unhealthy_threshold: 3, // 连续3次失败认为不健康
- healthy_threshold: 2, // 连续2次成功认为健康
- },
- },
- ],
- // 部署配置
- deploy: {
- production: {
- user: 'deploy',
- host: ['production-server'],
- ref: 'origin/main',
- repo: 'git@github.com:your-repo/trading-hedge-system.git',
- path: '/var/www/trading-hedge-system',
- 'pre-deploy-local': '',
- 'post-deploy': 'yarn install && yarn build && pm2 reload ecosystem.config.js --env production',
- 'pre-setup': '',
- // 对冲系统特殊部署要求
- 'pre-deploy': [
- 'echo "检查当前持仓状态..."',
- 'curl -s http://localhost:3001/health/positions || echo "系统未运行"',
- ].join(' && '),
- 'post-deploy-actions': [
- 'sleep 10', // 等待系统启动
- 'curl -f http://localhost:3001/health || exit 1', // 健康检查
- 'echo "对冲交易系统部署完成"',
- ].join(' && '),
- },
- staging: {
- user: 'deploy',
- host: ['staging-server'],
- ref: 'origin/develop',
- repo: 'git@github.com:your-repo/trading-hedge-system.git',
- path: '/var/www/trading-hedge-system-staging',
- 'post-deploy': 'yarn install && yarn build && pm2 reload ecosystem.config.js --env staging',
- },
- },
- }
|