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 = {
|
module.exports = {
|
||||||
|
fetchExchange,
|
||||||
buy,
|
buy,
|
||||||
sell,
|
sell,
|
||||||
active,
|
active,
|
||||||
|
|
|
||||||
|
|
@ -475,25 +475,28 @@ function plugins (settings, deviceId) {
|
||||||
|
|
||||||
function buyAndSell (rec, doBuy, tx) {
|
function buyAndSell (rec, doBuy, tx) {
|
||||||
const cryptoCode = rec.cryptoCode
|
const cryptoCode = rec.cryptoCode
|
||||||
const fiatCode = rec.fiatCode
|
return exchange.fetchExchange(settings, cryptoCode)
|
||||||
const cryptoAtoms = doBuy ? commissionMath.fiatToCrypto(tx, rec, deviceId, settings.config) : rec.cryptoAtoms.negated()
|
.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('')
|
const market = [fiatCode, cryptoCode].join('')
|
||||||
|
|
||||||
if (!exchange.active(settings, cryptoCode)) return
|
if (!exchange.active(settings, cryptoCode)) return
|
||||||
|
|
||||||
const direction = doBuy ? 'cashIn' : 'cashOut'
|
const direction = doBuy ? 'cashIn' : 'cashOut'
|
||||||
const internalTxId = tx ? tx.id : rec.id
|
const internalTxId = tx ? tx.id : rec.id
|
||||||
logger.debug('[%s] Pushing trade: %d', market, cryptoAtoms)
|
logger.debug('[%s] Pushing trade: %d', market, cryptoAtoms)
|
||||||
if (!tradesQueues[market]) tradesQueues[market] = []
|
if (!tradesQueues[market]) tradesQueues[market] = []
|
||||||
tradesQueues[market].push({
|
tradesQueues[market].push({
|
||||||
direction,
|
direction,
|
||||||
internalTxId,
|
internalTxId,
|
||||||
fiatCode,
|
fiatCode,
|
||||||
cryptoAtoms,
|
cryptoAtoms,
|
||||||
cryptoCode,
|
cryptoCode,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function consolidateTrades (cryptoCode, fiatCode) {
|
function consolidateTrades (cryptoCode, fiatCode) {
|
||||||
|
|
@ -550,19 +553,22 @@ function plugins (settings, deviceId) {
|
||||||
const deviceIds = devices.map(device => device.deviceId)
|
const deviceIds = devices.map(device => device.deviceId)
|
||||||
const lists = deviceIds.map(deviceId => {
|
const lists = deviceIds.map(deviceId => {
|
||||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||||
const fiatCode = localeConfig.fiatCurrency
|
|
||||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||||
|
|
||||||
return cryptoCodes.map(cryptoCode => ({
|
return Promise.all(cryptoCodes.map(cryptoCode => {
|
||||||
fiatCode,
|
return exchange.fetchExchange(settings, cryptoCode)
|
||||||
cryptoCode
|
.then(exchange => ({
|
||||||
|
fiatCode: exchange.account.currencyMarket,
|
||||||
|
cryptoCode
|
||||||
|
}))
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
const tradesPromises = _.uniq(_.flatten(lists))
|
return Promise.all(lists)
|
||||||
.map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode))
|
})
|
||||||
|
.then(lists => {
|
||||||
return Promise.all(tradesPromises)
|
return Promise.all(_.uniq(_.flatten(lists))
|
||||||
|
.map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode)))
|
||||||
})
|
})
|
||||||
.catch(logger.error)
|
.catch(logger.error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue