Skip to content

Instantly share code, notes, and snippets.

@jwoglom
Last active January 4, 2016 10:49
Show Gist options
  • Save jwoglom/8611034 to your computer and use it in GitHub Desktop.
Save jwoglom/8611034 to your computer and use it in GitHub Desktop.
Dogecoin to USD Realtime Converter
<!doctype html>
<html>
<head>
<title>Dogecoin to USD</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
<script type='text/javascript'>
// Sadly Cryptsy and Bitstamp don't support JSONP, so we have to use a proxy.
var proxy = 'http://jsonp.guffa.com/Proxy.ashx?url=';
genValue = function() {
var dogejson = "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132";
var btcjson = "http://www.bitstamp.net/api/ticker/";
var dogeval = 0, btcval = 0;
$.get(proxy+escape(dogejson), function(d) {
console.log(d);
dogeval = parseFloat(d['return']['markets']['DOGE']['lasttradeprice']);
$.get(proxy+escape(btcjson), function(e) {
console.log(e);
btcval = parseFloat(e['last']);
displayValue(dogeval, btcval);
}, "jsonp")
}, "jsonp");
}
displayValue = function(dogeval, btcval) {
dogetousd = dogeval * btcval;
usdtodoge = (1 / btcval) / dogeval;
$('.usdtodoge').each(function() {
var num = $(this).attr('usd');
var val = (typeof num != 'undefined' ? num * usdtodoge : usdtodoge);
$(this).html($(this).html() + ' ('+pretty(val,3) + ' DOGE)');
});
$('.dogetousd').each(function() {
var num = $(this).attr('doge');
var val = (typeof num != 'undefined' ? num * dogetousd : dogetousd);
$(this).html($(this).html() + ' ($'+pretty(val,3)+')');
});
}
pretty = function(dbl, pl) {
return parseInt(dbl * Math.pow(10,pl)) / Math.pow(10, pl);
}
$(function() {
genValue();
});
</script>
</head>
<body>
<h2>Dogecoin to USD Realtime Converter</h2>
<span class='usdtodoge' usd='5'>$5</span><br />
<span class='dogetousd' doge='10000'>10000 DOGE</span>
</body>
</html>
@jwoglom
Copy link
Author

jwoglom commented May 8, 2014

Good idea. I've just updated it to use Bitstamp.

Copy link

ghost commented Jul 1, 2014

Hey there! We are looking to implement this into a website. Would you mind if we credited/linked back to you?

Copy link

ghost commented Jul 1, 2014

Any chance this could be updated to use their websocket API? https://www.bitstamp.net/websocket/

@jwoglom
Copy link
Author

jwoglom commented Jul 10, 2014

@bitWatcher: Yes, that'd be fine with proper attribution. I'll look into the Websockets API and, if I do implement it, I'll do it as a separate gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment