Skip to the content.

PM2 Ecosystem Configuration

PM2 manages all SKYNET processes. The ecosystem file defines which engines run, how they restart, and resource limits.


File Location

/app/trading_engine/ecosystem.config.cjs

Required Processes (Infrastructure)

These must run before any scanner:

module.exports = {
  apps: [
    // Layer 1: Candle Cache Service
    {
      name: 'candle-cache',
      script: 'candle_cache_service.mjs',
      cwd: '/app/trading_engine',
      autorestart: true,
      restart_delay: 5000,
      max_memory_restart: '150M',
    },

    // Layer 2: Candle Cache Bridge
    {
      name: 'candle-bridge',
      script: 'scripts/candle_cache_bridge.mjs',
      cwd: '/app/trading_engine',
      autorestart: true,
      restart_delay: 5000,
      max_memory_restart: '100M',
    },

    // Layer 3: Market Data Service (REST fallback)
    {
      name: 'market-data',
      script: 'market_data_service.mjs',
      cwd: '/app/trading_engine',
      autorestart: true,
      restart_delay: 5000,
    },

    // Layer 4: Trade Tracker (HyperOpt)
    {
      name: 'trade-tracker',
      script: 'core/trade_tracker.mjs',
      cwd: '/app/trading_engine',
      autorestart: true,
      restart_delay: 10000,
    },

    // Layer 5: Your Scanner
    {
      name: 'my-scanner',
      script: 'scripts/my_scanner.mjs',
      cwd: '/app/trading_engine',
      autorestart: true,
      restart_delay: 5000,
      max_memory_restart: '150M',
    },
  ]
};

Process Dependencies

graph TD
    CCS[candle-cache] --> CB[candle-bridge]
    CB --> SCANNER[your-scanner]
    MD[market-data] -.fallback.-> SCANNER
    TT[trade-tracker] -.reads.-> SCANNER

Start order matters:

  1. candle-cache first (creates data)
  2. candle-bridge second (splits data)
  3. Scanners last (consume data)

Common PM2 Commands

# Start all processes
pm2 start ecosystem.config.cjs

# Start only infrastructure
pm2 start ecosystem.config.cjs --only candle-cache,candle-bridge

# Start only your scanner
pm2 start ecosystem.config.cjs --only my-scanner

# View logs
pm2 logs my-scanner --lines 50

# Restart one process
pm2 restart my-scanner

# Save current process list (survives reboot)
pm2 save

# Show status
pm2 status

# Show detailed info
pm2 show my-scanner

Memory Limits

Process Max Memory Why
candle-cache 150M Holds 200 symbols × 6 grans × 200 candles
candle-bridge 100M Reads/writes cache files
scanner 150M Typical scan cycle memory
trade-tracker 200M Tracks hundreds of open trades

Auto-Restart Rules


Log Locations

/root/.pm2/logs/
├── my-scanner-out.log      # stdout
├── my-scanner-error.log    # stderr
├── candle-cache-out.log
└── candle-cache-error.log