Skip to content

Commit

Permalink
Merge pull request #2291 from andyjenkinson/feature/coinfloor-balances
Browse files Browse the repository at this point in the history
Coinfloor balance parsing (single HTTP request only)
  • Loading branch information
kroitor committed Jun 1, 2018
2 parents 9a0d02e + 0db6f1f commit 530fa87
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions js/coinfloor.js
Expand Up @@ -3,7 +3,7 @@
// ---------------------------------------------------------------------------

const Exchange = require ('./base/Exchange');
const { ExchangeError, NotSupported } = require ('./base/errors');
const { NotSupported } = require ('./base/errors');

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -66,18 +66,33 @@ module.exports = class coinfloor extends Exchange {
});
}

fetchBalance (params = {}) {
let symbol = undefined;
async fetchBalance (params = {}) {
let market = undefined;
if ('symbol' in params)
symbol = params['symbol'];
market = this.findMarket (params['symbol']);
if ('id' in params)
symbol = params['id'];
if (!symbol)
throw new ExchangeError (this.id + ' fetchBalance requires a symbol param');
// todo parse balance
return this.privatePostIdBalance ({
'id': this.marketId (symbol),
market = this.findMarket (params['id']);
if (!market)
throw new NotSupported (this.id + ' fetchBalance requires a symbol param');
let response = await this.privatePostIdBalance ({
'id': market['id'],
});
let result = {
'info': response,
};
// base/quote used for keys e.g. "xbt_reserved"
let keys = market['id'].toLowerCase ().split ('/');
result[market['base']] = {
'free': parseFloat (response[keys[0] + '_available']),
'used': parseFloat (response[keys[0] + '_reserved']),
'total': parseFloat (response[keys[0] + '_balance']),
};
result[market['quote']] = {
'free': parseFloat (response[keys[1] + '_available']),
'used': parseFloat (response[keys[1] + '_reserved']),
'total': parseFloat (response[keys[1] + '_balance']),
};
return this.parseBalance (result);
}

async fetchOrderBook (symbol, limit = undefined, params = {}) {
Expand Down

0 comments on commit 530fa87

Please sign in to comment.