Write Configuration Changes
It can be convenient to programmatically change settings in the Gunbot configuration file (config.js
) directly from your custom strategies. After a change to this file, Gunbot picks up the changes automatically.
The following JavaScript example demonstrates a simple way to modify config.js
from within a custom Gunbot strategy.
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, to place a new override (YOUR_CUSTOM_PARAMETER
) on an existing pair (e.g., USDT-BTC
on mex_gunthy
exchange):
// Require the Node.js `fs` module to get access to 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');