Skip to main content

What are custom strategies?

Custom strategies allow you to build and run your own JavaScript code in Gunbot for spot and futures trading.

  • Use built-in trading methods, candle, and indicator data to quickly create custom strategies.
  • A strategy runs as an async function, executed once every time a trading pair 'cycles' in Gunbot.
  • Install and use your own additional JavaScript modules for advanced usage.

About the environment your code runs in

Here are some important technical facts to keep in mind:

  • Gunbot takes care of the exchange connection, collecting data, and making it available to a strategy.
  • Save strategies in your own .js files in a folder called ./customStrategies.
  • There is no Gunbot specific syntax, strategy code is plain JavaScript.
  • Strategy code has access to a single outside object: gb, which contains a number of trading methods and lots of data to work with.
  • There are no restrictions on what you can do with the provided trading methods, but exchange-defined restrictions apply (API usage rate limits, open orders limits, etc.).
  • There are no protections against double orders or any other unwanted behavior, so be careful.
  • Make sure to use JavaScript code compatible with Node v14.4.0.
  • Using console.log() logs to the main Gunbot console logs.
  • Code runs inside an async function, and you can use the await keyword to collect additional data like candle data for a different timeframe.
  • A strategy does not have to return anything, but you can use return statements to easily stop your code at a certain point.
  • A strategy can use custom JavaScript modules. Save these in a folder named user_modules inside your Gunbot folder.