From 3652871ea4a46d9a8dbd9577240a1dce700c07bb Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Mon, 10 Jul 2017 13:21:02 +0300 Subject: [PATCH] fix bitstamp exchange --- lib/admin/config.js | 2 +- lib/plugins/common/bitstamp.js | 19 ++++++++++++------- lib/plugins/ticker/bitstamp/bitstamp.js | 6 ------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/admin/config.js b/lib/admin/config.js index 81f53f64..0ce77b09 100644 --- a/lib/admin/config.js +++ b/lib/admin/config.js @@ -176,7 +176,7 @@ function fetchData () { {code: 'litecoind', display: 'litecoind', class: 'wallet', cryptos: ['LTC']}, {code: 'dashd', display: 'dashd', class: 'wallet', cryptos: ['DASH']}, {code: 'bitgo', display: 'BitGo', class: 'wallet', cryptos: ['BTC']}, - {code: 'bitstamp', display: 'Bitstamp', class: 'exchange', cryptos: ['BTC']}, + {code: 'bitstamp', display: 'Bitstamp', class: 'exchange', cryptos: ['BTC', 'LTC']}, {code: 'kraken', display: 'Kraken', class: 'exchange', cryptos: ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC']}, {code: 'mock-wallet', display: 'Mock wallet', class: 'wallet', cryptos: ALL_CRYPTOS}, {code: 'no-exchange', display: 'No exchange', class: 'exchange', cryptos: ALL_CRYPTOS}, diff --git a/lib/plugins/common/bitstamp.js b/lib/plugins/common/bitstamp.js index d2f945c2..91a868b0 100644 --- a/lib/plugins/common/bitstamp.js +++ b/lib/plugins/common/bitstamp.js @@ -3,7 +3,7 @@ const querystring = require('querystring') const axios = require('axios') const crypto = require('crypto') -const _ = require('lodash') +const _ = require('lodash/fp') const API_ENDPOINT = 'https://www.bitstamp.net/api/v2' @@ -42,20 +42,25 @@ function authRequest (config, path, data) { .digest('hex') .toUpperCase() - _.merge(data, { + const signedData = _.merge(data, { key: config.key, signature: signature, nonce: nonce }) - return request(path, 'POST', data) + return request(path, 'POST', signedData) } function buildMarket (fiatCode, cryptoCode) { - if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode) - if (fiatCode === 'USD') return 'btcusd' - if (fiatCode === 'EUR') return 'btceur' - throw new Error('Unsupported fiat: ' + fiatCode) + if (!_.includes(cryptoCode, ['BTC', 'LTC'])) { + throw new Error('Unsupported crypto: ' + cryptoCode) + } + + if (!_.includes(fiatCode, ['USD', 'EUR'])) { + throw new Error('Unsupported fiat: ' + fiatCode) + } + + return `${cryptoCode.toLowerCase()}${fiatCode.toLowerCase()}` } function request (path, method, data) { diff --git a/lib/plugins/ticker/bitstamp/bitstamp.js b/lib/plugins/ticker/bitstamp/bitstamp.js index 5718bbc5..8f8d03a9 100644 --- a/lib/plugins/ticker/bitstamp/bitstamp.js +++ b/lib/plugins/ticker/bitstamp/bitstamp.js @@ -3,11 +3,6 @@ const common = require('../../common/bitstamp') function ticker (account, fiatCode, cryptoCode) { return Promise.resolve() - .then(() => { - if (cryptoCode !== 'BTC') { - throw new Error('Unsupported crypto: ' + cryptoCode) - } - }) .then(() => { const market = common.buildMarket(fiatCode, cryptoCode) return common.request('/ticker/' + market, 'GET') @@ -23,4 +18,3 @@ function ticker (account, fiatCode, cryptoCode) { module.exports = { ticker } -