forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkets.js
More file actions
127 lines (118 loc) · 3.67 KB
/
markets.js
File metadata and controls
127 lines (118 loc) · 3.67 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
var Markets = function(markets, market_symbols) {
this.all = [];
var market_count = markets.length;
while(market_count--) {
var market_name = markets[market_count];
var market_config = market_symbols[market_name];
var market_obj = new Market(market_name, market_config['label'], market_config['submarkets']);
this.all.push(market_obj);
}
};
Markets.prototype = {
each: function(callback) {
var market_count = this.all.length;
while(market_count--) {
callback.call(this.all[market_count]);
}
},
by_symbol: function(symbol) {
var market_count = this.all.length;
while(market_count--) {
var found = this.all[market_count].by_symbol(symbol);
if(found) {
return found;
}
}
},
get: function(name) {
var market_count = this.all.length;
while(market_count--) {
if(this.all[market_count].name == name) {
return this.all[market_count];
}
}
}
};
var Market = function(name, display_name, submarkets) {
this.name = name;
this.display_name = display_name;
this.submarkets = [];
this.all_submarkets = [];
var submarket_count = submarkets.length;
while(submarket_count--) {
var submarket = submarkets[submarket_count];
var submarket_obj = new SubMarket(submarket['name'], submarket['label'], submarket['instruments']);
this.submarkets.push(submarket_obj);
this.all_submarkets.push(submarket_obj);
}
};
Market.prototype = {
translated_display_name: function() {
return text.localize(this.display_name);
},
by_symbol: function(symbol) {
var count = this.submarkets.length;
while(count--) {
found = this.submarkets[count].by_symbol(symbol);
if(found) {
found['market'] = this;
return found;
}
}
},
each: function(callback) {
var count = this.all_submarkets.length;
while(count--) {
callback.call(this.all_submarkets[count]);
}
},
get: function(name) {
if(name.toUpperCase() == 'ALL') {
return this.all_submarkets;
}
var count = this.submarkets.length;
while(count--) {
if(this.submarkets[count].name == name) {
return this.submarkets[count];
}
}
}
};
function localizeName() {
return text.localize(this.name);
}
var SubMarket = function(name, display_name, underlyings) {
this.name = name;
this.display_name = display_name;
this.underlyings = [];
var underlying_count = underlyings.length;
while(underlying_count--) {
var underlying = underlyings[underlying_count];
var underlying_object = {
name: underlying['label'],
symbol: underlying['value'],
translated_display_name: localizeName
};
this.underlyings.push(underlying_object);
}
};
SubMarket.prototype = {
translated_display_name: function() {
return text.localize(this.display_name);
},
each: function(callback) {
var underlying_count = this.underlyings.length;
while(underlying_count--) {
callback.call(this.underlyings[underlying_count]);
}
},
by_symbol: function(symbol) {
var underlying_count = this.underlyings.length;
while(underlying_count--) {
if(this.underlyings[underlying_count].symbol == symbol) {
return { submarket: this, underlying: this.underlyings[underlying_count] };
}
}
return;
},
};