> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stockly.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a user's portfolio

> The user's live stock portfolio — current holdings valued at market prices. `change` is the return versus cost basis (the total USD you've given for the stock they hold). Holdings are aggregated by stock symbol. `change` is null when there's no cost basis yet.



## OpenAPI

````yaml /openapi.json get /v1/users/{userId}/portfolio
openapi: 3.1.0
info:
  title: Stockly Partner API
  description: >-
    Create users, give them stock, and read their portfolios. All requests and
    responses are JSON.
  version: 1.0.0
servers:
  - url: https://api.stockly.com
    description: Production (replace with your Stockly API base URL)
security:
  - apiKey: []
tags:
  - name: Users
    description: Your customers.
  - name: Stock awards
    description: Give users stock and read back award status.
  - name: Portfolio
    description: A user's live stock holdings.
  - name: Catalog
    description: Stocks available to give.
paths:
  /v1/users/{userId}/portfolio:
    get:
      tags:
        - Portfolio
      summary: Get a user's portfolio
      description: >-
        The user's live stock portfolio — current holdings valued at market
        prices. `change` is the return versus cost basis (the total USD you've
        given for the stock they hold). Holdings are aggregated by stock symbol.
        `change` is null when there's no cost basis yet.
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: The user's portfolio
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Portfolio'
              example:
                value: 4.26
                costBasis: 3.93
                change: +8.4%
                holdings:
                  - asset: AAPL
                    quantity: 0.00427
                    value: 1.24
                    costBasis: 1.15
                    change: +7.8%
                  - asset: NVDA
                    quantity: 0.0006
                    value: 0.87
                    costBasis: 0.8
                    change: +8.8%
                  - asset: TSLA
                    quantity: 0.0072
                    value: 2.15
                    costBasis: 1.98
                    change: +8.6%
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: User not found in your app
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Portfolio:
      type: object
      properties:
        value:
          type: number
          description: Total current value in USD.
        costBasis:
          type: number
          description: Total USD given for the held stock.
        change:
          type:
            - string
            - 'null'
          description: Return vs cost basis, e.g. "+8.4%". Null if no cost basis yet.
        holdings:
          type: array
          items:
            $ref: '#/components/schemas/PortfolioHolding'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - bad_request
                - unauthorized
                - forbidden
                - not_found
                - conflict
                - unprocessable_entity
                - internal_error
                - upstream_error
            message:
              type: string
            details:
              description: Optional structured detail (e.g. validation issues).
            requestId:
              type: string
              description: Correlation id, also returned in the x-request-id header.
      example:
        error:
          code: conflict
          message: idempotencyKey was already used with a different payload
          details:
            idempotencyKey: order-1001-reward
          requestId: f0e1d2c3-4b5a-6789-0abc-def012345678
    PortfolioHolding:
      type: object
      properties:
        asset:
          type: string
          description: Stock ticker, e.g. AAPL.
        quantity:
          type: number
          description: Shares held.
        value:
          type: number
          description: Current value in USD.
        costBasis:
          type: number
          description: USD given for this holding.
        change:
          type:
            - string
            - 'null'
          description: Return vs cost basis for this holding.
  responses:
    Unauthorized:
      description: Missing or invalid x-api-key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Your Stockly API key. Identifies your app; you never pass an app id.

````