Skip to content

Instantly share code, notes, and snippets.

@snowkidind
Created July 12, 2018 21:37
Show Gist options
  • Save snowkidind/a42fb2c473bf9459e39eb704bedb52e2 to your computer and use it in GitHub Desktop.
Save snowkidind/a42fb2c473bf9459e39eb704bedb52e2 to your computer and use it in GitHub Desktop.
ticker:function(pair, cb){
const time = new Date().getTime();
if (time - lastTickerTime > 2000 ) {
// console.log("Get Ticker" + pair);
if (logAllApiCalls){
console.log(apiCallsCount + " ticker.binance.prices: " + pair + " - " + Date.now());
apiCallsCount += 1;
}
binance.prices(pair, (error, ticker) => {
if (error) {
console.log(pair);
console.log(chalk.red("binance.ticker error: " + error.body));
cb(false);
}
else {
lastTickerTime = new Date().getTime();
lastTicker = ticker[pair];
cb(ticker[pair]);
}
});
}
else {
// console.log("Using cached ticker");
cb(lastTicker);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment