Skip to content

Instantly share code, notes, and snippets.

@libasoles
Created May 1, 2018 02:32
Show Gist options
  • Save libasoles/d17a5e63072699f1a1e23b5944efe40b to your computer and use it in GitHub Desktop.
Save libasoles/d17a5e63072699f1a1e23b5944efe40b to your computer and use it in GitHub Desktop.
Consulta de ticker cada x segundos con api interna de cryptomkt
(()=>{
function init() {
const balance = helpers.getAvailableBalance()
console.log(`Balance disponible ${balance} ARS`)
}
function update() {
const coin = 'XLM'
const ticker = helpers.getTicker(coin)
console.log(coin, ticker)
}
/** config */
const config = {
base: 'ARS',
interval: 5, // segundos
}
/** helpers */
const helpers = {
getTicker: (coin = 'ETH') => {
const ticker = window.board[coin+config.base]
return {
bid: ticker.BID,
ask: ticker.ASK,
spread: ticker.ASK - ticker.BID
}
},
getBalance: (currency = 'ARS') => {
return window.balances.find(x=>x.currency_name === currency)
},
getAvailableBalance: (currency = 'ARS') => {
return parseFloat(helpers.getBalance(currency).disponible).toFixed(2);
},
}
init()
update()
setInterval(update, config.interval * 1000)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment