Skip to content

Plugins

Plugins in TradeHub allow you to extend the scripting environment with reusable utilities, external integrations, or advanced custom features.
They are similar to strategies but do not include setup() or update() functions. Instead, plugins run in the background and can hook into the bot lifecycle or expose custom utilities to strategies.


  • Plugins run in a separate context to add security and avoid polluting the global scripting environment.
  • If a plugin needs to execute logic during bot operation, it can register hooks using addHook() for setup or update.
  • Plugins can expose helper functions or tools for strategies to use.
  • Strategies can load plugins with trader.require('pluginName', options).
  • Plugins can access the network and filesystem if you grant permission on the plugin page.

Plugins receive a single api object containing all plugin-specific tools:

const { net, options, fs, trader, addUtil, log } = api;

Contains the entire scripting API context available in strategy scripts (balances, orders, indicators, etc.). Use this to interact with the trading environment.


A simplified, sandboxed file system API (similar to Node.js fs) for plugin-local storage.

  • Only works inside the plugin’s dedicated data folder.
  • Access outside this folder is blocked and will throw an error.
  • User must grant permission in the app settings.

Available Methods:

  • async fs.writeFile(filePath, data)

  • async fs.readFile(filePath)

  • async fs.mkdir(dirPath)

  • async fs.deleteFile(filePath)

  • async fs.listDir(dirPath)

  • fs.writeFileSync(filePath, data)

  • fs.readFileSync(filePath)

  • fs.mkdirSync(dirPath)

  • fs.deleteFileSync(filePath)

  • fs.listDirSync(dirPath)


A lightweight HTTP client based on Axios with the following methods:

  • async net.get(url, config?)
  • async net.post(url, data, config?)
  • async net.delete(url, config?)
  • async net.options(url, config?)
  • async net.put(url, data, config?)
  • async net.patch(url, data, config?)
  • async net.postForm(url, formData, config?)
  • async net.putForm(url, formData, config?)
  • async net.patchForm(url, formData, config?)

Each method will return:

{
data, status, statusText, headers, config
}

Lets you expose custom utility functions from a plugin into strategies.

addUtil("utilVarName", function callbackFunction() {
return "Hello from plugin!";
});

This makes the utility available in scripts via:

plugin.pluginName.utilVarName();

Identical to the scripting API log() function. Use it to log plugin activity within the console.


Contains options passed from the strategy when loading the plugin:

trader.require("pluginName", { apiKey: "1234", threshold: 10 });

These options are then accessible inside the plugin as options.


Plugins can hook into bot lifecycle events (setup or update):

api.trader.addHook("setup", () => {
log("Plugin hook: Running during setup.");
});
api.trader.addHook("update", async () => {
log("Plugin hook: Running during every update.");
});

Here’s a simple plugin that logs market data and adds a utility:

const { net, options, fs, trader, addUtil, log } = api;
// Add a custom utility for strategies
addUtil("printMarket", () => {
log("Current market:", trader.market);
});
// Hook into the bot setup phase
trader.addHook("setup", () => {
log("Plugin initialized for market:", trader.market);
});
// Hook into updates (runs on each tick/candle)
trader.addHook("update", () => {
log("Last candle close:", trader.candle.close);
});

Then, in your strategy script:

function setup() {
trader.require("myPlugin");
}
async function update() {
plugin.myPlugin.printMarket(); // Uses the utility added by the plugin
}

  • Plugins provide background logic and reusable tools.
  • They run with an isolated api object to keep the scripting environment clean.
  • Strategies can load plugins dynamically with trader.require().
  • Use plugins for external integrations, reusable functions, or persistent storage.