{
  "openapi": "3.1.0",
  "info": {
    "title": "CoinKirin API",
    "description": "Cryptocurrency market data API. Real-time prices, market caps, exchanges, news, social metrics, AI summaries, and more. JSON responses follow the {code, message?, data?} envelope, and the envelope code matches the HTTP status. Anonymous public reads: 80 req/min per IP. Price history, global charts, funding, and perpetual-futures reads: 10 req/min per IP. List, detail, search, convert, and ticker JSON are served from the market snapshot; tickers absent from the snapshot are an empty list. News detail is snapshot-only. Social-metrics latest is null and history is an empty list. Public accounts and authenticated operations were closed on 2026-10-13. Retired account URLs return HTTP 410 without credential validation. Request JSON bodies are limited to 32768 bytes. Anonymous ad tracking, analytics, client errors and translation feedback are closed (410) before body parsing or storage access. Ads are display-only, issue no tracking tokens and have a fail-closed 10 requests/minute/IP limit; successful displays and empty slots share a 15-second public cache. The only public POST is the read-only coins/batch query (32KiB, 1024 chunks, 5-second body deadline). As of 2026-10-14, client limits group IPv4 addresses and IPv6 /64 networks. History responses coalesce and share a bounded 15-second in-memory cache before PostgreSQL; unknown query keys do not change that cache identity. Public PostgreSQL operations use a read-only transaction with server-side statement, lock and transaction time limits. Funding/OI overview result sets have explicit caps; exceeding them returns 503 rather than truncated aggregate totals.",
    "version": "1.5.0",
    "contact": {
      "email": "api@coinkirin.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.coinkirin.com/api/v1"
    }
  ],
  "paths": {
    "/coins": {
      "get": {
        "summary": "List coins",
        "description": "Paginated list of cryptocurrencies with price, market cap, and volume data.",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 250
            }
          },
          {
            "name": "sort_by",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "market_cap",
              "enum": [
                "rank",
                "price_usd",
                "market_cap",
                "volume_24h",
                "change_1h",
                "change_24h",
                "change_7d",
                "name",
                "score"
              ]
            }
          },
          {
            "name": "sort_order",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "description": "Opaque cursor returned by the previous cursor page"
            }
          },
          {
            "name": "use_cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated coin list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedCoins"
                }
              }
            }
          }
        }
      }
    },
    "/coins/{slug}": {
      "get": {
        "summary": "Coin detail",
        "description": "Returns full coin doc when active. A previously-indexed slug that was de-listed returns HTTP 410 Gone with a minimal {slug, name, symbol} body; a slug that never existed returns HTTP 404.",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Coin details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "410": {
            "$ref": "#/components/responses/Gone"
          }
        }
      }
    },
    "/coins/gainers": {
      "get": {
        "summary": "Top gainers",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "24h",
              "enum": [
                "1h",
                "24h",
                "7d"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Top gaining coins (paginated)"
          }
        }
      }
    },
    "/coins/losers": {
      "get": {
        "summary": "Top losers",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "24h",
              "enum": [
                "1h",
                "24h",
                "7d"
              ]
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Top losing coins (paginated)"
          }
        }
      }
    },
    "/coins/recently-added": {
      "get": {
        "summary": "Recently added coins",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated new listings: launch_date within 400 days, excluding stables and market caps at or above 20B USD; if fewer than 10, dated non-stable coins fill the page"
          }
        }
      }
    },
    "/coins/history/{slug}": {
      "get": {
        "summary": "Price history (OHLCV)",
        "description": "PostgreSQL OHLCV for a slug present in the snapshot. 10 req/min per IP in addition to the anonymous cap. Cached longer than list JSON.",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "interval",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1h",
                "1d"
              ],
              "default": "1d"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OHLCV price history array"
          }
        }
      }
    },
    "/exchanges": {
      "get": {
        "summary": "List exchanges",
        "description": "Supports numbered pages or cursor pagination. Supplying cursor or use_cursor=1 selects cursor mode.",
        "tags": [
          "Exchanges"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 250
            }
          },
          {
            "name": "sort_by",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "volume_24h",
              "enum": [
                "volume_24h",
                "rank",
                "trust_score",
                "name",
                "year_established"
              ]
            }
          },
          {
            "name": "sort_order",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "desc",
              "enum": [
                "asc",
                "desc"
              ]
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "spot",
                "derivatives",
                "dex"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "use_cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated exchange list or cursor page"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/exchanges/{slug}": {
      "get": {
        "summary": "Exchange detail",
        "description": "Returns full exchange doc when active. A previously-indexed slug that was de-listed returns true HTTP 410 Gone with a minimal {slug, name} body.",
        "tags": [
          "Exchanges"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Exchange details"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "410": {
            "$ref": "#/components/responses/Gone"
          }
        }
      }
    },
    "/categories": {
      "get": {
        "summary": "List categories",
        "tags": [
          "Categories"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 250
            }
          },
          {
            "name": "sort_by",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "market_cap",
              "enum": [
                "market_cap",
                "volume_24h",
                "change_24h",
                "coin_count",
                "name"
              ]
            }
          },
          {
            "name": "sort_order",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "desc",
              "enum": [
                "asc",
                "desc"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated category list"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/categories/{slug}": {
      "get": {
        "summary": "Category detail with coins",
        "description": "coins_fallback=true means coins contains only the known upstream top_coins subset and must not be treated as a complete paginated membership list.",
        "tags": [
          "Categories"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Category details, coins array, and coins_fallback completeness flag"
          }
        }
      }
    },
    "/news": {
      "get": {
        "summary": "List news articles",
        "description": "Supports numbered pages or cursor pagination. Supplying cursor or use_cursor=1 selects cursor mode.",
        "tags": [
          "News"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 250
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 50
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "use_cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated news list or cursor page"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/news/{slug}": {
      "get": {
        "summary": "News article detail",
        "description": "Snapshot article only. Unknown or not-in-snapshot slugs return HTTP 404. Does not query the database.",
        "tags": [
          "News"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 160,
              "pattern": "^[a-z0-9][a-z0-9-]{0,159}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Full article"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/global/stats": {
      "get": {
        "summary": "Global market statistics",
        "tags": [
          "Global"
        ],
        "responses": {
          "200": {
            "description": "Total market cap, volume, BTC/ETH dominance"
          }
        }
      }
    },
    "/search": {
      "get": {
        "summary": "Search coins and exchanges",
        "tags": [
          "Search"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/ai/market-summary": {
      "get": {
        "summary": "AI market summary (JSON)",
        "tags": [
          "AI"
        ],
        "responses": {
          "200": {
            "description": "Structured market summary for LLM consumption"
          }
        }
      }
    },
    "/ai/market-summary.txt": {
      "get": {
        "summary": "AI market summary (plain text)",
        "tags": [
          "AI"
        ],
        "responses": {
          "200": {
            "description": "Plain text market summary",
            "content": {
              "text/plain": {}
            }
          }
        }
      }
    },
    "/coins/slugs": {
      "get": {
        "summary": "Coin slug list (for sitemap consumers)",
        "tags": [
          "Coins"
        ],
        "responses": {
          "200": {
            "description": "Array of all active coin slugs"
          }
        }
      }
    },
    "/coins/trending": {
      "get": {
        "summary": "Trending coins (by volume)",
        "tags": [
          "Coins"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Trending coin list"
          }
        }
      }
    },
    "/coins/spotlight": {
      "get": {
        "summary": "Promoted coins",
        "tags": [
          "Coins"
        ],
        "responses": {
          "200": {
            "description": "Sponsored coin list (rel=sponsored)"
          }
        }
      }
    },
    "/convert": {
      "get": {
        "summary": "Currency converter",
        "tags": [
          "Tools"
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "bitcoin"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "ethereum"
            }
          },
          {
            "name": "amount",
            "in": "query",
            "schema": {
              "type": "number",
              "default": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Conversion result with rate + USD reference prices"
          }
        }
      }
    },
    "/global/charts": {
      "get": {
        "summary": "Global market trend charts (BTC-derived proxy)",
        "description": "Returns a proxy series derived from Bitcoin price history (close / volume per point), NOT a true aggregate of total market capitalization or volume across all coins. BTC closely tracks overall market direction, so use this as a market-wide trend overview only; for current aggregate totals use /global/stats. 10 req/min per IP in addition to the anonymous cap.",
        "tags": [
          "Global"
        ],
        "parameters": [
          {
            "name": "interval",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "1d",
              "enum": [
                "1h",
                "1d"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "BTC-derived proxy series of {timestamp, close, volume} points (not true total-market history)"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/tickers/coin/{slug}": {
      "get": {
        "summary": "Trading pairs for a coin (sorted by 24h volume)",
        "description": "Snapshot tickers for the coin. Missing snapshot coverage is an empty list, not a database lookup.",
        "tags": [
          "Tickers"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 250
            }
          },
          {
            "name": "market_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "spot",
                "perpetual",
                "futures"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated ticker list"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/tickers/exchange/{slug}": {
      "get": {
        "summary": "Trading pairs on an exchange",
        "description": "Snapshot tickers for the exchange. Missing snapshot coverage is an empty list, not a database lookup.",
        "tags": [
          "Tickers"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 10000
            }
          },
          {
            "name": "page_size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 250
            }
          },
          {
            "name": "market_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "spot",
                "perpetual",
                "futures"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated ticker list"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/social-metrics/{slug}": {
      "get": {
        "summary": "Current social metrics for a coin (Twitter / Reddit / GitHub)",
        "description": "Not served from PostgreSQL. Known snapshot slugs return null.",
        "tags": [
          "Social"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Latest snapshot"
          }
        }
      }
    },
    "/social-metrics/{slug}/history": {
      "get": {
        "summary": "Historical social metric snapshots",
        "description": "Not served from PostgreSQL. Known snapshot slugs return an empty list.",
        "tags": [
          "Social"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Daily social metric snapshot series"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/coins/batch": {
      "post": {
        "summary": "Bulk fetch coin details by slug (max 100)",
        "tags": [
          "Coins"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "slugs"
                ],
                "properties": {
                  "slugs": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 64
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coin list (preserves slug order; missing slugs silently dropped)"
          }
        }
      }
    },
    "/ads/serve": {
      "get": {
        "summary": "Serve an active ad for a page position",
        "tags": [
          "Ads"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
            }
          },
          {
            "name": "position",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One read-only creative or null; no event tokens, cached publicly for 15 seconds"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "description": "Too many requests (10 requests/minute/IP); retry later"
          },
          "503": {
            "description": "Storage or rate limiter unavailable; fails closed"
          },
          "404": {
            "description": "Unknown public slot"
          }
        },
        "description": " Only current public UI slots are accepted: home/header, currencies/header, coin/sidebar, exchanges/header, exchange/sidebar, news/inline; other combinations return 404 before storage."
      }
    },
    "/funding/latest": {
      "get": {
        "summary": "Latest funding rates across exchanges",
        "tags": [
          "Funding"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data.items is a cross-exchange pivot sorted by spread_pct"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    },
    "/funding/overview": {
      "get": {
        "summary": "Funding, open-interest, and liquidation overview",
        "tags": [
          "Funding"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Same pivot as /funding/latest plus total_oi_usd and 24h liquidation totals"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    },
    "/funding/latest/{base}": {
      "get": {
        "summary": "Latest funding rates for a base asset",
        "tags": [
          "Funding"
        ],
        "parameters": [
          {
            "name": "base",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One CrossExchangeFundingRow, or data=null when the base has no USDT perp"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    },
    "/funding/history": {
      "get": {
        "summary": "Funding history for one exchange pair",
        "tags": [
          "Funding"
        ],
        "parameters": [
          {
            "name": "exchange",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "binance",
                "okx",
                "bybit"
              ]
            }
          },
          {
            "name": "pair",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "hours",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 168,
              "minimum": 1,
              "maximum": 720
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data.items chronological venue rates"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        },
        "description": " Requires a known snapshot asset. At most 720 hours and 10000 rows; larger responses return 503."
      }
    },
    "/funding/history/{base}": {
      "get": {
        "summary": "Cross-exchange funding history for a base asset",
        "tags": [
          "Funding"
        ],
        "parameters": [
          {
            "name": "base",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          },
          {
            "name": "hours",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 168,
              "minimum": 1,
              "maximum": 720
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Map of exchange → chronological rates"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        },
        "description": " Requires a known snapshot asset. At most 720 hours and 10000 rows; larger responses return 503."
      }
    },
    "/perp/oi-history/{base}": {
      "get": {
        "summary": "Hourly open-interest averages for a base asset",
        "tags": [
          "Perpetuals"
        ],
        "parameters": [
          {
            "name": "base",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data is hourly AVG(oi_usd) by exchange over 7 days for that base (USDT/USD/PERP pairs), oldest first"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        },
        "description": " Known crypto base required; exact exchange-native pair formats include OKX USDT-SWAP. Unknown bases do not query PostgreSQL."
      }
    },
    "/perp/liquidations/{base}": {
      "get": {
        "summary": "Recent liquidations for a base asset",
        "tags": [
          "Perpetuals"
        ],
        "parameters": [
          {
            "name": "base",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 16
            }
          },
          {
            "name": "hours",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 24,
              "minimum": 1,
              "maximum": 168
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Recent liquidation events"
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    },
    "/perp/liquidations-global": {
      "get": {
        "summary": "24h liquidations across the market",
        "tags": [
          "Perpetuals"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data.long_usd / data.short_usd are 24h totals (buy=long-liq, sell=short-liq). data.items is the largest events, not the full 24h sample. data.count is the 24h event total."
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    },
    "/perp/liquidations-stats": {
      "get": {
        "summary": "Aggregate liquidation statistics",
        "tags": [
          "Perpetuals"
        ],
        "parameters": [
          {
            "name": "hours",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 24,
              "minimum": 1,
              "maximum": 168
            }
          }
        ],
        "responses": {
          "200": {
            "description": "24h long/short totals. buy=long-liq, sell=short-liq. Not a truncated event sample."
          },
          "503": {
            "description": "Time-series backend unavailable"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiResponse": {
        "type": "object",
        "description": "Standard API envelope. The code field always matches the HTTP status.",
        "properties": {
          "code": {
            "type": "integer",
            "example": 200,
            "description": "Application and HTTP status (200 success)"
          },
          "message": {
            "type": "string",
            "description": "Empty on success; human-readable error message otherwise"
          },
          "data": {
            "description": "Endpoint-specific payload; null on error"
          }
        },
        "required": [
          "code"
        ]
      },
      "PaginatedCoins": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "example": 200
          },
          "data": {
            "type": "object",
            "properties": {
              "items": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Coin"
                }
              },
              "total": {
                "type": "integer"
              },
              "page": {
                "type": "integer"
              },
              "page_size": {
                "type": "integer"
              },
              "total_page": {
                "type": "integer"
              }
            }
          }
        }
      },
      "Coin": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "example": "bitcoin"
          },
          "name": {
            "type": "string",
            "example": "Bitcoin"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "rank": {
            "type": "integer",
            "example": 1
          },
          "price_usd": {
            "type": "number",
            "example": 67500.42
          },
          "market_cap": {
            "type": "number"
          },
          "volume_24h": {
            "type": "number"
          },
          "change_1h": {
            "type": "number"
          },
          "change_24h": {
            "type": "number"
          },
          "change_7d": {
            "type": "number"
          },
          "logo": {
            "type": "string"
          },
          "circulating_supply": {
            "type": "number"
          },
          "total_supply": {
            "type": "number"
          },
          "max_supply": {
            "type": "number"
          },
          "ath": {
            "type": "number"
          },
          "category": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid input",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid auth",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Entity not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiErrorResponse"
            }
          }
        }
      },
      "Gone": {
        "description": "Resource was previously indexed but is now permanently removed (true HTTP 410). The body carries {slug, name, symbol} so clients can render a 'removed' page or de-list. Use this to drop the resource from caches/indexes promptly — Google de-indexes 410 faster than 404.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiErrorResponse"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Rate limit exceeded (HTTP 429)",
        "headers": {
          "X-RateLimit-Limit": {
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Remaining": {
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Reset": {
            "schema": {
              "type": "integer"
            }
          },
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiErrorResponse"
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Coins",
      "description": "Cryptocurrency data"
    },
    {
      "name": "Exchanges",
      "description": "Exchange information"
    },
    {
      "name": "Categories",
      "description": "Coin categories"
    },
    {
      "name": "News",
      "description": "Crypto news"
    },
    {
      "name": "Global",
      "description": "Global market stats"
    },
    {
      "name": "Funding",
      "description": "Cross-exchange perpetual funding rates"
    },
    {
      "name": "Perpetuals",
      "description": "Open interest and liquidation data"
    },
    {
      "name": "Search",
      "description": "Search"
    },
    {
      "name": "Tickers",
      "description": "Trading pairs"
    },
    {
      "name": "AI",
      "description": "AI/LLM-friendly endpoints"
    },
    {
      "name": "Tools",
      "description": "Converter, calculators, utility endpoints"
    },
    {
      "name": "Social",
      "description": "Twitter / Reddit / GitHub metrics"
    },
    {
      "name": "Ads",
      "description": "Read-only ad display; anonymous event tracking is closed"
    }
  ]
}
