Comprehensive guide to the AgentX API for programmatic access and integration
The AgentX API provides programmatic access to the AgentX trading system, enabling integration with external systems and custom applications. This document provides detailed information about endpoints, request/response formats, and authentication requirements.
All API endpoints are relative to the base URL:
http://localhost:5000/api
API requests require authentication using an API key. Include the API key in the request header:
X-API-Key: your_api_key_here
API keys can be generated in the dashboard under Settings > API Access.
All API responses are in JSON format with the following structure:
{
"success": true,
"data": {
// Response data specific to the endpoint
},
"error": null
}
In case of an error:
{
"success": false,
"data": null,
"error": {
"code": "ERROR_CODE",
"message": "Error message description"
}
}
Get current system status.
{
"success": true,
"data": {
"status": "running",
"uptime_seconds": 3600,
"start_time": "2025-03-19T10:00:00Z",
"current_time": "2025-03-19T11:00:00Z",
"active_agents": 11,
"total_agents": 11,
"metrics": {
"messages_processed": 1500,
"errors": 0,
"warnings": 2
}
},
"error": null
}
Control system operation.
{
"action": "start" // Possible values: "start", "stop", "restart"
}
{
"success": true,
"data": {
"message": "System started successfully",
"status": "running"
},
"error": null
}
Get status of all agents.
{
"success": true,
"data": {
"chief_coordinator": {
"type": "CHIEF_COORDINATOR",
"layer": "EXECUTIVE",
"status": "running"
},
"risk_manager": {
"type": "RISK_MANAGER",
"layer": "EXECUTIVE",
"status": "running"
},
// Additional agents...
},
"error": null
}
Control agent operation.
{
"agent_id": "chief_coordinator",
"action": "restart"
}
{
"success": true,
"data": {
"message": "Agent chief_coordinator restarted successfully",
"status": "running"
},
"error": null
}
Get performance metrics.
Parameter | Type | Required | Description |
---|---|---|---|
period | string | No | Time period for metrics (default: "all", options: "day", "week", "month", "year", "all") |
{
"success": true,
"data": {
"returns": [
{
"date": "2025-03-18T00:00:00Z",
"daily_return": 0.0125,
"cumulative_return": 0.0125
},
{
"date": "2025-03-19T00:00:00Z",
"daily_return": 0.0075,
"cumulative_return": 0.0201
}
// Additional return data...
],
"drawdowns": [
{
"date": "2025-03-18T00:00:00Z",
"drawdown": 0.0
},
{
"date": "2025-03-19T00:00:00Z",
"drawdown": 0.0025
}
// Additional drawdown data...
],
"sharpe_ratio": 2.1,
"win_rate": 0.65,
"trade_count": 42,
"max_drawdown": 0.05,
"volatility": 0.12
},
"error": null
}
Get trade history.
Parameter | Type | Required | Description |
---|---|---|---|
limit | integer | No | Maximum number of trades to return (default: 100) |
offset | integer | No | Offset for pagination (default: 0) |
asset | string | No | Filter by asset (e.g., "BTC/USDT") |
action | string | No | Filter by action (e.g., "buy", "sell") |
status | string | No | Filter by status (e.g., "completed", "executing", "failed") |
{
"success": true,
"data": {
"trades": [
{
"order_id": "order_12345",
"trade_instruction": {
"asset": "BTC/USDT",
"action": "buy",
"quantity": 0.5,
"exchange": "binance",
"execution_strategy": "market"
},
"status": "completed",
"execution_price": 50000.0,
"created_at": "2025-03-19T10:30:00Z",
"completed_at": "2025-03-19T10:30:05Z"
},
// Additional trades...
],
"total": 42,
"limit": 100,
"offset": 0
},
"error": null
}
Get active trades.
{
"success": true,
"data": {
"active_trades": [
{
"order_id": "order_12346",
"trade_instruction": {
"asset": "ETH/USDT",
"action": "buy",
"quantity": 2.0,
"exchange": "binance",
"execution_strategy": "twap"
},
"status": "executing",
"progress": 0.5,
"created_at": "2025-03-19T11:00:00Z",
"estimated_completion": "2025-03-19T11:30:00Z"
},
// Additional active trades...
]
},
"error": null
}
In addition to the REST API, AgentX provides a Websocket API for real-time updates.
Connect to the Websocket endpoint:
ws://localhost:5000/ws
Include your API key in the connection query parameter:
ws://localhost:5000/ws?api_key=your_api_key_here
After connecting, subscribe to specific channels:
{
"action": "subscribe",
"channels": ["system", "trades", "alerts"]
}
Available channels:
system
: System status updatestrades
: Trade execution updatesalerts
: New alertsperformance
: Performance metric updatesportfolio
: Portfolio allocation updatesmarket_data
: Market data updates (requires asset parameter)For market data, specify the asset:
{
"action": "subscribe",
"channels": ["market_data"],
"parameters": {
"market_data": {
"assets": ["BTC/USDT", "ETH/USDT"],
"interval": "1m"
}
}
}
Messages received from the server follow this format:
{
"channel": "trades",
"event": "trade_executed",
"timestamp": "2025-03-19T11:15:00Z",
"data": {
// Event-specific data
}
}
Example trade execution event:
{
"channel": "trades",
"event": "trade_executed",
"timestamp": "2025-03-19T11:15:00Z",
"data": {
"order_id": "order_12347",
"asset": "BTC/USDT",
"action": "buy",
"quantity": 0.1,
"price": 51000.0,
"exchange": "binance"
}
}
Code | Description |
---|---|
AUTH_FAILED |
Authentication failed |
INVALID_REQUEST |
Invalid request format |
MISSING_PARAMETER |
Required parameter missing |
INVALID_PARAMETER |
Parameter value invalid |
RESOURCE_NOT_FOUND |
Requested resource not found |
SYSTEM_ERROR |
Internal system error |
AGENT_ERROR |
Agent-specific error |
RATE_LIMIT_EXCEEDED |
API rate limit exceeded |
API requests are subject to rate limiting:
When rate limit is exceeded, the API returns a 429 status code with the RATE_LIMIT_EXCEEDED
error.
The current API version is v1. Include the version in the URL:
http://localhost:5000/api/v1/system/status
Future API versions will be announced with appropriate migration guides.