Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit e7a2824

Browse files
authored
Merge pull request #1555 from mahdiyeh-fs/fix_mlt/mf_markets
Mahdiyeh/Fix: mlt/mf markets
2 parents 8578d44 + 4d340e0 commit e7a2824

File tree

6 files changed

+163
-129
lines changed

6 files changed

+163
-129
lines changed

src/assetindex/assetIndex.es6

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,25 @@ const checkVolatility = (market_name, market_names) => {
7373
const initTable = () => {
7474
getActiveSymAndAssetsData()
7575
.then((result) => {
76-
populateTable(result);
76+
liveapi
77+
.send({ active_symbols: "brief" })
78+
.then(function (response) {
79+
populateTable(result, response.active_symbols);
80+
})
7781
})
7882
.catch((error) => {
7983
$.growl.error({ message: error.message });
8084
console.error(error);
8185
});
8286

83-
function populateTable(result) {
84-
const active_symbols_data = local_storage.get('active_symbols');
85-
const filtered_active_symbols = filterRestrictedSymbols(active_symbols_data);
87+
function populateTable(result, symbols) {
88+
const active_symbols_data = symbols;
8689
const asset_index_data = [...result[0].asset_index];
8790

88-
if($.isEmptyObject(filtered_active_symbols) && $.isEmptyObject(asset_index_data)) return;
91+
if($.isEmptyObject(active_symbols_data) || $.isEmptyObject(asset_index_data)) return;
8992

90-
state.dropdown.market_submarkets = getObjectMarketSubmarkets(filtered_active_symbols);
91-
state.dropdown.sorted_markets = getSortedMarkets(filtered_active_symbols);
93+
state.dropdown.market_submarkets = getObjectMarketSubmarkets(active_symbols_data);
94+
state.dropdown.sorted_markets = getSortedMarkets(active_symbols_data);
9295
state.table.asset_data = asset_index_data;
9396

9497
header_el = asset_win_el.parent().find('.ui-dialog-title').addClass('with-content');

src/common/util.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
function filterRestrictedSymbols(active_symbols) {
2-
return active_symbols.filter(function(item) { return !/^(BOOM|CRASH|STP|CRY).+/i.test(item.symbol)});
1+
function isFinancialAccout() {
2+
if (local_storage.get('authorize')) {
3+
return /^(MF)/i.test(local_storage.get('authorize').loginid);
4+
}
5+
return false
36
}
47

58
function isTick(ohlc) {

src/instruments/instruments.es6

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,57 @@ import { getSortedMarketSubmarkets } from '../common/marketUtils';
66
import "jquery-growl";
77
import "common/util";
88

9-
const get_active_symbol = () => {
9+
const get_active_symbol = (landing_company, country) => {
10+
1011
liveapi
11-
.cached
1212
.send({ active_symbols: 'brief' })
13-
.then(function (data) {
14-
local_storage.set('active_symbols', data.active_symbols);
15-
const active_symbols = [];
16-
const active_markets = _(filterRestrictedSymbols(data.active_symbols)).groupBy('market').map(function (symbols) {
17-
const filtered_symbols = symbols;
18-
const sym = _.head(filtered_symbols);
19-
const market = { name: sym.market, display_name: sym.market_display_name };
20-
market.submarkets = _(filtered_symbols).groupBy('submarket').map(function (symbols) {
21-
const sym = _.head(symbols);
22-
const submarket = { name: sym.submarket, display_name: sym.submarket_display_name };
23-
submarket.instruments = _.map(symbols, function (sym) {
24-
active_symbols.push(sym.symbol);
25-
return {
26-
symbol: sym.symbol,
27-
display_name: sym.display_name,
28-
};
29-
});
30-
return submarket;
31-
}).value();
32-
return market;
13+
.then(function(data) {
14+
const active_symbols = [];
15+
let filtered_symbols;
16+
17+
local_storage.set('active_symbols', data.active_symbols);
18+
19+
const active_markets = _(data.active_symbols).groupBy('market').map(function (symbols) {
20+
const filtered_symbols = symbols;
21+
const sym = _.head(filtered_symbols);
22+
const market = { name: sym.market, display_name: sym.market_display_name };
23+
market.submarkets = _(filtered_symbols).groupBy('submarket').map(function (symbols) {
24+
const sym = _.head(symbols);
25+
const submarket = { name: sym.submarket, display_name: sym.submarket_display_name };
26+
submarket.instruments = _.map(symbols, function (sym) {
27+
active_symbols.push(sym.symbol);
28+
return {
29+
symbol: sym.symbol,
30+
display_name: sym.display_name,
31+
};
32+
});
33+
return submarket;
3334
}).value();
34-
markets = chartable_markets.map(function (m) {
35-
return {
36-
display_name: m.display_name,
37-
name: m.name,
38-
submarkets: m.submarkets.map(function (sm) {
39-
return {
40-
display_name: sm.display_name,
41-
instruments: sm.instruments.filter(function (ins) {
42-
return active_symbols.indexOf(ins.symbol) !== -1;
43-
})
44-
}
45-
}).filter(function (sm) {
46-
return sm.instruments.length !== 0;
47-
})
48-
}
49-
}).filter(function (m) {
50-
return m.submarkets.length !== 0;
51-
});
52-
markets = getSortedMarketSubmarkets(markets);
53-
const instruments = $("#nav-menu").find(".instruments");
54-
instruments.find('> ul').remove();
55-
menu.refreshMenu(instruments, markets, onMenuItemClick);
35+
return market;
36+
}).value();
37+
markets = chartable_markets.map(function (m) {
38+
return {
39+
display_name: m.display_name,
40+
name: m.name,
41+
submarkets: m.submarkets.map(function (sm) {
42+
return {
43+
display_name: sm.display_name,
44+
instruments: sm.instruments.filter(function (ins) {
45+
return active_symbols.indexOf(ins.symbol) !== -1;
46+
})
47+
}
48+
}).filter(function (sm) {
49+
return sm.instruments.length !== 0;
50+
})
51+
}
52+
}).filter(function (m) {
53+
return m.submarkets.length !== 0;
5654
});
55+
markets = getSortedMarketSubmarkets(active_markets);
56+
const instruments = $("#nav-menu").find(".instruments");
57+
instruments.find('> ul').remove();
58+
menu.refreshMenu(instruments, markets, onMenuItemClick);
59+
});
5760
}
5861

5962
function refresh_active_symbols() {
@@ -62,7 +65,14 @@ function refresh_active_symbols() {
6265
.cached
6366
.authorize()
6467
.then(() => {
65-
get_active_symbol();
68+
const country = local_storage.get('authorize').country;
69+
liveapi
70+
.cached
71+
.send({ landing_company: country })
72+
.then((data) => {
73+
const landing_company = data.landing_company
74+
get_active_symbol(landing_company, country);
75+
});
6676
});
6777
} else {
6878
get_active_symbol();

src/navigation/menu.es6

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import $ from 'jquery';
22
import '../common/util';
3+
import "jquery-growl";
34

45
/* you can filter the symbols with the options parameter, for example:
56
options: {
67
filter: (sym) => (sym.feed_license !== 'realtime')
78
}
89
*/
10+
const menu_config = {
11+
trade : '.trade a',
12+
instruments : '.instruments a',
13+
assetIndex : '.assetIndex',
14+
tradingTimes : '.tradingTimes',
15+
};
16+
17+
const trade_messages = {
18+
no_symbol : () => "Binary options trading is not available.".i18n(),
19+
};
20+
921
export const extractFilteredMarkets = (trading_times_data, options) => {
1022
const markets = trading_times_data.trading_times.markets.map((m) => {
1123
const market = {
@@ -50,11 +62,15 @@ export const extractChartableMarkets = (trading_times_data) => {
5062
};
5163

5264
export const refreshMenu = (root, markets, callback) => {
53-
const is_not_crypto = symbol => !/^(cry|JD)/i.test(symbol);
54-
const non_crypto_markets = markets.filter( m => is_not_crypto(m.name))
55-
65+
66+
if(markets.length == 0){
67+
Object.values(menu_config).map( menu => $(menu).addClass('disabled'));
68+
$.growl.error({message: trade_messages.no_symbol()});
69+
} else {
70+
Object.values(menu_config).map( menu => $(menu).removeClass('disabled'));
71+
}
5672
const menu = `<ul>${
57-
non_crypto_markets.map(m => `<li><div>${m.display_name}</div><ul>${
73+
markets.map(m => `<li><div>${m.display_name}</div><ul>${
5874
m.submarkets.map(s => `<li><div>${s.display_name}</div><ul>${
5975
s.instruments.map(i => `<li symbol='${i.symbol}' pip='${i.pip}'><div>${i.display_name}</div></li>`).join('')
6076
}</ul></li>`).join('')

src/trade/tradeMenu.es6

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const show_error = (err) => {
99
console.error(err);
1010
};
1111

12-
const get_active_symbol = () => {
12+
const get_active_symbol = (landing_company, country) => {
1313
liveapi
14-
.cached
1514
.send({ active_symbols: 'brief' })
1615
.then((data) => {
1716
/* clean up the data! */
18-
let markets = _(filterRestrictedSymbols(data.active_symbols)).groupBy('market').map((symbols) => {
19-
const filtered_symbols = symbols;
20-
const sym = _.head(filtered_symbols);
17+
const active_symbols = data.active_symbols;
18+
let markets = _(active_symbols).groupBy('market').map((symbols) => {
19+
const active_symbols = symbols;
20+
const sym = _.head(active_symbols);
2121
const market = { name: sym.market, display_name: sym.market_display_name };
22-
market.submarkets = _(filtered_symbols).groupBy('submarket').map((symbols) => {
22+
market.submarkets = _(active_symbols).groupBy('submarket').map((symbols) => {
2323
const sym = _.head(symbols);
2424
const submarket = { name: sym.submarket, display_name: sym.submarket_display_name };
2525
submarket.instruments = _.map(symbols, (sym) => ({
@@ -56,7 +56,14 @@ const refresh_active_symbols = () => {
5656
.cached
5757
.authorize()
5858
.then(() => {
59-
get_active_symbol();
59+
const country = local_storage.get('authorize').country;
60+
liveapi
61+
.cached
62+
.send({ landing_company: country })
63+
.then((data) => {
64+
const landing_company = data.landing_company
65+
get_active_symbol(landing_company, country);
66+
});
6067
})
6168
} else{
6269
get_active_symbol();

src/tradingtimes/tradingTimes.es6

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ const processData = (markets) => {
3838
const market_names = [];
3939
const submarket_names = { };
4040
markets
41-
.filter(eMarket => {
42-
const loginId = (local_storage.get('authorize') || {}).loginid || '';
43-
return (/MF/gi.test(loginId) && eMarket.name !== 'Synthetic Indices')
44-
|| (/MLT/gi.test(loginId) && eMarket.name === 'Synthetic Indices')
45-
|| (/MX/gi.test(loginId) && eMarket.name === 'Synthetic Indices')
46-
|| (!/MF/gi.test(loginId) && !/MLT/gi.test(loginId) && !/MX/gi.test(loginId));
47-
})
4841
.forEach((market) => {
4942
market_names.push(market.display_name);
5043
submarket_names[market.display_name] = [];
@@ -146,61 +139,59 @@ const initTradingWin = ($html) => {
146139
}
147140

148141
/* refresh the table with result of {trading_times:yyyy_mm_dd} from WS */
149-
const refresh = (data) => {
150-
const result = processData(menu.extractFilteredMarkets(data[0]));
151-
const active_symbols = local_storage.get('active_symbols');
152-
const filtered_symbols = filterRestrictedSymbols(active_symbols)
153-
let header = getObjectMarketSubmarkets(filtered_symbols);
154-
const markets_sorted_list = getSortedMarkets(filtered_symbols);
155-
156-
if($.isEmptyObject(header)) return;
157-
158-
function changed() {
159-
const val = $(this).val();
160-
const new_active_symbols = local_storage.get('active_symbols');
161-
const new_filtered_symbols = filterRestrictedSymbols(new_active_symbols);
162-
header = getObjectMarketSubmarkets(new_filtered_symbols);
163-
164-
if (header[val]) {
165-
const cumulative_submarkets = Object.keys(header[val]);
166-
submarket_names.update_list(getSortedSubmarkets(cumulative_submarkets));
167-
};
168-
169-
updateTable(result, market_names.val(), submarket_names.val());
170-
};
171-
172-
if (market_names == null) {
173-
const select = $('<select />');
174-
select.appendTo(subheader);
175-
market_names = windows.makeSelectmenu(select, {
176-
list: markets_sorted_list,
177-
inx: 0,
178-
});
179-
market_names.off('selectmenuchange', changed);
180-
market_names.on('selectmenuchange', changed);
181-
} else {
182-
market_names.update_list(markets_sorted_list);
183-
market_names.off('selectmenuchange', changed);
184-
market_names.on('selectmenuchange', changed);
185-
}
186-
187-
if (submarket_names == null) {
188-
const sub_select = $('<select />');
189-
sub_select.appendTo(subheader);
190-
submarket_names = windows.makeSelectmenu(sub_select, {
191-
list: getSortedSubmarkets(Object.keys(header[market_names.val()])),
192-
inx: 0,
193-
changed: changedFn,
194-
});
195-
submarket_names.off('selectmenuchange', changed);
196-
submarket_names.on('selectmenuchange', changed);
197-
} else {
198-
submarket_names.update_list(getSortedSubmarkets(Object.keys(header[market_names.val()])));
199-
submarket_names.off('selectmenuchange', changed);
200-
submarket_names.on('selectmenuchange', changed);
201-
}
202-
203-
updateTable(result, market_names.val(), submarket_names.val());
142+
const refresh = (data, symbols) => {
143+
const result = processData(menu.extractFilteredMarkets(data[0]));
144+
const active_symbols = symbols;
145+
let header = getObjectMarketSubmarkets(active_symbols);
146+
const markets_sorted_list = getSortedMarkets(active_symbols);
147+
148+
if($.isEmptyObject(header)) return;
149+
150+
function changed() {
151+
const val = $(this).val();
152+
const new_active_symbols = symbols;
153+
header = getObjectMarketSubmarkets(new_active_symbols);
154+
155+
if (header[val]) {
156+
const cumulative_submarkets = Object.keys(header[val]);
157+
submarket_names.update_list(getSortedSubmarkets(cumulative_submarkets));
158+
};
159+
160+
updateTable(result, market_names.val(), submarket_names.val());
161+
};
162+
163+
if (market_names == null) {
164+
const select = $('<select />');
165+
select.appendTo(subheader);
166+
market_names = windows.makeSelectmenu(select, {
167+
list: markets_sorted_list,
168+
inx: 0,
169+
});
170+
market_names.off('selectmenuchange', changed);
171+
market_names.on('selectmenuchange', changed);
172+
} else {
173+
market_names.update_list(markets_sorted_list);
174+
market_names.off('selectmenuchange', changed);
175+
market_names.on('selectmenuchange', changed);
176+
}
177+
178+
if (submarket_names == null) {
179+
const sub_select = $('<select />');
180+
sub_select.appendTo(subheader);
181+
submarket_names = windows.makeSelectmenu(sub_select, {
182+
list: getSortedSubmarkets(Object.keys(header[market_names.val()])),
183+
inx: 0,
184+
changed: changedFn,
185+
});
186+
submarket_names.off('selectmenuchange', changed);
187+
submarket_names.on('selectmenuchange', changed);
188+
} else {
189+
submarket_names.update_list(getSortedSubmarkets(Object.keys(header[market_names.val()])));
190+
submarket_names.off('selectmenuchange', changed);
191+
submarket_names.on('selectmenuchange', changed);
192+
}
193+
194+
updateTable(result, market_names.val(), submarket_names.val());
204195
};
205196

206197
const getCachedData = () => {
@@ -213,8 +204,12 @@ const initTradingWin = ($html) => {
213204
liveapi.cached.send(trading_times_request),
214205
])
215206
.then((results) => {
216-
refresh(results);
217-
$processing_msg.hide();
207+
liveapi
208+
.send({ active_symbols: "brief" })
209+
.then(function (response) {
210+
refresh(results, response.active_symbols);
211+
})
212+
$processing_msg.hide();
218213
})
219214
.catch((error) => {
220215
$.growl.error({ message: error.message });

0 commit comments

Comments
 (0)