aaa.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. Datafeeds = {}, Datafeeds.UDFCompatibleDatafeed = function () {
  2. "use strict";
  3. this._configuration = void 0, this._symbolSearch = null, this._symbolsStorage = null, this._enableLogging = !1, this._initializationFinished = !1, this._callbacks = {}, this._binary_websockets = new BinaryWebsockets, this._symbolRequestResponseHandler = new SymbolReqRespHandler(this._binary_websockets), this._historicalOHLCReqResHandler = new HistoricalOHLCReqRespHandler(this._binary_websockets), this._ohlcStreamingReqResHandler = new OHLCStreamingReqResHandler(this._binary_websockets, this._symbolRequestResponseHandler), this._supported_resolutions = [], this._supported_resolutions.push("1"), this._supported_resolutions.push("2"), this._supported_resolutions.push("3"), this._supported_resolutions.push("5"), this._supported_resolutions.push("10"), this._supported_resolutions.push("15"), this._supported_resolutions.push("30"), this._supported_resolutions.push("60"), this._supported_resolutions.push("120"), this._supported_resolutions.push("240"), this._supported_resolutions.push("480"), this._supported_resolutions.push("D"), this.globalNotifier = GlobalNotifier.getInstance(), this._initialize()
  4. }, Datafeeds.UDFCompatibleDatafeed.prototype.defaultConfiguration = function () {
  5. "use strict";
  6. return {
  7. supports_search: !0,
  8. supports_group_request: !1,
  9. supported_resolutions: this._supported_resolutions,
  10. supports_marks: !0,
  11. exchanges: [],
  12. symbolsTypes: [{name: "Forex", value: "Forex"}, {name: "Indices", value: "Indices"}, {
  13. name: "OTC Stocks",
  14. value: "OTC Stocks"
  15. }, {name: "Commodities", value: "Commodities"}, {name: "Volatility Indices", value: "Volatility Indices"}]
  16. }
  17. }, Datafeeds.UDFCompatibleDatafeed.prototype.on = function (a, b) {
  18. "use strict";
  19. return this._callbacks.hasOwnProperty(a) || (this._callbacks[a] = []), this._callbacks[a].push(b), this
  20. }, Datafeeds.UDFCompatibleDatafeed.prototype._fireEvent = function (a, b) {
  21. "use strict";
  22. if (this._callbacks.hasOwnProperty(a)) {
  23. for (var c = this._callbacks[a], d = 0; d < c.length; ++d) c[d](b);
  24. this._callbacks[a] = []
  25. }
  26. }, Datafeeds.UDFCompatibleDatafeed.prototype.onInitialized = function () {
  27. "use strict";
  28. this._initializationFinished = !0, this._fireEvent("initialized")
  29. }, Datafeeds.UDFCompatibleDatafeed.prototype._logMessage = function (a) {
  30. "use strict";
  31. if (this._enableLogging) {
  32. new Date
  33. }
  34. }, Datafeeds.UDFCompatibleDatafeed.prototype._initialize = function () {
  35. "use strict";
  36. var a = this;
  37. this._binary_websockets.init().then(function (b) {
  38. b && a._symbolRequestResponseHandler.init().then(function (b, c) {
  39. var d = a.defaultConfiguration();
  40. d.symbolsTypes = [];
  41. var e = b;
  42. e.forEach(function (a) {
  43. d.symbolsTypes.push({name: a, value: a})
  44. }), a._setupWithConfiguration(d)
  45. })
  46. })
  47. }, Datafeeds.UDFCompatibleDatafeed.prototype.onReady = function (a) {
  48. "use strict";
  49. var b = this;
  50. setTimeout(function () {
  51. b._configuration ? a(b._configuration) : b.on("configuration_ready", function () {
  52. a(b._configuration)
  53. })
  54. }, 0)
  55. }, Datafeeds.UDFCompatibleDatafeed.prototype._setupWithConfiguration = function (a) {
  56. "use strict";
  57. this._configuration = a, a.exchanges || (a.exchanges = []);
  58. var b = a.supported_resolutions || a.supportedResolutions;
  59. a.supported_resolutions = b;
  60. var c = a.symbols_types || a.symbolsTypes;
  61. if (a.symbols_types = c, !a.supports_search && !a.supports_group_request) throw"Unsupported datafeed configuration. Must either support search, or support group request";
  62. a.supports_search || (this._symbolSearch = new Datafeeds.SymbolSearchComponent(this)), a.supports_group_request ? this._symbolsStorage = new Datafeeds.SymbolsStorage(this) : this.onInitialized(), this._fireEvent("configuration_ready"), this._logMessage("Initialized with " + JSON.stringify(a))
  63. }, Datafeeds.UDFCompatibleDatafeed.prototype._symbolMetadata = function (a) {
  64. "use strict";
  65. var b = {}, c = function () {
  66. return "Indices" === a
  67. }, d = function () {
  68. return "OTC Stocks" === a
  69. }, e = function () {
  70. return "Commodities" === a
  71. }, f = function () {
  72. return "Volatility Indices" === a
  73. }, g = function () {
  74. return "Forex" === a
  75. };
  76. if (a) {
  77. var h = 1e4, i = "2200-2159:123456";
  78. g() && (h = 1e5), (d() || c() || e()) && (h = 100), f() && (h = 1e4, i = "24x7"), b = {
  79. pricescale: h,
  80. minmov: 1,
  81. session: i
  82. }
  83. }
  84. return b
  85. }, Datafeeds.UDFCompatibleDatafeed.prototype.searchSymbolsByName = function (a, b, c, d) {
  86. "use strict";
  87. if (!this._configuration) return void d([]);
  88. if (this._configuration.supports_search) {
  89. var e = this, f = function (a) {
  90. var b = [];
  91. return $.each(e._symbolRequestResponseHandler._markets, function (d, f) {
  92. f.name === c && $.each(f.submarkets, function (d, g) {
  93. $.each(g.symbols, function (d, g) {
  94. f.name.indexOf(c) !== -1 && (g.symbol.indexOf(a) === -1 && g.symbol_display.toUpperCase().indexOf(a) === -1 || b.push({
  95. symbol: g.symbol,
  96. description: g.symbol_display,
  97. type: f.name,
  98. exchange: "",
  99. full_name: g.symbol,
  100. supported_resolutions: e._supported_resolutions
  101. }))
  102. })
  103. })
  104. }), b
  105. };
  106. d(f(a))
  107. }
  108. }, Datafeeds.UDFCompatibleDatafeed.prototype.searchSymbolsByNameOnly = function (a) {
  109. "use strict";
  110. if (!this._configuration) return [];
  111. if (this._configuration.supports_search) {
  112. var b = this, c = [];
  113. return $.each(b._symbolRequestResponseHandler._markets, function (d, e) {
  114. $.each(e.submarkets, function (d, f) {
  115. $.each(f.symbols, function (d, f) {
  116. f.symbol.indexOf(a) === -1 && f.symbol_display.toUpperCase().indexOf(a) === -1 || c.push({
  117. symbol: f.symbol,
  118. description: f.symbol_display,
  119. type: e.name,
  120. exchange: "",
  121. full_name: f.symbol,
  122. supported_resolutions: b._supported_resolutions
  123. })
  124. })
  125. })
  126. }), c
  127. }
  128. }, Datafeeds.UDFCompatibleDatafeed.prototype.resolveSymbol = function (a, b, c) {
  129. "use strict";
  130. var d = this;
  131. setTimeout(function () {
  132. function e(a) {
  133. var c = a;
  134. d.postProcessSymbolInfo && (c = d.postProcessSymbolInfo(c)), b(c)
  135. }
  136. if (!d._initializationFinished) return void d.on("initialized", function () {
  137. d.resolveSymbol(a, b, c)
  138. });
  139. if (d._configuration.supports_group_request) d._initializationFinished ? d._symbolsStorage.resolveSymbol(a, e, c) : d.on("initialized", function () {
  140. d._symbolsStorage.resolveSymbol(a, e, c)
  141. }); else {
  142. var f = !1;
  143. $.each(d._symbolRequestResponseHandler._markets, function (b, c) {
  144. return $.each(c.submarkets, function (b, g) {
  145. return $.each(g.symbols, function (b, g) {
  146. if (g.symbol.indexOf(a) !== -1) {
  147. var h = d._symbolMetadata(c.name), i = h.pricescale, j = h.minmov, k = h.session;
  148. return e({
  149. name: g.symbol,
  150. timezone: "UTC",
  151. has_intraday: !0,
  152. has_no_volume: !0,
  153. ticker: g.symbol,
  154. description: g.symbol_display,
  155. type: c.name,
  156. minmov: j,
  157. pricescale: i,
  158. supported_resolutions: d._supported_resolutions,
  159. session: k
  160. }), f = !0, !1
  161. }
  162. }), !f
  163. }), !f
  164. }), f || c("unknown_symbol")
  165. }
  166. }, 0)
  167. }, Datafeeds.UDFCompatibleDatafeed.prototype.getBars = function (a, b, c, d, e, f) {
  168. "use strict";
  169. this.globalNotifier.loadingNotification(), this._historicalOHLCReqResHandler.getBars(a, e, f)
  170. }, Datafeeds.UDFCompatibleDatafeed.prototype.subscribeBars = function (a, b, c, d) {
  171. "use strict";
  172. this._ohlcStreamingReqResHandler.subscribeBars(a, c, d)
  173. }, Datafeeds.UDFCompatibleDatafeed.prototype.unsubscribeBars = function (a) {
  174. "use strict";
  175. this._ohlcStreamingReqResHandler.unsubscribeBars(a)
  176. }, Datafeeds.UDFCompatibleDatafeed.prototype.getMarks = function (a, b, c, d, e) {
  177. "use strict"
  178. }, Datafeeds.UDFCompatibleDatafeed.prototype.calculateHistoryDepth = function (a, b, c) {
  179. "use strict"
  180. }, Datafeeds.UDFCompatibleDatafeed.prototype.getQuotes = function (a, b, c) {
  181. "use strict"
  182. }, Datafeeds.UDFCompatibleDatafeed.prototype.subscribeQuotes = function (a, b, c, d) {
  183. "use strict"
  184. }, Datafeeds.UDFCompatibleDatafeed.prototype.unsubscribeQuotes = function (a) {
  185. "use strict"
  186. }, Datafeeds.SymbolsStorage = function (a) {
  187. "use strict";
  188. this._datafeed = a, this._symbolsInfo = {}, this._symbolsList = [], this._requestFullSymbolsList()
  189. }, Datafeeds.SymbolsStorage.prototype._requestFullSymbolsList = function () {
  190. "use strict";
  191. var a = this, b = this._datafeed;
  192. $.each(a._symbolRequestResponseHandler._markets, function (c, d) {
  193. $.each(d.submarkets, function (c, e) {
  194. $.each(e.symbols, function (c, e) {
  195. var f = b._symbolMetadata(d.symbol), g = f.pricescale, h = f.minmov, i = f.session, j = {
  196. name: e.symbol,
  197. base_name: e.symbol,
  198. description: e.symbol_display,
  199. full_name: e.symbol,
  200. legs: [e.symbol],
  201. has_intraday: !0,
  202. has_no_volume: !0,
  203. listed_exchange: [],
  204. exchange: [""],
  205. minmov: h,
  206. pricescale: g,
  207. type: d.name,
  208. session: i,
  209. ticker: e.symbol,
  210. timezone: "UTC",
  211. supported_resolutions: a._supported_resolutions,
  212. has_daily: !0,
  213. has_fractional_volume: !1,
  214. has_weekly_and_monthly: !0,
  215. has_empty_bars: !1,
  216. volume_precision: 0
  217. };
  218. a._symbolsInfo[e.symbol] = a._symbolsInfo[e.display_name] = j, a._symbolsList.push(e.symbol)
  219. })
  220. })
  221. }), this._symbolsList.sort(), this._datafeed.onInitialized()
  222. }, Datafeeds.SymbolsStorage.prototype.resolveSymbol = function (a, b, c) {
  223. "use strict";
  224. this._symbolsInfo.hasOwnProperty(a) ? b(this._symbolsInfo[a]) : c("invalid symbol")
  225. }, Datafeeds.SymbolSearchComponent = function (a) {
  226. "use strict";
  227. this._datafeed = a
  228. }, Datafeeds.SymbolSearchComponent.prototype.searchSymbolsByName = function (a, b) {
  229. "use strict";
  230. if (!this._datafeed._symbolsStorage) throw"Cannot use local symbol search when no groups information is available";
  231. for (var c = this._datafeed._symbolsStorage, d = [], e = !a.ticker || 0 === a.ticker.length, f = 0; f < c._symbolsList.length; ++f) {
  232. var g = c._symbolsList[f], h = c._symbolsInfo[g];
  233. if (!(a.type && a.type.length > 0 && h.type !== a.type) && ((e || 0 === h.name.toUpperCase().indexOf(a.ticker)) && d.push({
  234. symbol: h.name,
  235. full_name: h.full_name,
  236. description: h.description,
  237. exchange: h.exchange,
  238. params: [],
  239. type: h.type,
  240. ticker: h.name,
  241. supported_resolutions: this._datafeed._supported_resolutions
  242. }), d.length >= b)) break
  243. }
  244. a.onResultReadyCallback(d)
  245. }, BinaryWebsockets = function () {
  246. "use strict";
  247. this.unresolved_promises = [], this.callbacks = [], this.ws = null, this._commonUtils = CommonUtils.getInstance(), this.globalNotifier = GlobalNotifier.getInstance(), this.reqIdCounter = 0
  248. }, BinaryWebsockets.prototype.init = function () {
  249. var a = this;
  250. return this.ws = new WebSocket("wss://frontend.binaryws.com/websockets/v3?l=en&app_id=2742"), this.ws.onopen = function (b) {
  251. (a.unresolved_promises.connectionOpenEvent || []).forEach(function (a) {
  252. a.resolve(!0)
  253. }), delete a.unresolved_promises.connectionOpenEvent
  254. }, this.ws.onclose = function (b) {
  255. setTimeout(function () {
  256. a.init().then(function (b) {
  257. b && (a.callbacks.ohlc || []).forEach(function (b) {
  258. if (b.requestObject) {
  259. var c = b.requestObject.req_id && Object.keys(b.requestObject).length > 1,
  260. d = !b.requestObject.req_id && Object.keys(b.requestObject).length > 0;
  261. (c || d) && a.ws.send(JSON.stringify(b.requestObject))
  262. }
  263. })
  264. })
  265. }, 1e3)
  266. }, this.ws.onerror = function (b) {
  267. a.globalNotifier.noConnectionNotification(), $.growl.error({message: "Connection error. Refresh page!"}), a.unresolved_promises = [], a.callbacks = []
  268. }, this.ws.onmessage = function (b) {
  269. var c = JSON.parse(b.data);
  270. (a.callbacks[c.msg_type] || []).forEach(function (a) {
  271. a._callback(c)
  272. });
  273. var d = c.req_id, e = a.unresolved_promises[d];
  274. e && (c.error ? (c.error.echo_req = c.echo_req, e.reject(c.error)) : e.resolve(c), delete a.unresolved_promises[d])
  275. }, new Promise(function (b, c) {
  276. a.unresolved_promises.connectionOpenEvent = a.unresolved_promises.connectionOpenEvent || [], a.unresolved_promises.connectionOpenEvent.push({
  277. resolve: b,
  278. reject: c
  279. })
  280. })
  281. }, BinaryWebsockets.prototype.send_request = function (a) {
  282. a.req_id = ++this.reqIdCounter;
  283. var b = this, c = a.req_id && Object.keys(a).length > 1;
  284. return c ? new Promise(function (c, d) {
  285. b.unresolved_promises[a.req_id] = {resolve: c, reject: d}, b.ws.send(JSON.stringify(a))
  286. }) : Promise.reject({code: "EmptyRequest", message: "Empty Request", echo_req: a})
  287. }, BinaryWebsockets.prototype.on = function (a, b) {
  288. (this.callbacks[a] = this.callbacks[a] || []).push(b)
  289. }, BinaryWebsockets.prototype.request_trading_times = function () {
  290. "use strict";
  291. return this.send_request({trading_times: "" + (new Date).toISOString().slice(0, 10)})
  292. }, BinaryWebsockets.prototype.request_stop_ohlc_streaming = function (a, b) {
  293. "use strict";
  294. var c = this;
  295. return this.callbacks.ohlc = this.callbacks.ohlc || [], this.callbacks.ohlc.forEach(function (a, d) {
  296. if (a.listenerID === b) return c.callbacks.ohlc.splice(d, 1), !1
  297. }), this.send_request({forget: a})
  298. }, BinaryWebsockets.prototype.request_ohlc_streaming = function (a, b, c) {
  299. "use strict";
  300. var d = {ticks_history: a, end: "latest", count: 1, style: "candles", granularity: b, subscribe: 1};
  301. this.ws.send(JSON.stringify(d)), c && (c.requestObject = d, this.on("ohlc", c))
  302. }, BinaryWebsockets.prototype.request_candles = function (a) {
  303. "use strict";
  304. var b = a.count || 5e3, c = a.granularity, d = null;
  305. if (a.startTime) d = moment.utc(a.startTime); else {
  306. d = moment.utc();
  307. var e = this._commonUtils.parseSuffixAndIntValue();
  308. d = d.subtract(b * this._commonUtils.totalSecondsInABar(e.suffix, e.intVal), "seconds")
  309. }
  310. var f = moment.utc();
  311. f = f.subtract(3, "years"), f = f.add(2, "days"), d.isBefore(f) && (d = f);
  312. var g = {ticks_history: a.symbol, end: "latest", style: "candles", start: d.unix(), count: b, granularity: c};
  313. return void 0 !== a.adjust_start_time && null !== a.adjust_start_time || (g.adjust_start_time = 1), this.send_request(g)
  314. };
  315. var CommonUtils = function () {
  316. function a() {
  317. }
  318. a.prototype.parseSuffixAndIntValue = function () {
  319. "use strict";
  320. var a = TradingView.actualResolution.toUpperCase().replace("D", "").replace("M", "").replace("W", ""),
  321. b = "" === a ? 1 : parseInt(a), c = TradingView.actualResolution.replace("" + b, "");
  322. switch (c) {
  323. case"":
  324. b < 60 ? c = "M" : (b /= 60, c = "H");
  325. break;
  326. case"W":
  327. b *= 7, c = "D";
  328. break;
  329. case"M":
  330. b *= 30, c = "D"
  331. }
  332. return {suffix: c, intVal: b}
  333. }, a.prototype.totalSecondsInABar = function (a, b) {
  334. "use strict";
  335. var c = 0;
  336. switch (a) {
  337. case"M":
  338. c = 60 * b;
  339. break;
  340. case"H":
  341. c = 60 * b * 60;
  342. break;
  343. case"D":
  344. c = 24 * b * 60 * 60
  345. }
  346. return c
  347. };
  348. var b = null;
  349. return {
  350. getInstance: function () {
  351. return null === b && (b = new a, b.constructor = null), b
  352. }
  353. }
  354. }(), GlobalNotifier = function () {
  355. function a() {
  356. this.handleEvent = function (a) {
  357. var b = $(document).find("iframe").contents().find(".chart-status-picture");
  358. b.removeClass(b.attr("class")).addClass("chart-status-picture " + a)
  359. }
  360. }
  361. a.prototype.delayedNotification = function () {
  362. this.handleEvent("delayed-feed")
  363. }, a.prototype.realtimeNotification = function () {
  364. this.handleEvent("realtime-feed")
  365. }, a.prototype.loadingNotification = function () {
  366. this.handleEvent("loading")
  367. }, a.prototype.noConnectionNotification = function () {
  368. this.handleEvent("no-connection")
  369. };
  370. var b = null;
  371. return {
  372. getInstance: function () {
  373. return null === b && (b = new a, b.constructor = null), b
  374. }
  375. }
  376. }();
  377. HistoricalOHLCReqRespHandler = function (a) {
  378. this._binary_websockets = a, this._commonUtils = CommonUtils.getInstance()
  379. }, HistoricalOHLCReqRespHandler.prototype.getBars = function (a, b, c) {
  380. "use strict";
  381. var d = this._commonUtils.parseSuffixAndIntValue(), e = d.suffix, f = d.intVal,
  382. g = this._commonUtils.totalSecondsInABar(e, f);
  383. this._binary_websockets.request_candles({symbol: a.ticker, granularity: g}).catch(function () {
  384. c()
  385. }).then(function (a) {
  386. if (a.candles) {
  387. var c = [];
  388. a.candles.forEach(function (a) {
  389. var b = 1e3 * parseInt(a.epoch), d = parseFloat(a.open), e = parseFloat(a.high), f = parseFloat(a.low),
  390. g = parseFloat(a.close);
  391. c.push({time: b, open: d, high: e, low: f, close: g})
  392. }), b(c)
  393. }
  394. })
  395. }, OHLCStreamingReqResHandler = function (a, b) {
  396. this._binary_websockets = a, this._streamingMap = {}, this._commonUtils = CommonUtils.getInstance(), this._symbolRequestResponseHandler = b, this.globalNotifier = GlobalNotifier.getInstance()
  397. }, OHLCStreamingReqResHandler.prototype.subscribeBars = function (a, b, c) {
  398. var d = this, e = this._commonUtils.parseSuffixAndIntValue(),
  399. f = this._commonUtils.totalSecondsInABar(e.suffix, e.intVal);
  400. this._streamingMap[c] = {
  401. symbol: a.ticker,
  402. resolution: TradingView.actualResolution,
  403. timerHandler: null,
  404. granularity: f,
  405. lastBar: null,
  406. timerCallback: function () {
  407. d.globalNotifier.delayedNotification();
  408. var a = this;
  409. d._binary_websockets.request_candles({
  410. symbol: a.symbol,
  411. granularity: a.granularity,
  412. startTime: a.lastBar ? a.lastBar.time : null,
  413. count: a.lastBar ? null : 1,
  414. adjust_start_time: a.lastBar ? 0 : null
  415. }).catch(function (a) {
  416. }).then(function (c) {
  417. c && c.candles && c.candles.forEach(function (c) {
  418. var d = 1e3 * parseInt(c.epoch), e = parseFloat(c.open), f = parseFloat(c.high), g = parseFloat(c.low),
  419. h = parseFloat(c.close), i = {time: d, open: e, high: f, low: g, close: h};
  420. (!a.lastBar || i.time > a.lastBar.time) && (a.lastBar = i), b(i)
  421. })
  422. })
  423. },
  424. streamingCallback: function (a) {
  425. d.globalNotifier.realtimeNotification();
  426. var e = d._streamingMap[c];
  427. if (e && a.ohlc.symbol === e.symbol && a.ohlc.granularity === e.granularity) {
  428. e.server_request_id = a.ohlc.id;
  429. var f = 1e3 * parseInt(a.ohlc.open_time), g = parseFloat(a.ohlc.open), h = parseFloat(a.ohlc.high),
  430. i = parseFloat(a.ohlc.low), j = parseFloat(a.ohlc.close);
  431. f && g && h && i && j && (this.lastBar = {time: f, open: g, high: h, low: i, close: j}, b(this.lastBar))
  432. }
  433. }
  434. };
  435. var g = this._symbolRequestResponseHandler.findInstrumentObjectBySymbol(a.ticker);
  436. if (g) if (g.delay_amount > 0) {
  437. var h = this._streamingMap[c];
  438. h.timerHandler = setInterval(function () {
  439. h.timerCallback.call(h)
  440. }, 6e4)
  441. } else this._binary_websockets.request_ohlc_streaming(a.ticker, f, {
  442. listenerID: c,
  443. _callback: this._streamingMap[c].streamingCallback
  444. })
  445. }, OHLCStreamingReqResHandler.prototype.unsubscribeBars = function (a) {
  446. var b = this._streamingMap[a];
  447. b.timerHandler ? clearInterval(b.timerHandler) : this._binary_websockets.request_stop_ohlc_streaming(b.server_request_id, a).then(function () {
  448. }).catch(function () {
  449. }), delete this._streamingMap[a]
  450. }, SymbolReqRespHandler = function (a) {
  451. this._binary_websockets = a
  452. }, SymbolReqRespHandler.prototype.init = function () {
  453. "use strict";
  454. this._markets = null, this._symbolTypes = null;
  455. var a = this;
  456. return new Promise(function (b, c) {
  457. a._binary_websockets.request_trading_times().then(function (c) {
  458. a.process(c), b(a._symbolTypes, a._markets)
  459. }).catch(function (a) {
  460. "undefined" != typeof trackJs && trackJs.track("Unexpected response from server, [request_trading_times] Response error " + JSON.stringify(a))
  461. })
  462. })
  463. }, SymbolReqRespHandler.prototype.process = function (a) {
  464. "use strict";
  465. this._markets = [], this._symbolTypes = [];
  466. for (var b = 0; b < a.trading_times.markets.length; b++) {
  467. var c = a.trading_times.markets[b];
  468. this._symbolTypes.push(c.name);
  469. for (var d = {name: c.name, submarkets: []}, e = 0; e < c.submarkets.length; ++e) {
  470. for (var f = c.submarkets[e], g = {name: f.name, symbols: []}, h = 0; h < f.symbols.length; h++) {
  471. var i = f.symbols[h];
  472. i.feed_license && "chartonly" === i.feed_license || g.symbols.push({
  473. symbol: i.symbol,
  474. symbol_display: i.name,
  475. feed_license: i.feed_license || "realtime",
  476. delay_amount: i.delay_amount || 0
  477. })
  478. }
  479. d.submarkets.push(g)
  480. }
  481. this._markets.push(d)
  482. }
  483. }, SymbolReqRespHandler.prototype.findInstrumentObjectBySymbol = function (a) {
  484. var b = null, c = !0;
  485. return this._markets.forEach(function (d) {
  486. return d.submarkets.forEach(function (d) {
  487. return d.symbols.forEach(function (d) {
  488. return d.symbol === a && (b = $.extend(!0, {}, d), c = !1), c
  489. }), c
  490. }), c
  491. }), b
  492. }, function (a) {
  493. a.fn.bindFirst = function (b, c, d) {
  494. var e = b.indexOf("."), f = e > 0 ? b.substring(e) : "";
  495. return b = e > 0 ? b.substring(0, e) : b, d = void 0 === d ? c : d, c = "function" == typeof c ? {} : c, this.each(function () {
  496. var e = a(this), g = this["on" + b];
  497. g && (e.bind(b, function (a) {
  498. return g(a.originalEvent)
  499. }), this["on" + b] = null), e.bind(b + f, c, d);
  500. var h = e.data("events") || a._data(e[0], "events"), i = h[b], j = i.pop();
  501. i.unshift(j)
  502. })
  503. }, a.isEnterKeyPressed = function (a) {
  504. var b = a.keyCode ? a.keyCode : a.which;
  505. return "13" == b
  506. }
  507. }(jQuery);