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

# 錢包 - 盈虧明細

> 取得錢包按代幣分類的盈虧明細



## OpenAPI

````yaml /zh-Hant/api-reference/openapi-data-zh-Hant.yaml GET /v2/wallet/{chain}/{walletAddress}/pnl-details
openapi: 3.1.0
info:
  title: Services API
  description: Services API
  contact:
    name: AI
    email: ai@sx.ai
  license:
    name: MIT
  version: '1.0'
servers:
  - url: https://api.chainstream.io
    description: Production
security:
  - bearer_auth: []
  - api_key_auth: []
tags:
  - name: Blockchain
    description: 區塊鏈相關操作
  - name: Token
    description: 代幣相關操作
  - name: Trade
    description: 交易相關操作
  - name: Wallet
    description: 錢包相關操作
  - name: Dex
    description: DEX 相關操作
  - name: Ranking
    description: 排行榜相關操作
  - name: DexPool
    description: DEX 池子相關操作
  - name: Watchlist
    description: 關注列表相關操作
  - name: KYT
    description: KYT 相關操作
  - name: Webhook
    description: Webhook 相關操作
  - name: RedPacket
    description: 紅包相關操作
  - name: IPFS
    description: IPFS 相關操作
  - name: DexScreener
    description: DexScreener 相關操作
