{"version":3,"sources":["inoMsTechnicalChart.js"],"names":["inovestor","ms","technicalChart","config","suggestCountryPreference","suggestApiRelativeUrl","quoteRelativeUrl","dailyStockHistoricalRelativeUrl","intradayStockHistoricalRelativeUrl","$","apiClient","apiDataCache","makeApiRequestAsync","apiRelativeUrl","core","ajaxApi","type","contentType","error","Error","status","then","data","isNullOrUndefined","requestStatus","this","getSuggestionsAsync","userInput","stringFormat","term","countryPreference","when","getStockQuoteAsync","symbol","getStockHistoricalDataAsync","cacheKey","let","date","Date","setFullYear","getFullYear","setDate","getDate","startDate","getMonth","endDate","response","getStockIntradayDataAsync","libRef","jQuery","dataFeed","configurationData","supported_resolutions","exchanges","symbols_types","onReady","callback","setTimeout","searchSymbols","exchange","symbolType","onResultReadyCallback","symbols","forEach","suggestion","category","push","ticker","full_name","description","currentLanguage","nameFr","nameEn","resolveSymbol","symbolName","onSymbolResolvedCallback","onResolveErrorCallback","length","symbolInfo","quote","name","replace","session","timezone","minmov","pricescale","has_intraday","intraday_multipliers","visible_plots_set","has_weekly_and_monthly","volume_precision","data_status","fail","getBars","resolution","periodParams","onHistoryCallback","onErrorCallback","to","countBack","apiResponse","historicalDatas","noData","bars","dateFieldIndex","fields","indexOf","openFieldIndex","highFieldIndex","lowFieldIndex","closeFieldIndex","volumeFieldIndex","count","i","datas","bar","unixTimestamp","getTime","time","low","high","open","close","volume","reverse","subscribeBars","onRealtimeCallback","subscribeUID","onResetCacheNeededCallback","unsubscribeBars","subscriberUID","defaults","interval","datafeed","symbol_search_request_delay","fullscreen","autosize","disabled_features","time_frames","text"],"mappings":"AAAA,CAAA,SAAAA,GACAA,EAAAC,GAAAC,eAAAF,EAAAC,GAAAC,gBAAA,GAEAF,EAAAC,GAAAC,eAAAC,OAAA,CACAC,yBAAA,KACAC,sBAAA,iJACAC,iBAAA,2BACAC,gCAAA,qFACAC,mCAAA,+CACA,CACA,EAAAR,SAAA,EAGA,SAAAS,EAAAT,GA8EAA,EAAAC,GAAAC,eAAAQ,U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AA,KAAA7C,WAAA,KAAAzB,YAAA,SAAA,EACA,CAAAsE,KAAA,MAAA7C,WAAA,KAAAzB,YAAA,UAAA,EAEA,CAEA,GAAArE,UAAAC,GAAA+C,OAAAC,OAAAjD,UAAA","file":"../inoMsTechnicalChart.min.js","sourcesContent":["; (function (inovestor, undefined) {\n inovestor.ms.technicalChart = inovestor.ms.technicalChart || {};\n\n inovestor.ms.technicalChart.config = {\n suggestCountryPreference: 'ca',\n suggestApiRelativeUrl: 'search/suggest?q={term}&maxResult=15&searchedFields=symbol,nameen&requestedFields=exchange,symbol,nameen&countryPreference={countryPreference}',\n quoteRelativeUrl: 'quotes?symbols={symbol},',\n dailyStockHistoricalRelativeUrl: 'technicalChartDatas/daily?symbols={symbol}&startDate={startDate}&endDate={endDate}',\n intradayStockHistoricalRelativeUrl: 'technicalChartDatas/intraday?symbols={symbol}',\n };\n})(inovestor);\n\n\n; (function ($, inovestor, undefined) {\n function ApiClient() {\n const apiDataCache = {}\n\n function makeApiRequestAsync(apiRelativeUrl) {\n var options = { type: 'GET', contentType: 'application/json', error: function (error) { throw new Error(`Market Insights request error: ${error.status}`) } };\n\n return inovestor.ms.core.ajaxApi(apiRelativeUrl, options).then(function (data) {\n if (!inovestor.ms.core.isNullOrUndefined(data)) {\n if (data.requestStatus === 'invalidIdentifier') {\n //plugin.invalidIdentifierHandler();\n // TODO: Invalid identifier handler\n return [];\n }\n\n return data;\n }\n });\n }\n\n this.getSuggestionsAsync = function (userInput) {\n var suggestApiRelativeUrl = inovestor.ms.core.stringFormat(inovestor.ms.technicalChart.config.suggestApiRelativeUrl, {\n term: userInput,\n countryPreference: inovestor.ms.technicalChart.config.suggestCountryPreference\n });\n\n if (userInput) {\n return makeApiRequestAsync(suggestApiRelativeUrl);\n }\n\n return $.when([]);\n }\n\n this.getStockQuoteAsync = function (symbol) {\n var apiRelativeUrl = inovestor.ms.core.stringFormat(inovestor.ms.technicalChart.config.quoteRelativeUrl, { symbol: symbol });\n return makeApiRequestAsync(apiRelativeUrl);\n }\n\n this.getStockHistoricalDataAsync = function (symbol) {\n const cacheKey = `getStockHistoricalData_${symbol}`\n let data = apiDataCache[cacheKey]\n \n if (!data) {\n var date = new Date();\n // Remove 10 years from the date\n date.setFullYear(date.getFullYear() - 10);\n // And add a couple days just to make sure we don't hit the 10 years limit\n date.setDate(date.getDate() + 2);\n var apiRelativeUrl = inovestor.ms.core.stringFormat(inovestor.ms.technicalChart.config.dailyStockHistoricalRelativeUrl, {\n symbol: symbol,\n startDate: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`,\n endDate: ''\n });\n return makeApiRequestAsync(apiRelativeUrl).then(function (response) {\n apiDataCache[cacheKey] = response;\n return response;\n });\n }\n\n return $.when(data);\n }\n\n this.getStockIntradayDataAsync = function (symbol) {\n const cacheKey = `getStockIntradayData_${symbol}`\n let data = apiDataCache[cacheKey]\n\n if (!data) {\n var apiRelativeUrl = inovestor.ms.core.stringFormat(inovestor.ms.technicalChart.config.intradayStockHistoricalRelativeUrl, { symbol: symbol });\n return makeApiRequestAsync(apiRelativeUrl).then(function (response) {\n apiDataCache[cacheKey] = response;\n return response;\n });\n }\n\n return $.when(data);\n }\n }\n\n inovestor.ms.technicalChart.apiClient = new ApiClient();\n})(inovestor.ms.libRef.jQuery, inovestor);\n\n; (function ($, inovestor, undefined) {\n function DataFeed() {\n const configurationData = {\n supported_resolutions: ['1', '1D'],\n exchanges: [\n // {\n // value: '',\n // name: 'All',\n // desc: 'All (desc)',\n // },\n // {\n // value: 'XTSE',\n // name: 'TSX',\n // desc: 'TSX (desc)',\n // },\n // {\n // value: 'XTSX',\n // name: 'TSX Venture',\n // desc: 'TSX Venture (desc)',\n // },\n // {\n // value: 'XNYS',\n // name: 'NYSE',\n // desc: 'NYSE (desc)',\n // },\n // {\n // value: 'XNAS',\n // name: 'NASDAQ',\n // desc: 'NASDAQ (desc)',\n // },\n // {\n // value: 'XASE',\n // name: 'AMEX',\n // desc: 'AMEX (desc)',\n // },\n ],\n symbols_types: [\n // {\n // name: 'All',\n // value: '',\n // },\n // {\n // name: 'Stock',\n // value: 'stock',\n // },\n // {\n // name: 'ETF',\n // value: 'etf',\n // },\n ],\n };\n\n this.onReady = function (callback) {\n setTimeout(() => callback(configurationData));\n }\n\n this.searchSymbols = function (\n userInput,\n exchange,\n symbolType,\n onResultReadyCallback\n ) {\n inovestor.ms.technicalChart.apiClient.getSuggestionsAsync(userInput).then(function (data) {\n const symbols = []\n\n data.forEach((suggestion) => {\n if (suggestion.category === 'stock' || suggestion.category === 'etf') {\n symbols.push({\n symbol: suggestion.ticker,\n full_name: suggestion.symbol,\n ticker: suggestion.symbol,\n description: inovestor.ms.core.currentLanguage === 'fr' ? suggestion.nameFr : suggestion.nameEn,\n exchange: suggestion.exchange,\n type: suggestion.category,\n })\n }\n })\n\n onResultReadyCallback(symbols);\n });\n }\n\n this.resolveSymbol = function (\n symbolName,\n onSymbolResolvedCallback,\n onResolveErrorCallback\n ) {\n inovestor.ms.technicalChart.apiClient.getStockQuoteAsync(symbolName)\n .then(function (data) {\n const quotes = data;\n\n if (quotes.length === 1 && quotes[0].requestStatus === 'success') {\n const quote = quotes[0];\n\n const symbolInfo = {\n ticker: quote.symbol,\n name: `${quote.ticker} (${quote.exchange})`,\n description: (inovestor.ms.core.currentLanguage === 'fr' ? quote.nameFr : quote.nameEn).replace(/'/g, \"’\"),\n type: 'stock', // TODO: Get type. Also use suggestions' type to call the good getStockQuote\n session: '0930-1600',\n timezone: 'America/Toronto',\n exchange: quote.exchange,\n minmov: 1,\n pricescale: 100,\n has_intraday: true,\n intraday_multipliers: ['1'],\n visible_plots_set: 'ohlcv',\n has_weekly_and_monthly: false,\n supported_resolutions: configurationData.supported_resolutions,\n volume_precision: 2,\n // Due to a bug in the current code base, we can't set endofday if we want time_frames (which we do)\n // So streaming it is.\n // Ref: https://github.com/tradingview/charting_library/issues/3945\n //data_status: 'endofday',\n data_status: 'streaming',\n };\n\n onSymbolResolvedCallback(symbolInfo);\n } else {\n onResolveErrorCallback(`Symbol '${symbolName}'not found`)\n }\n })\n .fail(function (error) {\n onResolveErrorCallback('An error occurred')\n });;\n }\n\n this.getBars = function (symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) {\n const { from, to, countBack, firstDataRequest } = periodParams;\n\n // const urlParameters = {\n // symbols: parsedSymbol.exchange,\n // toTs: to,\n // limit: 2000,\n // };\n // const query = Object.keys(urlParameters)\n // .map(name => `${name}=${encodeURIComponent(urlParameters[name])}`)\n // .join('&');\n try {\n const apiTask = resolution === '1'\n ? inovestor.ms.technicalChart.apiClient.getStockIntradayDataAsync(symbolInfo.ticker)\n : inovestor.ms.technicalChart.apiClient.getStockHistoricalDataAsync(symbolInfo.ticker);\n\n apiTask.then(function (apiResponse) {\n const historicalDatas = apiResponse;\n\n if (historicalDatas.length === 0 || historicalDatas[0].requestStatus !== 'success') {\n // \"noData\" should be set if there is no data in the requested period.\n onHistoryCallback([], { noData: true });\n return;\n }\n\n const data = historicalDatas[0];\n let bars = [];\n\n const dateFieldIndex = data.fields.indexOf('date');\n const openFieldIndex = data.fields.indexOf('open');\n const highFieldIndex = data.fields.indexOf('high');\n const lowFieldIndex = data.fields.indexOf('low');\n const closeFieldIndex = data.fields.indexOf('close');\n const volumeFieldIndex = data.fields.indexOf('volume');\n\n // Start from the end of our dataset so we can add exactly how much bars are needed\n let count = 0;\n for (let i = data.datas.length - 1; i >= 0; i--) {\n const bar = data.datas[i];\n const date = new Date(bar[dateFieldIndex]);\n const unixTimestamp = date.getTime();\n\n if (count < countBack && unixTimestamp / 1000 < to) {\n bars = [...bars, {\n time: unixTimestamp,\n low: bar[lowFieldIndex],\n high: bar[highFieldIndex],\n open: bar[openFieldIndex],\n close: bar[closeFieldIndex],\n volume: bar[volumeFieldIndex],\n }];\n ++count;\n }\n }\n\n // Reverse the data array so newer dates are at the start of the array\n bars = bars.reverse();\n\n if (bars.length == 0) {\n // If all bars are filtered out, return noData\n onHistoryCallback([], { noData: true });\n } else {\n onHistoryCallback(bars, { noData: false });\n }\n });\n\n } catch (error) {\n onErrorCallback(error);\n }\n }\n\n this.subscribeBars = function (symbolInfo, resolution, onRealtimeCallback, subscribeUID, onResetCacheNeededCallback) {\n }\n\n this.unsubscribeBars = function (subscriberUID) {\n }\n }\n\n inovestor.ms.technicalChart.dataFeed = new DataFeed();\n})(inovestor.ms.libRef.jQuery, inovestor);\n; (function ($, inovestor, undefined) {\n\n // Create defaults parameters to pass to TradingView widget constructor.\n\n inovestor.ms.technicalChart.defaults = {\n interval: '1D',\n datafeed: inovestor.ms.technicalChart.dataFeed,\n timezone: 'America/Toronto',\n symbol_search_request_delay: 350,\n fullscreen: false,\n autosize: true,\n disabled_features: ['header_screenshot'],\n time_frames: [\n { text: \"1d\", resolution: \"1\", description: \"1 Day\" },\n { text: \"1m\", resolution: \"1D\", description: \"1 Month\" },\n { text: \"3m\", resolution: \"1D\", description: \"3 Months\" },\n { text: \"6m\", resolution: \"1D\", description: \"6 Months\" },\n { text: \"1y\", resolution: \"1D\", description: \"1 Year\" },\n { text: \"5y\", resolution: \"1D\", description: \"5 Years\" },\n { text: \"10y\", resolution: \"1D\", description: \"10 Years\" },\n ]\n }\n\n})(inovestor.ms.libRef.jQuery, inovestor);"]}