> ## 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 history

> Cumulative profit and loss of this key’s trading account at evenly spaced times from `start` to `end`, each point as of its time. The range is at most 365 days and 1000 points. A test key’s points have realized profit and loss only.



## OpenAPI

````yaml api-reference/openapi.json GET /pnl/history
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/history:
    get:
      tags:
        - Account
      summary: Get profit and loss history
      description: >-
        Cumulative profit and loss of this key’s trading account at evenly
        spaced times from `start` to `end`, each point as of its time. The range
        is at most 365 days and 1000 points. A test key’s points have realized
        profit and loss only.
      operationId: getPnlHistory
      parameters:
        - schema:
            type: string
            enum:
              - 1h
              - 1d
            default: 1d
            description: Spacing between points.
          required: false
          description: Spacing between points.
          name: interval
          in: query
        - schema:
            type: string
            format: date-time
            description: Start of the range. Defaults to 30 days before end.
          required: false
          description: Start of the range. Defaults to 30 days before end.
          name: start
          in: query
        - schema:
            type: string
            format: date-time
            description: End of the range. Defaults to now.
          required: false
          description: End of the range. Defaults to now.
          name: end
          in: query
        - 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
      responses:
        '200':
          description: Profit and loss of the key’s trading account over time
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        type: object
                        properties:
                          interval:
                            type: string
                            enum:
                              - 1h
                              - 1d
                          start:
                            type: string
                            format: date-time
                          end:
                            type: string
                            format: date-time
                          venue:
                            type: string
                            nullable: true
                            enum:
                              - kalshi
                              - polymarket
                              - polymarket_us
                              - hyperliquid
                          points:
                            type: array
                            items:
                              type: object
                              properties:
                                ts:
                                  type: string
                                  format: date-time
                                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+)?$
                              required:
                                - ts
                                - realized_pnl_usd
                                - unrealized_pnl_usd
                                - total_pnl_usd
                            description: >-
                              Cumulative profit and loss as the account’s profit
                              and loss record held it at each time, with
                              unrealized at the marks the record captured. GET
                              /v1/pnl marks open positions live, so the latest
                              point can trail it until the next capture.
                          livemode:
                            type: boolean
                        required:
                          - interval
                          - start
                          - end
                          - venue
                          - points
                          - 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:
                  interval: 1d
                  start: '2026-11-08T00:00:00.000Z'
                  end: '2026-11-10T00:00:00.000Z'
                  venue: null
                  points:
                    - ts: '2026-11-08T00:00:00.000Z'
                      realized_pnl_usd: '20'
                      unrealized_pnl_usd: '4'
                      total_pnl_usd: '24'
                    - ts: '2026-11-09T00:00:00.000Z'
                      realized_pnl_usd: '22.5'
                      unrealized_pnl_usd: '6'
                      total_pnl_usd: '28.5'
                    - ts: '2026-11-10T00:00:00.000Z'
                      realized_pnl_usd: '27.5'
                      unrealized_pnl_usd: '7.5'
                      total_pnl_usd: '35'
                  livemode: true
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '400':
          description: The interval or range is invalid or too large
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: The interval or range is invalid or too large
                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
        '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.