paths:
  /v2/wallet/{chain}/{walletAddress}/pnl-details:
    get:
      tags:
        - Wallet
      summary: 錢包 - 盈虧明細
      description: 取得錢包按代幣分類的盈虧明細
      operationId: get.pnl.details
      parameters:
        - name: chain
          in: path
          description: 支援網路列表中的鏈名稱
          required: true
          schema:
            $ref: '#/components/schemas/ChainSymbol'
          example: sol
        - name: walletAddress
          in: path
          description: 錢包地址
          required: true
          schema:
            type: string
          example: DfMxre4cKmvogbLrPigxmibVTTQDuzjdXojWzjCXXhzj
        - name: cursor
          in: query
          description: 分頁游標
          required: false
          schema:
            type: string
          example: eyJpZCI6IjEyMyJ9
        - name: limit
          in: query
          description: 每頁回傳結果數量
          required: false
          schema:
            type: integer
            format: int64
            default: 20
          example: 20
        - name: direction
          in: query
          description: 分頁方向（next 或 prev）
          required: false
          schema:
            oneOf:
              - $ref: '#/components/schemas/PageDirection'
            default: next
          example: next
        - name: resolution
          in: query
          description: 盈虧聚合的時間粒度
          required: true
          schema:
            $ref: '#/components/schemas/PnlResolution'
          example: 1d
        - name: positionState
          in: query
          description: 依持倉狀態篩選（持倉中或已平倉）
          required: false
          schema:
            $ref: '#/components/schemas/PositionState'
        - name: sortBy
          in: query
          description: 盈虧明細結果的排序欄位
          required: false
          schema:
            $ref: '#/components/schemas/PnlSortBy'
      responses:
        '200':
          description: 成功回應
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PnlDetailsResult'
components:
  schemas:
    ChainSymbol:
      type: string
      description: Supported blockchain chains
      enum:
        - sol
        - eth
        - bsc
    PageDirection:
      type: string
      description: Pagination direction
      enum:
        - next
        - prev
    PnlResolution:
      type: string
      description: PnL resolution period
      enum:
        - 1d
        - 7d
        - 30d
        - all
    PositionState:
      type: string
      description: Filter for PnL position state
      enum:
        - open
        - all
        - closed
    PnlSortBy:
      type: string
      description: Sort field for PnL details query
      enum:
        - totalPnl
        - realizedPnl
        - unrealizedPnl
    PnlDetailsResult:
      type: object
      description: Full PnL details result with cursor pagination.
      required:
        - summary
        - data
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/PnlDetailItem'
          description: 按代幣分類的盈虧明細列表
        endCursor:
          type:
            - string
            - 'null'
          description: 目前頁結束游標
          example: eyJpZCI6ImVuZCJ9
        hasNext:
          type: boolean
          description: 是否有下一頁
          example: false
        hasPrev:
          type: boolean
          description: 是否有上一頁
          example: false
        startCursor:
          type:
            - string
            - 'null'
          description: 目前頁起始游標
          example: eyJpZCI6InN0YXJ0In0=
        summary:
          $ref: '#/components/schemas/PnlDetailSummary'
          description: 彙總盈虧摘要
    PnlDetailItem:
      type: object
      description: PnL detail for a single wallet-token pair (mirrors TS PnlDetailItemDTO).
      required:
        - tokenAddress
        - walletAddress
        - balance
        - priceInUsd
        - currentValue
        - buys
        - sells
        - totalTrades
        - buyAmount
        - sellAmount
        - buyAmountInUsd
        - sellAmountInUsd
        - avgBuyPriceInUsd
        - avgSellPriceInUsd
        - realizedProfitInUsd
        - realizedProfitRatio
        - unrealizedProfitInUsd
        - unrealizedProfitRatio
        - totalProfitInUsd
        - totalProfitRatio
        - avgProfitPerTradeInUsd
        - isClosed
      properties:
        avgBuyPriceInUsd:
          type: string
          description: 平均買入價（USD 計）
          example: '0.00003324391014165111'
        avgProfitPerTradeInUsd:
          type: string
          description: 每筆交易平均利潤（USD 計）
          example: '3206068.5728287027967835484926836364'
        avgSellPriceInUsd:
          type: string
          description: 平均賣出價（USD 計）
          example: '0.00003185807445122603'
        balance:
          type: string
          description: 目前代幣餘額
          example: '1254982158.7106050000000000'
        buyAmount:
          type: string
          description: 總買入數量（代幣單位）
          example: '1457986404.2130240000000000'
        buyAmountInUsd:
          type: string
          description: 總買入金額（USD 計）
          example: '48469.1690094067802589'
        buys:
          type: string
          description: 買入交易次數
          example: '275'
        currentValue:
          type: string
          description: 目前持倉價值（USD 計）
          example: '1062513957.429816153652557077014'
        decimals:
          type: integer
          format: int32
          description: 代幣小數位數
          example: 6
        firstBuyAt:
          type:
            - integer
            - 'null'
          format: int64
          description: Timestamp of first buy (ms since epoch)
        isClosed:
          type: boolean
          description: Whether the position is fully closed (balance == 0)
        lastSellAt:
          type:
            - integer
            - 'null'
          format: int64
          description: Timestamp of last sell (ms since epoch)
        logoUri:
          type:
            - string
            - 'null'
          description: 代幣 Logo URI
          example: https://s1.chainstream.io/tokens/images/example.webp
        losses:
          type:
            - string
            - 'null'
          description: 虧損交易次數
          example: '5'
        name:
          type: string
          description: 代幣顯示名稱
          example: The Real World
        priceInUsd:
          type: string
          description: 目前代幣價格（USD 計）
          example: '0.8466367032033868'
        realizedProfitInUsd:
          type: string
          description: 已實現利潤（USD 計）
          example: '67.1297848453256596'
        realizedProfitRatio:
          type: string
          description: 已實現利潤率
          example: '0.00138499970635554473'
        sellAmount:
          type: string
          description: 總賣出數量（代幣單位）
          example: '203004245.5024190000000000'
        sellAmountInUsd:
          type: string
          description: 總賣出金額（USD 計）
          example: '6467.3243671310312402'
        sells:
          type: string
          description: 賣出交易次數
          example: '110'
        symbol:
          type: string
          description: 代幣代號
          example: TRW
        tokenAddress:
          type: string
          description: 代幣合約地址
          example: 4MbgMQGvXBWyxKsTfrvkcRgh5FNLg1VxLnzWqbsdPh7p
        totalCostInUsd:
          type:
            - string
            - 'null'
          description: 總成本（美元）
          example: '48469.17'
        totalProfitInUsd:
          type: string
          description: 總利潤（已實現 + 未實現，USD 計）
          example: '1234336400.539050576761666169683200000000'
        totalProfitRatio:
          type: string
          description: 總利潤率
          example: '25466.423827061972608618047859693225'
        totalTrades:
          type: string
          description: 總交易次數
          example: '385'
        transferInAmountInUsd:
          type:
            - string
            - 'null'
          description: 轉入總價值（美元）
          example: '150.00'
        transferInCount:
          type:
            - string
            - 'null'
          description: 轉入次數
          example: '3'
        transferOutAmountInUsd:
          type:
            - string
            - 'null'
          description: 轉出總價值（美元）
          example: '29.40'
        transferOutCount:
          type:
            - string
            - 'null'
          description: 轉出次數
          example: '1'
        unrealizedProfitInUsd:
          type: string
          description: 未實現利潤（USD 計）
          example: '1234336333.409265731436006569683200000000'
        unrealizedProfitRatio:
          type: string
          description: 未實現利潤率
          example: '25466.422442062266253073315832775971'
        walletAddress:
          type: string
          description: 錢包地址
          example: 54Pz1e35z9uoFdnxtzjp7xZQoFiofqhdayQWBMN7dsuy
        wins:
          type:
            - string
            - 'null'
          description: 盈利交易次數
          example: '12'
    PnlDetailSummary:
      type: object
      description: >-
        Aggregated PnL summary across all items (mirrors TS
        PnlDetailSummaryDTO).
      required:
        - tokens
        - buys
        - sells
        - totalTrades
        - wins
        - losses
        - winRate
        - buyAmountInUsd
        - sellAmountInUsd
        - totalCostInUsd
        - currentValue
        - realizedProfitInUsd
        - realizedProfitRatio
        - unrealizedProfitInUsd
        - totalProfitInUsd
        - avgProfitPerTradeInUsd
      properties:
        avgProfitPerTradeInUsd:
          type: string
          description: 每筆交易平均利潤（USD 計）
          example: '3206068.5728287027967835484926836364'
        buyAmountInUsd:
          type: string
          description: 總買入金額（USD 計）
          example: '48469.1690094067802589'
        buys:
          type: string
          description: 總買入次數
          example: '275'
        currentValue:
          type: string
          description: 目前持倉總價值（USD 計）
          example: '1062513957.429816153652557077014'
        losses:
          type: string
          description: 虧損交易次數
          example: '69'
        realizedProfitInUsd:
          type: string
          description: 總已實現利潤（USD 計）
          example: '67.1297848453256596'
        realizedProfitRatio:
          type: string
          description: 總已實現利潤率
          example: '0.0013849997063555447320269173'
        sellAmountInUsd:
          type: string
          description: 總賣出金額（USD 計）
          example: '6467.3243671310312402'
        sells:
          type: string
          description: 總賣出次數
          example: '110'
        tokens:
          type: string
          description: 交易代幣總數
          example: '1'
        totalCostInUsd:
          type: string
          description: 總成本（USD 計）
          example: '48469.1690094067802589'
        totalProfitInUsd:
          type: string
          description: 總利潤（USD 計）
          example: '1234336400.5390505767616661696832'
        totalTrades:
          type: string
          description: 總交易次數
          example: '385'
        transferInAmountInUsd:
          type: string
          description: 轉入總價值（美元）
          example: '350.00'
        transferInCount:
          type: string
          description: 轉入次數
          example: '5'
        transferOutAmountInUsd:
          type: string
          description: 轉出總價值（美元）
          example: '29.40'
        transferOutCount:
          type: string
          description: 轉出次數
          example: '2'
        unrealizedProfitInUsd:
          type: string
          description: 總未實現利潤（USD 計）
          example: '1234336333.4092657314360065696832'
        winRate:
          type: string
          description: 勝率
          example: '0.5688'
        wins:
          type: string
          description: 獲利交易次數
          example: '91'
  securitySchemes:
    bearer_auth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    api_key_auth:
      type: apiKey
      in: header
      name: X-API-KEY

````