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

# Solana 钱包 DeFi 仓位 API

> 获取 Solana 钱包在借贷、流动性、质押、杠杆和挂单上的 DeFi 仓位，附带价值、APY、健康度和可领取奖励。

钱包的 DeFi 仓位，按价值从大到小排列。可按 `platform` 或 `category` 筛选。

每个仓位包含：

* **`assets`**：仓位中的代币及其角色（`supplied`、`borrowed`、`liquidity` 或 `staked`）、数量、价格和价值。借入代币的 `usd` 为负数，因此各代币之和等于仓位的 `usd`。
* **`apy` 和 `yearlyUsd`**：按当前利率，仓位一年能赚多少，已扣除借款成本。杠杆仓位的 `apy` 可能是很大的负数。
* **`healthPercent`**（借款仓位）：100 表示没有债务，0 表示清算。
* **`inRange`**（集中流动性）：当前价格是否在仓位区间内。
* **`claimable`**：现在就能领取的奖励和手续费，价值见 `claimableUsd`，不计入 `usd`。

`id` 在仓位存续期间保持不变。代币名称、符号和 logo 在 `tokens` 中。

想查看按代币的交易盈亏？请使用 PnL V2 中的 [Get Wallet Positions](https://docs.solanatracker.io/cn/data-api/pnl-v2/wallet/get-wallet-positions.md)。

**分页。** 将 `nextCursor` 作为 `cursor` 传入，直到 `hasNextPage` 为 `false`，并保持筛选条件和 `sortDirection` 不变。

## SDK Example

```typescript
import { Client } from '@solana-tracker/data-api';

const client = new Client({ apiKey: 'YOUR_API_KEY' });

const data = await client.getWalletPositionsV2('CN8w8cuh87gZYjhpaPxbD78GTrBmUKmVysqgsC9uYu9i', {
  category: 'lending', // Or liquidity, staking, leverage, orders, rewards, other.
  // platform: 'kamino', // An id from client.getPortfolioPlatformsV2().
  limit: 50,
});

for (const position of data.positions) {
  console.log(position.name, position.usd, position.apy, position.healthPercent, position.claimableUsd);
}

// client.iterateWalletPositionsV2() walks every page.
```


## OpenAPI

````yaml /cn/data-api/wallet-v2/openapi.json get /v2/wallet/{wallet}/positions
openapi: 3.1.0
info:
  title: Solana Tracker Wallet API v2
  version: 2.0.0
  description: >-
    Solana 钱包持有和赚取的一切：代币，以及在借贷、流动性、质押、杠杆和挂单平台上的 DeFi 仓位，按 USD 和 SOL
    计价，并提供收益率、可领取奖励和净值历史。百分比直接用数字表示（6.99 即 6.99%），除另有说明外，时间均为 Unix 毫秒。
  contact:
    email: contact@solanatracker.io
servers:
  - url: https://data.solanatracker.io
    description: Production server
security:
  - apiKey: []
tags:
  - name: Wallet
    description: 钱包的净值、代币、DeFi 仓位和净值历史。
  - name: Platforms
    description: Wallet V2 支持的 DeFi 平台。
paths:
  /v2/wallet/{wallet}/positions:
    get:
      tags:
        - Wallet
      summary: Get Wallet Positions
      description: 钱包的 DeFi 仓位：借贷、流动性、农场、质押、杠杆和挂单。
      operationId: getWalletPositionsV2
      parameters:
        - $ref: '#/components/parameters/Wallet'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/Platform'
        - $ref: '#/components/parameters/Category'
        - $ref: '#/components/parameters/SortDirection'
      responses:
        '200':
          description: 一页钱包 DeFi 仓位。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WalletV2PositionsResponse'
              example:
                wallet: CN8w8cuh87gZYjhpaPxbD78GTrBmUKmVysqgsC9uYu9i
                slot: 475880664
                updatedAt: 1796067128569
                positions:
                  - id: kamino-vault-LnBhqBJEA4T8JpTSZBrWTFCL4Qa6nWJ6H72ukHkE729
                    platform: kamino
                    service: vault
                    category: liquidity
                    name: Kamino Vault
                    address: LnBhqBJEA4T8JpTSZBrWTFCL4Qa6nWJ6H72ukHkE729
                    usd: 26010.10554
                    apy: 8.77
                    yearlyUsd: 2280.462624
                    claimableUsd: 83.651952
                    healthPercent: null
                    inRange: null
                    assets:
                      - mint: 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo
                        role: supplied
                        amount: 26005.642935
                        priceUsd: 1.0001716013994661
                        usd: 26010.10554
                        apy: null
                        yearlyUsd: null
                    claimable:
                      - mint: 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo
                        amount: 83.6376
                        priceUsd: 1.0001716013994661
                        usd: 83.651952
                    image: >-
                      https://image.solanatracker.io/proxy?url=https%3A%2F%2Fplatform-images.solanatracker.io%2Fkamino.webp
                  - id: kamino-vault-ADietbkvGfEL5gYFzQN6wzazp4f221tEhZRPUGPck2Sy
                    platform: kamino
                    service: vault
                    category: liquidity
                    name: Kamino Vault
                    address: ADietbkvGfEL5gYFzQN6wzazp4f221tEhZRPUGPck2Sy
                    usd: 21154.671999
                    apy: 8
                    yearlyUsd: 1693.263872
                    claimableUsd: 0
                    healthPercent: null
                    inRange: null
                    assets:
                      - mint: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
                        role: supplied
                        amount: 21154.671999
                        priceUsd: 1
                        usd: 21154.671999
                        apy: null
                        yearlyUsd: null
                    claimable: []
                    image: >-
                      https://image.solanatracker.io/proxy?url=https%3A%2F%2Fplatform-images.solanatracker.io%2Fkamino.webp
                tokens:
                  EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v:
                    name: USD Coin
                    symbol: USDC
                    decimals: 6
                    image: >-
                      https://image.solanatracker.io/proxy?url=https://static.datapi.jup.ag/token-icons/6c4e5669d2a438653105399865445682e4a6cb51e19e1e61dc97578cd27bb9b2.webp
                    supply: 8121434516.222706
                    uri: null
                    description: null
                    creator: null
                    createdOn: null
                    twitter: https://twitter.com/circle
                    telegram: null
                    website: https://www.circle.com/en/usdc
                  2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo:
                    name: PayPal USD
                    symbol: PYUSD
                    decimals: 6
                    image: >-
                      https://image.solanatracker.io/proxy?url=https://static.datapi.jup.ag/token-icons/0817b3345e648b1663385bac48eb086877635ee27639c3d5da2a4d9dfd8603b1.webp
                    supply: 688682738.280124
                    uri: >-
                      https://token-metadata.paxos.com/pyusd_metadata/prod/solana/pyusd_metadata.json
                    description: >-
                      PayPal USD is designed to contribute to the opportunity
                      stablecoins offer for payments and is 100% backed by U.S.
                      dollar deposits, short-term U.S Treasuries and similar
                      cash equivalents. PayPal USD is redeemable 1:1 for U.S.
                      dollars and is issued by Paxos Trust Company.
                    creator: null
                    createdOn: null
                    twitter: null
                    telegram: null
                    website: null
                nextCursor: >-
                  eyJ2IjoyLCJhdCI6MTc5NjA2NzEyODU2OSwicyI6MjExNTQuNjcxOTk5LCJ0Ijoia2FtaW5vLXZhdWx0LUFEaWV0Ymt2R2ZFTDVnWUZ6UU42d3phenA0ZjIyMXRFaFpSUFVHUGNrMlN5IiwicSI6InB8ZHx8In0
                hasNextPage: true
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '503':
          $ref: '#/components/responses/Unavailable'
      x-codeSamples:
        - lang: typescript
          label: SDK
          source: >
            import { Client } from '@solana-tracker/data-api';


            const client = new Client({ apiKey: 'YOUR_API_KEY' });


            const data = await
            client.getWalletPositionsV2('CN8w8cuh87gZYjhpaPxbD78GTrBmUKmVysqgsC9uYu9i',
            {
              category: 'lending', // Or liquidity, staking, leverage, orders, rewards, other.
              // platform: 'kamino', // An id from client.getPortfolioPlatformsV2().
              limit: 50,
            });


            for (const position of data.positions) {
              console.log(position.name, position.usd, position.apy, position.healthPercent, position.claimableUsd);
            }


            // client.iterateWalletPositionsV2() walks every page.
      x-code-samples:
        - lang: typescript
          label: SDK
          source: >
            import { Client } from '@solana-tracker/data-api';


            const client = new Client({ apiKey: 'YOUR_API_KEY' });


            const data = await
            client.getWalletPositionsV2('CN8w8cuh87gZYjhpaPxbD78GTrBmUKmVysqgsC9uYu9i',
            {
              category: 'lending', // Or liquidity, staking, leverage, orders, rewards, other.
              // platform: 'kamino', // An id from client.getPortfolioPlatformsV2().
              limit: 50,
            });


            for (const position of data.positions) {
              console.log(position.name, position.usd, position.apy, position.healthPercent, position.claimableUsd);
            }


            // client.iterateWalletPositionsV2() walks every page.
components:
  parameters:
    Wallet:
      name: wallet
      in: path
      required: true
      schema:
        type: string
        default: CN8w8cuh87gZYjhpaPxbD78GTrBmUKmVysqgsC9uYu9i
      description: 钱包地址。
    Limit:
      name: limit
      in: query
      schema:
        type: integer
        minimum: 1
        maximum: 500
        default: 100
      description: 每页行数，最多 500。超过 500 时按 500 行返回。
    Cursor:
      name: cursor
      in: query
      schema:
        type: string
      description: 上一页返回的 `nextCursor`。其他参数需保持不变，否则请求会返回 400。
    Platform:
      name: platform
      in: query
      schema:
        type: string
        examples:
          - kamino
      description: >-
        只返回该平台的仓位。使用 [Get Portfolio
        Platforms](/cn/data-api/wallet-v2/platforms/get-portfolio-platforms) 中的
        `id`。
    Category:
      name: category
      in: query
      schema:
        type: string
        enum:
          - liquidity
          - lending
          - staking
          - leverage
          - orders
          - rewards
          - other
      description: 只返回该类别的仓位。
    SortDirection:
      name: sortDirection
      in: query
      schema:
        type: string
        enum:
          - DESC
          - ASC
        default: DESC
      description: '`DESC` 从大到小（默认），`ASC` 从小到大。没有值的行始终排在最后。'
  schemas:
    WalletV2PositionsResponse:
      type: object
      required:
        - wallet
        - slot
        - updatedAt
        - positions
        - tokens
        - nextCursor
        - hasNextPage
      properties:
        wallet:
          type: string
        slot:
          type: integer
          description: Solana slot the data was fetched at.
        updatedAt:
          type: integer
          description: When the data was fetched, in Unix milliseconds.
        positions:
          type: array
          items:
            $ref: '#/components/schemas/WalletV2Position'
        tokens:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/TradeTokenV2'
          description: 'Details of each token on the page: name, symbol, decimals and logo.'
        nextCursor:
          type:
            - string
            - 'null'
          description: Pass as `cursor` to get the next page. Null on the last page.
        hasNextPage:
          type: boolean
    WalletV2Position:
      type: object
      description: >-
        A DeFi position. Values are in USD and percentages are plain numbers.
        Values that are unknown or don't apply are null.
      required:
        - id
        - platform
        - service
        - category
        - name
        - address
        - usd
        - apy
        - yearlyUsd
        - claimableUsd
        - healthPercent
        - inRange
        - assets
        - claimable
      properties:
        id:
          type: string
          description: >-
            Unique position id, `platform-service-address`. Stays the same for
            the life of the position.
        platform:
          type: string
          description: Platform id from Get Portfolio Platforms.
        service:
          type: string
          description: Service id within the platform, such as `vault` or `lend`.
        category:
          type: string
          enum:
            - liquidity
            - lending
            - staking
            - leverage
            - orders
            - rewards
            - other
        name:
          type: string
          description: Display name, such as `Kamino Vault`.
        address:
          type: string
          description: On-chain address of the position.
        usd:
          type:
            - number
            - 'null'
          description: >-
            Value in USD: supplied minus borrowed. Claimable rewards are not
            included (see `claimableUsd`). Null when a token in it has no price.
        apy:
          type:
            - number
            - 'null'
          description: >-
            Yearly return in percent at today's rates, after borrowing costs.
            Can be negative, and very negative on leveraged positions. Liquidity
            positions earn 0 while out of range. Null when no rate is known.
        yearlyUsd:
          type:
            - number
            - 'null'
          description: >-
            USD earned per year at today's rates. Negative when the position
            costs more than it earns. Null when no rate is known.
        claimableUsd:
          type: number
          description: >-
            Value in USD of `claimable`. Net worth counts `usd` +
            `claimableUsd`.
        healthPercent:
          type:
            - number
            - 'null'
          description: >-
            For loans: how far the position is from liquidation. 100 means no
            debt, 0 means liquidation. Null for other positions or when unknown.
        inRange:
          type:
            - boolean
            - 'null'
          description: >-
            For concentrated liquidity: whether the current price is inside the
            position's range. Null for other positions.
        assets:
          type: array
          items:
            $ref: '#/components/schemas/WalletV2Asset'
        claimable:
          type: array
          items:
            $ref: '#/components/schemas/WalletV2Reward'
          description: Rewards and fees that can be claimed now.
        image:
          type:
            - string
            - 'null'
          description: Platform logo. Null when there is none.
    TradeTokenV2:
      type: object
      description: Token details, current at the time of the request.
      required:
        - name
        - symbol
        - decimals
        - image
        - supply
      properties:
        name:
          type:
            - string
            - 'null'
        symbol:
          type:
            - string
            - 'null'
        decimals:
          type:
            - integer
            - 'null'
        image:
          type:
            - string
            - 'null'
        supply:
          type:
            - number
            - 'null'
          description: Current supply, in whole tokens.
        uri:
          type:
            - string
            - 'null'
          description: Metadata link, when known.
        description:
          type:
            - string
            - 'null'
          description: At most 2,000 characters.
        creator:
          type:
            - string
            - 'null'
        createdOn:
          type:
            - string
            - 'null'
        twitter:
          type:
            - string
            - 'null'
        telegram:
          type:
            - string
            - 'null'
        website:
          type:
            - string
            - 'null'
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message.
    WalletV2Asset:
      type: object
      description: A token in a position.
      required:
        - mint
        - role
        - amount
        - priceUsd
        - usd
        - apy
        - yearlyUsd
      properties:
        mint:
          type: string
        role:
          type: string
          enum:
            - supplied
            - borrowed
            - liquidity
            - staked
          description: What the token does in the position. `borrowed` is debt.
        amount:
          type: number
          description: >-
            Amount in whole tokens, always positive. Already adjusted for
            decimals.
        priceUsd:
          type:
            - number
            - 'null'
          description: Price of one token in USD. Null when no price is available.
        usd:
          type:
            - number
            - 'null'
          description: Value in USD. Negative for borrowed tokens. Null without a price.
        apy:
          type:
            - number
            - 'null'
          description: >-
            Yearly rate in percent for this token: earned when supplied, paid
            when borrowed. Null when the platform has no rate per token.
        yearlyUsd:
          type:
            - number
            - 'null'
          description: >-
            USD per year at that rate. Negative for borrowed tokens. Null
            without a rate or price.
    WalletV2Reward:
      type: object
      description: A token that can be claimed.
      required:
        - mint
        - amount
        - priceUsd
        - usd
      properties:
        mint:
          type: string
        amount:
          type: number
          description: Amount in whole tokens.
        priceUsd:
          type:
            - number
            - 'null'
          description: Price of one token in USD. Null when no price is available.
        usd:
          type:
            - number
            - 'null'
          description: Value in USD. Null without a price.
  responses:
    BadRequest:
      description: 钱包地址或查询参数无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: 'Invalid sort. Valid options are: value, amount, change24h'
    Unauthorized:
      description: API 密钥缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unavailable:
      description: 暂时无法加载该钱包。请在 `Retry-After` 秒后重试。
      headers:
        Retry-After:
          description: 重试前需等待的秒数。
          schema:
            type: integer
            example: 1
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Wallet data is temporarily unavailable, please retry
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: API Key for authentication

````

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