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,7 +1,12 @@
|
|||
const axios = require('axios')
|
||||
const BN = require('../../../bn')
|
||||
|
||||
function ticker (account, fiatCode, cryptoCode) {
|
||||
const BN = require('../../bn')
|
||||
const { BTC, BCH } = require('../../new-admin/config/coins')
|
||||
|
||||
const CRYPTO = [BTC, BCH]
|
||||
const FIAT = 'ALL_CURRENCIES'
|
||||
|
||||
function ticker (fiatCode, cryptoCode) {
|
||||
return axios.get('https://bitpay.com/rates/' + cryptoCode + '/' + fiatCode)
|
||||
.then(r => {
|
||||
const data = r.data.data
|
||||
|
|
@ -17,5 +22,7 @@ function ticker (account, fiatCode, cryptoCode) {
|
|||
|
||||
module.exports = {
|
||||
ticker,
|
||||
name: 'BitPay'
|
||||
name: 'BitPay',
|
||||
CRYPTO,
|
||||
FIAT
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
const ccxt = require('ccxt')
|
||||
const BN = require('../../bn')
|
||||
const axios = require('axios')
|
||||
const _ = require('lodash/fp')
|
||||
const common = require('../common/ccxt')
|
||||
const axios = require('axios')
|
||||
const ccxt = require('ccxt')
|
||||
|
||||
function ticker (exchangeName, fiatCode, cryptoCode) {
|
||||
const exchange = new ccxt[exchangeName]()
|
||||
const BN = require('../../bn')
|
||||
const { buildMarket } = require('../common/ccxt')
|
||||
|
||||
if (fiatCode === 'EUR' || fiatCode === 'USD' || exchange.id === 'coinbase') {
|
||||
return getCurrencyRates(exchange, fiatCode, cryptoCode)
|
||||
function ticker (fiatCode, cryptoCode, tickerName) {
|
||||
const ticker = new ccxt[tickerName]({ timeout: 3000 })
|
||||
if (fiatCode === 'EUR' || fiatCode === 'USD' || ticker.id === 'coinbase') {
|
||||
return getCurrencyRates(ticker, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
return axios.get('https://bitpay.com/rates')
|
||||
|
|
@ -18,7 +18,7 @@ function ticker (exchangeName, fiatCode, cryptoCode) {
|
|||
const usdRate = findCurrencyRates(fxRates, 'USD')
|
||||
const fxRate = findCurrencyRates(fxRates, fiatCode).div(usdRate)
|
||||
|
||||
return getCurrencyRates(exchange, 'USD', cryptoCode)
|
||||
return getCurrencyRates(ticker, 'USD', cryptoCode)
|
||||
.then(res => ({
|
||||
rates: {
|
||||
ask: res.rates.ask.times(fxRate),
|
||||
|
|
@ -31,11 +31,11 @@ function ticker (exchangeName, fiatCode, cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function getCurrencyRates (exchange, fiatCode, cryptoCode) {
|
||||
function getCurrencyRates (ticker, fiatCode, cryptoCode) {
|
||||
try {
|
||||
if (exchange.has['fetchTicker']) {
|
||||
const symbol = common.verifyCurrencies(exchange.id, fiatCode, cryptoCode)
|
||||
return exchange.fetchTicker(symbol)
|
||||
if (ticker.has['fetchTicker']) {
|
||||
const symbol = buildMarket(fiatCode, cryptoCode, ticker.id)
|
||||
return ticker.fetchTicker(symbol)
|
||||
.then(res => ({
|
||||
rates: {
|
||||
ask: BN(res.ask),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const BN = require('../../../bn')
|
||||
const BN = require('../../bn')
|
||||
|
||||
function ticker (account, fiatCode, cryptoCode) {
|
||||
function ticker (fiatCode, cryptoCode) {
|
||||
return Promise.resolve({
|
||||
rates: {
|
||||
ask: BN(105),
|
||||
Loading…
Add table
Add a link
Reference in a new issue