{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://usehyperodds.com/webhooks/alert-v1.schema.json",
  "title": "Hyperodds alert webhook, version 1",
  "description": "The JSON body Hyperodds posts to a webhook URL for each alert and for a test message. Fields may be added; existing fields keep their meaning.",
  "type": "object",
  "required": [
    "id",
    "type",
    "created_at",
    "test",
    "alert",
    "market",
    "title",
    "text",
    "note",
    "facts",
    "data"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "The delivery id, also sent as the Hyperodds-Delivery header. The same on every retry of one delivery."
    },
    "type": {
      "type": "string",
      "enum": [
        "alert.new_market",
        "alert.edge",
        "alert.settling",
        "alert.rule_change",
        "alert.volume_spike",
        "test"
      ],
      "description": "Also sent as the Hyperodds-Event header."
    },
    "created_at": { "type": "string", "format": "date-time", "description": "When the alert fired, in UTC." },
    "test": {
      "type": "boolean",
      "description": "True for the test message sent when a URL is added or tested."
    },
    "alert": {
      "type": ["object", "null"],
      "description": "The alert rule that fired. On a test message, an example edge alert's, with a null id.",
      "required": ["id", "kind"],
      "properties": {
        "id": {
          "type": ["string", "null"],
          "description": "The rule's id, the same for every alert it sends."
        },
        "kind": {
          "type": "string",
          "enum": ["new_market", "edge", "settling", "rule_change", "volume_spike"]
        }
      }
    },
    "market": {
      "type": ["object", "null"],
      "description": "The market the alert is about. On a test message, an example market whose url is the Alerts page.",
      "required": ["outcome", "title", "url"],
      "properties": {
        "outcome": { "type": "integer", "description": "The HIP-4 outcome id." },
        "title": { "type": "string", "description": "The market or question, as the Console shows it." },
        "url": { "type": "string", "format": "uri", "description": "The market's page on usehyperodds.com." }
      }
    },
    "title": { "type": "string", "description": "What happened, for example \"Edge +4.2 pts\"." },
    "text": {
      "type": "string",
      "description": "One line with the details, as a notification would show it."
    },
    "note": {
      "type": "string",
      "description": "A sentence that goes with the facts, or an empty string when the alert has none."
    },
    "facts": {
      "type": "array",
      "description": "The details as label and value pairs, ready to show.",
      "items": {
        "type": "object",
        "required": ["label", "value"],
        "properties": { "label": { "type": "string" }, "value": { "type": "string" } }
      }
    },
    "data": {
      "type": "object",
      "description": "The alert's numbers for filters and formulas. Prices are decimals from 0 to 1, and every number is rounded as the alert's text shows it. The fields depend on the kind; a test message sends an example edge alert's.",
      "properties": {
        "deployer": {
          "type": ["string", "null"],
          "description": "The deployer's name; null when the name can't be shown."
        },
        "starts_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "new_market, settling: a game's start or a rate decision's time; null for a price market."
        },
        "settles_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "new_market, settling: when a price market settles; null for the rest."
        },
        "settles_by": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "new_market, settling: the latest a market that isn't a price market settles; null for a price market."
        },
        "outcomes": { "type": "integer", "description": "new_market: outcomes listed together." },
        "edge_pts": { "type": "number", "description": "edge: points after every fee." },
        "side": { "type": "string", "description": "edge: the side to buy." },
        "buy_price": { "type": ["number", "null"], "description": "edge: the price to buy that side now." },
        "fair_price": { "type": "number", "description": "edge: the fair line for that side." },
        "fair_method": {
          "type": "string",
          "description": "edge: where the fair line comes from. options: priced from listed options. realized-vol: from the asset's realized volatility, with no options to read. blend: options and realized volatility weighed together. consensus: other prediction markets on the same question.",
          "enum": ["options", "realized-vol", "blend", "consensus"]
        },
        "order_usd": { "type": "number", "description": "edge: the order size the edge is figured at." },
        "mid_price": {
          "type": ["number", "null"],
          "description": "settling: the mid price, for one market."
        },
        "markets": { "type": "integer", "description": "settling: markets settling together." },
        "changes": {
          "type": "array",
          "description": "rule_change: each changed term, up to 20, each name and value cut to 500 characters.",
          "items": {
            "type": "object",
            "required": ["field", "from", "to"],
            "properties": {
              "field": { "type": "string" },
              "from": { "type": ["string", "null"] },
              "to": { "type": ["string", "null"] }
            }
          }
        },
        "volume_1h_contracts": {
          "type": "integer",
          "description": "volume_spike: contracts traded in the last hour. Each contract pays $1 if its side wins."
        },
        "ratio": {
          "type": ["number", "null"],
          "description": "volume_spike: times the hourly average; null after a quiet day."
        }
      }
    }
  }
}
