Skip to main content
QuanuX strategies are built from modular components. You start in Python — where iteration is fast and the data science ecosystem is available — then graduate the logic to compiled code once you’re confident in the approach. This page covers how to write a strategy from scratch and how to use the Foundry API to generate higher-performance equivalents.

Strategy architecture

Every strategy in server/strategies/ is assembled from four component types, each inheriting from StrategyComponent defined in server/strategies/base.py. A CompositeStrategy wires these components together and drives the on_bar loop.

Writing a strategy in Python

The example below is drawn from the SmaCrossover strategy in server/strategies/full/SmaCrossover/.
Define parameters using a nested Pydantic model inside define_parameters. QuanuX validates and coerces all values at runtime when you call update_parameters.

Using the Foundry to generate code

Once your Python prototype is working, submit it to the AI Foundry to generate a faster equivalent. The Foundry dispatches your request as a NATS payload and returns a job ID immediately.

POST /api/foundry/forge

Submit a generation job for a strategy component. Request body
string
required
The type of component to generate. Accepted values: indicator, entry, exit, strategy.
string
required
The name for the generated component, used as the file and class identifier.
string
required
The output language. Accepted values: python, cython, cpp.
string
Semantic version string for the generated artifact, e.g. 1.0.0. Optional; defaults to null.
string
Natural-language description of the strategy logic. The Foundry uses this alongside the component type and name to guide code generation.
Response
string
required
Always "accepted" on success. The job runs asynchronously.
string
required
Unique job identifier in the format job_xxxxxxxx. Use this to correlate NATS telemetry events back to your request.
Example: generate a Cython signal component
Response

POST /api/foundry/verify

After the Foundry generates code, run equivalence testing to confirm the generated version produces mathematically identical output to your Python prototype. Request body
string
required
The name of the strategy to verify. Must match the name used in the forge request.
Response
string
required
Always "accepted". Verification runs asynchronously in a deterministic sandbox.
string
required
Unique job identifier for this verification run.
Example
cURL
Response

Git-as-Governance

Before a generated strategy can be promoted to C++ and deployed to the live spreader, it must be committed to your QuanuX repository. The spreader verifies the SHA-256 of every strategy artifact against a signed commit. An uncommitted or unsigned strategy will be rejected at deploy time.
Do not modify generated Cython .pyx files by hand after committing. Any change invalidates the SHA-256 signature and will block deployment. If you need to adjust the logic, submit a new forge request and re-verify.
Commit your strategy files before proceeding to backtesting: