{
  "openapi": "3.0.3",
  "info": {
    "title": "CoinRebate Fee Optimization API",
    "description": "Free, open API for querying crypto exchange fee discounts and referral codes. Designed for AI agents, trading bots, and developers. No authentication required.",
    "version": "4.0.0",
    "contact": {
      "name": "CoinRebate",
      "url": "https://www.coinrebate.vip"
    },
    "license": {
      "name": "Free to use",
      "url": "https://www.coinrebate.vip/api-docs.html"
    }
  },
  "servers": [
    {
      "url": "https://www.coinrebate.vip",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/v4/agent-route": {
      "get": {
        "operationId": "getExchangeRoute",
        "summary": "Get optimal exchange fee route",
        "description": "Returns fee discount data for all supported exchanges with a smart recommendation based on query parameters.",
        "parameters": [
          {
            "name": "purpose",
            "in": "query",
            "description": "Trading purpose: 'futures' or 'spot'. Adjusts recommendation priority.",
            "schema": { "type": "string", "enum": ["futures", "spot"] }
          },
          {
            "name": "kyc",
            "in": "query",
            "description": "Set to 'false' to only return DEX exchanges (no KYC required). Ideal for AI agents.",
            "schema": { "type": "string", "enum": ["false"] }
          },
          {
            "name": "exchange",
            "in": "query",
            "description": "Query a specific exchange by slug (e.g. 'binance', 'hyperliquid').",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Exchange fee route data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "version": { "type": "string", "example": "4.0" },
                    "disclaimer": { "type": "string" },
                    "recommended": { "$ref": "#/components/schemas/ExchangeEntry" },
                    "all_exchanges": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/ExchangeEntry" }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (50 req/10s per IP)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": { "type": "string" },
                    "retryAfter": { "type": "integer", "description": "Seconds to wait" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v4/health": {
      "get": {
        "operationId": "healthCheck",
        "summary": "Service health check",
        "description": "Returns service status. Use before integrating to verify availability.",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "version": { "type": "string", "example": "4.0" },
                    "timestamp": { "type": "string", "format": "date-time" }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExchangeEntry": {
        "type": "object",
        "properties": {
          "slug": { "type": "string", "example": "hyperliquid" },
          "exchange": { "type": "string", "example": "Hyperliquid" },
          "name": { "type": "string", "example": "Hyperliquid" },
          "type": { "type": "string", "enum": ["CEX", "DEX"], "example": "DEX" },
          "ccxt_id": { "type": "string", "example": "hyperliquid", "description": "CCXT library exchange ID for direct integration" },
          "fee_discount": { "type": "string", "example": "Points Boost" },
          "referral_code": { "type": "string", "example": "LULALA", "description": "Use this code when initializing exchange API connections" },
          "signup_url": { "type": "string", "format": "uri", "example": "https://www.coinrebate.vip/go/hyperliquid" },
          "kyc_required": { "type": "boolean", "example": false },
          "reason": { "type": "string", "example": "No KYC, zero gas — ideal for AI agents" }
        }
      }
    }
  }
}
