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

# Wallet PnL summary (Polymarket, FIFO)



## OpenAPI

````yaml /prediction-markets/openapi.json get /v1/accounts/{address}/pnl
openapi: 3.1.0
info:
  title: Prediction Market API (Beta)
  description: >-
    Unified **beta** prediction market API for Kalshi and Polymarket — markets,
    events, full historical trades and candlesticks, orderbooks, crypto up/down
    windows, and Polymarket wallet analytics. Read/market-data only.


    **Auth:** pass your Data API key in the `x-api-key` header.


    **Conventions:** response bodies use camelCase. Query params are snake_case
    (camelCase aliases accepted where noted).


    **Caching:** SWR endpoints may set `X-Cache` (`HIT` | `HIT-STALE` | `MISS`).
    Busy backends may return `503` with `SERVICE_BUSY`.


    **Realtime:** join `pm:*` rooms on
    `wss://datastream.solanatracker.io/{apiKey}` (same Datastream hub as other
    products — see Datastream → Prediction Markets).
  license:
    name: ''
  version: 0.1.0
servers:
  - url: https://prediction-market-api.solanatracker.io
    description: Public beta
security:
  - apiKey: []
tags:
  - name: Exchange
    description: Exchange status
  - name: Events
    description: >-
      Cross-exchange event groupings (Kalshi event_ticker, Polymarket Gamma
      grouped/negRisk events). Includes metadata: image, icon, description,
      tags, and nested markets with groupItemTitle.
  - name: Crypto
    description: >-
      Polymarket crypto up/down (Chainlink) Price to Beat, final price, chart
      history, and series windows.
  - name: Meta
    description: Categories, series, sports, live data
  - name: Markets
    description: Market data, orderbooks, candles
  - name: Trades
    description: Trade feeds
  - name: Accounts
    description: Polymarket wallet analytics (FIFO PnL)
  - name: Leaderboard
    description: Top wallet PnL rankings (Polymarket; Kalshi has no public wallets)
  - name: Stats
    description: Platform statistics
