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.Documentation Index
Fetch the complete documentation index at: https://docs.quanux.org/llms.txt
Use this file to discover all available pages before exploring further.
Strategy architecture
Every strategy inserver/strategies/ is assembled from four component types, each inheriting from StrategyComponent defined in server/strategies/base.py.
| Component | Base class | Responsibility |
|---|---|---|
| Signal | SignalModule | Analyze market data; return LONG, SHORT, or NEUTRAL |
| Entry | EntryModule | Generate an order dict when a signal is present |
| Risk | RiskModule | Calculate stop loss, take profit, and trailing stop levels |
| Exit | ExitModule | Decide whether an open position should close |
CompositeStrategy wires these components together and drives the on_bar loop.
Writing a strategy in Python
The example below is drawn from theSmaCrossover strategy in server/strategies/full/SmaCrossover/.
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 bodyThe type of component to generate. Accepted values:
indicator, entry, exit, strategy.The name for the generated component, used as the file and class identifier.
The output language. Accepted values:
python, cython, cpp.Semantic version string for the generated artifact, e.g.
1.0.0. Optional; defaults to null.Natural-language description of the strategy logic. The Foundry uses this alongside the component type and name to guide code generation.
Always
"accepted" on success. The job runs asynchronously.Unique job identifier in the format
job_xxxxxxxx. Use this to correlate NATS telemetry events back to your request.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 bodyThe name of the strategy to verify. Must match the
name used in the forge request.Always
"accepted". Verification runs asynchronously in a deterministic sandbox.Unique job identifier for this verification run.
cURL
Response