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

Method parseBalanceCustom

js/src/binance.js:3722–3841  ·  view source on GitHub ↗
(response, type = undefined, marginMode = undefined, isPortfolioMargin = false)

Source from the content-addressed store, hash-verified

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

Callers 3

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