The Cryptonomics™
  • Home
  • Blockchain
  • Bitcoin
  • Ethereum
  • NFTS
  • Altcoin
  • Mining
  • Consulting
Reading: python – How is crossWalletBalance calculated with Binance perpetual futures in cross-margin mode?
Share
Please enter CoinGecko Free Api Key to get this plugin works.
The Cryptonomics™The Cryptonomics™
Font ResizerAa
Search
  • Home
  • Blockchain
  • Bitcoin
  • Ethereum
  • NFTS
  • Altcoin
  • Mining
  • Consulting
Follow US
  • About Us
  • Advertising Solutions
  • Privacy
  • Terms
  • Advertise
Copyright © MetaMedia™ Capital Inc, All right reserved
The Cryptonomics™ > Bitcoin > python – How is crossWalletBalance calculated with Binance perpetual futures in cross-margin mode?
Bitcoin

python – How is crossWalletBalance calculated with Binance perpetual futures in cross-margin mode?

admin
Last updated: January 21, 2025 12:02 am
admin Published January 21, 2025
Share
python – How is crossWalletBalance calculated with Binance perpetual futures in cross-margin mode?


I am attempting to breed and determine how crossWalletBalance worth, retrieved from Binance API, is calculated by Binance in USDⓈ-M perpetual futures. Significantly, I would want it for simulating the calculation of liquidation costs in cross-margin mode in response to the system famous right here. Nevertheless, I am persistently failing to breed the worth from Binance API.

So far as I perceive, in cross-margin mode crossWalletBalance corresponds to the whole steadiness, comprised of pockets steadiness and margin steadiness, which incorporates unrealized PnLs, as described right here.

So as to confirm my calculations, I take advantage of Binance Testnet, the place I place market orders utilizing Python’s CCXT bindings. Let’s suppose I open a number of brief positions. By fetching all positions with non-zero variety of contracts, I retrieve deserialized JSON with related information on all open positions grouped by symbols:

positions = alternate.fetch_account_positions()
[pos for pos in positions if float(pos['contracts']) != 0]

Present free USDT steadiness is fetched utilizing one other HTTP-request wrapped into CCXT’s alternate.fetch_free_balance().

Fields of weird curiosity among the many JSON are:

  • initMargin – place preliminary margin; I take advantage of it for calculating margin steadiness;
  • unrealizedProfit – UPnL; I additionally use it for calculating margin steadiness;
  • crossWalletBalance – floor fact worth for reference and checking whether or not my calculations are right;
  • crossMargin – for reference, to double-check that crossWalletBalance minus all unrealizedProfits equals to it.

I assume that the price taken is 0.0004, and have double-checked this reality utilizing the historical past of my trades on Binance Testnet web page.

I’ve tried a number of formulae modifications based mostly on beforehand talked about manuals. Significantly, I take advantage of pockets steadiness system from right here:

Pockets Stability = Whole Internet Switch + Whole Realized Revenue + Whole Internet Funding Charge - Whole Fee

…assuming that:

  • Whole Internet Switch equals to free USDT steadiness;
  • Whole Realized Revenue is zero, as quickly as positions are nonetheless open;
  • Whole Internet Funding Charge is zero, since positions are assumed to be closed nearly instantly, subsequently, funding charges don’t relate;
  • Whole Fee is 0.0004. It’s taken as soon as, since positions are nonetheless open;

Significantly, amongst others, I’ve tried the next formulae:

  • crossWalletBalance == free USDT steadiness * Whole Fee + initMargins for all positions + unrealizedProfit for all positions, signal included;
  • crossWalletBalance == free USDT steadiness + (initMargins for all positions + unrealizedProfit) * Whole Fee for all positions, signal included.
  • Totally different variations that disregard charges or embody margin charges.

Nevertheless, contemplating that collaterals are about 13000 digital “USDT”s, and the trades are throughout the leveraged vary of a number of 1000’s of USDTs, I persistently obtain values that differ from the bottom fact crossWalletBalance worth from a number of to tens-hundreds of “USDT”s, relying on the system.

I’d be glad about any assist or hints on this respect.



Supply hyperlink

You Might Also Like

Crypto ETFs Maintain Rally With $462 Million for Bitcoin and $169 Million for Ether

Bitcoin Liquidity Evaluation Eyes $65,000 Help Retest to Come

Kraken 360 pre-TGE playbook Half 2: the 5-step execution window

Kraken Financial institution Secures Federal Reserve Grasp Account, Marking Historic Crypto Entry Into US Fee Rails

‘Liking Bitcoin’ Is Not Sufficient For US Authorities: David Bailey

Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Vitalik Buterin addresses controversy as Ethereum Basis sells one other 100 ETH Vitalik Buterin addresses controversy as Ethereum Basis sells one other 100 ETH
Next Article Coinbase Solana transactions delayed amid memecoin frenzy Coinbase Solana transactions delayed amid memecoin frenzy
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe to our newslettern

Get Newest Articles Instantly!

- Advertisement -
Ad imageAd image
Popular News
Altcoin Season ‘Recreation Is Over’: Matt Hougan
Altcoin Season ‘Recreation Is Over’: Matt Hougan
The journey to a mature asset administration system
The journey to a mature asset administration system
High 3 Meme Coin Gems Price Shopping for Earlier than Could 2024 – PEPE, WIF, and DOGEVERSE
High 3 Meme Coin Gems Price Shopping for Earlier than Could 2024 – PEPE, WIF, and DOGEVERSE

Follow Us on Socials

We use social media to react to breaking news, update supporters and share information

Facebook Instagram Linkedin Pinterest Tiktok Twitter Youtube
The Cryptonomics™

Cryptonomics Magazine is your premier digital source for blockchain insights, offering cutting-edge research, news, interviews, and ICO updates for everyone from entrepreneurs to institutions. We drive blockchain knowledge and growth.

Subscribe to our newsletter

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Altcoin Season ‘Recreation Is Over’: Matt Hougan
March 6, 2026
Dogecoin (DOGE) Retreats, Market Eyes Potential Prolonged Pullback
March 6, 2026
ETH Rally Towards $2.5K Held Again By Macro, Conflict, DApp Use
March 6, 2026
Weir to produce ENDURON® HPGR for Platreef Section 2 growth
March 6, 2026
Analyst Predicts 1,500% XRP Worth Improve To $15 If This Is A Wave 2
March 6, 2026
Copyright © The Cryptonomics™ , All right reserved
  • About Us
  • Advertising Solutions
  • Privacy
  • Terms
  • Advertise
Join Us!

Subscribe & Stay Ahead of the Curve with Cryptonomics !

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?