Skip to content
All library documents

Persisting Spread Strategy Variables with JSON Files

Article vn.py community

Summary

A VeighNa forum discussion explains how to preserve variables in a spread trading strategy across restarts. The suggested approach is to implement JSON file loading and saving in the strategy lifecycle: load stored values when the strategy starts and write current values when it stops. A participant points to JSON helper functions, and the original questioner shares an implementation that builds a file path, checks whether the file exists, restores selected variables, and serializes strategy variables for later use.

The example illustrates basic state persistence rather than a built-in spread module feature. It reports no testing or safeguards beyond handling file access and parsing errors. The file path is hard-coded in the sample, and the selection of variables to restore is specific to that strategy, so users would need to adapt both details to their own environment and state requirements.

Key ideas

  • Strategy variables can be saved to JSON when a spread strategy stops.
  • Stored state can be loaded during startup before trading resumes.
  • The example restores selected variables and writes the strategy variables to a file.
  • File paths and the set of persisted fields must be adapted to each strategy.
  • The discussion does not describe built-in persistence or broader recovery safeguards.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.