-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcandlestick.js
56 lines (50 loc) · 1.28 KB
/
candlestick.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
let addChart = () => $('<div/>').appendTo('#charts')[0]
function chartFrom(url) {
$.ajax({
url: url,
success: function(result) {
let {data, title} = result;
let {x, y, type} = data;
y = y.map(parseFloat);
Plotly.newPlot(addChart(), [{x, y, title, type}], {title});
}
});
}
function ohlcChartFrom(url) {
$.ajax({
url: url,
success: function(result) {
let {data, title} = result;
let {x, open, high, low, close, type} = data;
open = open.map(parseFloat);
high = high.map(parseFloat);
low = low.map(parseFloat);
close = close.map(parseFloat);
var layout = {
title: title,
dragmode: 'zoom',
margin: { r: 10, t: 25, b: 40, l: 60 },
showlegend: false,
xaxis: {
autorange: true,
domain: [0, 1],
title: 'Date',
type: 'date'
},
yaxis: {
autorange: true,
domain: [0, 1],
type: 'linear'
}
};
ohlc = {x, open, high, low, close, type};
Plotly.newPlot(addChart(), [ohlc], layout);
}
});
};
$( document ).ready(function() {
chartFrom("/daily_close_price");
ohlcChartFrom('/candlestick_1m');
ohlcChartFrom('/candlestick_1h');
ohlcChartFrom('/candlestick_1d');
});