forked from MaxLaumeister/bitlisten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratebox.js
46 lines (40 loc) · 1.27 KB
/
ratebox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var rateboxTimeout;
var currentExchange;
var ratebox_ms = 3000; // 3 second update interval
var globalRate = -1; // set upon first rate received
function setGlobalRate(rate) {
if (globalRate === -1) {
var checkbox = $("#showDollarCheckBox");
checkbox.prop("disabled", false);
checkbox.parent().removeClass("disabled");
}
$("#rate").html(parseFloat(rate).toFixed(2));
globalRate = rate;
}
rateboxGetRate = function() {
$.getJSON("https://blockchain.info/ticker?cors=true", function(data) {
setGlobalRate(data.USD.last);
});
};
$(document).ready(function() {
// Bitstamp websocket API
var pusher = new Pusher('de504dc5763aeef9ff52');
var channel = pusher.subscribe('live_trades');
channel.bind('trade', function(ticker) {
setGlobalRate(ticker.price);
if (rateboxTimeout) clearTimeout(rateboxTimeout);
});
});
switchExchange = function(exchangeName) {
clearTimeout(rateboxTimeout);
currentExchange = exchangeName;
$("#rate").html("---");
if (exchangeName == "bitstamp") {
$("#bitstampRate").css("color", "white");
$("#mtgoxRate").css("color", "gray");
} else if (exchangeName == "mtgox") {
$("#mtgoxRate").css("color", "white");
$("#bitstampRate").css("color", "gray");
}
rateboxGetRate();
};