MCPcopy Create free account
hub / github.com/ccxt/ccxt / parseBalanceCustom

Method parseBalanceCustom

ts/src/binance.ts:3714–3825  ·  view source on GitHub ↗
(response, type = undefined, marginMode = undefined, isPortfolioMargin = false)

Source from the content-addressed store, hash-verified

3712 }
3713
3714 parseBalanceCustom (response, type = undefined, marginMode = undefined, isPortfolioMargin = false): Balances {
3715 const result = {
3716 'info': response,
3717 };
3718 let timestamp: Int = undefined;
3719 const isolated = marginMode === 'isolated';
3720 const cross = (type === 'margin') || (marginMode === 'cross');
3721 if (isPortfolioMargin) {
3722 for (let i = 0; i < response.length; i++) {
3723 const entry = response[i];
3724 const account = this.account ();
3725 const currencyId = this.safeString (entry, 'asset');
3726 const code = this.safeCurrencyCode (currencyId);
3727 if (type === 'linear') {
3728 account['free'] = this.safeString (entry, 'umWalletBalance');
3729 account['used'] = this.safeString (entry, 'umUnrealizedPNL');
3730 } else if (type === 'inverse') {
3731 account['free'] = this.safeString (entry, 'cmWalletBalance');
3732 account['used'] = this.safeString (entry, 'cmUnrealizedPNL');
3733 } else if (cross) {
3734 const borrowed = this.safeString (entry, 'crossMarginBorrowed');
3735 const interest = this.safeString (entry, 'crossMarginInterest');
3736 account['debt'] = Precise.stringAdd (borrowed, interest);
3737 account['free'] = this.safeString (entry, 'crossMarginFree');
3738 account['used'] = this.safeString (entry, 'crossMarginLocked');
3739 account['total'] = this.safeString (entry, 'crossMarginAsset');
3740 } else {
3741 const usedLinear = this.safeString (entry, 'umUnrealizedPNL');
3742 const usedInverse = this.safeString (entry, 'cmUnrealizedPNL');
3743 const totalUsed = Precise.stringAdd (usedLinear, usedInverse);
3744 const totalWalletBalance = this.safeString (entry, 'totalWalletBalance');
3745 account['total'] = Precise.stringAdd (totalUsed, totalWalletBalance);
3746 }
3747 result[code] = account;
3748 }
3749 } else if (!isolated && ((type === 'spot') || cross)) {
3750 timestamp = this.safeInteger (response, 'updateTime');
3751 const balances = this.safeList2 (response, 'balances', 'userAssets', []);
3752 for (let i = 0; i < balances.length; i++) {
3753 const balance = balances[i];
3754 const currencyId = this.safeString (balance, 'asset');
3755 const code = this.safeCurrencyCode (currencyId);
3756 const account = this.account ();
3757 account['free'] = this.safeString (balance, 'free');
3758 account['used'] = this.safeString (balance, 'locked');
3759 if (cross) {
3760 const debt = this.safeString (balance, 'borrowed');
3761 const interest = this.safeString (balance, 'interest');
3762 account['debt'] = Precise.stringAdd (debt, interest);
3763 }
3764 result[code] = account;
3765 }
3766 } else if (isolated) {
3767 const assets = this.safeList (response, 'assets', []);
3768 for (let i = 0; i < assets.length; i++) {
3769 const asset = assets[i];
3770 const marketId = this.safeString (asset, 'symbol');
3771 const symbol = this.safeSymbol (marketId, undefined, undefined, 'spot');

Callers 5

handle_balance_wsMethod · 0.95
fetchBalanceMethod · 0.95
handleBalanceWsMethod · 0.95
handleAccountStatusWsMethod · 0.95

Calls 14

parseBalanceHelperMethod · 0.95
accountMethod · 0.45
safeStringMethod · 0.45
safeCurrencyCodeMethod · 0.45
stringAddMethod · 0.45
safeIntegerMethod · 0.45
safeList2Method · 0.45
safeListMethod · 0.45
safeSymbolMethod · 0.45
safeDictMethod · 0.45
safeBalanceMethod · 0.45
isArrayMethod · 0.45

Tested by

no test coverage detected