Fix ratchet errors on commission and ticker
This commit is contained in:
parent
fe72b4fcaf
commit
3dd7503e45
5 changed files with 22 additions and 41 deletions
|
|
@ -29,7 +29,7 @@ function toObj (row) {
|
||||||
|
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
const objKey = _.camelCase(key)
|
const objKey = _.camelCase(key)
|
||||||
if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto'])) {
|
if (_.includes(key, ['crypto_atoms', 'fiat', 'cash_in_fee', 'cash_in_fee_crypto', 'commission_percentage', 'raw_ticker_price'])) {
|
||||||
newObj[objKey] = BN(row[key])
|
newObj[objKey] = BN(row[key])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ function toObj (row) {
|
||||||
|
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
const objKey = _.camelCase(key)
|
const objKey = _.camelCase(key)
|
||||||
if (key === 'crypto_atoms' || key === 'fiat') {
|
if (_.includes(key, ['crypto_atoms', 'fiat', 'commission_percentage', 'raw_ticker_price'])) {
|
||||||
newObj[objKey] = BN(row[key])
|
newObj[objKey] = BN(row[key])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,6 @@ const PONG_TTL = '1 week'
|
||||||
const tradesQueues = {}
|
const tradesQueues = {}
|
||||||
|
|
||||||
function plugins (settings, deviceId) {
|
function plugins (settings, deviceId) {
|
||||||
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) {
|
function buildRates (tickers) {
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
|
|
@ -198,8 +190,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 || 0)
|
const cashInCommission = BN(config.cashInCommission)
|
||||||
const cashOutCommission = BN(config.cashOutCommission || 0)
|
const cashOutCommission = config.cashOutCommission ? BN(config.cashOutCommission) : null
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -239,12 +231,13 @@ function plugins (settings, deviceId) {
|
||||||
const balances = arr.slice(cryptoCodesCount + 3, 2 * cryptoCodesCount + 3)
|
const balances = arr.slice(cryptoCodesCount + 3, 2 * cryptoCodesCount + 3)
|
||||||
const testNets = arr.slice(2 * cryptoCodesCount + 3)
|
const testNets = arr.slice(2 * cryptoCodesCount + 3)
|
||||||
const coinParams = _.zip(cryptoCodes, testNets)
|
const coinParams = _.zip(cryptoCodes, testNets)
|
||||||
|
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cassettes,
|
cassettes,
|
||||||
rates: buildRates(tickers),
|
rates: buildRates(tickers),
|
||||||
balances: buildBalances(balances),
|
balances: buildBalances(balances),
|
||||||
coins: _.map(mapCoinSettings, coinParams),
|
coins: _.zipWith(_.assign, coinsWithoutRate, tickers),
|
||||||
configVersion
|
configVersion
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -795,8 +788,7 @@ function plugins (settings, deviceId) {
|
||||||
buy,
|
buy,
|
||||||
sell,
|
sell,
|
||||||
notificationsEnabled,
|
notificationsEnabled,
|
||||||
notifyOperator,
|
notifyOperator
|
||||||
getRawTickerPrice
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
25
lib/tx.js
25
lib/tx.js
|
|
@ -4,11 +4,10 @@ const CashInTx = require('./cash-in/cash-in-tx')
|
||||||
const CashOutTx = require('./cash-out/cash-out-tx')
|
const CashOutTx = require('./cash-out/cash-out-tx')
|
||||||
|
|
||||||
function process (tx, pi) {
|
function process (tx, pi) {
|
||||||
return massage(tx, pi).then(mtx => {
|
const mtx = massage(tx, pi)
|
||||||
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) {
|
||||||
|
|
@ -17,9 +16,6 @@ function post (tx, pi) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function massage (tx, pi) {
|
function massage (tx, pi) {
|
||||||
const direction = _.get('direction', tx)
|
|
||||||
const cryptoCode = _.get('cryptoCode', tx)
|
|
||||||
const fiatCode = _.get('fiatCode', tx)
|
|
||||||
const isDateField = r => r === 'created' || _.endsWith('_time', r)
|
const isDateField = r => r === 'created' || _.endsWith('_time', r)
|
||||||
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})
|
||||||
|
|
@ -33,11 +29,13 @@ function massage (tx, pi) {
|
||||||
cashInFee: BN(r.cashInFee),
|
cashInFee: BN(r.cashInFee),
|
||||||
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
||||||
commissionPercentage: BN(r.commissionPercentage),
|
commissionPercentage: BN(r.commissionPercentage),
|
||||||
|
rawTickerPrice: BN(r.rawTickerPrice),
|
||||||
minimumTx: BN(r.minimumTx)
|
minimumTx: BN(r.minimumTx)
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
cryptoAtoms: BN(r.cryptoAtoms),
|
cryptoAtoms: BN(r.cryptoAtoms),
|
||||||
fiat: BN(r.fiat),
|
fiat: BN(r.fiat),
|
||||||
|
rawTickerPrice: BN(r.rawTickerPrice),
|
||||||
commissionPercentage: BN(r.commissionPercentage)
|
commissionPercentage: BN(r.commissionPercentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,16 +45,7 @@ function massage (tx, pi) {
|
||||||
const mapper = _.flow(
|
const mapper = _.flow(
|
||||||
transformDates,
|
transformDates,
|
||||||
mapBN,
|
mapBN,
|
||||||
_.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)
|
return mapper(tx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
package-lock.json
generated
16
package-lock.json
generated
|
|
@ -2888,7 +2888,7 @@
|
||||||
},
|
},
|
||||||
"debug-log": {
|
"debug-log": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "http://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz",
|
||||||
"integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=",
|
"integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
|
@ -3457,7 +3457,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": {
|
"chalk": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.3",
|
||||||
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||||
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
|
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -3470,7 +3470,7 @@
|
||||||
},
|
},
|
||||||
"strip-ansi": {
|
"strip-ansi": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -3670,7 +3670,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"doctrine": {
|
"doctrine": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "http://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
||||||
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
|
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -3689,7 +3689,7 @@
|
||||||
},
|
},
|
||||||
"load-json-file": {
|
"load-json-file": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz",
|
||||||
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
"integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -3710,7 +3710,7 @@
|
||||||
},
|
},
|
||||||
"pify": {
|
"pify": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
|
@ -9002,7 +9002,7 @@
|
||||||
},
|
},
|
||||||
"require-uncached": {
|
"require-uncached": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "http://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
||||||
"integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
|
"integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -10422,7 +10422,7 @@
|
||||||
},
|
},
|
||||||
"table": {
|
"table": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.3",
|
||||||
"resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/table/-/table-4.0.3.tgz",
|
||||||
"integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==",
|
"integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue