Code readability and added the forgotten mocks
This commit is contained in:
parent
134eaaa518
commit
7accdaa84f
12 changed files with 126 additions and 96 deletions
|
|
@ -1,28 +1,32 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const CRYPTO = {
|
||||
bitstamp: ['BTC', 'ETH', 'LTC', 'BCH'],
|
||||
itbit: ['BTC', 'ETH', 'LTC', 'BCH'],
|
||||
kraken: ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC', 'BCH'],
|
||||
coinbase: ['BTC', 'ETH', 'LTC', 'BCH', 'ZEC', 'DASH']
|
||||
const kraken = require('../exchange/kraken')
|
||||
const bitstamp = require('../exchange/bitstamp')
|
||||
const itbit = require('../exchange/itbit')
|
||||
const bitpay = require('../ticker/bitpay')
|
||||
const { COINS } = require('../../new-admin/config/coins')
|
||||
const { BTC, BCH, DASH, ETH, LTC, ZEC } = COINS
|
||||
|
||||
const ALL = {
|
||||
kraken: kraken,
|
||||
bitstamp: bitstamp,
|
||||
itbit: itbit,
|
||||
bitpay: bitpay,
|
||||
coinbase: {
|
||||
CRYPTO: [BTC, ETH, LTC, DASH, ZEC, BCH],
|
||||
FIAT: 'ALL_CURRENCIES'
|
||||
}
|
||||
}
|
||||
|
||||
const FIAT = {
|
||||
bitstamp: ['USD', 'EUR'],
|
||||
itbit: ['USD'],
|
||||
kraken: ['USD', 'EUR']
|
||||
}
|
||||
|
||||
function verifyCurrencies (exchangeName, fiatCode, cryptoCode) {
|
||||
if (!_.includes(cryptoCode, CRYPTO[exchangeName])) {
|
||||
function buildMarket (fiatCode, cryptoCode, serviceName) {
|
||||
if (!_.includes(cryptoCode, ALL[serviceName].CRYPTO)) {
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
}
|
||||
if (exchangeName !== 'coinbase') {
|
||||
if (!_.includes(fiatCode, FIAT[exchangeName])) {
|
||||
throw new Error('Unsupported fiat: ' + fiatCode)
|
||||
}
|
||||
const fiatSupported = ALL[serviceName].FIAT
|
||||
if (fiatSupported !== 'ALL_CURRENCIES' && !_.includes(fiatCode, fiatSupported)) {
|
||||
throw new Error('Unsupported fiat: ' + fiatCode)
|
||||
}
|
||||
return cryptoCode + '/' + fiatCode
|
||||
}
|
||||
|
||||
module.exports = { verifyCurrencies, CRYPTO, FIAT }
|
||||
module.exports = { buildMarket, ALL }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue