QuantDinger API conventions (OpenAPI SSOT)

May 31, 2026 · View on GitHub

This document defines the contract rules for QuantDinger HTTP APIs. Machine-readable specs:

SpecPathAudience
Human Web API (flask-smorest)docs/api/openapi.yamlFrontend, integrators, community
Agent Gatewaydocs/agent/agent-openapi.jsonAI agents, MCP, automation

Browse the human spec locally: open docs/api/index.html (Redoc).


1. Two API surfaces

Human Web API (/api/...)

  • Authenticated with user JWT (Authorization: Bearer <jwt>) unless noted.
  • Used by the QuantDinger web/mobile UI.

Agent Gateway (/api/agent/v1/...)

  • Authenticated with agent tokens (qd_agent_...), scoped (R/W/B/...).
  • Documented separately; do not mix agent routes into the human spec without an x-agent-only tag.
  • See docs/agent/AGENT_QUICKSTART.md.

2. Response envelopes

Human API — success

{
  "code": 1,
  "msg": "success",
  "data": { }
}
FieldTypeNotes
codeint1 = success
msgstringHuman-readable status
dataanyPayload; may be null

Human API — error

{
  "code": 0,
  "msg": "Error description",
  "data": null
}

HTTP status is often 400, 401, 403, or 500 depending on the route.

OpenAPI schemas: HumanSuccessEnvelope, HumanErrorEnvelope in docs/api/openapi.yaml.

Agent Gateway — success / error

Agent routes use message (not msg) and code: 0 on success. Errors may include details and retriable. See docs/agent/agent-openapi.json.


3. Authentication

SchemeHeaderUsed by
HumanJWTAuthorization: Bearer <jwt>Human Web API
AgentTokenAuthorization: Bearer qd_agent_.../api/agent/v1/* only

Obtain JWT via POST /api/auth/login (documented in a future migration phase).


4. Visibility tiers

Tag or extension every operation when migrating to flask-smorest:

TierOpenAPIWho may rely on it
Publicdefault tag, no extensionOpen-source community, third-party clients
Internalx-visibility: internalQuantDinger product; may change without notice
Privatex-visibility: privateAdmin / sensitive; minimal public docs

Public modules (migration priority): community, market, indicator, backtest, global-market, health.

Internal / sensitive: strategy, credentials, billing, quick-trade, broker adapters (ibkr, alpaca, mt5).


5. Naming and versioning

  • Paths: lowercase, kebab-case segments (/api/global-market/...).
  • Query params: snake_case (page_size, sort_by).
  • JSON bodies: snake_case (match existing backend).
  • Document breaking changes in PR descriptions; CI runs oasdiff against committed docs/api/openapi.yaml.
  • Future human API versioning: prefer /api/v2/... over silent breaking changes.

6. Pagination (lists)

Common shape inside data:

{
  "items": [],
  "total": 0,
  "page": 1,
  "page_size": 12
}

OpenAPI schema: PaginationMeta (fields may be inlined per route during migration).


7. Contributing API changes

  1. New Public route — implement with flask-smorest in app/openapi/routes/ (or migrate existing Blueprint).
  2. Regenerate speccd backend_api_python && python scripts/export_openapi.py
  3. Commit — include updated docs/api/openapi.yaml in the same PR.
  4. Agent routes — update docs/agent/agent-openapi.json separately.
  5. PR checklist — see CONTRIBUTING.md.

Local interactive docs (debug mode): /api/docs/swagger and /api/docs/redoc when OPENAPI_ENABLED=true or PYTHON_API_DEBUG=true.


8. Migration status

ModuleStatusSpec source
Health (/, /health, /api/health)Migratedflask-smorest
Agent GatewayHand-written OpenAPI + CI lintdocs/agent/agent-openapi.json
All other modulesLegacy Flask BlueprintNot yet in openapi.yaml

Phase 1+ will migrate community, market, etc. incrementally.