Skip to main content

Persistent Storage in Gunbot

Gunbot frequently executes custom strategy code for each trading pair. One of the challenges encountered in this environment is maintaining variable persistence across different execution cycles.

Understanding Variable Persistence

Within custom strategies, variables are reset with each strategy execution. This reset poses a challenge for strategies that require continuity in data handling across multiple cycles.

Implementing Persistent Storage

Persistent storage can be achieved using gb.data.pairLedger.customStratStore. This object, initially undefined, must be explicitly initialized for data storage:


// Initialize customStratStore within pairLedger object

gb.data.pairLedger.customStratStore = gb.data.pairLedger.customStratStore || {};

This code snippet sets up a dedicated storage area within the pair ledger, allowing for data persistence across bot restarts. Best Practices and Limitations

While customStratStore allows for data persistence, it is not foolproof. Unexpected terminations may reset the data. Gunbot's built-in strategies typically avoid heavy reliance on persistently stored data, preferring to work with exchange-provided information. Similarly, when building custom strategies, minimal dependence on persistent storage is advisable.