API Documentation

Overview

The Market Making System provides a REST API for metrics collection and system monitoring. The API is built with FastAPI and follows RESTful conventions.

Base URL

http://localhost:8000

Authentication

Currently no authentication required (internal service).

Endpoints

GET /health

Health check endpoint to verify service availability.

Request:

GET /health

Response:

{
  "status": "ok",
  "timestamp": "2026-01-06T10:00:00.000Z"
}

Status Codes:

  • 200: Service is healthy
  • 500: Service is unhealthy

POST /metrics/collect

Webhook endpoint for n8n-triggered metrics collection. Collects system snapshots including account balance, market data, grid status, and regime analysis.

Request:

POST /metrics/collect
Content-Type: application/json
 
{
  "source": "n8n_schedule",
  "trigger_time": "2026-01-06T10:00:00Z",
  "collection_id": "optional_custom_id"
}

Request Parameters:

  • source (optional): Identifier for the trigger source (default: “n8n_schedule”)
  • trigger_time (optional): ISO 8601 timestamp of when collection was triggered
  • collection_id (optional): Custom identifier for the collection

Response:

{
  "status": "success",
  "collection_id": "metrics_20260106_100000",
  "timestamp": "2026-01-06T10:00:00.000Z",
  "data_points_collected": 15,
  "storage_status": "committed",
  "dashboard_updated": true,
  "trigger_source": "n8n_schedule"
}

Error Response:

{
  "status": "error",
  "collection_id": "failed",
  "timestamp": "2026-01-06T10:00:00.000Z",
  "data_points_collected": 0,
  "storage_status": "failed",
  "dashboard_updated": false,
  "trigger_source": "n8n_schedule",
  "error": "Detailed error message"
}

Status Codes:

  • 200: Metrics collected successfully
  • 500: Collection failed

Data Models

WebhookRequest

class WebhookRequest(BaseModel):
    trigger_time: Optional[str] = None
    collection_id: Optional[str] = None
    source: Optional[str] = "n8n_schedule"

HealthResponse

class HealthResponse(BaseModel):
    status: str
    timestamp: str

MetricsResponse

class MetricsResponse(BaseModel):
    status: str
    collection_id: str
    timestamp: str
    data_points_collected: int
    storage_status: str
    dashboard_updated: bool
    trigger_source: str
    error: Optional[str] = None

Error Handling

The API implements comprehensive error handling:

  • Validation Errors: Invalid request data returns 422 with detailed validation messages
  • Internal Errors: System failures return 500 with error details
  • Exchange Errors: Exchange API failures are logged but don’t break the collection process
  • Configuration Errors: Missing or invalid configuration returns 500

Rate Limiting

Currently no rate limiting implemented (internal service).

Monitoring

  • All requests are logged with correlation IDs
  • Metrics collection operations are tracked
  • Health checks monitor system components
  • Errors are logged with full context

Future Endpoints

Planned API expansions:

  • GET /metrics/history: Retrieve historical metrics
  • GET /regime/current: Get current market regime
  • GET /grids/status: Get grid trading status
  • POST /grids/create: Create new grid configuration
  • POST /regime/analyze: Trigger regime analysis