Merge pull request #1064 from siiky/fix/lam-266/profits-calculation
Profits calculation
This commit is contained in:
commit
43afaae89f
4 changed files with 47 additions and 20 deletions
|
|
@ -11,7 +11,7 @@ const logDateFormat = require('../../../logs').logDateFormat
|
|||
|
||||
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
|
||||
const txLogFields = ['txClass', 'id', 'deviceId', 'toAddress', 'cryptoAtoms',
|
||||
'cryptoCode', 'fiat', 'fiatCode', 'fee', 'status',
|
||||
'cryptoCode', 'fiat', 'fiatCode', 'fee', 'status', 'fiatProfit',
|
||||
'dispense', 'notified', 'redeem', 'phone', 'error',
|
||||
'created', 'confirmedAt', 'hdIndex', 'swept', 'timedout',
|
||||
'dispenseConfirmed', 'provisioned1', 'provisioned2',
|
||||
|
|
|
|||
|
|
@ -126,21 +126,28 @@ function simplifiedBatch (data) {
|
|||
...it,
|
||||
status: getStatus(it),
|
||||
fiatProfit: getProfit(it).toString(),
|
||||
cryptoAmount: getCryptoAmount(it)
|
||||
cryptoAmount: getCryptoAmount(it).toString()
|
||||
}))
|
||||
|
||||
return _.compose(_.map(_.pick(fields)), addSimplifiedFields)(data)
|
||||
}
|
||||
|
||||
const getCryptoAmount = it => coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode).toString()
|
||||
const getCryptoAmount = it => coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode)
|
||||
|
||||
const getProfit = it => {
|
||||
const discountValue = _.isNil(it.discount) ? BN(100) : BN(100).minus(it.discount)
|
||||
const discountPercentage = BN(discountValue).div(100)
|
||||
const commissionPercentage = BN(it.commissionPercentage).times(discountPercentage)
|
||||
const getCommissionFee = it => BN(commissionPercentage).times(BN(it.fiat))
|
||||
if (!it.cashInFee) return getCommissionFee(it)
|
||||
return getCommissionFee(it).plus(BN(it.cashInFee))
|
||||
/* fiat - crypto*tickerPrice + fee */
|
||||
const calcCashInProfit = (fiat, crypto, tickerPrice, fee) => fiat.minus(crypto.times(tickerPrice)).plus(fee)
|
||||
/* crypto*tickerPrice - fiat */
|
||||
const calcCashOutProfit = (fiat, crypto, tickerPrice) => crypto.times(tickerPrice).minus(fiat)
|
||||
|
||||
const fiat = BN(it.fiat)
|
||||
const crypto = getCryptoAmount(it)
|
||||
const tickerPrice = BN(it.rawTickerPrice)
|
||||
const isCashIn = it.txClass === 'cashIn'
|
||||
|
||||
return isCashIn
|
||||
? calcCashInProfit(fiat, crypto, tickerPrice, BN(it.cashInFee))
|
||||
: calcCashOutProfit(fiat, crypto, tickerPrice)
|
||||
}
|
||||
|
||||
const getCashOutStatus = it => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue