Code readability and added the forgotten mocks

This commit is contained in:
José Oliveira 2021-01-25 23:51:39 +00:00 committed by Josh Harvey
parent 134eaaa518
commit 7accdaa84f
12 changed files with 126 additions and 96 deletions

View file

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

View file

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

View file

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