{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/metastreams/json-schema/metastreams-ui-portfolio-response-schema.json",
  "title": "UiPortfolioResponse",
  "description": "The summed spot holdings of the named wallets.",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/metastreams-openapi.json#/components/schemas/UiPortfolioResponse",
  "type": "object",
  "required": [
    "totalValueUsd",
    "asOf",
    "wallets",
    "spot"
  ],
  "properties": {
    "asOf": {
      "$ref": "#/$defs/UnixMilliseconds",
      "description": "Serve-time snapshot instant."
    },
    "spot": {
      "$ref": "#/$defs/UiSpotPortfolio",
      "description": "Spot holdings of every named wallet."
    },
    "stats": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/UiPortfolioStats",
          "description": "Timeframe performance; present only under `include=stats`."
        }
      ],
      "description": "Timeframe performance; present only under `include=stats`."
    },
    "totalValueUsd": {
      "$ref": "#/$defs/Decimal",
      "description": "Sum of every product's value; spot is the only product."
    },
    "wallets": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/UiWalletDescriptor"
      },
      "description": "Each named wallet's share, in request order. The shares sum to the matching total.\nTheir `stats` sum to `stats`."
    }
  },
  "$defs": {
    "Decimal": {
      "type": "string",
      "format": "decimal",
      "description": "An exact decimal, as a string."
    },
    "SpotChain": {
      "type": "string",
      "description": "Chain slug. One spelling per chain, in paths and bodies alike. Only a chain with spot data is published.",
      "enum": [
        "solana",
        "bsc",
        "robinhood",
        "elysium",
        "ethereum",
        "base"
      ]
    },
    "UiMoney": {
      "type": "object",
      "description": "A chain-denominated value with its USD equivalent. The enclosing object carries the\n`chain` that names `native`'s unit.",
      "required": [
        "native"
      ],
      "properties": {
        "native": {
          "$ref": "#/$defs/Decimal",
          "description": "Value in the owning chain's gas asset."
        },
        "usd": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/Decimal",
              "description": "Value in USD; `null` when the native asset is unpriced."
            }
          ],
          "description": "Value in USD; `null` when the native asset is unpriced."
        }
      }
    },
    "UiPnlBuckets": {
      "type": "object",
      "description": "Positions per realized-PnL tier within a timeframe.",
      "required": [
        "moonshot",
        "pump",
        "win",
        "loss",
        "rekt"
      ],
      "properties": {
        "loss": {
          "type": "integer",
          "format": "int64",
          "description": "Realized down to -50%.",
          "minimum": 0
        },
        "moonshot": {
          "type": "integer",
          "format": "int64",
          "description": "Realized 5x or better.",
          "minimum": 0
        },
        "pump": {
          "type": "integer",
          "format": "int64",
          "description": "Realized 2x to 5x.",
          "minimum": 0
        },
        "rekt": {
          "type": "integer",
          "format": "int64",
          "description": "Realized worse than -50%.",
          "minimum": 0
        },
        "win": {
          "type": "integer",
          "format": "int64",
          "description": "Realized 1x to 2x.",
          "minimum": 0
        }
      }
    },
    "UiPortfolioStats": {
      "type": "object",
      "description": "`include=stats`: performance over the four standard timeframes. A position joins a\ntimeframe by the age of its first purchase, never its last activity.",
      "required": [
        "oneDay",
        "sevenDays",
        "thirtyDays",
        "max"
      ],
      "properties": {
        "max": {
          "$ref": "#/$defs/UiTimeframeStats",
          "description": "Every position in scope."
        },
        "oneDay": {
          "$ref": "#/$defs/UiTimeframeStats",
          "description": "Positions whose first purchase falls in the last day."
        },
        "sevenDays": {
          "$ref": "#/$defs/UiTimeframeStats",
          "description": "Positions whose first purchase falls in the last seven days."
        },
        "thirtyDays": {
          "$ref": "#/$defs/UiTimeframeStats",
          "description": "Positions whose first purchase falls in the last thirty days."
        }
      }
    },
    "UiSpotPortfolio": {
      "type": "object",
      "description": "Spot holdings per chain: gas and stablecoin balances plus open positions.",
      "required": [
        "valueUsd",
        "balancesValueUsd",
        "positionsValueUsd",
        "chains"
      ],
      "properties": {
        "balancesValueUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "Sum of every chain's priced native and stable balances."
        },
        "chains": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/UiSpotPortfolioChain"
          },
          "description": "Per-chain cells. The whole portfolio has one per chain in scope, zeroed where it holds\nnothing. A wallet's share has only the cells it holds."
        },
        "positionsValueUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "Sum of every chain's priced open-position value."
        },
        "valueUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "`balancesValueUsd + positionsValueUsd`."
        }
      }
    },
    "UiSpotPortfolioChain": {
      "type": "object",
      "description": "One chain's balance and open-position value.",
      "required": [
        "chain",
        "nativeBalance",
        "stableBalanceUsd",
        "positionsValue",
        "valueUsd"
      ],
      "properties": {
        "chain": {
          "$ref": "#/$defs/SpotChain",
          "description": "Chain this cell covers."
        },
        "nativeBalance": {
          "$ref": "#/$defs/UiMoney",
          "description": "The chain's gas asset balance; zero when no balance row exists."
        },
        "positionsValue": {
          "$ref": "#/$defs/UiMoney",
          "description": "Sum over open positions of `holdings × token price`."
        },
        "stableBalanceUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "Sum of the stablecoin balances other than the gas asset, priced 1:1."
        },
        "valueUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "`nativeBalance.usd + stableBalanceUsd + positionsValue.usd`, priced components only."
        }
      }
    },
    "UiTimeframeChainStats": {
      "type": "object",
      "description": "One chain's PnL within a timeframe.",
      "required": [
        "chain",
        "open",
        "unrealized",
        "realized"
      ],
      "properties": {
        "chain": {
          "$ref": "#/$defs/SpotChain",
          "description": "Chain this cell covers."
        },
        "open": {
          "type": "integer",
          "format": "int64",
          "description": "Open positions on this chain, priced or not.",
          "minimum": 0
        },
        "realized": {
          "$ref": "#/$defs/UiMoney",
          "description": "Realized PnL across every cycle, from open and closed positions alike."
        },
        "unrealized": {
          "$ref": "#/$defs/UiMoney",
          "description": "Unrealized PnL on what is still held."
        }
      }
    },
    "UiTimeframeStats": {
      "type": "object",
      "description": "One timeframe's aggregate over the positions inside it.",
      "required": [
        "open",
        "unrealizedUsd",
        "realizedUsd",
        "trades",
        "buckets",
        "chains"
      ],
      "properties": {
        "buckets": {
          "$ref": "#/$defs/UiPnlBuckets",
          "description": "Positions per realized-PnL tier."
        },
        "chains": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/UiTimeframeChainStats"
          },
          "description": "Per-chain PnL. The whole portfolio has one per chain in scope, zeroed where it has no\nposition. A wallet's share has only the chains it has a position on."
        },
        "open": {
          "type": "integer",
          "format": "int64",
          "description": "Open positions in this timeframe, priced or not.",
          "minimum": 0
        },
        "realizedUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "Sum of every chain's realized PnL in USD."
        },
        "trades": {
          "$ref": "#/$defs/UiTradeCounts",
          "description": "Trade counts across every cycle."
        },
        "unrealizedUsd": {
          "$ref": "#/$defs/Decimal",
          "description": "Sum of every chain's unrealized PnL in USD."
        }
      }
    },
    "UiTradeCounts": {
      "type": "object",
      "description": "Trade counts within a timeframe, over every cycle each position has had.",
      "required": [
        "total",
        "buys",
        "sells"
      ],
      "properties": {
        "buys": {
          "type": "integer",
          "format": "int64",
          "description": "Buy-side trades.",
          "minimum": 0
        },
        "sells": {
          "type": "integer",
          "format": "int64",
          "description": "Sell-side trades.",
          "minimum": 0
        },
        "total": {
          "type": "integer",
          "format": "int64",
          "description": "`buys + sells`.",
          "minimum": 0
        }
      }
    },
    "UiWalletAddresses": {
      "type": "object",
      "description": "A wallet's per-family addresses. A named wallet has one family, so the other is absent.",
      "properties": {
        "evm": {
          "type": [
            "string",
            "null"
          ],
          "description": "EVM `0x` address, lowercase."
        },
        "solana": {
          "type": [
            "string",
            "null"
          ],
          "description": "Solana base58 address."
        }
      }
    },
    "UiWalletDescriptor": {
      "type": "object",
      "description": "One named wallet and its share of the portfolio.",
      "required": [
        "addresses",
        "spot"
      ],
      "properties": {
        "addresses": {
          "$ref": "#/$defs/UiWalletAddresses",
          "description": "The wallet's address, under its family."
        },
        "spot": {
          "$ref": "#/$defs/UiSpotPortfolio",
          "description": "This wallet's spot holdings."
        },
        "stats": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/UiPortfolioStats",
              "description": "This wallet's timeframe performance; present only under `include=stats`."
            }
          ],
          "description": "This wallet's timeframe performance; present only under `include=stats`."
        }
      }
    },
    "UnixMilliseconds": {
      "type": "integer",
      "format": "int64",
      "description": "An instant, as milliseconds since the Unix epoch."
    }
  }
}