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

# FIFO PnL breakdown for a wallet

> Computes per-token realized PnL using FIFO (First In, First Out) cost-basis accounting.
Each sell is matched against the oldest remaining buy lots to determine the exact cost basis consumed.
Returns per-token breakdown plus aggregated totals in SOL and USD.




## OpenAPI

````yaml openapi-spec/history.yaml get /api/sol/wallets/{address}/pnl
openapi: 3.0.3
info:
  title: Raze Database API
  description: >
    Paid subscription API for Solana transaction data and history.


    ## Batch Requests

    All endpoints with path parameters (mint, signer, address, tokenMint,
    ownerAddress) support batch queries

    via comma-separated values. For example:
    `/api/sol/trades/mint/mint1,mint2,mint3?limit=50`


    - Maximum 10 values per batch request

    - Each value must be a valid address (>= 32 characters)

    - Single values behave identically to non-batch requests

    - Batch response format: `{ "success": true, "results": { "value1": {...},
    "value2": {...} }, "count": N, "timestamp": "..." }`

    - Each key in `results` contains the full single-entity response

    - Queries run in parallel for maximum performance
  version: 1.0.0
servers:
  - url: https://api.raze.bot
    description: >-
      Raze global History API — GeoDNS routes to the nearest region
      automatically
security:
  - ApiKeyAuth: []
paths:
  /api/sol/wallets/{address}/pnl:
    get:
      summary: FIFO PnL breakdown for a wallet
      description: >
        Computes per-token realized PnL using FIFO (First In, First Out)
        cost-basis accounting.

        Each sell is matched against the oldest remaining buy lots to determine
        the exact cost basis consumed.

        Returns per-token breakdown plus aggregated totals in SOL and USD.
      operationId: getWalletFifoPnl
      parameters:
        - name: address
          in: path
          required: true
          schema:
            type: string
          example: 62ThHC1rs2GUfa8J4Qjcj5GD2MSL2d65pcJtenNieDnm
        - name: from
          in: query
          schema:
            type: integer
          description: Start timestamp (Unix seconds).
        - name: to
          in: query
          schema:
            type: integer
          description: End timestamp (Unix seconds)
        - name: limit
          in: query
          schema:
            type: integer
            default: 50000
            maximum: 50000
          description: Maximum number of trades to process for FIFO calculation
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WalletFifoPnlResponse'
        '400':
          description: Invalid address
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Database error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    WalletFifoPnlResponse:
      type: object
      properties:
        success:
          type: boolean
        address:
          type: string
        data:
          type: object
          properties:
            totalRealizedPnlSol:
              type: number
              description: Total realized PnL across all tokens (SOL)
            totalRealizedPnlUsd:
              type: number
              description: Total realized PnL across all tokens (USD)
            totalUnrealizedCostSol:
              type: number
              description: Total cost basis of tokens still held (SOL)
            totalUnrealizedCostUsd:
              type: number
              description: Total cost basis of tokens still held (USD)
            tokenCount:
              type: integer
              description: Number of unique tokens traded
            tokens:
              type: array
              items:
                $ref: '#/components/schemas/FifoTokenPnl'
        tradesProcessed:
          type: integer
          description: Total number of trades analyzed
        truncated:
          type: boolean
          description: True if trade limit was reached (results may be incomplete)
        solPriceUsd:
          type: number
        timestamp:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
        code:
          type: string
        success:
          type: boolean
      example:
        error: Unauthorized
        message: Invalid API key
        code: INVALID_KEY
        success: false
    FifoTokenPnl:
      type: object
      properties:
        mint:
          type: string
        realizedPnlSol:
          type: number
          description: FIFO realized PnL for this token (SOL)
        totalCostBasis:
          type: number
          description: Total SOL spent buying this token
        unrealizedCostSol:
          type: number
          description: Cost basis of remaining unsold lots (SOL)
        unrealizedTokens:
          type: number
          description: Token amount still held across remaining lots
        unrealizedLots:
          type: integer
          description: Number of buy lots not yet fully consumed
        totalBuys:
          type: integer
        totalSells:
          type: integer
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: query
      name: apiKey

````