Process Management

In this section, you’ll learn how to manage the trading process using pm2.

Install pm2

npm install -g pm2

Start the process

Create a process named “trader”. The --kill-timeout gives the strategy time to release resources on shutdown.

pm2 start trader.py --name "trader" --kill-timeout 10000

List all processes

pm2 ls

Stop the process

pm2 stop trader

Using a Config File

Generate a template config file:

pm2 init

Then start with the config:

pm2 start ecosystem.config.js

Example ecosystem.config.js:

module.exports = {
  apps: [
    {
      name: 'demo',
      interpreter: '/root/NexusTrader/.venv/bin/python',
      cmd: 'demo.py',
      args: '--name test --age 25 --city shanghai',
      instances: 1,
      kill_timeout: 20000,
      max_memory_restart: '8G',
      autorestart: true,
    },
  ],
};

More resources