Fixed bitstamp coin scaling (#167)

The coin scaling for the bistamp excahnge was using a satoshi scaling for ETH when it should have been using wei.
This commit is contained in:
Rafael Taranto 2018-09-19 12:56:22 -03:00 committed by Josh Harvey
parent 38aa006ecc
commit de4a675a43
4 changed files with 13 additions and 14 deletions

View file

@ -61,7 +61,7 @@ const CRYPTO_CURRENCIES = [
} }
] ]
module.exports = {buildUrl, cryptoDir, blockchainDir, configPath, cryptoCurrencies, getCryptoCurrency} module.exports = {buildUrl, cryptoDir, blockchainDir, configPath, cryptoCurrencies, getCryptoCurrency, toUnit}
function getCryptoCurrency (cryptoCode) { function getCryptoCurrency (cryptoCode) {
const cryptoCurrency = _.find(['cryptoCode', cryptoCode], CRYPTO_CURRENCIES) const cryptoCurrency = _.find(['cryptoCode', cryptoCode], CRYPTO_CURRENCIES)
@ -97,3 +97,10 @@ function cryptoDir (cryptoRec) {
function configPath (cryptoRec) { function configPath (cryptoRec) {
return path.resolve(cryptoDir(cryptoRec), cryptoRec.configFile) return path.resolve(cryptoDir(cryptoRec), cryptoRec.configFile)
} }
function toUnit (cryptoAtoms, cryptoCode) {
const cryptoRec = getCryptoCurrency(cryptoCode)
const unitScale = cryptoRec.unitScale
return cryptoAtoms.shift(-unitScale)
}

View file

@ -1,5 +1,3 @@
const coinUtils = require('../../coin-utils')
const PAIRS = { const PAIRS = {
BTC: { BTC: {
USD: 'XXBTZUSD', USD: 'XXBTZUSD',
@ -27,10 +25,4 @@ const PAIRS = {
} }
} }
module.exports = {PAIRS, toUnit} module.exports = {PAIRS}
function toUnit (cryptoAtoms, cryptoCode) {
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
const unitScale = cryptoRec.unitScale
return cryptoAtoms.shift(-unitScale)
}

View file

@ -1,6 +1,5 @@
const common = require('../../common/bitstamp') const common = require('../../common/bitstamp')
const coinUtils = require('../../../coin-utils')
const SATOSHI_SHIFT = 8
function buy (account, cryptoAtoms, fiatCode, cryptoCode) { function buy (account, cryptoAtoms, fiatCode, cryptoCode) {
return trade('buy', account, cryptoAtoms, fiatCode, cryptoCode) return trade('buy', account, cryptoAtoms, fiatCode, cryptoCode)
@ -27,7 +26,7 @@ function trade (type, account, cryptoAtoms, _fiatCode, cryptoCode) {
try { try {
const market = common.buildMarket(fiatCode, cryptoCode) const market = common.buildMarket(fiatCode, cryptoCode)
const options = {amount: cryptoAtoms.shift(-SATOSHI_SHIFT).toFixed(8)} const options = {amount: coinUtils.toUnit(cryptoAtoms, cryptoCode).toFixed(8)}
return common.authRequest(account, '/' + type + '/market/' + market, options) return common.authRequest(account, '/' + type + '/market/' + market, options)
.catch(e => { .catch(e => {

View file

@ -3,6 +3,7 @@ const Kraken = require('kraken-api')
const _ = require('lodash/fp') const _ = require('lodash/fp')
const common = require('../../common/kraken') const common = require('../../common/kraken')
const coinUtils = require('../../../coin-utils')
var PAIRS = common.PAIRS var PAIRS = common.PAIRS
@ -18,7 +19,7 @@ function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
function trade (account, type, cryptoAtoms, fiatCode, cryptoCode) { function trade (account, type, cryptoAtoms, fiatCode, cryptoCode) {
const kraken = new Kraken(account.apiKey, account.privateKey, {timeout: 30000}) const kraken = new Kraken(account.apiKey, account.privateKey, {timeout: 30000})
const amount = common.toUnit(cryptoAtoms, cryptoCode) const amount = coinUtils.toUnit(cryptoAtoms, cryptoCode)
const amountStr = amount.toFixed(6) const amountStr = amount.toFixed(6)
const pair = _.includes(fiatCode, ['USD', 'EUR']) const pair = _.includes(fiatCode, ['USD', 'EUR'])