QuantDinger Extension Guide¶
This guide explains how to add features without making the backend harder to maintain. Prefer small, boring, easy-to-review changes.
Before You Start¶
- Find the closest existing module.
- Read
docs/architecture/ARCHITECTURE.mdanddocs/architecture/MODULE_BOUNDARIES.md. - Decide whether the change is API, service, adapter, data, worker, or docs.
- Keep route paths and response fields backward-compatible unless a breaking change is explicitly approved.
Add a Human Web API Endpoint¶
Use this flow for routes consumed by the web or mobile UI:
- Add the route in the closest route module, or create a small sibling module if the current file is already large.
- Keep the route thin: validate input, call a service, return JSON.
- Put workflow logic in
app/services/<feature>/...when the feature has more than one workflow. Use a flat service file only for small one-off helpers. - Add or update OpenAPI tag metadata in
app/openapi/register.pyandapp/openapi/tags.pywhen introducing a new route family. - Regenerate the human API spec:
cd backend_api_python
python scripts/export_openapi.py
- Run the OpenAPI smoke test when dependencies are available:
cd backend_api_python
python -m pytest tests/test_openapi.py -q
Add an Agent Gateway Endpoint¶
Use this flow for external AI agents, MCP clients, and automation:
- Add code under
app/routes/agent_v1. - Enforce token scopes using the existing agent security helpers.
- Keep write/trade actions explicit and auditable.
- Update
docs/agent/agent-openapi.json. - Do not mix agent-only routes into the human OpenAPI spec.
Add a Market Data Source¶
- Implement the adapter in
app/data_sources. - Return normalized rows:
{
"time": 1710000000,
"open": 1.0,
"high": 1.2,
"low": 0.9,
"close": 1.1,
"volume": 1000.0,
}
- Register selection logic in
DataSourceFactory. - Keep provider-specific column names inside the adapter.
- Include market, symbol, timeframe, exchange, and market type in cache keys where relevant.
- Add a small smoke check or script if the provider has fragile symbol rules.
Add a Symbol Master Data Source¶
- Prefer database-backed master data over hardcoded symbol lists.
- Put sync/import logic in scripts or service modules, not route files.
- Keep seed SQL deterministic so fresh Docker installs work offline.
- Make search tolerant of symbol, name, alias, and localized company names.
- Do not hardcode large symbol lists in Python route modules.
Add an Exchange or Broker Adapter¶
- Put low-level API calls under
app/services/live_trading. - Normalize account, position, order, fill, and error shapes.
- Keep exchange precision and sizing logic near the adapter.
- Keep strategy lifecycle outside the adapter.
- Add explicit notes for market type support: - spot - swap/perpetual - US stock - paper/live
- If an adapter supports live orders, document idempotency and retry behavior.
Add a Strategy Runtime Feature¶
- Avoid adding more unrelated logic to
trading_executor.py. - Extract new behavior into a focused service module first.
- Keep order intent creation separate from order execution.
- Keep market data reads separate from account mutation.
- Add safeguards for duplicate starts, duplicate orders, and worker restarts.
Add a Backtest Feature¶
- Avoid growing
backtest.pyunless the change is tiny. - Prefer extracting: - data loading - signal evaluation - execution model - metrics - report formatting
- Preserve historical result compatibility.
- Clearly document fill assumptions.
Add an AI Feature¶
- Keep prompts and skill definitions separate from provider calls.
- Keep provider adapters behind a service boundary.
- Localize user-facing text through translation/i18n structures.
- Do not let AI flows place live orders without explicit existing trade APIs, permissions, billing checks, and audit logs.
- For streaming routes, handle cancellation and partial failures.
Add Settings¶
- Define the setting in the backend settings registry.
- Choose whether it is public, admin-only, or internal.
- Keep secrets out of public config endpoints.
- If the setting changes OpenAPI behavior, regenerate
docs/api/openapi.yaml. - Keep environment variable names stable and documented.
Add Background Work¶
- Put startup wiring in
app/startup.py. - Put worker behavior in a dedicated service module.
- Add a clear owner/lock model for multi-process deployments.
- Make work idempotent before adding retries.
- Log start, stop, retry, and failure states in English.
Verification Checklist¶
Run the smallest useful checks for the change:
python -m py_compile path/to/changed_file.py
python scripts/check_mojibake.py
For API changes:
cd backend_api_python
python scripts/export_openapi.py
python -m pytest tests/test_openapi.py -q
For Docker/deploy changes:
docker compose config
For frontend-only work, use the frontend dev server. Do not run production builds during every small iteration unless the change touches bundling, environment injection, or release assets.
