ecosystem.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. module.exports = {
  2. apps: [
  3. {
  4. name: 'complete-trading-system',
  5. script: 'run-production.ts',
  6. interpreter: 'tsx',
  7. instances: 1,
  8. autorestart: true,
  9. watch: false,
  10. max_memory_restart: '1G',
  11. // 环境变量
  12. env: {
  13. NODE_ENV: 'development',
  14. LOG_LEVEL: 'info',
  15. HEALTH_CHECK_PORT: 3001,
  16. },
  17. env_production: {
  18. NODE_ENV: 'production',
  19. LOG_LEVEL: 'info',
  20. LOG_DIR: './logs',
  21. HEALTH_CHECK_PORT: 3001,
  22. ENABLE_HEALTH_API: 'true',
  23. ENABLE_STRUCTURED_LOGGING: 'true',
  24. },
  25. // 日志配置 - 对冲交易系统需要详细的日志记录
  26. log_file: './logs/pm2-combined.log',
  27. out_file: './logs/pm2-out.log',
  28. error_file: './logs/pm2-error.log',
  29. log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
  30. // 重启策略 - 对冲系统需要稳定运行
  31. min_uptime: '30s', // 最少运行30秒才认为启动成功
  32. max_restarts: 5, // 最大重启次数
  33. restart_delay: 5000, // 重启延迟5秒
  34. // 监控配置
  35. pmx: true,
  36. monitoring: {
  37. // 对冲交易关键指标监控
  38. custom_probes: [
  39. {
  40. name: 'Active Positions',
  41. agg_type: 'avg',
  42. },
  43. {
  44. name: 'Global Delta',
  45. agg_type: 'avg',
  46. },
  47. {
  48. name: 'Hedge Executions/min',
  49. agg_type: 'sum',
  50. },
  51. ],
  52. },
  53. // 进程配置
  54. exec_mode: 'fork', // 对冲系统使用fork模式,避免cluster模式的状态问题
  55. // 优雅关闭配置 - 确保对冲仓位安全关闭
  56. kill_timeout: 30000, // 30秒优雅关闭时间
  57. wait_ready: true, // 等待应用就绪信号
  58. listen_timeout: 10000, // 监听超时10秒
  59. // 健康检查配置
  60. health_check: {
  61. endpoint: 'http://localhost:3001/health',
  62. interval: 30000, // 30秒检查一次
  63. timeout: 10000, // 10秒超时
  64. unhealthy_threshold: 3, // 连续3次失败认为不健康
  65. healthy_threshold: 2, // 连续2次成功认为健康
  66. },
  67. },
  68. ],
  69. // 部署配置
  70. deploy: {
  71. production: {
  72. user: 'deploy',
  73. host: ['production-server'],
  74. ref: 'origin/main',
  75. repo: 'git@github.com:your-repo/trading-hedge-system.git',
  76. path: '/var/www/trading-hedge-system',
  77. 'pre-deploy-local': '',
  78. 'post-deploy': 'yarn install && yarn build && pm2 reload ecosystem.config.js --env production',
  79. 'pre-setup': '',
  80. // 对冲系统特殊部署要求
  81. 'pre-deploy': [
  82. 'echo "检查当前持仓状态..."',
  83. 'curl -s http://localhost:3001/health/positions || echo "系统未运行"',
  84. ].join(' && '),
  85. 'post-deploy-actions': [
  86. 'sleep 10', // 等待系统启动
  87. 'curl -f http://localhost:3001/health || exit 1', // 健康检查
  88. 'echo "对冲交易系统部署完成"',
  89. ].join(' && '),
  90. },
  91. staging: {
  92. user: 'deploy',
  93. host: ['staging-server'],
  94. ref: 'origin/develop',
  95. repo: 'git@github.com:your-repo/trading-hedge-system.git',
  96. path: '/var/www/trading-hedge-system-staging',
  97. 'post-deploy': 'yarn install && yarn build && pm2 reload ecosystem.config.js --env staging',
  98. },
  99. },
  100. }