fix: use selected fiat currency on exchange to store queued trades on the database
This commit is contained in:
parent
47c548c956
commit
0b719be8eb
2 changed files with 32 additions and 25 deletions
|
|
@ -66,6 +66,7 @@ function getMarkets () {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
fetchExchange,
|
||||
buy,
|
||||
sell,
|
||||
active,
|
||||
|
|
|
|||
|
|
@ -475,7 +475,9 @@ function plugins (settings, deviceId) {
|
|||
|
||||
function buyAndSell (rec, doBuy, tx) {
|
||||
const cryptoCode = rec.cryptoCode
|
||||
const fiatCode = rec.fiatCode
|
||||
return exchange.fetchExchange(settings, cryptoCode)
|
||||
.then(_exchange => {
|
||||
const fiatCode = _exchange.account.currencyMarket
|
||||
const cryptoAtoms = doBuy ? commissionMath.fiatToCrypto(tx, rec, deviceId, settings.config) : rec.cryptoAtoms.negated()
|
||||
|
||||
const market = [fiatCode, cryptoCode].join('')
|
||||
|
|
@ -494,6 +496,7 @@ function plugins (settings, deviceId) {
|
|||
cryptoCode,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function consolidateTrades (cryptoCode, fiatCode) {
|
||||
|
|
@ -550,19 +553,22 @@ function plugins (settings, deviceId) {
|
|||
const deviceIds = devices.map(device => device.deviceId)
|
||||
const lists = deviceIds.map(deviceId => {
|
||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||
const fiatCode = localeConfig.fiatCurrency
|
||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||
|
||||
return cryptoCodes.map(cryptoCode => ({
|
||||
fiatCode,
|
||||
return Promise.all(cryptoCodes.map(cryptoCode => {
|
||||
return exchange.fetchExchange(settings, cryptoCode)
|
||||
.then(exchange => ({
|
||||
fiatCode: exchange.account.currencyMarket,
|
||||
cryptoCode
|
||||
}))
|
||||
}))
|
||||
})
|
||||
|
||||
const tradesPromises = _.uniq(_.flatten(lists))
|
||||
.map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode))
|
||||
|
||||
return Promise.all(tradesPromises)
|
||||
return Promise.all(lists)
|
||||
})
|
||||
.then(lists => {
|
||||
return Promise.all(_.uniq(_.flatten(lists))
|
||||
.map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode)))
|
||||
})
|
||||
.catch(logger.error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue