{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.bullpen.fi/reference/schemas/hyperliquid.orders.schema.json",
  "title": "bullpen hyperliquid orders JSON output",
  "description": "Stable schema for documented open orders success envelopes, including dex-scoped frontend order reports.",
  "type": "object",
  "oneOf": [
    {
      "$ref": "#/$defs/basic_orders_report"
    },
    {
      "$ref": "#/$defs/frontend_orders_report"
    }
  ],
  "$defs": {
    "basic_orders_report": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "address",
        "orders"
      ],
      "properties": {
        "schema_version": {
          "type": "integer",
          "const": 1
        },
        "address": {
          "$ref": "#/$defs/evm_address"
        },
        "orders": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/basic_order"
          }
        }
      },
      "not": {
        "required": [
          "kind"
        ]
      }
    },
    "frontend_orders_report": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "schema_version",
        "kind",
        "address",
        "all_dexes",
        "orders"
      ],
      "properties": {
        "schema_version": {
          "type": "integer",
          "const": 1
        },
        "kind": {
          "type": "string",
          "enum": [
            "hyperliquid_frontend_orders_report",
            "hyperliquid_frontend_orders_all_dex_report"
          ]
        },
        "address": {
          "$ref": "#/$defs/evm_address"
        },
        "dex": {
          "type": "string",
          "minLength": 1
        },
        "dex_scope": {
          "type": "string",
          "enum": [
            "single",
            "all"
          ]
        },
        "all_dexes": {
          "type": "boolean"
        },
        "requested_dexes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/dex_identity"
          }
        },
        "partial": {
          "type": "boolean"
        },
        "per_dex": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/per_dex_orders"
          }
        },
        "orders": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/frontend_order"
          }
        }
      }
    },
    "decimal_string": {
      "type": "string",
      "pattern": "^-?\\d+(?:\\.\\d+)?$"
    },
    "evm_address": {
      "type": "string",
      "pattern": "^0x[0-9A-Fa-f]{40}$"
    },
    "basic_order": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "coin",
        "side",
        "limit_px",
        "sz",
        "oid",
        "timestamp_iso"
      ],
      "properties": {
        "coin": {
          "type": "string",
          "minLength": 1
        },
        "side": {
          "type": "string",
          "minLength": 1
        },
        "limit_px": {
          "$ref": "#/$defs/decimal_string"
        },
        "sz": {
          "$ref": "#/$defs/decimal_string"
        },
        "oid": {
          "type": "integer",
          "minimum": 0
        },
        "timestamp": {
          "type": "integer",
          "minimum": 0
        },
        "timestamp_iso": {
          "type": "string",
          "minLength": 1
        },
        "orig_sz": {
          "$ref": "#/$defs/decimal_string"
        }
      }
    },
    "frontend_order": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "coin",
        "side",
        "limit_px",
        "sz",
        "oid",
        "timestamp_iso",
        "is_position_tpsl",
        "is_trigger",
        "order_type",
        "orig_sz",
        "reduce_only",
        "trigger_condition",
        "trigger_px"
      ],
      "properties": {
        "dex_id": {
          "type": "string",
          "minLength": 1
        },
        "dex_label": {
          "type": "string",
          "minLength": 1
        },
        "dex": {
          "type": "string",
          "minLength": 1
        },
        "dex_identity": {
          "$ref": "#/$defs/dex_identity"
        },
        "instrument_id": {
          "type": "string",
          "minLength": 1
        },
        "row_key": {
          "type": "string",
          "minLength": 1
        },
        "coin": {
          "type": "string",
          "minLength": 1
        },
        "side": {
          "type": "string",
          "minLength": 1
        },
        "limit_px": {
          "$ref": "#/$defs/decimal_string"
        },
        "sz": {
          "$ref": "#/$defs/decimal_string"
        },
        "oid": {
          "type": "integer",
          "minimum": 0
        },
        "timestamp": {
          "type": "integer",
          "minimum": 0
        },
        "timestamp_iso": {
          "type": "string",
          "minLength": 1
        },
        "is_position_tpsl": {
          "type": "boolean"
        },
        "is_trigger": {
          "type": "boolean"
        },
        "order_type": {
          "type": "string",
          "minLength": 1
        },
        "orig_sz": {
          "$ref": "#/$defs/decimal_string"
        },
        "reduce_only": {
          "type": "boolean"
        },
        "tif": {
          "type": [
            "string",
            "null"
          ]
        },
        "trigger_condition": {
          "type": "string",
          "minLength": 1
        },
        "trigger_px": {
          "$ref": "#/$defs/decimal_string"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/frontend_order"
          }
        }
      }
    },
    "dex_identity": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "dex_id",
        "dex_label"
      ],
      "properties": {
        "dex_id": {
          "type": "string",
          "minLength": 1
        },
        "dex_label": {
          "type": "string",
          "minLength": 1
        },
        "dex": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "per_dex_orders": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "dex_id",
        "label",
        "status",
        "order_count",
        "orders"
      ],
      "properties": {
        "dex_id": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "dex": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "minLength": 1
        },
        "order_count": {
          "type": "integer",
          "minimum": 0
        },
        "orders": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/frontend_order"
          }
        }
      }
    }
  }
}
