-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
89 lines (83 loc) · 1.75 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var pr = new XMLHttpRequest();
pr.responseType = "json";
var xhttp = new XMLHttpRequest();
xhttp.responseType = "json";
var c = false;
var cpicked;
pr.open("GET", "https://trade.ton-rocket.com/pairs", true);
pr.send();
pr.onreadystatechange = function() {
if (!(this.readyState == 4)) {
return;
}
var pairs = pr.response.data;
var select = document.getElementById('coin');
for (var j = 0; j < pairs.length; j++) {
var coin = pairs[j].name.split("-")[0];
if (j == 0) {
getData(coin);
}
if (coin == 'TONCOIN') {
continue;
}
var opt = document.createElement('option');
opt.value = coin;
opt.innerText = coin;
select.appendChild(opt);
}
}
var start = new Date();
start.setMonth(start.getMonth() - 1);
var end = new Date();
function getData(coin) {
cpicked = coin;
window.ct = coin;
window.updatePrice();
xhttp.open("GET", `https://trade.ton-rocket.com/time-series/${coin}-TONCOIN?startDate=${start.toISOString()}&endDate=${end.toISOString()}&period=PERIOD_12_HOURS`, true);
xhttp.send();
}
xhttp.onreadystatechange = function() {
if (!(this.readyState == 4)) {
return;
}
var jd = xhttp.response;
if (!jd.success) {
alert("Ошибка xRocket Trade API");
return;
}
var data = jd.data.timeSeries;
var cd = [];
for (var j = 0; j < data.length; j++) {
var z = data[j];
cd.push({
x: new Date(z.openTime),
y: [z.openRate, z.maxRate, z.minRate, z.closeRate]
})
}
var options = {
series: [{
data: cd
}],
chart: {
type: 'candlestick',
height: 350
},
title: {
text: `${cpicked}-TON`,
align: 'left'
},
xaxis: {
type: 'datetime'
},
yaxis: {
tooltip: {
enabled: true
}
}
};
if (c) {
c.destroy();
}
c = new ApexCharts(document.querySelector("#chart"), options);
c.render();
}