-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (48 loc) · 1.92 KB
/
Copy pathindex.js
File metadata and controls
54 lines (48 loc) · 1.92 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
// const core = require('@actions/core');
// const github = require('@actions/github');
const moment = require('moment');
const axios = require('axios');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
/**
* Example of using techanjs in a node runtime environment
*/
const fs = require('fs');
const d3 = require('d3');
const techan = require('techan');
const chart = require('./chart.js');
async function run() {
const { data } = await axios.get('https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1d&limit=100');
const csvData = data.map(d => {
return {
Date: moment(d[0]).format('DD-MMM-YY'),
Open: d[1],
High: d[2],
Low: d[3],
Close: d[4],
Volume: d[5]
};
});
const { document } = (new JSDOM('')).window;
// Create the chart, passing in runtime environment specific setup: node d3, techan and csv data
const body = d3.select(document.body).call(chart(d3, techan, csvData));
var stream = fs.createWriteStream("chart.svg");
stream.once('open', function(fd) {
stream.write('<?xml version="1.0" encoding="utf-8"?>\n');
stream.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n');
stream.write(body.html());
stream.end();
});
const { data: { priceChangePercent, lastPrice, highPrice, lowPrice } } = await axios.get('https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT');
const stats = `|$${parseFloat(lastPrice).toFixed(2)}|${parseFloat(priceChangePercent).toFixed(2)}%|$${parseFloat(highPrice).toFixed(2)}|$${parseFloat(lowPrice).toFixed(2)}|\n\n`;
var stream = fs.createWriteStream("README.md");
stream.once('open', function(fd) {
stream.write('# Bitcoin Stats\n\n');
stream.write('BTC/USDT|24h change|24h high|24h low|\n');
stream.write('|---|---|---|---|\n');
stream.write(stats);
stream.write('<img src="./chart.svg">\n');
stream.end();
});
};
run();