fix bitstamp exchange

This commit is contained in:
Josh Harvey 2017-07-10 13:21:02 +03:00
parent 97bab49e15
commit 3652871ea4
3 changed files with 13 additions and 14 deletions

View file

@ -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},

View file

@ -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) {

View file

@ -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
}