!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Datafeeds={})}(this,function(e){"use strict";var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};var r=!1;function s(e){if(r){var t=new Date;console.log(t.toLocaleTimeString()+"."+t.getMilliseconds()+"> "+e)}}function o(e){return void 0===e?"":"string"==typeof e?e:e.message}var i=function(){function e(e,t){this._datafeedUrl=e,this._requester=t}return e.prototype.getBars=function(e,t,r,s){var i=this,n={symbol:e.ticker||"",resolution:t,from:r,to:s};return new Promise(function(e,t){i._requester.sendRequest(i._datafeedUrl,"history",n).then(function(r){if("ok"===r.s||"no_data"===r.s){var s=[],o={noData:!1};if("no_data"===r.s)o.noData=!0,o.nextTime=r.nextTime;else for(var i=void 0!==r.v,n=void 0!==r.o,a=0;a0)){this._requestsPending=0;var t=function(t){r._requestsPending+=1,r._updateDataForSubscriber(t).then(function(){e._requestsPending-=1,s("DataPulseProvider: data for #"+t+" updated successfully, pending="+e._requestsPending)}).catch(function(r){e._requestsPending-=1,s("DataPulseProvider: data for #"+t+" updated with error="+o(r)+", pending="+e._requestsPending)})},r=this;for(var i in this._subscribers)t(i)}},e.prototype._updateDataForSubscriber=function(e){var t=this,r=this._subscribers[e],s=parseInt((Date.now()/1e3).toString()),o=s-function(e,t){var r=0;r="D"===e?t:"M"===e?31*t:"W"===e?7*t:t*parseInt(e)/1440;return 24*r*60*60}(r.resolution,10);return this._historyProvider.getBars(r.symbolInfo,r.resolution,o,s).then(function(r){t._onSubscriberDataReceived(e,r)})},e.prototype._onSubscriberDataReceived=function(e,t){if(this._subscribers.hasOwnProperty(e)){var r=t.bars;if(0!==r.length){var o=r[r.length-1],i=this._subscribers[e];if(!(null!==i.lastBarTime&&o.timei.lastBarTime){if(r.length<2)throw new Error("Not enough bars in history for proper pulse update. Need at least 2.");var n=r[r.length-2];i.listener(n)}i.lastBarTime=o.time,i.listener(o)}}}else s("DataPulseProvider: Data comes for already unsubscribed subscription #"+e)},e}();var a=function(){function e(e){this._subscribers={},this._requestsPending=0,this._quotesProvider=e,setInterval(this._updateQuotes.bind(this,1),1e4),setInterval(this._updateQuotes.bind(this,0),6e4)}return e.prototype.subscribeQuotes=function(e,t,r,o){this._subscribers[o]={symbols:e,fastSymbols:t,listener:r},s("QuotesPulseProvider: subscribed quotes with #"+o)},e.prototype.unsubscribeQuotes=function(e){delete this._subscribers[e],s("QuotesPulseProvider: unsubscribed quotes with #"+e)},e.prototype._updateQuotes=function(e){var t=this;if(!(this._requestsPending>0)){var r=function(r){i._requestsPending++;var n=i._subscribers[r];i._quotesProvider.getQuotes(1===e?n.fastSymbols:n.symbols).then(function(o){t._requestsPending--,t._subscribers.hasOwnProperty(r)&&(n.listener(o),s("QuotesPulseProvider: data for #"+r+" ("+e+") updated successfully, pending="+t._requestsPending))}).catch(function(i){t._requestsPending--,s("QuotesPulseProvider: data for #"+r+" ("+e+") updated with error="+o(i)+", pending="+t._requestsPending)})},i=this;for(var n in this._subscribers)r(n)}},e}();function u(e,t,r){var s=e[t];return Array.isArray(s)?s[r]:s}var c=function(){function e(e,t,r){this._exchangesList=["NYSE","FOREX","AMEX"],this._symbolsInfo={},this._symbolsList=[],this._datafeedUrl=e,this._datafeedSupportedResolutions=t,this._requester=r,this._readyPromise=this._init(),this._readyPromise.catch(function(e){console.error("SymbolsStorage: Cannot init, error="+e.toString())})}return e.prototype.resolveSymbol=function(e){var t=this;return this._readyPromise.then(function(){var r=t._symbolsInfo[e];return void 0===r?Promise.reject("invalid symbol"):Promise.resolve(r)})},e.prototype.searchSymbols=function(e,t,r,s){var o=this;return this._readyPromise.then(function(){var i=[],n=0===e.length;e=e.toUpperCase();for(var a=function(s){var a=o._symbolsInfo[s];if(void 0===a)return"continue";if(r.length>0&&a.type!==r)return"continue";if(t&&t.length>0&&a.exchange!==t)return"continue";var u=a.name.toUpperCase().indexOf(e),c=a.description.toUpperCase().indexOf(e);if((n||u>=0||c>=0)&&!i.some(function(e){return e.symbolInfo===a})){var l=u>=0?u:8e3+c;i.push({symbolInfo:a,weight:l})}},u=0,c=o._symbolsList;u