Use commission rate from machine instead of server
This commit is contained in:
parent
578a39a721
commit
9f3457f14d
2 changed files with 30 additions and 37 deletions
|
|
@ -32,22 +32,12 @@ const PONG_TTL = '1 week'
|
|||
const tradesQueues = {}
|
||||
|
||||
function plugins (settings, deviceId) {
|
||||
function getCommissionPercentage (cryptoCode) {
|
||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
|
||||
return {
|
||||
cashIn: BN(cryptoConfig.cashInCommission).div(100),
|
||||
cashOut: BN(cryptoConfig.cashOutCommission).div(100)
|
||||
}
|
||||
}
|
||||
|
||||
async function getRawTickerPrice (fiatCode, cryptoCode) {
|
||||
const tickers = await ticker.getRates(settings, fiatCode, cryptoCode)
|
||||
|
||||
return {
|
||||
cashIn: _.get(['rates', 'ask'], tickers),
|
||||
cashOut: _.get(['rates', 'bid'], tickers)
|
||||
}
|
||||
function getRawTickerPrice (fiatCode, cryptoCode) {
|
||||
return ticker.getRates(settings, fiatCode, cryptoCode)
|
||||
.then(tickers => ({
|
||||
cashIn: _.get(['rates', 'ask'], tickers),
|
||||
cashOut: _.get(['rates', 'bid'], tickers)
|
||||
}))
|
||||
}
|
||||
|
||||
function buildRates (tickers) {
|
||||
|
|
@ -208,6 +198,8 @@ function plugins (settings, deviceId) {
|
|||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
const minimumTx = BN(config.minimumTx)
|
||||
const cashInFee = BN(config.cashInFee)
|
||||
const cashInCommission = BN(config.cashInCommission)
|
||||
const cashOutCommission = BN(config.cashOutCommission)
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
|
||||
return {
|
||||
|
|
@ -215,6 +207,8 @@ function plugins (settings, deviceId) {
|
|||
display: cryptoRec.display,
|
||||
minimumTx: BN.max(minimumTx, cashInFee),
|
||||
cashInFee,
|
||||
cashInCommission,
|
||||
cashOutCommission,
|
||||
cryptoNetwork
|
||||
}
|
||||
}
|
||||
|
|
@ -802,7 +796,6 @@ function plugins (settings, deviceId) {
|
|||
sell,
|
||||
notificationsEnabled,
|
||||
notifyOperator,
|
||||
getCommissionPercentage,
|
||||
getRawTickerPrice
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
lib/tx.js
40
lib/tx.js
|
|
@ -3,12 +3,12 @@ const BN = require('./bn')
|
|||
const CashInTx = require('./cash-in/cash-in-tx')
|
||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||
|
||||
async function process (tx, pi) {
|
||||
const mtx = await massage(tx, pi)
|
||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||
|
||||
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
||||
function process (tx, pi) {
|
||||
return massage(tx, pi).then(mtx => {
|
||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
||||
})
|
||||
}
|
||||
|
||||
function post (tx, pi) {
|
||||
|
|
@ -16,7 +16,7 @@ function post (tx, pi) {
|
|||
.then(_.set('dirty', false))
|
||||
}
|
||||
|
||||
async function massage (tx, pi) {
|
||||
function massage (tx, pi) {
|
||||
const direction = _.get('direction', tx)
|
||||
const cryptoCode = _.get('cryptoCode', tx)
|
||||
const fiatCode = _.get('fiatCode', tx)
|
||||
|
|
@ -24,15 +24,6 @@ async function massage (tx, pi) {
|
|||
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
|
||||
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
||||
const transformDates = r => mapValuesWithKey(transformDate, r)
|
||||
const logCommission = r => _.assign(r, {
|
||||
commissionPercentage: _.get(direction
|
||||
, pi.getCommissionPercentage(cryptoCode))
|
||||
})
|
||||
|
||||
const tickerPrice = await pi.getRawTickerPrice(fiatCode, cryptoCode)
|
||||
const logRawTickerPrice = r => _.assign(r, {
|
||||
rawTickerPrice: _.get(direction, tickerPrice)
|
||||
})
|
||||
|
||||
const mapBN = r => {
|
||||
const update = r.direction === 'cashIn'
|
||||
|
|
@ -41,11 +32,13 @@ async function massage (tx, pi) {
|
|||
fiat: BN(r.fiat),
|
||||
cashInFee: BN(r.cashInFee),
|
||||
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
||||
commissionPercentage: BN(r.commissionPercentage),
|
||||
minimumTx: BN(r.minimumTx)
|
||||
}
|
||||
: {
|
||||
cryptoAtoms: BN(r.cryptoAtoms),
|
||||
fiat: BN(r.fiat)
|
||||
fiat: BN(r.fiat),
|
||||
commissionPercentage: BN(r.commissionPercentage)
|
||||
}
|
||||
|
||||
return _.assign(r, update)
|
||||
|
|
@ -54,9 +47,16 @@ async function massage (tx, pi) {
|
|||
const mapper = _.flow(
|
||||
transformDates,
|
||||
mapBN,
|
||||
logCommission,
|
||||
logRawTickerPrice,
|
||||
_.unset('dirty'))
|
||||
_.unset('dirty'),
|
||||
withTickerPrice)
|
||||
|
||||
function withTickerPrice (r) {
|
||||
return pi.getRawTickerPrice(fiatCode, cryptoCode).then(tickerPrice => {
|
||||
return _.assign(r, {
|
||||
rawTickerPrice: _.get(direction, tickerPrice)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return mapper(tx)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue