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

# Get profit and loss

> Realized, unrealized and total profit and loss of this key’s trading account, overall and per venue. Filter by `venue` or `market_id`. A live key reads its account’s profit and loss ledger, or for one market its positions there. A test key replays its simulated fills for realized profit and loss, and totals unrealized profit and loss exactly as a live key does over its simulated positions, which are marked as the Lean portfolio marks live ones: Polymarket at the last trade, Hyperliquid at the venue’s mid. A position on a resolved market counts no unrealized profit and loss; unrealized and total are null while any other position has no mark.



## OpenAPI

````yaml api-reference/openapi.json GET /pnl
openapi: 3.0.0
info:
  title: Lean API
  version: 0.1.0
  description: >-
    Programmatic access to Lean: canonical sports markets, quotes, orders,
    positions and balances.
servers:
  - url: '{baseUrl}/v1'
    description: Lean API
    variables:
      baseUrl:
        default: https://api.lean.xyz
        description: >-
          The Lean API base URL, without /v1. Same value as LEAN_API_URL in the
          guides.
security:
  - apiKey: []
paths:
  /pnl:
    get:
      tags:
        - Account
      summary: Get profit and loss
      description: >-
        Realized, unrealized and total profit and loss of this key’s trading
        account, overall and per venue. Filter by `venue` or `market_id`. A live
        key reads its account’s profit and loss ledger, or for one market its
        positions there. A test key replays its simulated fills for realized
        profit and loss, and totals unrealized profit and loss exactly as a live
        key does over its simulated positions, which are marked as the Lean
        portfolio marks live ones: Polymarket at the last trade, Hyperliquid at
        the venue’s mid. A position on a resolved market counts no unrealized
        profit and loss; unrealized and total are null while any other position
        has no mark.
      operationId: getPnl
      parameters:
        - schema:
            type: string
            enum:
              - kalshi
              - polymarket
              - polymarket_us
              - hyperliquid
            description: Only profit and loss on this venue.
          required: false
          description: Only profit and loss on this venue.
          name: venue
          in: query
        - schema:
            type: string
            minLength: 1
            maxLength: 512
            description: >-
              Only profit and loss on this market: realized from its closed and
              reduced positions, unrealized from its open ones.
          required: false
          description: >-
            Only profit and loss on this market: realized from its closed and
            reduced positions, unrealized from its open ones.
          name: market_id
          in: query
      responses:
        '200':
          description: Profit and loss of the key’s trading account
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        type: object
                        properties:
                          realized_pnl_usd:
                            type: string
                            pattern: ^-?\d+(?:\.\d+)?$
                          unrealized_pnl_usd:
                            type: string
                            nullable: true
                            pattern: ^-?\d+(?:\.\d+)?$
                            description: >-
                              What open positions are worth at their mark
                              prices, or at cost without one, less their cost
                              basis. A position on a resolved market has settled
                              into realized and counts none. Null when a
                              position has no known cost or a venue could not be
                              read.
                          total_pnl_usd:
                            type: string
                            nullable: true
                            pattern: ^-?\d+(?:\.\d+)?$
                          venues:
                            type: array
                            items:
                              type: object
                              properties:
                                venue:
                                  type: string
                                  enum:
                                    - kalshi
                                    - polymarket
                                    - polymarket_us
                                    - hyperliquid
                                realized_pnl_usd:
                                  type: string
                                  pattern: ^-?\d+(?:\.\d+)?$
                                unrealized_pnl_usd:
                                  type: string
                                  nullable: true
                                  pattern: ^-?\d+(?:\.\d+)?$
                                total_pnl_usd:
                                  type: string
                                  nullable: true
                                  pattern: ^-?\d+(?:\.\d+)?$
                                updated_at:
                                  type: string
                                  nullable: true
                                  format: date-time
                                  description: >-
                                    When this venue’s profit and loss record
                                    last changed, or null when it was read live
                                    or has no record yet.
                              required:
                                - venue
                                - realized_pnl_usd
                                - unrealized_pnl_usd
                                - total_pnl_usd
                                - updated_at
                          market_id:
                            type: string
                            nullable: true
                          unavailable:
                            type: array
                            items:
                              type: string
                              enum:
                                - kalshi
                                - polymarket
                                - polymarket_us
                                - hyperliquid
                          as_of:
                            type: string
                            format: date-time
                          livemode:
                            type: boolean
                        required:
                          - realized_pnl_usd
                          - unrealized_pnl_usd
                          - total_pnl_usd
                          - venues
                          - market_id
                          - unavailable
                          - as_of
                          - livemode
                      meta:
                        type: object
                        properties:
                          timestampMs:
                            type: integer
                            minimum: 0
                          requestId:
                            type: string
                            minLength: 1
                          traceId:
                            type: string
                            minLength: 1
                          cachedAtMs:
                            type: integer
                            minimum: 0
                          source:
                            type: string
                            enum:
                              - cache
                              - database
                              - clickhouse
                              - upstream
                              - fallback
                              - internal
                        required:
                          - timestampMs
                          - requestId
                    required:
                      - success
                      - data
                      - meta
                  - $ref: '#/components/schemas/ApiError'
              example:
                success: true
                data:
                  realized_pnl_usd: '27.5'
                  unrealized_pnl_usd: '7.5'
                  total_pnl_usd: '35'
                  venues:
                    - venue: polymarket
                      realized_pnl_usd: '15'
                      unrealized_pnl_usd: '5'
                      total_pnl_usd: '20'
                      updated_at: '2026-11-10T16:00:00.000Z'
                    - venue: hyperliquid
                      realized_pnl_usd: '12.5'
                      unrealized_pnl_usd: '2.5'
                      total_pnl_usd: '15'
                      updated_at: '2026-11-10T16:00:00.000Z'
                  market_id: null
                  unavailable: []
                  as_of: '2026-11-10T17:00:00.000Z'
                  livemode: true
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '400':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Invalid request
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '401':
          description: Missing, invalid, expired or revoked API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid, expired or revoked API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '403':
          description: The key lacks the scope this route needs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: This API key lacks the scope this route needs
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '404':
          description: No market has this id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: No market has this id
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '429':
          description: API error
          headers:
            Retry-After:
              description: Seconds remaining in the upstream read cooldown, when available
              schema:
                type: integer
                minimum: 0
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: RATE_LIMITED
                  message: Too many requests for this API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '500':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: INTERNAL_ERROR
                  message: An internal error occurred.
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
components:
  schemas:
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - VALIDATION_ERROR
                - NOT_FOUND
                - UNAUTHORIZED
                - FORBIDDEN
                - CONFLICT
                - UPSTREAM_ERROR
                - RATE_LIMITED
                - INTERNAL_ERROR
                - FEATURE_DISABLED
                - CONDITIONAL_SELL_REJECTED
                - CONDITIONAL_SELL_ACTIVE
            message:
              type: string
              minLength: 1
            details:
              nullable: true
          required:
            - code
            - message
        meta:
          type: object
          properties:
            timestampMs:
              type: integer
              minimum: 0
            requestId:
              type: string
              minLength: 1
            traceId:
              type: string
              minLength: 1
            cachedAtMs:
              type: integer
              minimum: 0
            source:
              type: string
              enum:
                - cache
                - database
                - clickhouse
                - upstream
                - fallback
                - internal
          required:
            - timestampMs
            - requestId
      required:
        - success
        - error
        - meta
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        A Lean API key, sent as `Authorization: Bearer <key>`. A test key
        (`lean_sk_test_...`) simulates orders and fills with no money; a live
        key (`lean_sk_live_...`) trades for real within the key's limits. Every
        successful response says which mode answered in `data.livemode`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.