Skip to main content

Wallet

Subscribe to the wallet stream to see changes to your wallet in real-time.

info
  • There is no snapshot event given at the time when the subscription is successful
  • The unrealised PnL change does not trigger an event

Topic: wallet

Response Parameters

ParameterTypeComments
idstringMessage ID
topicstringTopic name
creationTimenumberData created timestamp (ms)
dataarrayObject
> accountTypestringAccount type.
  • UTA2.0: UNIFIED
  • UTA1.0: UNIFIED (spot/linear/options), CONTRACT(inverse)
  • Classic: CONTRACT, SPOT
> accountLTVstringdeprecated field
> accountIMRatestringAccount IM rate
  • You can refer to this Glossary to understand the below fields calculation and mearning
  • All below account wide fields are not applicable to
    UTA2.0(isolated margin),
    UTA1.0(isolated margin), UTA1.0(CONTRACT),
    classic account(SPOT, CONTRACT)
  • > accountMMRatestringAccount MM rate
    > totalEquitystringAccount total equity (USD)
    > totalWalletBalancestringAccount wallet balance (USD): ∑Asset Wallet Balance By USD value of each asset
    > totalMarginBalancestringAccount margin balance (USD): totalWalletBalance + totalPerpUPL
    > totalAvailableBalancestringAccount available balance (USD), Cross Margin: totalMarginBalance - totalInitialMargin
    > totalPerpUPLstringAccount Perps and Futures unrealised p&l (USD): ∑Each Perp and USDC Futures upl by base coin
    > totalInitialMarginstringAccount initial margin (USD): ∑Asset Total Initial Margin Base Coin
    > totalMaintenanceMarginstringAccount maintenance margin (USD): ∑ Asset Total Maintenance Margin Base Coin
    > coinarrayObject
    >> coinstringCoin name, such as BTC, ETH, USDT, USDC
    >> equitystringEquity of coin
    >> usdValuestringUSD value of coin. If this coin cannot be collateral, then it is 0
    >> walletBalancestringWallet balance of coin
    >> freestringAvailable balance for Spot wallet. This is a unique field for Classic SPOT
    >> lockedstringLocked balance due to the Spot open order
    >> spotHedgingQtystringThe spot asset qty that is used to hedge in the portfolio margin, truncate to 8 decimals and "0" by default This is a unique field for Unified account
    >> borrowAmountstringBorrow amount of coin
    >> availableToBorrowstringdeprecated field, always return "" due to feature of main-sub UID sharing borrow quota. Please refer to availableToBorrow in the Get Collateral Info
    >> availableToWithdrawstringAvailable amount to withdraw of coin
    >> accruedIntereststringAccrued interest
    >> totalOrderIMstringPre-occupied margin for order. For portfolio margin mode, it returns ""
    >> totalPositionIMstringSum of initial margin of all positions + Pre-occupied liquidation fee. For portfolio margin mode, it returns ""
    >> totalPositionMMstringSum of maintenance margin for all positions. For portfolio margin mode, it returns ""
    >> unrealisedPnlstringUnrealised P&L
    >> cumRealisedPnlstringCumulative Realised P&L
    >> bonusstringBonus. This is a unique field for UNIFIED account
    >> collateralSwitchbooleanWhether it can be used as a margin collateral currency (platform)
    • When marginCollateral=false, then collateralSwitch is meaningless
    • This is a unique field for UNIFIED account
    >> marginCollateralbooleanWhether the collateral is turned on by user (user)
    • When marginCollateral=true, then collateralSwitch is meaningful
    • This is a unique field for UNIFIED account

    Subscribe Example

    {
    "op": "subscribe",
    "args": [
    "wallet"
    ]
    }
    from pybit.unified_trading import WebSocket
    from time import sleep
    ws = WebSocket(
    testnet=True,
    channel_type="private",
    api_key="XXXXX",
    api_secret="XXXXX",
    )
    def handle_message(message):
    print(message)
    ws.wallet_stream(callback=handle_message)
    while True:
    sleep(1)

    Stream Example

    {
    "id": "592324d2bce751-ad38-48eb-8f42-4671d1fb4d4e",
    "topic": "wallet",
    "creationTime": 1700034722104,
    "data": [
    {
    "accountIMRate": "0",
    "accountMMRate": "0",
    "totalEquity": "10262.91335023",
    "totalWalletBalance": "9684.46297164",
    "totalMarginBalance": "9684.46297164",
    "totalAvailableBalance": "9556.6056555",
    "totalPerpUPL": "0",
    "totalInitialMargin": "0",
    "totalMaintenanceMargin": "0",
    "coin": [
    {
    "coin": "BTC",
    "equity": "0.00102964",
    "usdValue": "36.70759517",
    "walletBalance": "0.00102964",
    "availableToWithdraw": "0.00102964",
    "availableToBorrow": "",
    "borrowAmount": "0",
    "accruedInterest": "0",
    "totalOrderIM": "",
    "totalPositionIM": "",
    "totalPositionMM": "",
    "unrealisedPnl": "0",
    "cumRealisedPnl": "-0.00000973",
    "bonus": "0",
    "collateralSwitch": true,
    "marginCollateral": true,
    "locked": "0",
    "spotHedgingQty": "0.01592413"
    }
    ],
    "accountLTV": "0",
    "accountType": "UNIFIED"
    }
    ]
    }