HyperTrade provides a comprehensive REST API for Agent-driven crypto trading research and execution. The API is built with FastAPI and follows RESTful conventions.
Base URL: http://localhost:3334/api
Production URL: http://47.79.36.92:3333/api
API Documentation: Visit /docs for interactive Swagger documentation.
GET /api/research/strategy-cardslists current V2 and explicit legacy-compatible cards.GET /api/research/strategy-cards/funnelreturns the Manifest-denominated research funnel.POST /api/research/strategy-cards/reconcileidempotently backfills projection tables.GET /api/research/strategy-cards/{card_id}/snapshotslists immutable snapshots.POST /api/research/strategy-cards/{card_id}/decisionsrecords an idempotent human review fact.
All endpoints require the administrator session. Reconcile and decisions can write only StrategyCard projection/audit tables; no endpoint authorizes BitPro, paper, live, order or capital mutation.
POST /api/portfolio/observation-windowscaptures bounded read-only BitPro evidence.GET /api/portfolio/observation-windowslists immutable summary windows.GET /api/portfolio/observation-windows/{window_id}returns one quality/statistics projection.GET /api/portfolio/observation-windows/{left_id}/diff/{right_id}compares window status and coverage.
Capture requests accept only bounds and Card selection, never client-supplied statistics or source
payloads. Responses expose sample window, freshness, source hashes, quality gaps and Decimal strings;
raw_series_persisted=false and execution_authorized=false are invariant.
POST/GET /api/portfolio/paper-cohortsbuilds or lists immutable comparison snapshots.GET /api/portfolio/paper-cohorts/{id}andGET .../{left}/diff/{right}inspect/diff a cohort.POST /api/portfolio/paper-cohorts/{id}/decisionsrecords an expiring label review.POST/GET /api/portfolio/shadow-portfoliosbuilds or lists hypothetical proposals.GET /api/portfolio/shadow-portfolios/{id}andGET .../{left}/diff/{right}inspect/diff one.POST /api/portfolio/shadow-portfolios/{id}/reviewsrecords scenario accept/reject/hold.
All endpoints require the administrator session. Cohort decisions and Shadow reviews are audit facts,
not execution approvals. Shadow responses keep hypothetical=true, execution_authorized=false,
capital_authorized=false, paper_lifecycle_authorized=false, and orders_created=false.
Most read endpoints are publicly accessible. Write operations and privileged actions require admin session authentication.
Authenticate and obtain a session cookie.
Request Body:
{
"username": "string",
"password": "string"
}Response:
{
"status": "ok",
"username": "string"
}Cookie Set: hypertrade_session (HttpOnly, SameSite=Lax)
Clear the session cookie.
Authentication: Required
Response:
{
"status": "ok"
}Get the current authenticated user.
Authentication: Required
Response:
{
"username": "string"
}Health check endpoint.
Response:
{
"status": "ok",
"service": "hypertrade-api"
}Complete system overview including providers, tools, connectors, market state, recent runs, trace events, and service status.
Response:
{
"generated_at": "2026-07-05T12:00:00Z",
"providers": [...],
"tools": [...],
"connectors": [...],
"market": {
"ticker_count": 100,
"latest_ticker_at": "2026-07-05T11:59:00Z",
"latest_update_age_seconds": 60,
"top_movers": [...]
},
"agent_runs": {
"total_count": 1234,
"recent": [...]
},
"rag": {
"document_count": 50,
"chunk_count": 500
},
"memory": {
"active_count": 80,
"total_count": 100,
"latest_created_at": "2026-07-05T10:00:00Z"
},
"trace": {
"total_count": 5000,
"recent_events": [...]
},
"paper": {...},
"strategy_lab": {...},
"live_orders": {...},
"bitpro": {...},
"evals": {...}
}List available chat providers and their configuration.
Response:
{
"providers": [
{
"name": "deepseek",
"display_name": "DeepSeek",
"configured": true,
"selected": true,
"model": "",
"available_models": []
}
]
}Switch the active chat provider and model.
Authentication: Required
Request Body:
{
"provider": "deepseek",
"model": ""
}Response:
{
"default_provider": "deepseek",
"model": "",
"providers": [...]
}List all registered Agent tools with their policies.
Response:
{
"tools": [
{
"name": "market.summary",
"description": "Summarize OKX SWAP market state.",
"category": "market",
"requires_approval": false,
"policy": {
"scope": "read",
"approval": "none",
"idempotency": "not_required",
"source_of_truth": "hypertrade_db",
"timeout_class": "standard",
"safe_sample_limit": 0,
"failure_behavior": "return_structured_error"
},
"connector_origin": null
}
]
}AgentTask is the durable control record. AgentRun is one immutable execution
attempt linked through resource_type=agent_run and resource_id.
Create a durable operator Session. Authentication required. Provider config must contain names/models only; credentials are discarded.
List durable Sessions. GET /agent/sessions/{session_id} reads one Session.
Create a queued Task. Authentication required. The request includes
objective, a unique idempotency_key, optional kind, parent/resource refs,
and bounded budget fields.
List Tasks, optionally filtered by session_id or status.
GET /agent/tasks/{task_id} includes the latest checkpoint projection.
Supported actions are pause, resume, cancel, retry, and branch.
Authentication required. Every request requires reason and
idempotency_key; actor defaults to operator.
Read append-only safe events with after=<sequence> and bounded limit.
Stream events using SSE. Resume with after=<sequence> or Last-Event-ID.
Each committed event includes an SSE id equal to its Task sequence.
Create a new Agent run with a free-form prompt.
New runs are automatically wrapped in an inline-reserved Session/Task. Clients
may send Idempotency-Key; a completed duplicate returns the linked Run.
Request Body:
{
"prompt": "看下目前市场的热度怎么样"
}Response:
{
"run_id": "run_abc123",
"prompt": "看下目前市场的热度怎么样",
"status": "completed",
"report": "...",
"metadata": {...},
"trace": [...],
"created_at": "2026-07-05T12:00:00Z",
"completed_at": "2026-07-05T12:00:05Z"
}Create a streaming Agent run with Server-Sent Events.
Request Body:
{
"prompt": "请做行情归纳"
}Response: Server-Sent Events stream
Event Types:
run_start: Run initializedtool_start: Tool execution startedtool_complete: Tool execution completedrun_complete: Run finished
Example Events:
event: run_start
data: {"run_id": "run_abc123", "prompt": "..."}
event: tool_start
data: {"tool": "market.summary", "started_at": "..."}
event: tool_complete
data: {"tool": "market.summary", "result": {...}}
event: run_complete
data: {"run_id": "run_abc123", "status": "completed", "report": "..."}
List recent Agent runs (latest 25).
Response:
{
"runs": [
{
"id": "run_abc123",
"prompt": "看下目前市场的热度怎么样",
"status": "completed",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Get detailed information about a specific run.
Response:
{
"run_id": "run_abc123",
"prompt": "...",
"status": "completed",
"report": "...",
"metadata": {...},
"trace": [...],
"created_at": "...",
"completed_at": "..."
}Cancel a running Agent run.
Authentication: Required
Response:
{
"status": "cancelled",
"run_id": "run_abc123"
}Get latest market tickers for all OKX SWAP instruments.
Response:
{
"tickers": [
{
"inst_id": "BTC-USDT-SWAP",
"last": "50000.0",
"volume_ccy_24h": "1000000.0",
"change_utc0_pct": "2.5",
"updated_at": "2026-07-05T12:00:00Z"
}
],
"count": 100,
"latest_at": "2026-07-05T12:00:00Z"
}Get ticker for a specific symbol.
Path Parameters:
symbol: Symbol name (e.g.,BTC,ETH) or instrument ID (e.g.,BTC-USDT-SWAP)
Response:
{
"inst_id": "BTC-USDT-SWAP",
"last": "50000.0",
"volume_ccy_24h": "1000000.0",
"change_utc0_pct": "2.5",
"funding_rate": "0.0001",
"open_interest": "5000000.0",
"updated_at": "2026-07-05T12:00:00Z"
}Get candlestick data for a symbol.
Path Parameters:
symbol: Symbol name or instrument ID
Query Parameters:
bar: Timeframe (e.g.,1H,4H,1D), default1Hlimit: Number of candles, default100, max500
Response:
{
"symbol": "BTC",
"inst_id": "BTC-USDT-SWAP",
"bar": "1H",
"candles": [
{
"ts": "2026-07-05T12:00:00Z",
"open": "50000.0",
"high": "50500.0",
"low": "49800.0",
"close": "50200.0",
"volume": "1000.0"
}
],
"count": 100,
"trend_features": {
"sma_20": "50100.0",
"ema_12": "50150.0",
"rsi_14": "55.0"
}
}Compare multiple symbols for relative strength ranking.
Request Body:
{
"symbols": ["BTC", "ETH", "SOL"],
"bar": "4H",
"limit": 100
}Response:
{
"symbols": ["BTC", "ETH", "SOL"],
"bar": "4H",
"comparison": [
{
"symbol": "SOL",
"rank": 1,
"change_pct": "5.2",
"relative_strength": "strong"
},
{
"symbol": "ETH",
"rank": 2,
"change_pct": "3.1",
"relative_strength": "moderate"
},
{
"symbol": "BTC",
"rank": 3,
"change_pct": "1.8",
"relative_strength": "moderate"
}
]
}Search knowledge documents with citation-ready results.
Query Parameters:
query: Search query string (required)limit: Number of results, default5, max20
Response:
{
"query": "风控",
"hits": [
{
"chunk_id": "chunk_123",
"document_path": "docs/knowledge/risk-management.md",
"content": "风控是交易系统的核心...",
"score": 0.85,
"metadata": {
"section": "风险管理基础"
}
}
],
"count": 3
}Search or list memory items.
Query Parameters:
query: Search query (optional)tag: Filter by tag (optional)type: Filter by type (observation,strategy_knowledge,market_context) (optional)limit: Number of results, default10, max50
Response:
{
"items": [
{
"id": "mem_abc123",
"type": "strategy_knowledge",
"content": "动量突破策略在趋势市场中表现良好...",
"tags": ["strategy", "momentum", "breakout"],
"confidence": 0.8,
"importance": 0.9,
"disabled": false,
"usage_count": 5,
"created_at": "2026-07-05T10:00:00Z"
}
],
"count": 1
}Delete or disable a memory item.
Authentication: Required
Response:
{
"status": "deleted",
"memory_id": "mem_abc123"
}Research Evidence V2 is append-only. Read endpoints return effective expiry, source-health/data-gap projections, content hash, lifecycle, and legacy labels; they never promote Memory into a verified fact.
Append one discriminated fact, inference, counter_evidence, or data_gap.
Authentication required. Common fields include claim, scope, sources,
confidence, as_of, optional valid_until, Task/Node/role refs, and supporting
or opposing evidence IDs. Facts require an available non-Memory source.
List V2 evidence. Filters: task_id, type, status, symbol, and limit.
Set include_legacy=true without other filters to include explicitly labelled
legacy experiment and Memory projections.
Read one V2 or legacy record. V2 responses include stable content_hash,
stored_status, effective status, source_health, data_gaps, and lifecycle.
Read bounded relation nodes/edges. depth defaults to 2 and is capped at 5.
Supported lifecycle actions are supersede, expire, and reject.
Authentication required. Expire/reject require a reason; supersede requires
a reason plus a complete replacement evidence payload. Historical claim/payload
content is never updated in place.
Manifests contain semantic inputs and version hashes, never full prompts, credentials,
private reasoning, raw candles, or raw BitPro results. A SHA-256 fingerprint
identifies the immutable manifest; executions are append-only attempts.
Register ExperimentManifestV1. Authentication required. The request includes an
idempotency key, optional Task/ResearchJob refs, and optional audited
force_rerun/force_reason. Same-fingerprint queued/running/completed work returns the
existing execution; failed work requires an explicit force reason.
List manifest projections. limit defaults to 50 and is capped at 500.
Read the immutable manifest and executions with bounded refs, metrics, artifacts, actual usage, errors and Evidence associations.
Read append-only attempts for one fingerprint.
Explain differences as strategy, data, costs, model, prompt, tool,
policy, or runtime.
Create a new strategy research record.
Request Body:
{
"prompt": "研究ETH趋势突破策略"
}Response:
{
"research_id": "res_abc123",
"prompt": "研究ETH趋势突破策略",
"status": "created",
"report": "...",
"created_at": "2026-07-05T12:00:00Z"
}List recent strategy research records.
Query Parameters:
limit: Number of results, default10, max50
Response:
{
"research_records": [
{
"research_id": "res_abc123",
"prompt": "研究ETH趋势突破策略",
"status": "completed",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Create a new strategy experiment with multiple variants.
Request Body:
{
"prompt": "实验ETH动量突破策略的不同参数"
}Response:
{
"experiment_id": "exp_abc123",
"variants": ["baseline", "fast", "conservative"],
"results": [...],
"winner": "fast",
"next_experiment": "尝试优化止损参数"
}Plan the next experiment based on prior evidence.
Request Body:
{
"prompt": "基于之前的动量策略证据,规划下一个实验"
}Response:
{
"plan": "...",
"prior_evidence": [...],
"suggested_variants": [...]
}List recent strategy experiments.
Response:
{
"experiments": [
{
"experiment_id": "exp_abc123",
"prompt": "...",
"winner": "fast",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Get strategy library aggregated from memory.
Query Parameters:
strategy_name: Filter by strategy name (optional)tag: Filter by tag (optional)
Response:
{
"strategies": [
{
"strategy_name": "momentum_breakout_v1",
"evidence_count": 5,
"avg_confidence": 0.85,
"tags": ["momentum", "breakout"],
"latest_evidence": {...}
}
]
}Create and run a backtest.
Request Body:
{
"research_id": "res_abc123",
"strategy_key": "momentum_breakout_v1",
"initial_cash": "100000",
"symbol": "BTC",
"bar": "1H",
"candle_limit": 100,
"candle_source": "okx",
"use_live_candles": true
}Response:
{
"backtest_id": "bt_abc123",
"status": "completed",
"metrics": {
"total_return_pct": 15.5,
"sharpe_ratio": 1.8,
"max_drawdown_pct": -8.2,
"win_rate": 0.65,
"total_trades": 50
},
"equity_curve": [...],
"trades": [...]
}List recent backtests.
Query Parameters:
limit: Number of results, default10, max50
Response:
{
"backtests": [
{
"backtest_id": "bt_abc123",
"strategy_key": "momentum_breakout_v1",
"total_return_pct": 15.5,
"status": "completed",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Get paper trading status and positions.
Response:
{
"enabled": true,
"running": true,
"equity_usdt": "105000.0",
"starting_equity_usdt": "100000.0",
"pnl_usdt": "5000.0",
"pnl_pct": "5.0",
"positions": [
{
"symbol": "BTC",
"side": "long",
"size": "0.5",
"entry_price": "48000.0",
"current_price": "50000.0",
"pnl_usdt": "1000.0"
}
]
}Control paper trading (pause, resume, close, reset).
Authentication: Required
Request Body:
{
"action": "pause",
"symbol": "BTC"
}Actions:
pause: Pause trading for a symbol or allresume: Resume tradingclose: Close all positionsreset: Reset to initial state
Response:
{
"status": "ok",
"action": "pause",
"symbol": "BTC"
}Create a live order intent (requires approval before execution).
Request Body:
{
"symbol": "BTC",
"side": "buy",
"size": "0.01",
"order_type": "market",
"price": null,
"reason": "API smoke test"
}Response:
{
"intent_id": "loi_abc123",
"status": "pending_approval",
"symbol": "BTC",
"side": "buy",
"size": "0.01",
"created_at": "2026-07-05T12:00:00Z"
}List live order intents.
Response:
{
"intents": [
{
"intent_id": "loi_abc123",
"status": "pending_approval",
"symbol": "BTC",
"side": "buy",
"size": "0.01",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Approve a pending order intent.
Authentication: Required
Request Body:
{
"reason": "Approved for testing"
}Response:
{
"status": "approved",
"intent_id": "loi_abc123",
"approved_at": "2026-07-05T12:01:00Z"
}Reject a pending order intent.
Authentication: Required
Request Body:
{
"reason": "Risk limit exceeded"
}Response:
{
"status": "rejected",
"intent_id": "loi_abc123",
"rejected_at": "2026-07-05T12:01:00Z"
}Execute an approved order intent on OKX Testnet.
Authentication: Required
Response:
{
"status": "executed",
"intent_id": "loi_abc123",
"order_id": "okx_order_123",
"executed_at": "2026-07-05T12:02:00Z"
}Check BitPro MCP health and capabilities.
Response:
{
"status": "ok",
"capabilities": [...],
"tool_groups": ["market", "strategy", "backtest", "paper", "live_read"],
"remote_mcp": true
}Get BitPro K-line data.
Path Parameters:
symbol: Symbol name
Query Parameters:
timeframe: Timeframe (e.g.,1H,4H)limit: Number of candles, default100
Response:
{
"symbol": "BTC",
"timeframe": "1H",
"klines": [...]
}Get BitPro paper trading dashboard.
Query Parameters:
strategy_id: Filter by strategy ID (optional)
Response:
{
"running_strategies": [...],
"alerts": [...],
"data_gaps": []
}Get BitPro live positions (read-only diagnostics).
Query Parameters:
exchange: Exchange name, defaultokxsymbol: Filter by symbol (optional)
Response:
{
"positions": [
{
"symbol": "BTC",
"side": "long",
"size": "0.5",
"unrealized_pnl": "1000.0"
}
]
}List all monitor definitions.
Response:
{
"monitors": [
{
"monitor_id": "mon_bitpro_paper_all",
"name": "BitPro Paper Monitor",
"description": "Monitor all running BitPro paper strategies",
"schedule": "*/5 * * * *",
"enabled": true
}
]
}Manually run a monitor.
Response:
{
"monitor_id": "mon_bitpro_paper_all",
"status": "completed",
"alerts_generated": 2,
"run_at": "2026-07-05T12:00:00Z"
}List recent alerts.
Query Parameters:
severity: Filter by severity (info,warning,critical) (optional)limit: Number of results, default25, max100
Response:
{
"alerts": [
{
"alert_id": "alert_123",
"monitor_id": "mon_bitpro_paper_all",
"severity": "warning",
"message": "Strategy paper_momentum_v1 has high drawdown",
"created_at": "2026-07-05T12:00:00Z"
}
]
}Get connector capabilities and tool metadata.
Response:
{
"connectors": [
{
"connector_id": "bitpro",
"name": "BitPro MCP Adapter",
"configured": true,
"capabilities": [...],
"tools": [...]
}
]
}Get the required deterministic Agent evaluation suite status. This endpoint does not call a Provider and does not run Promptfoo/Ragas.
Response:
{
"status": "passed",
"case_count": 40,
"legacy_case_count": 14,
"research_os_case_count": 26,
"cases": [],
"research_os": {
"status": "passed",
"suite_version": "research_os_golden_v2",
"case_count": 26,
"categories": {
"normal": 5,
"data_integrity": 5,
"recovery": 4,
"fault": 4,
"safety": 6,
"cursor": 2
},
"data_boundary": {
"prompts_included": false,
"tool_arguments_included": false,
"profitability_scored": false
}
},
"quality": {
"metric_contract": "agent_research_quality.v2",
"status": "passed",
"provider_baseline": "not_loaded",
"cohorts": {
"chat_answer": 2,
"tool_required": 2,
"research_graph": 16,
"safety": 6
},
"failure_categories": {}
},
"mode": "deterministic"
}Get current world model state snapshot.
Response:
{
"timestamp": "2026-07-05T12:00:00Z",
"market_state": {...},
"portfolio": {...},
"risk_metrics": {...}
}Get world model portfolio state.
Response:
{
"equity_usdt": "105000.0",
"positions": [...],
"risk_exposure": {...}
}List available defensive actions.
Authentication: Required
Response:
{
"actions": [
{
"action_id": "reduce_position_btc",
"description": "Reduce BTC position by 50%",
"risk_level": "medium",
"conditions": [...]
}
]
}List defensive action execution attempts.
Authentication: Required
Query Parameters:
limit: Number of results, default25
Response:
{
"attempts": [
{
"attempt_id": "att_123",
"action_id": "reduce_position_btc",
"status": "executed",
"executed_at": "2026-07-05T11:00:00Z"
}
]
}Execute a defensive action.
Authentication: Required
Request Body:
{
"action_id": "reduce_position_btc",
"idempotency_key": "key_123",
"world_state": null
}Response:
{
"status": "executed",
"action_id": "reduce_position_btc",
"executed_at": "2026-07-05T12:00:00Z",
"result": {...}
}Returns the fixed role catalog, prompt/policy hashes, budgets, and DAG edges. Public, read-only, and never starts research.
Creates an idempotent research_graph Agent Task for an active mandate. Administrator
authentication is required. capabilities only controls optional roles;
operator_tool_allowlist can narrow but never expand each role's read-only policy.
Lists graph tasks without allowing unrelated Agent Tasks to consume the requested page.
Returns the Task configuration, fixed topology, all node attempts, bounded usage, Evidence V2 records, and latest checkpoint. Provider private reasoning and raw artifacts are not exposed.
Runs a queued graph inline when the background worker is not claiming tasks. Administrator authentication is required. Normal production execution is performed by the durable Task worker. Role tools remain read-only; StrategySpec validation is handed to the existing ResearchOrchestrator queue.
Lists persisted robustness decisions newest first. Each item contains the immutable experiment execution/fingerprint references, policy version, final status, gate summary and bounded scenario result references. This endpoint is read-only and does not run a backtest or start paper/live trading.
Returns one validation with its locked-OOS, walk-forward, parameter-sensitivity,
cost-stress and optional regime scenarios. Gate outcomes are passed, failed,
unknown, or not_applicable; final status is validated, rejected, needs_data,
or needs_review. A missing required metric never becomes a pass.
404 is returned when the validation does not exist. These read endpoints do not
require administrator authentication; all underlying writes remain orchestrator-owned.
All error responses follow a consistent format:
4xx Client Errors:
{
"detail": "Error message"
}502 BitPro Unavailable:
{
"detail": {
"status": "unavailable",
"service": "bitpro_mcp",
"message": "Connection failed",
"status_code": 502,
"tool_calls": [...]
}
}Common HTTP Status Codes:
200: Success400: Bad Request401: Not Authenticated403: Forbidden404: Not Found502: BitPro/External Service Unavailable500: Internal Server Error
No rate limiting is currently enforced, but it's recommended to:
- Limit concurrent streaming runs to 5
- Space market data requests at least 1 second apart
- Use streaming endpoints for long-running Agent tasks
WebSocket support is not currently implemented. Use the Server-Sent Events (SSE) streaming endpoint /api/agent/runs/stream for real-time updates.
API version: 0.1.0
The API is in active development. Breaking changes will be announced in release notes.