Plugin Principle and Development
How it works
A trading plugin is a short piece of code executed on a docker: when you click "Execute" on the trading terminal page, the platform sends the plugin code and the exchange account selected in the module to the selected docker, runs it, and shows the return value in the module. The following entry points share the same execution mechanism:
| Entry point | Code that runs | Notes |
|---|---|---|
| Trading terminal plugin | A strategy of type "Trading Plugin" in your strategy library | Added and executed on the trading terminal page |
| Debug Tool (development tools) | JavaScript code written on the page | For testing API calls |
| Extended API PluginRun | source in the request, or an existing strategy of the account | For programs |
MCP plugin_* tools | Built-in functions for market data, orders and so on | For AI assistants, authorized by the trade permission, see Integrations → AI Integration |
No live trading bot is created and nothing is charged; one run lasts at most 5 minutes and is interrupted on timeout. It suits simple tasks that assist manual trading, such as iceberg orders, placing or cancelling orders in bulk, or calculations; logic that has to run for a long time should be a live trading bot.
Writing a plugin
Create a strategy and set its type to "Trading Plugin" on the new-strategy page. Trading plugins, the debugging tool and PluginRun support JavaScript only.
The plugin's entry point is main(), and its return value is the result: a returned table or chart object is shown as a table or chart in the module (see Integrations → Trading Terminal → Plugin Examples). Logs written with Log() are not shown in the module.
Using a plugin
- Add: open the module menu on the trading terminal page; the trading plugins in your strategy library are listed there. Choose one to add it.
- Execute: click "Execute" in the plugin module to run it.
Data directory
When plugins and the debug tool run on a docker, their working directory is logs/storage/p<number>/ under the docker's running directory (one directory starting with p per platform account, created on the first run). If an exchange account used by the trading terminal configures its key as a key file path (file:///xxx.txt), put the key file in this directory.