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
  • Under the new logic of UTA manual borrow, spotBorrow field corresponding to spot liabilities is detailed in the announcement.
    Old walletBalance = New walletBalance - spotBorrow

Topic: wallet

Response Parameters

ParameterTypeComments
idstringMessage ID
topicstringTopic name
creationTimenumberData created timestamp (ms)
dataarrayObject
> accountTypestringAccount type UNIFIED
> accountIMRatestringAccount IM rate
  • You can refer to this Glossary to understand the below fields calculation and mearning
  • All account wide fields are not applicable to isolated margin
  • > accountMMRatestringAccount MM rate
    > totalEquitystringAccount total equity (USD): ∑Asset Equity By USD value of each asset
    > 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 - Haircut - totalInitialMargin.
    • Porfolio Margin: total Equity - Haircut - 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
    > accountIMRateByMpstringYou can ignore this field, and refer to accountIMRate, which has the same calculation
    > accountMMRateByMpstringYou can ignore this field, and refer to accountMMRate, which has the same calculation
    > totalInitialMarginByMpstringYou can ignore this field, and refer to totalInitialMargin, which has the same calculation
    > totalMaintenanceMarginByMpstringYou can ignore this field, and refer to totalMaintenanceMargin, which has the same calculation
    > accountLTVstringDeprecated field
    > coinarrayObject
    >> coinstringCoin name, such as BTC, ETH, USDT, USDC
    >> equitystringEquity of coin. Asset Equity = Asset Wallet Balance + Asset Perp UPL + Asset Future UPL + Asset Option Value = walletBalance - spotBorrow + unrealisedPnl + Asset Option Value
    >> usdValuestringUSD value of coin. If this coin cannot be collateral, then it is 0
    >> walletBalancestringWallet balance of coin
    >> 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
    >> borrowAmountstringBorrow amount of coin = spot liabilities + derivatives liabilities
    >> 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
    >> collateralSwitchbooleanWhether it can be used as a margin collateral currency (platform)
    • When marginCollateral=false, then collateralSwitch is meaningless
    >> marginCollateralbooleanWhether the collateral is turned on by user (user)
    • When marginCollateral=true, then collateralSwitch is meaningful
    >> spotBorrowstringBorrow amount by spot margin trade and manual borrow amount(does not include borrow amount by spot margin active order). spotBorrow field corresponding to spot liabilities is detailed in the announcement.
    >> freestringDeprecated since there is no Spot wallet any more
    >> availableToBorrowstringDeprecated field, always return "". Please refer to availableToBorrow in the Get Collateral Info
    >> availableToWithdrawstringDeprecated for accountType=UNIFIED from 9 Jan, 2025
    • Transferable balance: you can use Get Transferable Amount (Unified) or Get All Coins Balance instead
    • Derivatives available balance:
      isolated margin: walletBalance - totalPositionIM - totalOrderIM - locked - bonus
      cross & portfolio margin: look at field totalAvailableBalance(USD), which needs to be converted into the available balance of accordingly coin through index price
    • Spot (margin) available balance: refer to Get Borrow Quota (Spot)

    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="xxxxxxxxxxxxxxxxxx",
    api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    )
    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",
    "accountIMRateByMp": "0",
    "accountMMRate": "0",
    "accountMMRateByMp": "0",
    "totalEquity": "10262.91335023",
    "totalWalletBalance": "9684.46297164",
    "totalMarginBalance": "9684.46297164",
    "totalAvailableBalance": "9556.6056555",
    "totalPerpUPL": "0",
    "totalInitialMargin": "0",
    "totalInitialMarginByMp": "0",
    "totalMaintenanceMargin": "0",
    "totalMaintenanceMarginByMp": "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",
    "spotBorrow": "0"
    }
    ],
    "accountLTV": "0",
    "accountType": "UNIFIED"
    }
    ]
    }