Skip to content

Instantly share code, notes, and snippets.

@nodeninja
Created June 29, 2012 07:16
Show Gist options
  • Save nodeninja/3016434 to your computer and use it in GitHub Desktop.
Save nodeninja/3016434 to your computer and use it in GitHub Desktop.
getDisplay: function(exchangeData) {
var options = {max: true};
var buyPrices = createBinaryHeap(options);
var sellPrices = createBinaryHeap(options);
var buys = exchangeData.buys;
var sells = exchangeData.sells;
if (sells) {
for (var price in sells.volumes) {
sellPrices.push(price);
}
}
if (buys) {
for (var price in buys.volumes) {
buyPrices.push(price);
}
}
var padding = " | ";
var stringBook = "\n";
while (sellPrices.size() > 0) {
var sellPrice = sellPrices.pop()
stringBook += padding + sellPrice + ", " + sells.volumes[sellPrice] + "\n";
}
while (buyPrices.size() > 0) {
var buyPrice = buyPrices.pop();
stringBook += buyPrice + ", " + buys.volumes[buyPrice] + "\n";
}
stringBook += "\n\n";
for (var i=0; exchangeData.trades && i<exchangeData.trades.length; i++) {
var trade = exchangeData.trades[i];
stringBook += "TRADE " + trade.volume + " @ " + trade.price + "\n";
}
return stringBook;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment