Skip to content

Commit

Permalink
feat(bybit): v5 add funding balance
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Mar 2, 2023
1 parent a32f098 commit e649f77
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions js/bybit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2820,11 +2820,31 @@ module.exports = class bybit extends Exchange {
// "time": 1672125441042
// }
//
// funding v5
// {
// retCode: '0',
// retMsg: 'success',
// result: {
// memberId: '452265',
// accountType: 'FUND',
// balance: [
// {
// coin: 'BTC',
// transferBalance: '0.2',
// walletBalance: '0.2',
// bonus: ''
// }
// ]
// },
// retExtInfo: {},
// time: '1677781902858'
// }
//
const result = {
'info': response,
};
const responseResult = this.safeValue (response, 'result', {});
const currencyList = this.safeValueN (responseResult, [ 'loanAccountList', 'list', 'coin', 'balances' ]);
const currencyList = this.safeValueN (responseResult, [ 'loanAccountList', 'list', 'coin', 'balances', 'balance' ]);
if (currencyList === undefined) {
// usdc wallet
const code = 'USDC';
Expand Down Expand Up @@ -2988,9 +3008,13 @@ module.exports = class bybit extends Exchange {

async fetchDerivativesBalance (params = {}) {
await this.loadMarkets ();
let type = undefined;
[ type, params ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
type = (type === undefined) ? undefined : type.toLowerCase ();
if (type !== 'unified' && type !== 'funding') {
type = 'unified'; // all other values are invalid
}
const accountTypes = this.safeValue (this.options, 'accountsByType', {});
const type = this.safeString (params, 'type');
params = this.omit (params, [ 'type' ]);
const request = {
'accountType': this.safeString (accountTypes, type),
};
Expand Down Expand Up @@ -3072,19 +3096,18 @@ module.exports = class bybit extends Exchange {
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/en/latest/manual.html?#balance-structure}
*/
await this.loadMarkets ();
let type = undefined;
[ type, params ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
const [ type, query ] = this.handleMarketTypeAndParams ('fetchBalance', undefined, params);
if (type === 'spot') {
return await this.fetchSpotBalance (params);
return await this.fetchSpotBalance (query);
}
const [ enableUnifiedMargin, enableUnifiedAccount ] = await this.isUnifiedEnabled ();
if (enableUnifiedAccount) {
return await this.fetchDerivativesBalance (this.extend (params, { 'type': 'unified' }));
return await this.fetchDerivativesBalance (params);
} else if (enableUnifiedMargin) {
return await this.fetchUnifiedMarginBalance (params);
return await this.fetchUnifiedMarginBalance (query);
} else {
// linear/inverse future/swap
return await this.fetchDerivativesBalance (this.extend (params, { 'type': 'swap' }));
return await this.fetchDerivativesBalance (this.extend (query, { 'type': 'swap' }));
}
}

Expand Down

0 comments on commit e649f77

Please sign in to comment.