Skip to content

Commit

Permalink
Support the different bitfinex wallet types (Fixes #9)
Browse files Browse the repository at this point in the history
This sums up the balances of the different wallets available in Bitfinex.
  • Loading branch information
greimela committed May 8, 2019
1 parent 648ab02 commit 0530c2c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/modules/exchanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,26 @@ export function continuouslyFetchBalances(): ThunkAction {
};
}

async function fetchBalances(exchange: Exchange) {
const connector = new ccxt[exchange.type](exchange.credentials);
if (exchange.type === 'bitfinex') {
const totalBalances = {};
for (const type of ['exchange', 'trading', 'deposit']) {
const partialBalance = await connector.fetchTotalBalance({ type });
Object.keys(partialBalance).forEach(key => {
totalBalances[key] = (totalBalances[key] || 0) + partialBalance[key];
});
}
return totalBalances;
}
return connector.fetchTotalBalance();
}

function fetchBalancesForExchange(exchange: Exchange): ThunkAction {
return async (dispatch: Dispatch) => {
await dispatch(incrementExchangeRequestCounter(exchange.id));
try {
const connector = new ccxt[exchange.type](exchange.credentials);
const balances: Balances = _.pickBy(
await connector.fetchTotalBalance(),
balance => balance > 0
);
const balances: Balances = _.pickBy(await fetchBalances(exchange), balance => balance > 0);
await dispatch(
updateExchangeBalances(exchange.id, _.mapKeys(balances, (value, key) => unifySymbols(key)))
);
Expand Down

0 comments on commit 0530c2c

Please sign in to comment.