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

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