Last active
January 6, 2025 16:44
-
-
Save supertestnet/e9ac6b3653994d8a9a02d5169fd6066e to your computer and use it in GitHub Desktop.
Some javascript for fetching the historical price of bitcoin on any date since Kraken existed
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> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ccxt.browser.min.js"></script> | |
<!-- the manual for using the ccxt library is here: https://github.com/ccxt/ccxt/wiki/ --> | |
</head> | |
<body> | |
<script> | |
(async()=>{ | |
var date = "2016-07-26"; | |
var exchange = new ccxt.kraken(); | |
if ( exchange.has[ 'fetchTrades' ] ) { | |
console.log( 'loading markets...' ); | |
await exchange.loadMarkets(); | |
console.log( 'markets loaded!' ); | |
var since = new Date( date ).getTime(); | |
console.log( 'fetching historical price' ); | |
var trades = await exchange.fetchTrades( "BTC/USD", since, 1 ); | |
console.log( 'historical price fetched!' ); | |
console.log( `on ${date} the price of bitcoin was $${trades[ 0 ][ "price" ].toFixed( 2 )}` ); | |
} else return alert( `this exchange does not support historical prices` ); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment