fix: correctly calculate fiat profit
This commit is contained in:
parent
412f3ac2b5
commit
c07ee43b85
1 changed files with 15 additions and 8 deletions
|
|
@ -124,21 +124,28 @@ function simplifiedBatch (data) {
|
||||||
...it,
|
...it,
|
||||||
status: getStatus(it),
|
status: getStatus(it),
|
||||||
fiatProfit: getProfit(it).toString(),
|
fiatProfit: getProfit(it).toString(),
|
||||||
cryptoAmount: getCryptoAmount(it)
|
cryptoAmount: getCryptoAmount(it).toString()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return _.compose(_.map(_.pick(fields)), addSimplifiedFields)(data)
|
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 getProfit = it => {
|
||||||
const discountValue = _.isNil(it.discount) ? BN(100) : BN(100).minus(it.discount)
|
/* fiat - crypto*tickerPrice + fee */
|
||||||
const discountPercentage = BN(discountValue).div(100)
|
const calcCashInProfit = (fiat, crypto, tickerPrice, fee) => fiat.minus(crypto.times(tickerPrice)).plus(fee)
|
||||||
const commissionPercentage = BN(it.commissionPercentage).times(discountPercentage)
|
/* crypto*tickerPrice - fiat */
|
||||||
const getCommissionFee = it => BN(commissionPercentage).times(BN(it.fiat))
|
const calcCashOutProfit = (fiat, crypto, tickerPrice) => crypto.times(tickerPrice).minus(fiat)
|
||||||
if (!it.cashInFee) return getCommissionFee(it)
|
|
||||||
return getCommissionFee(it).plus(BN(it.cashInFee))
|
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 => {
|
const getCashOutStatus = it => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue