{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/fablerlabs-com/json-schema/fablerlabs-com-krw-price-snapshot-schema.json",
  "title": "KrwPriceSnapshot",
  "x-generated": "2026-11-07",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/fablerlabs-com-openapi.yaml#/components/schemas/KrwPriceSnapshot",
  "type": "object",
  "required": [
    "symbol",
    "quote",
    "requested_exchange",
    "sources",
    "exchanges",
    "spread",
    "fetched_at",
    "scope"
  ],
  "properties": {
    "symbol": {
      "type": "string",
      "description": "Uppercase-normalized requested symbol."
    },
    "quote": {
      "type": "string",
      "const": "KRW"
    },
    "requested_exchange": {
      "type": "string",
      "enum": [
        "all",
        "upbit",
        "bithumb"
      ]
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/KrwSourceStatus"
      }
    },
    "exchanges": {
      "type": "object",
      "description": "Keyed by exchange (upbit, bithumb); only present for exchanges that returned a fresh, well-formed quote.",
      "properties": {
        "upbit": {
          "$ref": "#/$defs/KrwExchangeQuote"
        },
        "bithumb": {
          "$ref": "#/$defs/KrwExchangeQuote"
        }
      }
    },
    "spread": {
      "oneOf": [
        {
          "$ref": "#/$defs/KrwPriceSpread"
        },
        {
          "type": "null"
        }
      ],
      "description": "Present only when both upbit and bithumb returned a quote; null otherwise."
    },
    "fetched_at": {
      "type": "string",
      "format": "date-time"
    },
    "scope": {
      "type": "string"
    }
  },
  "$defs": {
    "KrwExchangeQuote": {
      "type": "object",
      "required": [
        "price_krw",
        "volume_24h_token",
        "notional_24h_krw",
        "change_rate",
        "change_basis",
        "upstream_as_of"
      ],
      "properties": {
        "price_krw": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "volume_24h_token": {
          "type": "number",
          "minimum": 0
        },
        "notional_24h_krw": {
          "type": "number",
          "minimum": 0
        },
        "change_rate": {
          "type": "number",
          "description": "Exchange-reported change as a decimal fraction (e.g. 0.0123 for +1.23%). Interpret using change_basis."
        },
        "change_basis": {
          "type": "string",
          "enum": [
            "previous_close",
            "rolling_24h"
          ],
          "description": "Upbit reports change versus the previous daily close; Bithumb reports rolling 24-hour change."
        },
        "upstream_as_of": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "KrwPriceSpread": {
      "type": "object",
      "required": [
        "absolute_krw",
        "midpoint_pct",
        "lower_exchange",
        "higher_exchange"
      ],
      "properties": {
        "absolute_krw": {
          "type": "number",
          "minimum": 0
        },
        "midpoint_pct": {
          "type": "number",
          "minimum": 0,
          "description": "Absolute spread as a percentage of the two exchanges' midpoint price."
        },
        "lower_exchange": {
          "type": "string",
          "enum": [
            "upbit",
            "bithumb"
          ]
        },
        "higher_exchange": {
          "type": "string",
          "enum": [
            "upbit",
            "bithumb"
          ]
        }
      }
    },
    "KrwSourceStatus": {
      "type": "object",
      "required": [
        "exchange",
        "status"
      ],
      "properties": {
        "exchange": {
          "type": "string",
          "enum": [
            "upbit",
            "bithumb"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "ok",
            "error",
            "not_requested"
          ]
        },
        "error": {
          "type": "string",
          "description": "Bounded source error category; upstream response bodies are never exposed."
        }
      }
    }
  }
}