Date: 2024-12-29
Feature: Multi-account wash trading system for BTC pairs
Status: Complete
Base URL: http://localhost:3000/api/v1
Authentication: Bearer token (JWT)
Content-Type: application/json
Rate Limiting: 100 requests/minute per client
POST /sessions
Request Body:
{
"name": "BTC Wash Trading Session 1",
"strategyId": "equal-volume-btc",
"accountIds": ["account-1", "account-2", "account-3"],
"targetVolume": 10.5,
"duration": 3600000
}
Response (201 Created):
{
"success": true,
"data": {
"id": "session-123",
"name": "BTC Wash Trading Session 1",
"strategy": {
"id": "equal-volume-btc",
"name": "Equal Volume BTC Strategy",
"type": "equal_volume",
"symbol": "BTC/USD"
},
"accounts": ["account-1", "account-2", "account-3"],
"status": "pending",
"targetVolume": 10.5,
"currentVolume": 0,
"startTime": null,
"endTime": null,
"duration": 3600000,
"createdAt": "2024-12-29T10:00:00Z",
"updatedAt": "2024-12-29T10:00:00Z"
}
}
GET /sessions/{sessionId}
Response (200 OK):
{
"success": true,
"data": {
"id": "session-123",
"name": "BTC Wash Trading Session 1",
"status": "active",
"targetVolume": 10.5,
"currentVolume": 3.2,
"progress": 30.5,
"orderPairs": 15,
"successfulPairs": 12,
"failedPairs": 1,
"riskMetrics": {
"totalExposure": 50000,
"maxDrawdown": 0.02,
"currentDrawdown": 0.01,
"riskScore": 25,
"alerts": []
},
"startTime": "2024-12-29T10:05:00Z",
"estimatedEndTime": "2024-12-29T11:05:00Z"
}
}
GET /sessions?status=active&limit=10&offset=0
Query Parameters:
status
(optional): Filter by session statuslimit
(optional): Number of sessions to return (default: 10)offset
(optional): Number of sessions to skip (default: 0)Response (200 OK):
{
"success": true,
"data": {
"sessions": [
{
"id": "session-123",
"name": "BTC Wash Trading Session 1",
"status": "active",
"targetVolume": 10.5,
"currentVolume": 3.2,
"progress": 30.5,
"startTime": "2024-12-29T10:05:00Z"
}
],
"pagination": {
"total": 1,
"limit": 10,
"offset": 0,
"hasMore": false
}
}
}
POST /sessions/{sessionId}/start
Response (200 OK):
{
"success": true,
"data": {
"id": "session-123",
"status": "active",
"startTime": "2024-12-29T10:05:00Z",
"message": "Session started successfully"
}
}
POST /sessions/{sessionId}/pause
Response (200 OK):
{
"success": true,
"data": {
"id": "session-123",
"status": "paused",
"pausedAt": "2024-12-29T10:30:00Z",
"message": "Session paused successfully"
}
}
POST /sessions/{sessionId}/resume
Response (200 OK):
{
"success": true,
"data": {
"id": "session-123",
"status": "active",
"resumedAt": "2024-12-29T10:35:00Z",
"message": "Session resumed successfully"
}
}
POST /sessions/{sessionId}/stop
Response (200 OK):
{
"success": true,
"data": {
"id": "session-123",
"status": "completed",
"endTime": "2024-12-29T10:40:00Z",
"finalVolume": 8.7,
"message": "Session stopped successfully"
}
}
GET /accounts
Response (200 OK):
{
"success": true,
"data": {
"accounts": [
{
"id": "account-1",
"name": "Primary Trading Account",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"balance": {
"total": 100000,
"available": 85000,
"used": 15000
},
"positions": [
{
"symbol": "BTC/USD",
"side": "long",
"size": 0.5,
"entryPrice": 45000,
"markPrice": 46000,
"unrealizedPnl": 500
}
],
"riskLimits": {
"maxPositionSize": 0.1,
"stopLossThreshold": 0.05,
"maxSlippage": 0.02
},
"isActive": true,
"lastUpdated": "2024-12-29T10:00:00Z"
}
]
}
}
GET /accounts/{accountId}
Response (200 OK):
{
"success": true,
"data": {
"id": "account-1",
"name": "Primary Trading Account",
"address": "0x1234567890abcdef1234567890abcdef12345678",
"balance": {
"total": 100000,
"available": 85000,
"used": 15000
},
"positions": [
{
"symbol": "BTC/USD",
"side": "long",
"size": 0.5,
"entryPrice": 45000,
"markPrice": 46000,
"unrealizedPnl": 500
}
],
"riskLimits": {
"maxPositionSize": 0.1,
"stopLossThreshold": 0.05,
"maxSlippage": 0.02
},
"isActive": true,
"createdAt": "2024-12-29T09:00:00Z",
"lastUpdated": "2024-12-29T10:00:00Z"
}
}
PUT /accounts/{accountId}/risk-limits
Request Body:
{
"maxPositionSize": 0.15,
"stopLossThreshold": 0.03,
"maxSlippage": 0.015
}
Response (200 OK):
{
"success": true,
"data": {
"id": "account-1",
"riskLimits": {
"maxPositionSize": 0.15,
"stopLossThreshold": 0.03,
"maxSlippage": 0.015
},
"updatedAt": "2024-12-29T10:00:00Z",
"message": "Risk limits updated successfully"
}
}
GET /strategies
Response (200 OK):
{
"success": true,
"data": {
"strategies": [
{
"id": "equal-volume-btc",
"name": "Equal Volume BTC Strategy",
"type": "equal_volume",
"symbol": "BTC/USD",
"parameters": {
"volumeDistribution": "equal",
"priceRange": {
"min": 0.001,
"max": 0.01
},
"timing": {
"minInterval": 30000,
"maxInterval": 120000,
"orderSize": {
"min": 0.1,
"max": 0.5
}
},
"riskLimits": {
"maxPositionSize": 0.1,
"stopLossThreshold": 0.05,
"maxSlippage": 0.02
}
},
"isActive": true,
"createdAt": "2024-12-29T09:00:00Z"
}
]
}
}
POST /strategies
Request Body:
{
"name": "Custom BTC Strategy",
"type": "custom",
"symbol": "BTC/USD",
"parameters": {
"volumeDistribution": "weighted",
"priceRange": {
"min": 0.002,
"max": 0.008
},
"timing": {
"minInterval": 45000,
"maxInterval": 90000,
"orderSize": {
"min": 0.2,
"max": 0.8
}
},
"riskLimits": {
"maxPositionSize": 0.12,
"stopLossThreshold": 0.04,
"maxSlippage": 0.015
}
}
}
Response (201 Created):
{
"success": true,
"data": {
"id": "custom-btc-strategy-1",
"name": "Custom BTC Strategy",
"type": "custom",
"symbol": "BTC/USD",
"parameters": {
"volumeDistribution": "weighted",
"priceRange": {
"min": 0.002,
"max": 0.008
},
"timing": {
"minInterval": 45000,
"maxInterval": 90000,
"orderSize": {
"min": 0.2,
"max": 0.8
}
},
"riskLimits": {
"maxPositionSize": 0.12,
"stopLossThreshold": 0.04,
"maxSlippage": 0.015
}
},
"isActive": true,
"createdAt": "2024-12-29T10:00:00Z"
}
}
GET /sessions/{sessionId}/orders?status=filled&limit=20&offset=0
Query Parameters:
status
(optional): Filter by order statuslimit
(optional): Number of orders to return (default: 20)offset
(optional): Number of orders to skip (default: 0)Response (200 OK):
{
"success": true,
"data": {
"orders": [
{
"id": "order-pair-1",
"sessionId": "session-123",
"buyOrder": {
"id": "buy-order-1",
"accountId": "account-1",
"symbol": "BTC/USD",
"side": "buy",
"type": "limit",
"size": 0.3,
"price": 45000,
"status": "filled",
"filledSize": 0.3,
"averagePrice": 45005,
"fees": 13.5,
"slippage": 0.001,
"createdAt": "2024-12-29T10:05:00Z"
},
"sellOrder": {
"id": "sell-order-1",
"accountId": "account-2",
"symbol": "BTC/USD",
"side": "sell",
"type": "limit",
"size": 0.3,
"price": 45010,
"status": "filled",
"filledSize": 0.3,
"averagePrice": 45008,
"fees": 13.5,
"slippage": 0.001,
"createdAt": "2024-12-29T10:05:00Z"
},
"status": "filled",
"volume": 0.3,
"expectedProfit": 3.0,
"actualProfit": 2.7,
"fees": 27.0,
"slippage": 0.001,
"executionTime": 1250,
"createdAt": "2024-12-29T10:05:00Z"
}
],
"pagination": {
"total": 15,
"limit": 20,
"offset": 0,
"hasMore": false
}
}
}
GET /sessions/{sessionId}/risk
Response (200 OK):
{
"success": true,
"data": {
"sessionId": "session-123",
"totalExposure": 50000,
"maxDrawdown": 0.02,
"currentDrawdown": 0.01,
"sharpeRatio": 1.8,
"volatility": 0.15,
"correlation": 0.95,
"riskScore": 25,
"alerts": [
{
"id": "alert-1",
"type": "position_size",
"severity": "medium",
"message": "Account account-1 position size approaching limit",
"threshold": 0.08,
"currentValue": 0.075,
"accountId": "account-1",
"isAcknowledged": false,
"createdAt": "2024-12-29T10:15:00Z"
}
],
"lastUpdated": "2024-12-29T10:15:00Z"
}
}
POST /sessions/{sessionId}/risk/alerts/{alertId}/acknowledge
Response (200 OK):
{
"success": true,
"data": {
"id": "alert-1",
"isAcknowledged": true,
"acknowledgedAt": "2024-12-29T10:20:00Z",
"message": "Risk alert acknowledged successfully"
}
}
GET /health
Response (200 OK):
{
"success": true,
"data": {
"status": "healthy",
"timestamp": "2024-12-29T10:00:00Z",
"version": "1.0.0",
"uptime": 3600,
"components": {
"database": "healthy",
"pacifica-api": "healthy",
"websocket": "healthy",
"risk-manager": "healthy"
},
"metrics": {
"activeSessions": 2,
"totalAccounts": 20,
"ordersPerMinute": 45,
"averageLatency": 85
}
}
}
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid request parameters",
"details": {
"field": "targetVolume",
"reason": "Must be greater than 0"
}
}
}
VALIDATION_ERROR
: Request validation failedSESSION_NOT_FOUND
: Session does not existACCOUNT_NOT_FOUND
: Account does not existSTRATEGY_NOT_FOUND
: Strategy does not existINSUFFICIENT_BALANCE
: Account balance insufficientRISK_LIMIT_EXCEEDED
: Risk limit exceededRATE_LIMIT_EXCEEDED
: API rate limit exceededINTERNAL_ERROR
: Internal server error200 OK
: Request successful201 Created
: Resource created successfully400 Bad Request
: Invalid request parameters401 Unauthorized
: Authentication required403 Forbidden
: Insufficient permissions404 Not Found
: Resource not found429 Too Many Requests
: Rate limit exceeded500 Internal Server Error
: Server errorconst ws = new WebSocket('ws://localhost:3000/ws');
{
"type": "session_update",
"data": {
"sessionId": "session-123",
"status": "active",
"currentVolume": 3.2,
"progress": 30.5,
"orderPairs": 15,
"successfulPairs": 12,
"failedPairs": 1,
"timestamp": "2024-12-29T10:15:00Z"
}
}
{
"type": "order_update",
"data": {
"sessionId": "session-123",
"orderPairId": "order-pair-1",
"status": "filled",
"volume": 0.3,
"profit": 2.7,
"fees": 27.0,
"executionTime": 1250,
"timestamp": "2024-12-29T10:15:00Z"
}
}
{
"type": "risk_alert",
"data": {
"sessionId": "session-123",
"alertId": "alert-1",
"type": "position_size",
"severity": "medium",
"message": "Account position size approaching limit",
"accountId": "account-1",
"timestamp": "2024-12-29T10:15:00Z"
}
}
{
"type": "system_status",
"data": {
"status": "healthy",
"activeSessions": 2,
"ordersPerMinute": 45,
"averageLatency": 85,
"timestamp": "2024-12-29T10:15:00Z"
}
}
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200
{
"success": false,
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Try again in 60 seconds.",
"retryAfter": 60
}
}
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
POST /auth/refresh
Request Body:
{
"refreshToken": "refresh_token_here"
}
Response (200 OK):
{
"success": true,
"data": {
"accessToken": "new_access_token",
"refreshToken": "new_refresh_token",
"expiresIn": 3600
}
}