Created
May 1, 2018 02:32
-
-
Save libasoles/d17a5e63072699f1a1e23b5944efe40b to your computer and use it in GitHub Desktop.
Consulta de ticker cada x segundos con api interna de cryptomkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(()=>{ | |
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