fix: build markets requests and caching
This commit is contained in:
parent
0e7ca4e563
commit
21925ae145
4 changed files with 33 additions and 16 deletions
|
|
@ -50,19 +50,26 @@ function active (settings, cryptoCode) {
|
|||
}
|
||||
|
||||
function getMarkets () {
|
||||
const filterExchanges = _.filter(it => it.class === 'exchange')
|
||||
const filterExchanges = _.filter(it => it.class === 'exchange' && !it.dev && it.code !== 'no-exchange')
|
||||
const availableExchanges = _.map(it => it.code, filterExchanges(accounts.ACCOUNT_LIST))
|
||||
|
||||
return _.reduce(
|
||||
(acc, value) =>
|
||||
Promise.all([acc, ccxt.getMarkets(value, ALL_CRYPTOS)])
|
||||
.then(([a, markets]) => Promise.resolve({
|
||||
...a,
|
||||
[value]: markets
|
||||
})),
|
||||
Promise.resolve({}),
|
||||
availableExchanges
|
||||
)
|
||||
const fetchMarketForExchange = exchange =>
|
||||
ccxt.getMarkets(exchange, ALL_CRYPTOS)
|
||||
.then(markets => ({ exchange, markets }))
|
||||
.catch(error => ({
|
||||
exchange,
|
||||
markets: [],
|
||||
error: error.message
|
||||
}))
|
||||
|
||||
const transformToObject = _.reduce((acc, { exchange, markets }) => ({
|
||||
...acc,
|
||||
[exchange]: markets
|
||||
}), {})
|
||||
|
||||
const promises = _.map(fetchMarketForExchange, availableExchanges)
|
||||
return Promise.all(promises)
|
||||
.then(transformToObject)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue