{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/immix/json-schema/immix-trading-policy-row-schema.json",
  "title": "TradingPolicyRow",
  "description": "A trading policy as the API serves it: the `TradingPolicyUpdated` record plus the row extras (`globalSequence`; the deprecated `unscaled`, never present since 0.3.3) — the one shape its reads and its commands answer.",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/immix-rest-openapi.json#/components/schemas/TradingPolicyRow",
  "type": "object",
  "properties": {
    "tradingPolicyId": {
      "type": "integer",
      "description": "Sticky entity key."
    },
    "version": {
      "type": "string",
      "pattern": "^-?[0-9]+$",
      "description": "The row's version — monotonic per record, bumped on every change; orders record which version governed them. int64 as a decimal JSON string"
    },
    "orgId": {
      "type": "integer",
      "description": "Owner-stamped."
    },
    "instrumentId": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+$",
      "description": "The refdata instrument — carried, not resolved here; 0 = the organisation-wide default row. int64 as a decimal JSON string"
    },
    "status": {
      "$ref": "#/$defs/TradingPolicyUpdatedStatus",
      "description": "UNKNOWN is the unset sentinel: outputs only — as input, omit the field instead; explicit UNKNOWN refuses 400. The value set is append-only: a consumer READING this field treats an unknown name as UNKNOWN, never as an error; as input an unknown name refuses 400 — the parse is strict"
    },
    "isTradingHalted": {
      "type": "boolean",
      "description": "The halt: true on the organisation-wide default row halts the organisation; true on a per-instrument row halts that instrument. False is the decode default — but no order is admitted without an ACTIVE policy row at all: the real gate is the row's existence. a boolean; absent reads false"
    },
    "maxOrderQty": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "maxLength": 64,
      "description": "Per-order quantity cap; 0 = no cap. The organisation-wide default row has no scale context — a non-zero value on it is refused INVALID_FIELD. money (a Decimal on the wire: a scaled integer with its own scale), served as an exact decimal string at the value's own scale — every fractional digit that scale states, trailing zeros included; never raw; null when the 0 sentinel means unset"
    },
    "maxOrderNotional": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "maxLength": 64,
      "description": "Per-order notional cap; 0 = no cap; refused non-zero on org-default rows as maxOrderQty. money (a Decimal on the wire: a scaled integer with its own scale), served as an exact decimal string at the value's own scale — every fractional digit that scale states, trailing zeros included; never raw; null when the 0 sentinel means unset"
    },
    "priceCollarBps": {
      "type": [
        "integer",
        "null"
      ],
      "description": "The limit-price collar against the market-data top-of-book reference; 0 = no collar — the reference-freshness gate still applies unconditionally, since the reference is mandatory."
    },
    "refFreshnessNs": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+$",
      "description": "How fresh the top-of-book reference must be at admission (the NO_REFERENCE_PRICE gate); 0 disables the age comparison alone — the reference itself stays mandatory for every order type, so an absent reference refuses either way. int64 as a decimal JSON string"
    },
    "instructFreshnessNs": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+$",
      "description": "How stale an accepted but never instructed order may be when it reaches the venue: past it the connector never places it and the order disposes toward INSTRUCTION_EXPIRED. 0 = the connector's configured default window, never a lockout. int64 as a decimal JSON string"
    },
    "degradedGraceNs": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^-?[0-9]+$",
      "description": "The admission tolerance for a degraded connection: an order-entry credential whose connection has been DEGRADED for no longer than this still admits; DOWN always refuses, and a cancel never gates. 0 = any DEGRADED refuses (the strict reading). Measured from the health fact's envelope time, so every member agrees. int64 as a decimal JSON string"
    },
    "maxOpenOrders": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Open-order ceiling; 0 = none. Counted over the organisation's open orders as a whole: the tighter of the governing row's and the organisation-wide default row's stated ceilings binds. A per-instrument row's ceiling is not yet scoped to its instrument."
    },
    "maxOrdersPerMinute": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Entry-rate ceiling per tumbling minute of stream time, enforced at the orders owner; 0 = no ceiling. Counted over the organisation's accepted orders in the minute: the tighter of the governing row's and the organisation-wide default row's stated ceilings binds, as maxOpenOrders does."
    },
    "pendingByUserId": {
      "type": [
        "integer",
        "null"
      ],
      "description": "The user whose proposal is pending, so an approver is checked to be someone else; 0 when nothing is pending."
    },
    "pendingTransition": {
      "$ref": "#/$defs/TradingPolicyUpdatedPendingTransition",
      "description": "ACTIVATE, AMEND, RETIRE or RESUME_TRADING; NONE otherwise. NONE is the unset sentinel: outputs only — as input, omit the field instead; explicit NONE refuses 400. The value set is append-only: a consumer READING this field treats an unknown name as NONE, never as an error; as input an unknown name refuses 400 — the parse is strict"
    },
    "globalSequence": {
      "$ref": "#/$defs/GlobalSequenceValue"
    },
    "unscaled": {
      "type": "boolean",
      "description": "Never present since 0.3.3: every money value on this API states its own scale on the wire — a policy amount or cap since 0.3.3, an order's and an execution's since 0.3.2, a balance's since 0.3.1 — so a row is never served raw, whether or not this member holds the asset or instrument it references. Kept, deprecated, so a client generated from 0.3.2 still compiles; it goes at the next major.",
      "deprecated": true
    }
  },
  "required": [
    "tradingPolicyId",
    "version",
    "orgId",
    "status",
    "pendingTransition",
    "globalSequence"
  ],
  "$defs": {
    "GlobalSequenceValue": {
      "type": "string",
      "pattern": "^[0-9]+$",
      "description": "The position as a decimal string — the last change this member had applied, orders, balance readings and algo instances included.",
      "title": "GlobalSequenceValue"
    },
    "TradingPolicyUpdatedPendingTransition": {
      "type": "string",
      "enum": [
        "NONE",
        "ACTIVATE",
        "AMEND",
        "REACTIVATE",
        "UNFREEZE",
        "RETIRE",
        "REVOKE",
        "ROTATE",
        "RESUME_TRADING"
      ],
      "description": "ACTIVATE, AMEND, RETIRE or RESUME_TRADING; NONE otherwise. NONE is the unset sentinel: outputs only — as input, omit the field instead; explicit NONE refuses 400. The value set is append-only: a consumer READING this field treats an unknown name as NONE, never as an error; as input an unknown name refuses 400 — the parse is strict",
      "title": "TradingPolicyUpdatedPendingTransition"
    },
    "TradingPolicyUpdatedStatus": {
      "type": "string",
      "enum": [
        "UNKNOWN",
        "DRAFT",
        "PENDING_APPROVAL",
        "ACTIVE",
        "RETIRED"
      ],
      "description": "UNKNOWN is the unset sentinel: outputs only — as input, omit the field instead; explicit UNKNOWN refuses 400. The value set is append-only: a consumer READING this field treats an unknown name as UNKNOWN, never as an error; as input an unknown name refuses 400 — the parse is strict",
      "title": "TradingPolicyUpdatedStatus"
    }
  }
}