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 = {}
|
const tradesQueues = {}
|
||||||
|
|
||||||
function plugins (settings, deviceId) {
|
function plugins (settings, deviceId) {
|
||||||
function getCommissionPercentage (cryptoCode) {
|
function getRawTickerPrice (fiatCode, cryptoCode) {
|
||||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, settings.config)
|
return ticker.getRates(settings, fiatCode, cryptoCode)
|
||||||
|
.then(tickers => ({
|
||||||
return {
|
cashIn: _.get(['rates', 'ask'], tickers),
|
||||||
cashIn: BN(cryptoConfig.cashInCommission).div(100),
|
cashOut: _.get(['rates', 'bid'], tickers)
|
||||||
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 buildRates (tickers) {
|
function buildRates (tickers) {
|
||||||
|
|
@ -208,6 +198,8 @@ function plugins (settings, deviceId) {
|
||||||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||||
const minimumTx = BN(config.minimumTx)
|
const minimumTx = BN(config.minimumTx)
|
||||||
const cashInFee = BN(config.cashInFee)
|
const cashInFee = BN(config.cashInFee)
|
||||||
|
const cashInCommission = BN(config.cashInCommission)
|
||||||
|
const cashOutCommission = BN(config.cashOutCommission)
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -215,6 +207,8 @@ function plugins (settings, deviceId) {
|
||||||
display: cryptoRec.display,
|
display: cryptoRec.display,
|
||||||
minimumTx: BN.max(minimumTx, cashInFee),
|
minimumTx: BN.max(minimumTx, cashInFee),
|
||||||
cashInFee,
|
cashInFee,
|
||||||
|
cashInCommission,
|
||||||
|
cashOutCommission,
|
||||||
cryptoNetwork
|
cryptoNetwork
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -802,7 +796,6 @@ function plugins (settings, deviceId) {
|
||||||
sell,
|
sell,
|
||||||
notificationsEnabled,
|
notificationsEnabled,
|
||||||
notifyOperator,
|
notifyOperator,
|
||||||
getCommissionPercentage,
|
|
||||||
getRawTickerPrice
|
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 CashInTx = require('./cash-in/cash-in-tx')
|
||||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||||
|
|
||||||
async function process (tx, pi) {
|
function process (tx, pi) {
|
||||||
const mtx = await massage(tx, pi)
|
return massage(tx, pi).then(mtx => {
|
||||||
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
if (mtx.direction === 'cashIn') return CashInTx.post(mtx, pi)
|
||||||
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
if (mtx.direction === 'cashOut') return CashOutTx.post(mtx, pi)
|
||||||
|
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
||||||
return Promise.reject(new Error('No such tx direction: ' + mtx.direction))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function post (tx, pi) {
|
function post (tx, pi) {
|
||||||
|
|
@ -16,7 +16,7 @@ function post (tx, pi) {
|
||||||
.then(_.set('dirty', false))
|
.then(_.set('dirty', false))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function massage (tx, pi) {
|
function massage (tx, pi) {
|
||||||
const direction = _.get('direction', tx)
|
const direction = _.get('direction', tx)
|
||||||
const cryptoCode = _.get('cryptoCode', tx)
|
const cryptoCode = _.get('cryptoCode', tx)
|
||||||
const fiatCode = _.get('fiatCode', 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 transformDate = (v, k) => isDateField(k) ? new Date(v) : v
|
||||||
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
const mapValuesWithKey = _.mapValues.convert({'cap': false})
|
||||||
const transformDates = r => mapValuesWithKey(transformDate, r)
|
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 mapBN = r => {
|
||||||
const update = r.direction === 'cashIn'
|
const update = r.direction === 'cashIn'
|
||||||
|
|
@ -41,11 +32,13 @@ async function massage (tx, pi) {
|
||||||
fiat: BN(r.fiat),
|
fiat: BN(r.fiat),
|
||||||
cashInFee: BN(r.cashInFee),
|
cashInFee: BN(r.cashInFee),
|
||||||
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
||||||
|
commissionPercentage: BN(r.commissionPercentage),
|
||||||
minimumTx: BN(r.minimumTx)
|
minimumTx: BN(r.minimumTx)
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
cryptoAtoms: BN(r.cryptoAtoms),
|
cryptoAtoms: BN(r.cryptoAtoms),
|
||||||
fiat: BN(r.fiat)
|
fiat: BN(r.fiat),
|
||||||
|
commissionPercentage: BN(r.commissionPercentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.assign(r, update)
|
return _.assign(r, update)
|
||||||
|
|
@ -54,9 +47,16 @@ async function massage (tx, pi) {
|
||||||
const mapper = _.flow(
|
const mapper = _.flow(
|
||||||
transformDates,
|
transformDates,
|
||||||
mapBN,
|
mapBN,
|
||||||
logCommission,
|
_.unset('dirty'),
|
||||||
logRawTickerPrice,
|
withTickerPrice)
|
||||||
_.unset('dirty'))
|
|
||||||
|
function withTickerPrice (r) {
|
||||||
|
return pi.getRawTickerPrice(fiatCode, cryptoCode).then(tickerPrice => {
|
||||||
|
return _.assign(r, {
|
||||||
|
rawTickerPrice: _.get(direction, tickerPrice)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return mapper(tx)
|
return mapper(tx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue