{
  "openapi": "3.1.0",
  "info": {
    "title": "ATrader Pro - Automated Trading API & Agent Protocol",
    "version": "1.0.0",
    "description": "Official machine-readable API and agentic interface for ATrader Pro (https://atrader.pro). Provides automated trading bots, live AI confluence signals, risk calculators, and Deriv WebSocket execution with zero-friction free-tier access and demo sandbox support.",
    "termsOfService": "https://atrader.pro/terms",
    "contact": {
      "name": "ATrader Pro Developer Support",
      "url": "https://atrader.pro/docs/api",
      "email": "contato@atrader.pro"
    },
    "license": {
      "name": "Proprietary - Free Developer Tier",
      "url": "https://atrader.pro/terms"
    },
    "x-versioning": {
      "policy": "Semantic Versioning 2.0.0 (SemVer)",
      "deprecationPolicy": "Deprecations are announced 90 days in advance via Deprecation and Sunset HTTP headers (RFC 8594).",
      "stability": "GA (Generally Available)"
    }
  },
  "servers": [
    {
      "url": "https://atrader.pro",
      "description": "Production Server (v1)"
    }
  ],
  "components": {
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "description": "OAuth 2.0 PKCE authentication via Deriv Authorization Server (RFC 8414)",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://oauth.deriv.com/oauth2/authorize",
            "tokenUrl": "https://oauth.deriv.com/oauth2/token",
            "scopes": {
              "read": "Read-only access to account settings, open positions, balance and bot catalog",
              "trade": "Execute automated trades via ATrader bots and Deriv WebSockets",
              "trading_information": "Access trading history, transaction statements, win rate analytics, and telemetry",
              "payments": "Access cashier deposit status and withdrawal history",
              "admin": "Configure bot parameters, risk management rules, and martingale limits"
            }
          }
        }
      },
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API-Key / Deriv-Token",
        "description": "Instant self-serve developer token generated at https://atrader.pro/app/settings or https://app.deriv.com/account/api-token"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "example": "BAD_REQUEST",
            "description": "Machine-readable error code"
          },
          "message": {
            "type": "string",
            "example": "Invalid parameters provided in request",
            "description": "Human-readable error description"
          },
          "status": {
            "type": "integer",
            "example": 400
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "responses": {
      "400BadRequest": {
        "description": "Bad Request - Invalid payload or parameters",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "401Unauthorized": {
        "description": "Unauthorized - Missing or invalid API token or OAuth bearer",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "403Forbidden": {
        "description": "Forbidden - Insufficient scope permissions",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "404NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "429RateLimited": {
        "description": "Rate limit exceeded - Retry after specified delay",
        "headers": {
          "Retry-After": {
            "schema": { "type": "integer" },
            "description": "Seconds to wait before retrying"
          },
          "RateLimit-Limit": {
            "schema": { "type": "integer" }
          },
          "RateLimit-Remaining": {
            "schema": { "type": "integer" }
          },
          "RateLimit-Reset": {
            "schema": { "type": "integer" }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "500InternalError": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/bots": {
      "get": {
        "summary": "List available trading bots",
        "description": "Returns the catalog of 14 free AI trading bots (Apex Trend, Quantum Pulse, Nexus AI, etc.) with strategy types, recommended assets, and default multipliers.",
        "operationId": "listBots",
        "responses": {
          "200": {
            "description": "Catalog of automated trading bots",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "bots": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "name": { "type": "string" },
                          "strategy": { "type": "string" },
                          "recommendedAsset": { "type": "string" },
                          "winRate": { "type": "string" },
                          "freeTier": { "type": "boolean" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": { "$ref": "#/components/responses/429RateLimited" },
          "500": { "$ref": "#/components/responses/500InternalError" }
        }
      }
    },
    "/api/signals": {
      "get": {
        "summary": "Get real-time AI confluence signals",
        "description": "Streams or fetches latest statistical signals with >90% win rate across 15 synthetic and forex assets on M1, M2, and M5 timeframes.",
        "operationId": "getSignals",
        "responses": {
          "200": {
            "description": "Live confluence signals"
          },
          "429": { "$ref": "#/components/responses/429RateLimited" },
          "500": { "$ref": "#/components/responses/500InternalError" }
        }
      }
    },
    "/api/status": {
      "get": {
        "summary": "System health and WebSocket telemetry",
        "description": "Check operational status, WebSocket ping latency, and Deriv API connection health.",
        "operationId": "getStatus",
        "responses": {
          "200": {
            "description": "Platform status and telemetry"
          },
          "429": { "$ref": "#/components/responses/429RateLimited" },
          "500": { "$ref": "#/components/responses/500InternalError" }
        }
      }
    },
    "/api/trade": {
      "post": {
        "summary": "Execute bot contract order",
        "description": "Places an automated trade contract in either Demo Virtual Sandbox (VRTC) or Real account.",
        "operationId": "executeTrade",
        "security": [
          { "OAuth2": ["trade"] },
          { "ApiKeyAuth": [] }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["symbol", "contractType", "stake"],
                "properties": {
                  "symbol": { "type": "string", "example": "1HZ100V" },
                  "contractType": { "type": "string", "example": "DIGITDIFF" },
                  "stake": { "type": "number", "example": 1.0 },
                  "duration": { "type": "integer", "example": 1 },
                  "durationUnit": { "type": "string", "example": "t" },
                  "sandbox": { "type": "boolean", "default": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Trade executed successfully"
          },
          "400": { "$ref": "#/components/responses/400BadRequest" },
          "401": { "$ref": "#/components/responses/401Unauthorized" },
          "403": { "$ref": "#/components/responses/403Forbidden" },
          "429": { "$ref": "#/components/responses/429RateLimited" },
          "500": { "$ref": "#/components/responses/500InternalError" }
        }
      }
    },
    "/api/markdown": {
      "get": {
        "summary": "Accept-negotiated markdown documentation",
        "description": "Returns token-budget-optimized Markdown representation of any page or resource according to RFC 9110 acceptmarkdown.com standards.",
        "operationId": "getMarkdown",
        "responses": {
          "200": {
            "description": "Markdown content",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/404NotFound" },
          "429": { "$ref": "#/components/responses/429RateLimited" },
          "500": { "$ref": "#/components/responses/500InternalError" }
        }
      }
    }
  }
}
