Skip to main content

Write Configuration Changes

You can programmatically change settings in the Gunbot configuration file (config.js) directly from your custom strategies. After changes are written, Gunbot picks them up automatically.

The JavaScript example below shows one way to modify config.js from a custom Gunbot strategy.

Caution

Modifying config.js directly from a strategy requires careful implementation. Errors in the written configuration can lead to Gunbot failing to start or behaving unexpectedly. Always ensure your modified configuration is valid JSON and adheres to Gunbot's structure. It's also a good practice to back up config.js before extensive programmatic modifications.

Prepare configuration changes. For example, place a new override (YOUR_CUSTOM_PARAMETER) on an existing pair (for example, USDT-BTC on the mex_gunthy exchange):

// Require the Node.js `fs` module to access file system methods.
const fs = gb.method.require('fs');

// Path of the file to modify.
const configPath = './config.js';

// Prepare configuration changes. For example, place a new override on an existing pair.
// Make sure to adapt 'mex_gunthy' and 'USDT-BTC' to your specific exchange and pair.
let configClone = {...gb.data.config};
configClone.pairs.mex_gunthy['USDT-BTC'].override.YOUR_CUSTOM_PARAMETER = 6;
const formattedConfig = JSON.stringify(configClone, null, 4);

// Write the changes using a synchronous method (`fs.writeFileSync`)
// to ensure the changes are written immediately when this line is executed.
fs.writeFileSync(configPath, formattedConfig, 'utf8');