Comprehensive API documentation for the REChain Autonomous Agent for Pythagorean Perpetual Futures.
The agent provides a RESTful API for monitoring, administration, and trading operations. All endpoints require authentication unless otherwise specified.
Most endpoints require an API key sent in the x-api-key header:
curl -H "x-api-key: your-api-key" http://localhost:3000/api/endpointAdmin endpoints require an admin token in the x-admin-token header:
curl -H "x-admin-token: your-admin-token" http://localhost:3000/admin/endpointFor wallet-based authentication:
- Get a nonce:
GET /web3/nonce - Sign the message containing the nonce
- Verify signature:
POST /web3/verify
All endpoints are relative to the base URL: http://localhost:3000 (or your configured domain)
Description: Liveness probe endpoint Authentication: None Response: 200 OK
Description: Readiness probe endpoint Authentication: None Response: 200 OK
Description: Get operational status metrics Authentication: API key required Response: JSON object with status information
Description: Get current position exposure breakdown Authentication: API key required Response: JSON array of position objects
Description: Get historical performance and PnL summary Authentication: API key required Response: JSON object with performance metrics
Description: Server-Sent Events stream for real-time metrics Authentication: API key required Events:
metrics: Emitted every 5 seconds with current metricsrebalance: Emitted when rebalancing occurserror: Emitted on errors
Example Client Code:
const eventSource = new EventSource('/metrics/stream');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Metrics update:', data);
};Description: Register a new webhook Authentication: Admin token required Body:
{
"url": "https://your-webhook-endpoint.com"
}Response: 201 Created with webhook details
Description: Remove a webhook Authentication: Admin token required Body:
{
"url": "https://your-webhook-endpoint.com"
}Response: 200 OK
Description: List all registered webhooks Authentication: Admin token required Response: JSON array of webhook objects
Description: Manually refresh metrics (if provider supports refresh) Authentication: Admin token required Response: 200 OK
Description: Update metrics (file/stub providers) Authentication: Admin token required Response: 200 OK
Description: Emit a custom event Authentication: Admin token required Body:
{
"event": "custom.event.name",
"payload": {"key": "value"}
}Response: 200 OK
Description: Safe configuration view (sensitive data redacted) Authentication: Admin token required Response: JSON configuration object
Description: List active sessions with metadata Authentication: Admin token required Response: JSON array of session objects
Description: Remove a session Authentication: Admin token required Body:
{
"sessionId": "session-id-to-remove"
}Response: 200 OK
Description: Grant admin role to a session Authentication: Admin token required Body:
{
"sessionId": "session-id-to-elevate"
}Response: 200 OK with updated session details
Description: Generate a nonce for wallet authentication Authentication: None Response:
{
"id": "unique-request-id",
"nonce": "random-nonce-string"
}Description: Verify wallet signature and create session Authentication: None Body:
{
"id": "request-id-from-nonce",
"address": "0xWalletAddress",
"signature": "signature-string",
"message": "message-containing-nonce"
}Response:
{
"sessionId": "generated-session-id",
"exp": "expiration-timestamp"
}Description: DID authentication stub (for testing) Authentication: None Body:
{
"did": "did:example:123",
"proof": "stub-proof"
}Response:
{
"sessionId": "generated-session-id",
"exp": "expiration-timestamp"
}The agent emits various events that can be sent to registered webhooks:
- rebalance: Position rebalancing occurred
- metrics.update: Metrics were updated
- metrics.refresh: Metrics were manually refreshed
- auth.web3: Web3 authentication succeeded
- auth.did: DID authentication succeeded
- metrics.tick: Periodic metrics tick (enable with
WEBHOOK_ON_TICK=true)
Webhook requests include security headers:
x-signature: sha256=<hmac>- HMAC signaturex-id: Unique identifier for deduplicationx-ts: Timestamp for validation
Signature Calculation:
const hmac = HMAC_SHA256(WEBHOOK_SECRET, x-id + x-ts + body)Environment variables for webhook configuration:
WEBHOOK_SECRET: Secret for signature validationWEBHOOK_MAX_RETRIES: Maximum retry attempts (default: 3)WEBHOOK_RETRY_DELAY_MS: Retry delay in millisecondsWEBHOOK_ON_TICK: Enable tick events (default: false)
The API implements rate limiting to prevent abuse:
- General endpoints: 100 requests per minute
- Admin endpoints: 20 requests per minute
- Authentication endpoints: 10 requests per minute
Rate limit headers are included in responses:
X-RateLimit-Limit: Maximum requests allowedX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Time when limit resets
Standard error response format:
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error message",
"details": {}
}
}UNAUTHORIZED: Authentication required or invalidFORBIDDEN: Insufficient permissionsNOT_FOUND: Resource not foundRATE_LIMITED: Rate limit exceededVALIDATION_ERROR: Invalid request dataINTERNAL_ERROR: Server error
The API follows semantic versioning. Current version: v0.1.0
Version can be specified in the Accept header:
Accept: application/vnd.pythagorean-agent.v0.1.0+json
All successful responses return JSON with consistent structure:
{
"data": {
// Endpoint-specific data
},
"meta": {
"timestamp": "2023-01-01T00:00:00Z",
"version": "0.1.0"
}
}For complete API specification, see openapi.yaml or visit /docs when the server is running.
The OpenAPI spec provides:
- Interactive API documentation
- Request/response schemas
- Authentication requirements
- Error responses
- Example requests
import { PythagoreanAgentClient } from 'pythagorean-agent-client';
const client = new PythagoreanAgentClient({
baseUrl: 'http://localhost:3000',
apiKey: 'your-api-key'
});
// Example usage
const metrics = await client.getMetrics();from pythagorean_agent import Client
client = Client(
base_url="http://localhost:3000",
api_key="your-api-key"
)
metrics = client.get_metrics()For API-related issues:
- Check the OpenAPI documentation at
/docs - Review server logs for error details
- Test endpoints with curl or Postman
- Create issues on GitHub for bugs or feature requests
Note: This documentation is for version 0.1.0 of the API. Check for updates in future releases.