paths:
  /v1/accounts/{address}/pnl:
    get:
      tags:
        - Accounts
      summary: Wallet PnL summary (Polymarket, FIFO)
      operationId: get_account_pnl_path
      parameters:
        - name: address
          in: path
          description: Ethereum wallet address
          required: true
          schema:
            type: string
        - name: period_days
          in: query
          description: Rolling window in days such as 7, 30, or 90 (omit for all-time)
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
        - name: fresh
          in: query
          description: Bypass Redis; ClickHouse serving path remains exact and bounded
          required: false
          schema:
            type: boolean
      responses:
        '200':
          description: PnL summary with positions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WalletPnlSummary'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorBody'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorBody'
        '408':
          description: Request timeout
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorBody'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorBody'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorBody'
components:
  schemas:
    WalletPnlSummary:
      type: object
      description: Wallet-level PnL summary across all positions.
      required:
        - address
        - exchange
        - costMethod
        - totalInvestedUsd
        - totalProceedsUsd
        - realizedPnlUsd
        - unrealizedPnlUsd
        - totalPnlUsd
        - marketsTraded
        - openPositions
        - activePositionCount
        - heldTokenPositionCount
        - redeemablePositionCount
        - resolvedPositionCount
        - positions
      properties:
        activePositionCount:
          type: integer
          minimum: 0
        address:
          type: string
          description: The wallet address.
        costMethod:
          type: string
          description: Cost basis method (`fifo`).
        exchange:
          $ref: '#/components/schemas/Exchange'
          description: >-
            Exchange (Polymarket on-chain; Kalshi has no public wallet
            addresses).
        heldTokenPositionCount:
          type: integer
          minimum: 0
        marketsTraded:
          type: integer
          description: Number of distinct markets traded.
          minimum: 0
        openPositions:
          type: integer
          description: Number of positions currently open (net_tokens > 0).
          minimum: 0
        positions:
          type: array
          items:
            $ref: '#/components/schemas/WalletPosition'
          description: Individual position details.
        realizedPnlUsd:
          type: number
          format: double
          description: Sum of realized PnL across all closed/partially-closed positions.
        redeemablePositionCount:
          type: integer
          minimum: 0
        resolvedPositionCount:
          type: integer
          minimum: 0
        totalInvestedUsd:
          type: number
          format: double
          description: Total USDC spent across all positions.
        totalPnlUsd:
          type: number
          format: double
          description: Net PnL (realized + unrealized).
        totalProceedsUsd:
          type: number
          format: double
          description: Total USDC received from sells.
        unrealizedPnlUsd:
          type: number
          format: double
          description: >-
            Sum of unrealized PnL for open positions (where current price is
            known).
    ApiErrorBody:
      type: object
      description: Standard API error response envelope.
      required:
        - error
        - code
      properties:
        code:
          type: integer
          format: int32
          description: HTTP status code (duplicated for convenience).
          minimum: 0
        error:
          type: string
        errorCode:
          type:
            - string
            - 'null'
          description: >-
            Stable machine-readable code: RATE_LIMITED, SERVICE_BUSY,
            BAD_REQUEST, NOT_FOUND, INTERNAL.
    Exchange:
      type: string
      enum:
        - polymarket
        - kalshi
    WalletPosition:
      type: object
      description: A single position (holding) in a prediction market outcome token.
      required:
        - assetId
        - exchange
        - positionStatus
        - marketStatus
        - isActive
        - isResolved
        - isRedeemable
        - isRedeemed
        - netTokens
        - avgCostBasis
        - totalCostUsd
        - totalProceedsUsd
        - realizedPnlUsd
        - buyCount
        - sellCount
        - resolved
        - firstTradeAt
        - lastTradeAt
      properties:
        assetId:
          type: string
          description: The outcome token's asset ID.
        avgCostBasis:
          type: number
          format: double
          description: Average cost basis per token (0.0–1.0 probability scale).
        buyCount:
          type: integer
          format: int64
          description: Number of buy fills.
          minimum: 0
        costMethod:
          type:
            - string
            - 'null'
          description: Cost basis method used (`fifo`).
        currentPrice:
          type:
            - number
            - 'null'
          format: double
          description: Current market price for this outcome (0.0–1.0).
        eventId:
          type:
            - string
            - 'null'
          description: Parent Gamma event id when known.
        eventSlug:
          type:
            - string
            - 'null'
          description: Parent Gamma event slug when known.
        eventTitle:
          type:
            - string
            - 'null'
          description: Parent event title when known.
        exchange:
          $ref: '#/components/schemas/Exchange'
          description: Exchange this position is on.
        firstTradeAt:
          type: string
          description: ISO-8601 first trade time.
        groupItemTitle:
          type:
            - string
            - 'null'
        isActive:
          type: boolean
        isRedeemable:
          type: boolean
        isRedeemed:
          type: boolean
        isResolved:
          type: boolean
        lastTradeAt:
          type: string
          description: ISO-8601 last trade time.
        markPrice:
          type:
            - number
            - 'null'
          format: double
          description: Authoritative current or final settlement mark.
        marketId:
          type:
            - string
            - 'null'
          description: Polymarket condition id when resolved.
        marketStatus:
          $ref: '#/components/schemas/MarketStatus'
        marketTitle:
          type:
            - string
            - 'null'
          description: Human-readable market title/question (if we can resolve it).
        netTokens:
          type: number
          format: double
          description: Net tokens held (positive = long, negative = short / oversold).
        outcomeIndex:
          type:
            - integer
            - 'null'
          format: int32
          minimum: 0
        outcomeLabel:
          type:
            - string
            - 'null'
        positionStatus:
          $ref: '#/components/schemas/PositionStatus'
        positionValueUsd:
          type:
            - number
            - 'null'
          format: double
          description: Value of remaining tokens at the authoritative mark.
        realizedPnlUsd:
          type: number
          format: double
          description: Realized FIFO PnL, including final settlement PnL once resolved.
        remainingCostBasisUsd:
          type:
            - number
            - 'null'
          format: double
          description: Unsettled cost basis; zero after authoritative market settlement.
        resolved:
          type: boolean
          description: True once the outcome has an authoritative settlement value.
        returnPct:
          type:
            - number
            - 'null'
          format: double
          description: Return on remaining FIFO cost basis.
        sellCount:
          type: integer
          format: int64
          description: Number of sell fills.
          minimum: 0
        settledTokens:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Shares economically settled at the final payout (resolved positions
            only).
        settlementValueUsd:
          type:
            - number
            - 'null'
          format: double
          description: Final payout value of the remaining shares when resolved.
        totalCostUsd:
          type: number
          format: double
          description: Total USDC spent acquiring this position.
        totalProceedsUsd:
          type: number
          format: double
          description: Total USDC received from partial sells.
        unrealizedPnlUsd:
          type:
            - number
            - 'null'
          format: double
          description: >-
            Unrealized PnL for unresolved positions; zero after authoritative
            settlement.
    MarketStatus:
      type: string
      enum:
        - active
        - closed_pending_resolution
        - resolved
        - inactive
    PositionStatus:
      type: string
      enum:
        - active
        - closed
        - closed_pending_resolution
        - resolved_won
        - resolved_lost
        - resolved
        - redeemed
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Solana Tracker Data API key

````