{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/coinrithm-com/json-schema/coinrithm-com-futures-position-envelope-schema.json",
  "title": "FuturesPositionEnvelope",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/coinrithm-com-futures-api-openapi.yml#/components/schemas/FuturesPositionEnvelope",
  "type": "object",
  "properties": {
    "position": {
      "$ref": "#/$defs/FuturesPosition"
    },
    "idempotentReplay": {
      "type": "boolean",
      "description": "present (true) on a replay"
    }
  },
  "$defs": {
    "Freshness": {
      "type": "object",
      "description": "Data-freshness descriptor. Futures + spot use ageSeconds; PM uses\nageMinutes. `status` is a freshness label; `basis` (PM only) names which\ntimestamp the age was measured against.\n",
      "properties": {
        "asOf": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "ageSeconds": {
          "type": [
            "number",
            "null"
          ],
          "description": "futures / spot"
        },
        "ageMinutes": {
          "type": [
            "number",
            "null"
          ],
          "description": "PM"
        },
        "status": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "fresh",
            "lagging",
            "stale",
            "unknown",
            null
          ],
          "description": "fresh | lagging (PM only) | stale | unknown. PM lagging>=45m &\nstale>=2h; spot/futures stale>120s.\n"
        },
        "basis": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "latest_snapshot",
            "source_update",
            "processed",
            "event_update",
            "unknown"
          ],
          "description": "PM only — which timestamp the age was measured against.\n"
        }
      }
    },
    "FuturesFundingSource": {
      "type": "object",
      "required": [
        "venue",
        "symbol",
        "fundingIntervalHours"
      ],
      "description": "Current venue/contract funding reference. Historical charges are represented by funding events.",
      "properties": {
        "venue": {
          "type": "string",
          "description": "Current funding venue identifier."
        },
        "symbol": {
          "type": "string",
          "description": "Current venue perpetual symbol."
        },
        "fundingIntervalHours": {
          "type": "integer",
          "description": "Current venue funding interval in hours."
        }
      }
    },
    "FuturesPosition": {
      "type": "object",
      "description": "Mock futures position. Live-mark fields (markPrice, unrealizedPnlMusd,\nliquidationDistancePct, atLiquidation) are added only on OPEN positions in\nthe list endpoint; they may be null when no live mark is available.\n",
      "properties": {
        "id": {
          "type": "integer"
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "closed",
            "liquidated"
          ]
        },
        "coin": {
          "type": "object",
          "properties": {
            "ucid": {
              "type": "string"
            },
            "symbol": {
              "type": "string"
            },
            "name": {
              "type": "string"
            }
          }
        },
        "side": {
          "type": "string",
          "enum": [
            "long",
            "short"
          ]
        },
        "leverage": {
          "type": "number"
        },
        "entryPrice": {
          "type": "number"
        },
        "marginMusd": {
          "type": "number"
        },
        "notionalMusd": {
          "type": "number"
        },
        "sizeCoin": {
          "type": "number"
        },
        "maintenanceMarginRate": {
          "type": "number"
        },
        "liquidationPrice": {
          "type": "number"
        },
        "freshnessAtEntry": {
          "$ref": "#/$defs/Freshness"
        },
        "stopLossPrice": {
          "type": [
            "number",
            "null"
          ],
          "description": "Resting stop-loss trigger (null = none)."
        },
        "takeProfitPrice": {
          "type": [
            "number",
            "null"
          ],
          "description": "Resting take-profit trigger (null = none)."
        },
        "exitPrice": {
          "type": [
            "number",
            "null"
          ]
        },
        "exitReason": {
          "type": [
            "string",
            "null"
          ],
          "description": "user_close | liquidation | stop_loss | take_profit"
        },
        "realizedPnlMusd": {
          "type": [
            "number",
            "null"
          ]
        },
        "fillModel": {
          "type": [
            "string",
            "null"
          ],
          "description": "Fill model pinned when the position opened; null for legacy mark fills."
        },
        "openedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "closedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "markPrice": {
          "type": [
            "number",
            "null"
          ],
          "description": "list endpoint, open positions only"
        },
        "unrealizedPnlMusd": {
          "type": [
            "number",
            "null"
          ]
        },
        "fundingPaidMusd": {
          "type": [
            "number",
            "null"
          ],
          "description": "Signed cumulative funding applied in mUSD (positive = paid, negative = received); omitted or null when unavailable. Zero is a meaningful value."
        },
        "fundingAppliedThrough": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "Latest timestamp through which cumulative funding was applied; omitted or null when unavailable."
        },
        "currentFundingReference": {
          "description": "Current venue/contract reference for this coin; this is current metadata, not proof of historical funding charges.",
          "oneOf": [
            {
              "$ref": "#/$defs/FuturesFundingSource"
            },
            {
              "type": "null"
            }
          ]
        },
        "liquidationDistancePct": {
          "type": [
            "number",
            "null"
          ]
        },
        "atLiquidation": {
          "type": [
            "boolean",
            "null"
          ]
        }
      }
    }
  }
}