{
  "openapi": "3.0.3",
  "info": {
    "title": "CoinRebate Fee Optimization API",
    "description": "Free, open API for querying crypto exchange fee discounts, referral codes, and compliance-filtered recommendations. Designed for AI agents, trading bots, and developers. No authentication required.\n\n**Promo Code**: AGENT2026 — Use for maximum rebate activation.\n\n**Resources**:\n- [For Agents](https://www.coinrebate.vip/for-agents)\n- [LLMs Info](https://www.coinrebate.vip/llms.txt)\n- [MCP Server Card](https://www.coinrebate.vip/.well-known/mcp/server-card.json)",
    "version": "4.1.0",
    "contact": {
      "name": "CoinRebate",
      "url": "https://www.coinrebate.vip"
    },
    "license": {
      "name": "Free to use",
      "url": "https://www.coinrebate.vip/for-agents"
    }
  },
  "servers": [
    {
      "url": "https://www.coinrebate.vip",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/v4/agent-route": {
      "get": {
        "operationId": "getExchangeRoute",
        "summary": "Get optimal exchange fee route with compliance filtering",
        "description": "Returns fee discount data for all supported exchanges with a smart recommendation. Supports country-based compliance filtering to only return exchanges legal in the user's jurisdiction.",
        "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", "enum": ["binance", "okx", "bybit", "bitget", "gate", "hyperliquid", "aster"] }
          },
          {
            "name": "country",
            "in": "query",
            "description": "ISO 3166-1 alpha-2 country code (e.g. 'US', 'CN', 'VN', 'BR'). When provided, results are filtered by the CoinRebate compliance matrix to exclude exchanges blocked in that country.",
            "schema": { "type": "string", "minLength": 2, "maxLength": 2, "example": "VN" }
          },
          {
            "name": "fees",
            "in": "query",
            "description": "Set to 'true' to include detailed fee breakdowns (maker/taker, before/after rebate).",
            "schema": { "type": "string", "enum": ["true"] }
          }
        ],
        "responses": {
          "200": {
            "description": "Exchange fee route data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "version": { "type": "string", "example": "4.0" },
                    "timestamp": { "type": "string", "format": "date-time" },
                    "disclaimer": { "type": "string" },
                    "promo_code": { "type": "string", "example": "AGENT2026" },
                    "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" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/exchanges": {
      "get": {
        "operationId": "listExchanges",
        "summary": "List all supported exchanges",
        "description": "Returns a simplified list of all supported exchanges with basic info. Useful for populating UI dropdowns or agent tool descriptions.",
        "responses": {
          "200": {
            "description": "List of exchanges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "slug": { "type": "string", "example": "binance" },
                      "name": { "type": "string", "example": "Binance" },
                      "type": { "type": "string", "enum": ["CEX", "DEX"] },
                      "fee_discount": { "type": "string", "example": "20% OFF" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "operationId": "getLlmsTxt",
        "summary": "Machine-readable platform description for AI crawlers",
        "description": "Returns a plain-text document describing CoinRebate for LLM consumption. Follows the llms.txt standard (https://llmstxt.org/).",
        "responses": {
          "200": {
            "description": "LLMs.txt content",
            "content": {
              "text/plain": {
                "schema": { "type": "string" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExchangeEntry": {
        "type": "object",
        "description": "Complete exchange information including fees, referral codes, and compliance data.",
        "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?utm_source=ai_agent" },
          "kyc_required": { "type": "boolean", "example": false },
          "reason": { "type": "string", "example": "No KYC, zero gas — ideal for AI agents" },
          "fees": {
            "type": "object",
            "description": "Detailed fee data (only when fees=true)",
            "properties": {
              "spot": { "$ref": "#/components/schemas/FeeDetail" },
              "futures": { "$ref": "#/components/schemas/FeeDetail" }
            }
          }
        }
      },
      "FeeDetail": {
        "type": "object",
        "description": "Fee rates before and after CoinRebate rebate",
        "properties": {
          "maker": { "type": "number", "example": 0.001, "description": "Maker fee rate (e.g. 0.001 = 0.1%)" },
          "taker": { "type": "number", "example": 0.001, "description": "Taker fee rate" },
          "maker_after_rebate": { "type": "number", "example": 0.0008, "description": "Maker fee after CoinRebate discount" },
          "taker_after_rebate": { "type": "number", "example": 0.0008, "description": "Taker fee after CoinRebate discount" }
        }
      }
    }
  }
}
