Skip to content

Commit

Permalink
Swap Bitstamp price for Coinbase, duct tape + bubblegum style
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLaumeister committed Sep 22, 2022
1 parent 50c4b01 commit 9daf955
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bitlisten.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitlisten.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div id="header" class="serif interface">
<div id="rateBox">
<span id="rate">---</span> <span id="units">USD / BTC</span><br />
<span class="rateButton" id="bitstampRate" onclick="switchExchange('bitstamp');">Bitstamp</span>
<span class="rateButton" id="coinbaseRate" onclick="switchExchange('coinbase');">Coinbase</span>
</div>
<img src="images/logo.png" alt="BitListen">
<div id="headerInfo">
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $(document).ready(function() {
// Spam the following line into console, it's kind of fun.
// new Block(228158, 270, 100 * satoshi, 153 * 1024);

switchExchange("bitstamp");
switchExchange("coinbase");

// Attach mouseover qr
$("#donationAddress").qr();
Expand Down
32 changes: 12 additions & 20 deletions src/ratebox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var rateboxTimeout;
var currentExchange;
var ratebox_ms = 3000; // 3 second update interval
var ratebox_ms = 10000; // 10 second update interval
var globalRate = -1; // set upon first rate received

function setGlobalRate(rate) {
Expand All @@ -14,32 +14,24 @@ function setGlobalRate(rate) {
}

rateboxGetRate = function() {
$.getJSON("https://blockchain.info/ticker?cors=true", function(data) {
setGlobalRate(data.USD.last);
});
$.ajax({
dataType: "json",
cache: false,
url: "https://api.coinbase.com/v2/prices/BTC-USD/spot",
success: function(data) {
setGlobalRate(data.data.amount);
rateboxTimeout = setTimeout(rateboxGetRate, ratebox_ms);
}
});
};

$(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");
if (exchangeName == "coinbase") {
$("#coinbaseRate").css("color", "white");
}

rateboxGetRate();
Expand Down

0 comments on commit 9daf955

Please sign in to comment.