Last active
January 4, 2016 10:49
-
-
Save jwoglom/8611034 to your computer and use it in GitHub Desktop.
Dogecoin to USD Realtime Converter
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
<!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> |
@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
Any chance this could be updated to use their websocket API? https://www.bitstamp.net/websocket/