> ## 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 token balance

> Recibe el cambio de balance de un token concreto para una wallet de Solana vía Datastream WebSocket para alertas granulares por token.

## SDK Example

```typescript theme={null}
import { Datastream } from '@solana-tracker/data-api';

const dataStream = new Datastream({
  wsUrl: 'wss://datastream.solanatracker.io/YOUR_API_KEY',
});

dataStream.on('error', console.error);
await dataStream.connect();

const sub = dataStream.subscribe.wallet('FbMxP3GVq8TQ36nbYgx4NP9iygMpwAwFWJwW81ioCiSF').tokenBalance('6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN').on((data) => {
  console.log(data);
});

// sub.unsubscribe();
```


## AsyncAPI

````yaml es/datastream/wallet.json walletTokenBalance
id: walletTokenBalance
title: Wallet token balance
description: Saldo de un token concreto
servers:
  - id: production
    protocol: wss
    host: datastream.solanatracker.io
    bindings: []
    variables:
      - id: apiKey
        description: Su clave API única de la suscripción a Data API
        defaultValue: YOUR_DATASTREAM_KEY
        allowedValues: []
        examples: []
address: /
parameters: []
bindings: []
operations:
  - &ref_2
    id: subscribeToTokenBalance
    title: Subscribe to token balance
    description: Subscribe to token balance
    type: receive
    messages:
      - &ref_5
        id: joinTokenBalance
        payload:
          - name: joinTokenBalance
            description: Subscribe to specific token balance
            type: object
            properties:
              - name: type
                type: string
                description: join
                required: true
              - name: room
                type: string
                description: Wallet token balance room
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - room
          properties:
            type:
              type: string
              const: join
              default: join
              x-parser-schema-id: <anonymous-schema-66>
            room:
              type: string
              pattern: ^wallet:[A-Za-z0-9]{32,44}:[A-Za-z0-9]{32,44}:balance$
              description: Wallet token balance room
              default: >-
                wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance
              x-parser-schema-id: <anonymous-schema-67>
          examples:
            - type: join
              room: >-
                wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance
          x-parser-schema-id: <anonymous-schema-65>
        title: Join token balance
        description: Subscribe to specific token balance
        example: |-
          {
            "type": "join",
            "room": "wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: joinTokenBalance
          - id: x-parser-message-name
            value: joinTokenBalance
    bindings: []
    extensions: &ref_1
      - id: x-codeSamples
        value: &ref_8
          - lang: typescript
            label: SDK
            source: >
              import { Datastream } from '@solana-tracker/data-api';


              const dataStream = new Datastream({
                wsUrl: 'wss://datastream.solanatracker.io/YOUR_API_KEY',
              });


              dataStream.on('error', console.error);

              await dataStream.connect();


              const sub =
              dataStream.subscribe.wallet('FbMxP3GVq8TQ36nbYgx4NP9iygMpwAwFWJwW81ioCiSF').tokenBalance('6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN').on((data)
              => {
                console.log(data);
              });


              // sub.unsubscribe();
      - id: x-parser-unique-object-id
        value: walletTokenBalance
  - &ref_4
    id: receiveTokenBalanceData
    title: Receive token balance data
    description: Receive balance updates
    type: send
    messages:
      - &ref_7
        id: tokenBalanceMessage
        payload:
          - name: tokenBalanceMessage
            description: Token balance change notification
            type: object
            properties:
              - name: type
                type: string
                description: message
                required: false
              - name: room
                type: string
                required: false
              - name: data
                type: object
                examples: &ref_0
                  - wallet: FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1
                    token: Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
                    amount: 78816.844996
                  - wallet: FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1
                    token: So11111111111111111111111111111111111111112
                    amount: 1.2345
                required: false
                properties:
                  - name: wallet
                    type: string
                    description: Wallet public key that received the balance update
                    required: true
                  - name: token
                    type: string
                    description: >-
                      Token mint address. Native SOL uses the wrapped SOL mint
                      `So11111111111111111111111111111111111111112` (same
                      identifier for SOL balance updates on these rooms).
                    required: true
                  - name: amount
                    type: number
                    description: >-
                      UI token amount after the update (decimal human units, not
                      raw integer base units / lamports). Example:
                      `78816.844996` for a fractional SPL balance. Use this
                      value for display and reconciliation against UI balances;
                      convert with mint decimals if you need raw integer
                      amounts.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: message
              x-parser-schema-id: <anonymous-schema-72>
            room:
              type: string
              x-parser-schema-id: <anonymous-schema-73>
            data:
              type: object
              required:
                - wallet
                - token
                - amount
              properties:
                wallet:
                  type: string
                  description: Wallet public key that received the balance update
                  x-parser-schema-id: <anonymous-schema-59>
                token:
                  type: string
                  description: >-
                    Token mint address. Native SOL uses the wrapped SOL mint
                    `So11111111111111111111111111111111111111112` (same
                    identifier for SOL balance updates on these rooms).
                  x-parser-schema-id: <anonymous-schema-60>
                amount:
                  type: number
                  description: >-
                    UI token amount after the update (decimal human units, not
                    raw integer base units / lamports). Example: `78816.844996`
                    for a fractional SPL balance. Use this value for display and
                    reconciliation against UI balances; convert with mint
                    decimals if you need raw integer amounts.
                  x-parser-schema-id: <anonymous-schema-61>
              examples: *ref_0
              x-parser-schema-id: BalanceUpdate
          examples:
            - type: message
              data:
                wallet: FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1
                token: Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
                amount: 76989.158861
              room: >-
                wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance
          x-parser-schema-id: <anonymous-schema-71>
        title: Token balance message
        description: Token balance change notification
        example: |-
          {
            "type": "message",
            "data": {
              "wallet": "FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1",
              "token": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
              "amount": 76989.158861
            },
            "room": "wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: tokenBalanceMessage
          - id: x-parser-message-name
            value: tokenBalanceMessage
    bindings: []
    extensions: *ref_1
  - &ref_3
    id: unsubscribeFromTokenBalance
    title: Unsubscribe from token balance
    description: Unsubscribe
    type: receive
    messages:
      - &ref_6
        id: leaveTokenBalance
        payload:
          - name: leaveTokenBalance
            description: Unsubscribe from token balance
            type: object
            properties:
              - name: type
                type: string
                description: leave
                required: true
              - name: room
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - type
            - room
          properties:
            type:
              type: string
              const: leave
              default: leave
              x-parser-schema-id: <anonymous-schema-75>
            room:
              type: string
              default: >-
                wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance
              x-parser-schema-id: <anonymous-schema-76>
          examples:
            - type: leave
              room: >-
                wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance
          x-parser-schema-id: <anonymous-schema-74>
        title: Leave token balance
        description: Unsubscribe from token balance
        example: |-
          {
            "type": "leave",
            "room": "wallet:FV1r15rbNKkJanXLheoJA7fXEq6NDuMJ3bukXuhJWyV1:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB:balance"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: leaveTokenBalance
          - id: x-parser-message-name
            value: leaveTokenBalance
    bindings: []
    extensions: *ref_1
sendOperations:
  - *ref_2
  - *ref_3
receiveOperations:
  - *ref_4
sendMessages:
  - *ref_5
  - *ref_6
receiveMessages:
  - *ref_7
extensions:
  - id: x-codeSamples
    value: *ref_8
  - id: x-parser-unique-object-id
    value: walletTokenBalance
securitySchemes:
  - id: apiKeyAuth
    name: apiKey
    type: httpApiKey
    description: >-
      API key for authentication. Include your Datastream key in the connection
      URL: wss://datastream.solanatracker.io/{DATASTREAM_KEY}
    in: header
    extensions: []

````

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