Skip to content

Instantly share code, notes, and snippets.

@suissa
Last active December 5, 2017 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suissa/042348a1b2f1f6137434f49309c1ad76 to your computer and use it in GitHub Desktop.
Save suissa/042348a1b2f1f6137434f49309c1ad76 to your computer and use it in GitHub Desktop.
soh brincandoooo
const axios = require( 'axios' )
const COIN = process.argv.reverse()[0].toUpperCase()
console.log('------------------------------------');
console.log(COIN);
console.log('------------------------------------');
const EXCHANGE_URL = 'https://www.mercadobitcoin.net/api/BTC/ticker/'
const COINMARKETCAP_URL = `https://api.coinmarketcap.com/v1/ticker/bitcoin/${COIN}`
const DOLLAR_URL = 'http://api.promasters.net.br/cotacao/v1/valores?moedas=USD&alt=json'
const BLEUTRADE_MARKETS = 'https://bleutrade.com/api/v2/public/'
const transformMoney = ( dollar ) => ( reais ) =>
Number( reais / dollar )
const getURL = ( url ) => axios.get( url )
const getMarketcap = () => getURL( COINMARKETCAP_URL )
const getDollar = () => getURL( DOLLAR_URL )
const getMarkets = async (EXCHANGE_URL) => {
const list = await getURL(EXCHANGE_URL + 'getlist')
return new Set( markets.data.result.map( coin => {
const result = coin.MarketCurrency
if (coin.IsActive)
return result
}))
}
const getCurrencies = async (EXCHANGE_URL) => {
const list = await getURL(EXCHANGE_URL + 'getcurrencies')
return [...new Set(list.data.result.map(coin => {
const result = {
currency: coin.Currency,
name: coin.CurrencyLong
}
if (coin.IsActive)
return result
}))]
}
const getTicker = async (COIN, EXCHANGE_URL) => {
const list = await getURL(EXCHANGE_URL + `getticker?market=${COIN}_BTC`)
console.log('------------------------------------');
console.log(COIN + ': ', list.data.result);
console.log('------------------------------------');
// return
}
const proccessData2 = async (response) => {
const list = await getCurrencies(BLEUTRADE_MARKETS)
// const isIn = !!list.filter(coin => coin.currency == COIN).length
console.log('list: ', list)
// console.log(`is ${COIN} in? `, isIn)
// console.log('list ' + COIN, list.filter(coin => console.log(coin)));
const ticker = await getTicker(COIN, BLEUTRADE_MARKETS)
}
const getExchangeValues = ( ticker ) => {
const [ highR, lowR,, lastR ] = Object.values( ticker )
return [ highR, lowR, lastR ]
}
const getExchangeValuesIn = ( dollar ) => ( values ) =>
values.map( transformMoney( dollar ) )
// const proccessData = async ( response ) => {
// const result_marketcap = await getMarketcap()
// const bitcoin = result_marketcap.data[ 0 ].price_usd
// const result_dollar = await getDollar()
// const dollar = result_dollar.data.valores.USD.valor
// const getExchangeValuesInUSD = getExchangeValuesIn( dollar )
// console.log( '1 BTC = U$', bitcoin )
// console.log( '1 USD = R$', dollar )
// console.log( '\n------------------------------------' )
// console.log( 'mercadobitcoin' )
// console.log( '------------------------------------' )
// const [ highR, lowR, lastR ] = getExchangeValues( response.data.ticker )
// const [ highU, lowU, lastU ] = getExchangeValuesInUSD( [ highR, lowR, lastR ] )
// console.log( 'R$ high, low, last:', highR, lowR, lastR )
// console.log( 'U$ high, low, last:', highU, lowU, lastU )
// }
const logError = error => console.log( error )
axios
.get( EXCHANGE_URL )
.then( proccessData2 )
.catch( logError )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment