Created
June 29, 2012 07:16
-
-
Save nodeninja/3016434 to your computer and use it in GitHub Desktop.
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
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