retesere20

sample-bundle-tv

Nov 4th, 2019
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !function(e, t) {
  2. "object" == typeof exports && "undefined" != typeof module ? t(exports) : "function" == typeof define && define.amd ? define(["exports"], t) : t(e.Datafeeds = {})
  3. }(this, function(e) {
  4. "use strict";
  5. var t = Object.setPrototypeOf || {
  6. __proto__: []
  7. }instanceof Array && function(e, t) {
  8. e.__proto__ = t
  9. }
  10. || function(e, t) {
  11. for (var r in t)
  12. t.hasOwnProperty(r) && (e[r] = t[r])
  13. }
  14. ;
  15. var r = !1;
  16. function n(e) {
  17. if (r) {
  18. var t = new Date;
  19. console.log(t.toLocaleTimeString() + "." + t.getMilliseconds() + "> " + e)
  20. }
  21. }
  22. function c(e) {
  23. return void 0 === e ? "" : "string" == typeof e ? e : e.message
  24. }
  25. var i = (s.prototype.getBars = function(e, t, r, s) {
  26. var o = this
  27. , i = {
  28. symbol: e.ticker || "",
  29. resolution: t,
  30. from: r,
  31. to: s
  32. };
  33. return new Promise(function(a, u) {
  34. o._requester.sendRequest(o._datafeedUrl, "history", i).then(function(e) {
  35. if ("ok" === e.s || "no_data" === e.s) {
  36. var t = []
  37. , r = {
  38. noData: !1
  39. };
  40. if ("no_data" === e.s)
  41. r.noData = !0,
  42. r.nextTime = e.nextTime;
  43. else
  44. for (var s = void 0 !== e.v, o = void 0 !== e.o, i = 0; i < e.t.length; ++i) {
  45. var n = {
  46. time: 1e3 * e.t[i],
  47. close: Number(e.c[i]),
  48. open: Number(e.c[i]),
  49. high: Number(e.c[i]),
  50. low: Number(e.c[i])
  51. };
  52. o && (n.open = Number(e.o[i]),
  53. n.high = Number(e.h[i]),
  54. n.low = Number(e.l[i])),
  55. s && (n.volume = Number(e.v[i])),
  56. t.push(n)
  57. }
  58. a({
  59. bars: t,
  60. meta: r
  61. })
  62. } else
  63. u(e.errmsg)
  64. }).catch(function(e) {
  65. var t = c(e);
  66. console.warn("HistoryProvider: getBars() failed, error=" + t),
  67. u(t)
  68. })
  69. }
  70. )
  71. }
  72. ,
  73. s);
  74. function s(e, t) {
  75. this._datafeedUrl = e,
  76. this._requester = t
  77. }
  78. var a = (o.prototype.subscribeBars = function(e, t, r, s) {
  79. this._subscribers.hasOwnProperty(s) ? n("DataPulseProvider: already has subscriber with id=" + s) : (this._subscribers[s] = {
  80. lastBarTime: null,
  81. listener: r,
  82. resolution: t,
  83. symbolInfo: e
  84. },
  85. n("DataPulseProvider: subscribed for #" + s + " - {" + e.name + ", " + t + "}"))
  86. }
  87. ,
  88. o.prototype.unsubscribeBars = function(e) {
  89. delete this._subscribers[e],
  90. n("DataPulseProvider: unsubscribed for #" + e)
  91. }
  92. ,
  93. o.prototype._updateData = function() {
  94. var r = this;
  95. if (!(0 < this._requestsPending)) {
  96. this._requestsPending = 0;
  97. var e = function(t) {
  98. s._requestsPending += 1,
  99. s._updateDataForSubscriber(t).then(function() {
  100. r._requestsPending -= 1,
  101. n("DataPulseProvider: data for #" + t + " updated successfully, pending=" + r._requestsPending)
  102. }).catch(function(e) {
  103. r._requestsPending -= 1,
  104. n("DataPulseProvider: data for #" + t + " updated with error=" + c(e) + ", pending=" + r._requestsPending)
  105. })
  106. }
  107. , s = this;
  108. for (var t in this._subscribers)
  109. e(t)
  110. }
  111. }
  112. ,
  113. o.prototype._updateDataForSubscriber = function(t) {
  114. var r = this
  115. , e = this._subscribers[t]
  116. , s = parseInt((Date.now() / 1e3).toString())
  117. , o = s - function(e, t) {
  118. return 24 * ("D" === e || "1D" === e ? t : "M" === e || "1M" === e ? 31 * t : "W" === e || "1W" === e ? 7 * t : t * parseInt(e) / 1440) * 60 * 60
  119. }(e.resolution, 10);
  120. return this._historyProvider.getBars(e.symbolInfo, e.resolution, o, s).then(function(e) {
  121. r._onSubscriberDataReceived(t, e)
  122. })
  123. }
  124. ,
  125. o.prototype._onSubscriberDataReceived = function(e, t) {
  126. if (this._subscribers.hasOwnProperty(e)) {
  127. var r = t.bars;
  128. if (0 !== r.length) {
  129. var s = r[r.length - 1]
  130. , o = this._subscribers[e];
  131. if (!(null !== o.lastBarTime && s.time < o.lastBarTime)) {
  132. if (null !== o.lastBarTime && s.time > o.lastBarTime) {
  133. if (r.length < 2)
  134. throw new Error("Not enough bars in history for proper pulse update. Need at least 2.");
  135. var i = r[r.length - 2];
  136. o.listener(i)
  137. }
  138. o.lastBarTime = s.time,
  139. o.listener(s)
  140. }
  141. }
  142. } else
  143. n("DataPulseProvider: Data comes for already unsubscribed subscription #" + e)
  144. }
  145. ,
  146. o);
  147. function o(e, t) {
  148. this._subscribers = {},
  149. this._requestsPending = 0,
  150. this._historyProvider = e,
  151. setInterval(this._updateData.bind(this), t)
  152. }
  153. var u = (l.prototype.subscribeQuotes = function(e, t, r, s) {
  154. this._subscribers[s] = {
  155. symbols: e,
  156. fastSymbols: t,
  157. listener: r
  158. },
  159. n("QuotesPulseProvider: subscribed quotes with #" + s)
  160. }
  161. ,
  162. l.prototype.unsubscribeQuotes = function(e) {
  163. delete this._subscribers[e],
  164. n("QuotesPulseProvider: unsubscribed quotes with #" + e)
  165. }
  166. ,
  167. l.prototype._updateQuotes = function(s) {
  168. var o = this;
  169. if (!(0 < this._requestsPending)) {
  170. var e = function(t) {
  171. i._requestsPending++;
  172. var r = i._subscribers[t];
  173. i._quotesProvider.getQuotes(1 === s ? r.fastSymbols : r.symbols).then(function(e) {
  174. o._requestsPending--,
  175. o._subscribers.hasOwnProperty(t) && (r.listener(e),
  176. n("QuotesPulseProvider: data for #" + t + " (" + s + ") updated successfully, pending=" + o._requestsPending))
  177. }).catch(function(e) {
  178. o._requestsPending--,
  179. n("QuotesPulseProvider: data for #" + t + " (" + s + ") updated with error=" + c(e) + ", pending=" + o._requestsPending)
  180. })
  181. }
  182. , i = this;
  183. for (var t in this._subscribers)
  184. e(t)
  185. }
  186. }
  187. ,
  188. l);
  189. function l(e) {
  190. this._subscribers = {},
  191. this._requestsPending = 0,
  192. this._quotesProvider = e,
  193. setInterval(this._updateQuotes.bind(this, 1), 1e4),
  194. setInterval(this._updateQuotes.bind(this, 0), 6e4)
  195. }
  196. function d(e, t, r, s) {
  197. var o = e[t];
  198. return !Array.isArray(o) || s && !Array.isArray(o[0]) ? o : o[r]
  199. }
  200. var h = (f.prototype.resolveSymbol = function(t) {
  201. var r = this;
  202. return this._readyPromise.then(function() {
  203. var e = r._symbolsInfo[t];
  204. return void 0 === e ? Promise.reject("invalid symbol") : Promise.resolve(e)
  205. })
  206. }
  207. ,
  208. f.prototype.searchSymbols = function(a, u, c, o) {
  209. var l = this;
  210. return this._readyPromise.then(function() {
  211. var i = []
  212. , n = 0 === a.length;
  213. a = a.toUpperCase();
  214. for (var e = function(e) {
  215. var t = l._symbolsInfo[e];
  216. if (void 0 === t)
  217. return "continue";
  218. if (0 < c.length && t.type !== c)
  219. return "continue";
  220. if (u && 0 < u.length && t.exchange !== u)
  221. return "continue";
  222. var r = t.name.toUpperCase().indexOf(a)
  223. , s = t.description.toUpperCase().indexOf(a);
  224. if ((n || 0 <= r || 0 <= s) && !i.some(function(e) {
  225. return e.symbolInfo === t
  226. })) {
  227. var o = 0 <= r ? r : 8e3 + s;
  228. i.push({
  229. symbolInfo: t,
  230. weight: o
  231. })
  232. }
  233. }, t = 0, r = l._symbolsList; t < r.length; t++)
  234. e(r[t]);
  235. var s = i.sort(function(e, t) {
  236. return e.weight - t.weight
  237. }).slice(0, o).map(function(e) {
  238. var t = e.symbolInfo;
  239. return {
  240. symbol: t.name,
  241. full_name: t.full_name,
  242. description: t.description,
  243. exchange: t.exchange,
  244. params: [],
  245. type: t.type,
  246. ticker: t.name
  247. }
  248. });
  249. return Promise.resolve(s)
  250. })
  251. }
  252. ,
  253. f.prototype._init = function() {
  254. for (var e = this, t = [], r = {}, s = 0, o = this._exchangesList; s < o.length; s++) {
  255. var i = o[s];
  256. r[i] || (r[i] = !0,
  257. t.push(this._requestExchangeData(i)))
  258. }
  259. return Promise.all(t).then(function() {
  260. e._symbolsList.sort(),
  261. n("SymbolsStorage: All exchanges data loaded")
  262. })
  263. }
  264. ,
  265. f.prototype._requestExchangeData = function(s) {
  266. var o = this;
  267. return new Promise(function(t, r) {
  268. o._requester.sendRequest(o._datafeedUrl, "symbol_info", {
  269. group: s
  270. }).then(function(e) {
  271. try {
  272. o._onExchangeDataReceived(s, e)
  273. } catch (e) {
  274. return void r(e)
  275. }
  276. t()
  277. }).catch(function(e) {
  278. n("SymbolsStorage: Request data for exchange '" + s + "' failed, reason=" + c(e)),
  279. t()
  280. })
  281. }
  282. )
  283. }
  284. ,
  285. f.prototype._onExchangeDataReceived = function(t, r) {
  286. var e = this
  287. , s = 0;
  288. try {
  289. for (var o = r.symbol.length, i = void 0 !== r.ticker; s < o; ++s) {
  290. var n = r.symbol[s]
  291. , a = d(r, "exchange-listed", s)
  292. , u = d(r, "exchange-traded", s)
  293. , c = u + ":" + n
  294. , l = i ? d(r, "ticker", s) : n
  295. , h = {
  296. ticker: l,
  297. name: n,
  298. base_name: [a + ":" + n],
  299. full_name: c,
  300. listed_exchange: a,
  301. exchange: u,
  302. description: d(r, "description", s),
  303. has_intraday: p(d(r, "has-intraday", s), !1),
  304. has_no_volume: p(d(r, "has-no-volume", s), !1),
  305. minmov: d(r, "minmovement", s) || d(r, "minmov", s) || 0,
  306. minmove2: d(r, "minmove2", s) || d(r, "minmov2", s),
  307. fractional: d(r, "fractional", s),
  308. pricescale: d(r, "pricescale", s),
  309. type: d(r, "type", s),
  310. session: d(r, "session-regular", s),
  311. timezone: d(r, "timezone", s),
  312. supported_resolutions: p(d(r, "supported-resolutions", s, !0), e._datafeedSupportedResolutions),
  313. force_session_rebuild: d(r, "force-session-rebuild", s),
  314. has_daily: p(d(r, "has-daily", s), !0),
  315. intraday_multipliers: p(d(r, "intraday-multipliers", s, !0), ["1", "5", "15", "30", "60"]),
  316. has_weekly_and_monthly: d(r, "has-weekly-and-monthly", s),
  317. has_empty_bars: d(r, "has-empty-bars", s),
  318. volume_precision: p(d(r, "volume-precision", s), 0)
  319. };
  320. e._symbolsInfo[l] = h,
  321. e._symbolsInfo[n] = h,
  322. e._symbolsInfo[c] = h,
  323. e._symbolsList.push(n)
  324. }
  325. } catch (e) {
  326. throw new Error("SymbolsStorage: API error when processing exchange " + t + " symbol #" + s + " (" + r.symbol[s] + "): " + e.message)
  327. }
  328. }
  329. ,
  330. f);
  331. function f(e, t, r) {
  332. this._exchangesList = ["NYSE", "FOREX", "AMEX"],
  333. this._symbolsInfo = {},
  334. this._symbolsList = [],
  335. this._datafeedUrl = e,
  336. this._datafeedSupportedResolutions = t,
  337. this._requester = r,
  338. this._readyPromise = this._init(),
  339. this._readyPromise.catch(function(e) {
  340. console.error("SymbolsStorage: Cannot init, error=" + e.toString())
  341. })
  342. }
  343. function p(e, t) {
  344. return void 0 !== e ? e : t
  345. }
  346. function _(e, t, r) {
  347. var s = e[t];
  348. return Array.isArray(s) ? s[r] : s
  349. }
  350. var m = (
  351. b.prototype.onReady = function(e) {
  352. var t = this;
  353. this._configurationReadyPromise.then(function() {
  354. e(t._configuration)
  355. })
  356. }
  357. ,
  358. b.prototype.getQuotes = function(e, t, r) {
  359. this._quotesProvider.getQuotes(e).then(t).catch(r)
  360. }
  361. ,
  362. b.prototype.subscribeQuotes = function(e, t, r, s) {
  363. this._quotesPulseProvider.subscribeQuotes(e, t, r, s)
  364. }
  365. ,
  366. b.prototype.unsubscribeQuotes = function(e) {
  367. this._quotesPulseProvider.unsubscribeQuotes(e)
  368. }
  369. ,
  370. b.prototype.calculateHistoryDepth = function(e, t, r) {}
  371. ,
  372. b.prototype.getMarks = function(e, t, r, s, o) {
  373. if (this._configuration.supports_marks) {
  374. var i = {
  375. symbol: e.ticker || "",
  376. from: t,
  377. to: r,
  378. resolution: o
  379. };
  380. this._send("marks", i).then(function(e) {
  381. if (!Array.isArray(e)) {
  382. for (var t = [], r = 0; r < e.id.length; ++r)
  383. t.push({
  384. id: _(e, "id", r),
  385. time: _(e, "time", r),
  386. color: _(e, "color", r),
  387. text: _(e, "text", r),
  388. label: _(e, "label", r),
  389. labelFontColor: _(e, "labelFontColor", r),
  390. minSize: _(e, "minSize", r)
  391. });
  392. e = t
  393. }
  394. s(e)
  395. }).catch(function(e) {
  396. n("UdfCompatibleDatafeed: Request marks failed: " + c(e)),
  397. s([])
  398. })
  399. }
  400. }
  401. ,
  402. b.prototype.getTimescaleMarks = function(e, t, r, s, o) {
  403. if (this._configuration.supports_timescale_marks) {
  404. var i = {
  405. symbol: e.ticker || "",
  406. from: t,
  407. to: r,
  408. resolution: o
  409. };
  410. this._send("timescale_marks", i).then(function(e) {
  411. if (!Array.isArray(e)) {
  412. for (var t = [], r = 0; r < e.id.length; ++r)
  413. t.push({
  414. id: _(e, "id", r),
  415. time: _(e, "time", r),
  416. color: _(e, "color", r),
  417. label: _(e, "label", r),
  418. tooltip: _(e, "tooltip", r)
  419. });
  420. e = t
  421. }
  422. s(e)
  423. }).catch(function(e) {
  424. n("UdfCompatibleDatafeed: Request timescale marks failed: " + c(e)),
  425. s([])
  426. })
  427. }
  428. }
  429. ,
  430. b.prototype.getServerTime = function(r) {
  431. this._configuration.supports_time && this._send("time").then(function(e) {
  432. var t = parseInt(e);
  433. isNaN(t) || r(t)
  434. }).catch(function(e) {
  435. n("UdfCompatibleDatafeed: Fail to load server time, error=" + c(e))
  436. })
  437. }
  438. ,
  439. b.prototype.searchSymbols = function(t, e, r, s) {
  440. if (this._configuration.supports_search) {
  441. var o = {
  442. limit: 30,
  443. query: t.toUpperCase(),
  444. type: r,
  445. exchange: e
  446. };
  447. this._send("search", o).then(function(e) {
  448. if (void 0 !== e.s)
  449. return n("UdfCompatibleDatafeed: search symbols error=" + e.errmsg),
  450. void s([]);
  451. s(e)
  452. }).catch(function(e) {
  453. n("UdfCompatibleDatafeed: Search symbols for '" + t + "' failed. Error=" + c(e)),
  454. s([])
  455. })
  456. } else {
  457. if (null === this._symbolsStorage)
  458. throw new Error("UdfCompatibleDatafeed: inconsistent configuration (symbols storage)");
  459. this._symbolsStorage.searchSymbols(t, e, r, 30).then(s).catch(s.bind(null, []))
  460. }
  461. }
  462. ,
  463. b.prototype.resolveSymbol = function(e, t, r) {
  464. n("Resolve requested");
  465. var s = Date.now();
  466. function o(e) {
  467. n("Symbol resolved: " + (Date.now() - s) + "ms"),
  468. t(e)
  469. }
  470. if (this._configuration.supports_group_request) {
  471. if (null === this._symbolsStorage)
  472. throw new Error("UdfCompatibleDatafeed: inconsistent configuration (symbols storage)");
  473. this._symbolsStorage.resolveSymbol(e).then(o).catch(r)
  474. } else {
  475. var i = {
  476. symbol: e
  477. };
  478. this._send("symbols", i).then(function(e) {
  479. void 0 !== e.s ? r("unknown_symbol") : o(e)
  480. }).catch(function(e) {
  481. n("UdfCompatibleDatafeed: Error resolving symbol: " + c(e)),
  482. r("unknown_symbol")
  483. })
  484. }
  485. }
  486. ,
  487. b.prototype.getBars = function(e, t, r, s, o, i) {
  488. this._historyProvider.getBars(e, t, r, s).then(function(e) {
  489. o(e.bars, e.meta)
  490. }).catch(i)
  491. }
  492. ,
  493. b.prototype.subscribeBars = function(e, t, r, s, o) {
  494. this._dataPulseProvider.subscribeBars(e, t, r, s)
  495. }
  496. ,
  497. b.prototype.unsubscribeBars = function(e) {
  498. this._dataPulseProvider.unsubscribeBars(e)
  499. }
  500. ,
  501. b.prototype._requestConfiguration = function() {
  502. return this._send("config").catch(function(e) {
  503. return n("UdfCompatibleDatafeed: Cannot get datafeed configuration - use default, error=" + c(e)),
  504. null
  505. })
  506. }
  507. ,
  508. b.prototype._send = function(e, t) {
  509. return this._requester.sendRequest(this._datafeedURL, e, t)
  510. }
  511. ,
  512. b.prototype._setupWithConfiguration = function(e) {
  513. if (void 0 === (this._configuration = e).exchanges && (e.exchanges = []),
  514. !e.supports_search && !e.supports_group_request)
  515. throw new Error("Unsupported datafeed configuration. Must either support search, or support group request");
  516. !e.supports_group_request && e.supports_search || (this._symbolsStorage = new h(this._datafeedURL,e.supported_resolutions || [],this._requester)),
  517. n("UdfCompatibleDatafeed: Initialized with " + JSON.stringify(e))
  518. }
  519. ,
  520. b);
  521. function b(e, t, r, s) {
  522. void 0 === s && (s = 1e4);
  523. var o = this;
  524. this._configuration = {
  525. supports_search: !1,
  526. supports_group_request: !0,
  527. supported_resolutions: ["1", "5", "15", "30", "60", "1D", "1W", "1M"],
  528. supports_marks: !1,
  529. supports_timescale_marks: !1
  530. },
  531. this._symbolsStorage = null,
  532. this._datafeedURL = e,
  533. this._requester = r,
  534. this._historyProvider = new i(e,this._requester),
  535. this._quotesProvider = t,
  536. this._dataPulseProvider = new a(this._historyProvider,s),
  537. this._quotesPulseProvider = new u(this._quotesProvider),
  538. this._configurationReadyPromise = this._requestConfiguration().then(function(e) {
  539. null === e && (e = {
  540. supports_search: !1,
  541. supports_group_request: !0,
  542. supported_resolutions: ["1", "5", "15", "30", "60", "1D", "1W", "1M"],
  543. supports_marks: !1,
  544. supports_timescale_marks: !1
  545. }),
  546. o._setupWithConfiguration(e)
  547. })
  548. }
  549. var y = (v.prototype.getQuotes = function(e) {
  550. var s = this;
  551. return new Promise(function(t, r) {
  552. s._requester.sendRequest(s._datafeedUrl, "quotes", {
  553. symbols: e
  554. }).then(function(e) {
  555. "ok" === e.s ? t(e.d) : r(e.errmsg)
  556. }).catch(function(e) {
  557. var t = c(e);
  558. n("QuotesProvider: getQuotes failed, error=" + t),
  559. r("network error: " + t)
  560. })
  561. }
  562. )
  563. }
  564. ,
  565. v);
  566. function v(e, t) {
  567. this._datafeedUrl = e,
  568. this._requester = t
  569. }
  570. var g = (P.prototype.sendRequest = function(e, t, r) {
  571. if (void 0 !== r) {
  572. var s = Object.keys(r);
  573. 0 !== s.length && (t += "?"),
  574. t += s.map(function(e) {
  575. return encodeURIComponent(e) + "=" + encodeURIComponent(r[e].toString())
  576. }).join("&")
  577. }
  578. n("New request: " + t);
  579. var o = {
  580. credentials: "same-origin"
  581. };
  582. return void 0 !== this._headers && (o.headers = this._headers),
  583. fetch(e + "/" + t, o).then(function(e) {
  584. return e.text()
  585. }).then(function(e) {
  586. return JSON.parse(e)
  587. })
  588. }
  589. ,
  590. P);
  591. function P(e) {
  592. e && (this._headers = e)
  593. }
  594. var q, w, D, S = (t(q = k, w = D = m),
  595. void (q.prototype = null === w ? Object.create(w) : (x.prototype = w.prototype,
  596. new x)),
  597. k);
  598. function x() {
  599. this.constructor = q
  600. }
  601. function k(e, t) {
  602. void 0 === t && (t = 1e4);
  603. var r = new g
  604. , s = new y(e,r);
  605. return D.call(this, e, s, r, t) || this
  606. }
  607. e.UDFCompatibleDatafeed = S,
  608. Object.defineProperty(e, "__esModule", {
  609. value: !0
  610. })
  611. });
RAW Paste Data