forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlivechart.js
More file actions
170 lines (143 loc) · 5.24 KB
/
livechart.js
File metadata and controls
170 lines (143 loc) · 5.24 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var minDT = new Date();
minDT.setUTCFullYear(minDT.getUTCFullYear - 3);
var liveChartsFromDT, liveChartsToDT, liveChartConfig;
var updateDatesFromConfig = function(config) {
var duration = $('#live_chart_duration li[data-live=' + config.live + ']').attr('id');
var now = new Date();
liveChartsFromDT.setDateTime(new Date(now.getTime() - (duration * 1000)));
liveChartsToDT.setDateTime(now);
};
var show_chart_for_instrument = function() {
var symb, disp_symb;
$("#instrument_select .deleteme").remove();
$("#instrument_select option:selected").each(function(){
symb = $(this).val();
disp_symb = $(this).text();
});
if (symb) {
liveChartConfig.update({
symbol: symb,
update_url: 1
});
updateLiveChart(liveChartConfig);
}
};
var remove_highlight_chart_duration = function () {
$('#live_chart_duration').find('.live_charts_stream_button').each( function () {
$(this).find('span').removeClass('current');
});
};
var build_markets_select = function() {
var market_select = $("#market_select");
markets.each(function() {
market_select.append("<option id='opt_" + this.name + "' value='" + this.name + "'>" + this.translated_display_name() + "</option>");
});
$("#market_select").val(liveChartConfig.market.name);
build_instrument_select();
$("#market_select").change(build_instrument_select);
};
var build_instrument_select = function() {
var instrument_select = $("#instrument_select");
var market = markets.get($('#market_select').val());
$("#instrument_span").hide();
if(market) {
$("#instrument_select option").remove();
instrument_select.append("<option class='deleteme'></option>");
market.each(function() {
this.each(function() {
instrument_select.append("<option value='" + this.symbol + "'>" + this.translated_display_name() + "</option>");
});
});
$("#instrument_span").show();
$("#instrument_select").change(show_chart_for_instrument);
$("#instrument_select").val(liveChartConfig.symbol.symbol);
}
};
var init_live_chart = function () {
liveChartsFromDT = new DateTimePicker({
id: "live_charts_from",
onChange: function(date) { liveChartsToDT.setMinDateTime(date); }
});
liveChartsToDT = new DateTimePicker({
id: "live_charts_to",
onChange: function(date) { liveChartsFromDT.setMaxDateTime(date); }
});
liveChartConfig = new LiveChartConfig({
renderTo: 'live_chart_div',
});
configure_livechart();
build_markets_select();
$(".notice").hide();
$("#live_chart_extended_options").hide();
$("#live_charts_show_extended_options").on('click', function(e){
e.preventDefault();
$("#live_chart_extended_options").toggle();
});
$("#live_charts_high_barrier").change(function(){
var val = $(this).val();
if(liveChartConfig.has_indicator('high') || !val) {
live_chart.remove_indicator('high');
}
if (val) {
var barrier = new LiveChartIndicator.Barrier({ name: "high", value: val, color: 'green'});
live_chart.add_indicator(barrier);
}
});
$("#live_charts_low_barrier").change(function(){
var val = $(this).val();
if(liveChartConfig.has_indicator('low') || !val) {
live_chart.remove_indicator('low');
}
if (val) {
var barrier = new LiveChartIndicator.Barrier({ name: "low", value: val, color: 'red'});
live_chart.add_indicator(barrier);
}
});
$('#live_charts_hide_spot').hide();
$("#live_charts_show_spot").on('click', function(e){
e.preventDefault();
var barrier = new LiveChartIndicator.Barrier({ name: "spot", value: "+0"});
live_chart.add_indicator(barrier);
$(this).hide();
$('#live_charts_hide_spot').show();
});
$("#live_charts_hide_spot").on('click', function(e){
e.preventDefault();
live_chart.remove_indicator('spot');
$(this).hide();
$('#live_charts_show_spot').show();
});
$("#live_charts_show_interval").on('click', function() {
liveChartConfig.update({
interval: {
from: liveChartsFromDT.getDateTime(),
to: liveChartsToDT.getDateTime()
},
update_url: 1
});
updateLiveChart(liveChartConfig);
});
$("#live_chart_duration").on('duration_change', function(e) {
updateDatesFromConfig(e.config);
});
show_chart_for_instrument();
updateDatesFromConfig(liveChartConfig);
};
pjax_config_page('livechart', function() {
return {
onLoad: function() {
init_live_chart();
},
onUnload: function() {
live_chart.close_chart();
live_chart = null;
}
};
});
//The first time some one loads live chart in the session, the script might not have finished loading by the time onLoad.fire() was called.
//So we check if livechart was not configured when we loaded this script then we initialize it manually.
$(function() {
if(!live_chart && /livechart/.test(window.location.pathname)) {
init_live_chart();
}
});