{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tradecat.local/contracts/tradecat-auto-paper-account-state.schema.json",
  "title": "TradeCat Auto Paper Account State",
  "description": "Prompt-safe local paper account state derived only from TradeCat's paper ledger, never from Binance account/order endpoints.",
  "type": "object",
  "required": ["schema", "schema_version", "mode", "source", "provenance", "safety", "cash_balance_usdt", "equity_usdt", "open_positions", "recent_paper_orders", "recent_fills", "hard_boundaries", "limitations"],
  "properties": {
    "schema": {"const": "tradecat_auto.paper_account_state.v1"},
    "schema_version": {"const": "1.0.0"},
    "mode": {"const": "paper"},
    "source": {"const": "local_tradecat_paper_ledger"},
    "provenance": {
      "type": "object",
      "required": ["source"],
      "properties": {
        "source": {"const": "local_tradecat_paper_ledger"},
        "ledger_schema": {"type": "string"}
      },
      "additionalProperties": true
    },
    "safety": {
      "type": "object",
      "required": ["public_readonly_market_data", "public_readonly", "paper_or_watch_only", "real_orders", "signed_requests", "reads_api_keys", "binance_account_state"],
      "properties": {
        "public_readonly_market_data": {"const": true},
        "public_readonly": {"const": true},
        "paper_or_watch_only": {"const": true},
        "real_orders": {"const": false},
        "signed_requests": {"const": false},
        "reads_api_keys": {"const": false},
        "binance_account_state": {"const": false}
      },
      "additionalProperties": true
    },
    "cash_balance_usdt": {"type": "number"},
    "equity_usdt": {"type": "number"},
    "initial_balance_usdt": {"type": "number"},
    "realized_pnl_usdt": {"type": "number"},
    "unrealized_pnl_usdt": {"type": "number"},
    "open_positions": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
    "recent_paper_orders": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["schema", "schema_version", "order_id", "symbol", "order_type", "status", "real_order"],
        "properties": {
          "schema": {"const": "tradecat_auto.paper_order.v1"},
          "schema_version": {"const": "1.0.0"},
          "order_id": {"type": "string"},
          "symbol": {"type": "string"},
          "order_type": {
            "enum": [
              "PAPER_MARKET",
              "PAPER_POST_ONLY_MAKER_ASSUMPTION",
              "PAPER_TAKER_PUBLIC_DEPTH_ESTIMATE"
            ]
          },
          "status": {"enum": ["FILLED", "REJECTED", "CANCELLED"]},
          "real_order": {"const": false},
          "exchange_order_id": {"type": ["null", "string"]}
        },
        "additionalProperties": true
      }
    },
    "recent_fills": {"type": "array", "items": {"type": "object", "additionalProperties": true}},
    "closed_positions_count": {"type": "integer", "minimum": 0},
    "last_updated_at": {"type": ["string", "null"]},
    "hard_boundaries": {
      "type": "object",
      "required": ["real_orders", "signed_requests", "reads_api_keys", "binance_account_state"],
      "properties": {
        "real_orders": {"const": false},
        "signed_requests": {"const": false},
        "reads_api_keys": {"const": false},
        "binance_account_state": {"const": false}
      },
      "additionalProperties": true
    },
    "limitations": {"type": "array", "items": {"type": "string"}}
  },
  "additionalProperties": true
}
