-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-btc-historical-data.js
42 lines (32 loc) · 986 Bytes
/
get-btc-historical-data.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
/**
* Get BTC Historical data from CoinMarketCap
*/
// https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20171024&end=20180124
var $table = document.querySelector('table.table');
var data = [];
/**
* @param {string} str
*/
function formatNumber ( str ) {
let s = str;
while ( s.indexOf( '.' ) !== -1 ) {
s = s.replace( '.', '' );
}
s = s.replace( ',', '.' );
return +s;
}
for ( let $row of $table.rows ) {
if ( $row.rowIndex === 0 ) { continue; }
let candle = {
date: new Date($row.cells[ 0 ].innerText).getTime(),
open: formatNumber( $row.cells[ 1 ].innerText ),
high: formatNumber( $row.cells[ 2 ].innerText ),
low: formatNumber( $row.cells[ 3 ].innerText ),
close: formatNumber( $row.cells[ 4 ].innerText ),
volume: formatNumber( $row.cells[ 5 ].innerText ),
marketCap: formatNumber( $row.cells[ 6 ].innerText )
};
data.push( candle );
}
// console.table( data );
console.log( JSON.stringify( data ) );