Files
ai/datafeeds/udf/dist/bundle.js
ejukovskiy 261fc36962 VERSION 16 @ 2020-07-17 13:08:09.461606
Volume transparency bars #5076
widget.changeTheme should not record an Undo entry in the Undo/Redo stack #4982
Event when source price scale is changed #4884
Time value in shape creating #4878
Price axis icons don't change after applyOverrides #4865
Cannot disable bottom toolbar timezone menu via "timezone_menu" property #4836
Showleftaxis is not valid on the mobile #4828
Fix TypeScript typings for onVisibleRangeChanged method #4802
Invalid on Mobile: 'paneProperties.legendProperties.showBarChange': false,  #4797
API to attach an indicator to a particular price scale #4788
saveLoadAdapter is stringified #4776
Changing price scale of the study via changePriceScale method doesn't applies immediately #4774
Broker Config Order Market not visible #4765
[Bug] In the trading mask changing price doesn't update pips #4761
Maximize chart button #4744
Custom study plot color has no effect #4740
Moving average on seconds (createStudy) #4730
[Bug] BUY button get enable after clicking on both pips fields #4718
Overrides are not applied when defaults button is pressed #4706
Trading Terminal passes parentOrderId object while modifying the order #4705
Watermark settings are not saved to LocalStorage #4681
tvWidget.activeChart().resolution() return randomly "D" or "1D" for the daily time-frame #4630
cannot override default background color #4621
Bring to front operation is unavailable in 1.16 #4611
New style of pane buttons #4608
New mobile friendly style of the legend #4607
Centered Zoom with Ctrl #4606
TERMINAL: Apply Date Range to all charts in layout if Sync Interval is enabled #4605
Updated style of the measure tool #4604
New style of indicator loading status #4603
New measure styles #4602
Adaptive drawings dialogs #4600
Allow createStudy use undo #4590
Crosshair only on long press on mobile #4574
saveChartToServer does not call the callbacks if  !autoSaveNeeded #4573
How to get current theme? #4534
getAllShapes returns trend_line instead of 'extended' #4507
hideMarksOnBar in v1.15 #4506
Trend_angle is not returned via getAllShapes #4498
 How to disable vertical scrolling on the mobile side #4483
Add support for holidays and exchange working days in session spec #4467
closePopupsAndDialogs : The screenshot popup is not being closed #4438
Redirect on TV homepage after mouse click release #4423
setBodyFont of position line tool doesn't work correctly #4353
subscribe('drawing_event') click is not working #4302
"Eraser" and "dot" cursors doesn't work on IE11 #4238
zOrder for shapes with saved layout #4219
Errors/warning in console after load chart #4196
Main series API #4169
Scrolling to the top - href=“#”  #4136
Tracking mode #4111
Order line drag with middle mouse button doesn't trigger onMove #4084
There are no values or na ​​in the legend of the additional symbol (compare/add) until hover the cursor on the chart #4058
closePopupsAndDialogs doesn't work for new indicators dialog #4051
toolbar_bg doesn't affect top toolbar #3998
Check if symbol sync is enabled #3997
DOM bottom buttons are missing tooltips #3979
Question about D or 1D resolution #3861
Twitter intent button Android app #3732
Avoid chart appending storage version and "study_templates or charts" to chartStorageAPI #3702
unexpected study id by assigning studies_access option #3630
Drawing shape on indicator/study #3408
Top header in fullscreen? #2610
Allow to modify end date of long/short position tool #2381
Chart can scroll with mouse movement but no button pressed down #1908
Adaptive design for Properties dialog #862
2020-07-17 16:08:28 +03:00

2 lines
13 KiB
JavaScript

!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 n(e){var t;r&&(t=new Date,console.log(t.toLocaleTimeString()+"."+t.getMilliseconds()+"> "+e))}function c(e){return void 0===e?"":"string"==typeof e?e:e.message}var i=(s.prototype.getBars=function(e,t,r,s){var o=this,i={symbol:e.ticker||"",resolution:t,from:r,to:s};return new Promise(function(a,u){o._requester.sendRequest(o._datafeedUrl,"history",i).then(function(e){if("ok"===e.s||"no_data"===e.s){var t=[],r={noData:!1};if("no_data"===e.s)r.noData=!0,r.nextTime=e.nextTime;else for(var s=void 0!==e.v,o=void 0!==e.o,i=0;i<e.t.length;++i){var n={time:1e3*e.t[i],close:Number(e.c[i]),open:Number(e.c[i]),high:Number(e.c[i]),low:Number(e.c[i])};o&&(n.open=Number(e.o[i]),n.high=Number(e.h[i]),n.low=Number(e.l[i])),s&&(n.volume=Number(e.v[i])),t.push(n)}a({bars:t,meta:r})}else u(e.errmsg)}).catch(function(e){var t=c(e);console.warn("HistoryProvider: getBars() failed, error="+t),u(t)})})},s);function s(e,t){this._datafeedUrl=e,this._requester=t}var a=(o.prototype.subscribeBars=function(e,t,r,s){this._subscribers.hasOwnProperty(s)?n("DataPulseProvider: already has subscriber with id="+s):(this._subscribers[s]={lastBarTime:null,listener:r,resolution:t,symbolInfo:e},n("DataPulseProvider: subscribed for #"+s+" - {"+e.name+", "+t+"}"))},o.prototype.unsubscribeBars=function(e){delete this._subscribers[e],n("DataPulseProvider: unsubscribed for #"+e)},o.prototype._updateData=function(){var r=this;if(!(0<this._requestsPending)){this._requestsPending=0;var e=this;for(var t in this._subscribers)!function(t){e._requestsPending+=1,e._updateDataForSubscriber(t).then(function(){--r._requestsPending,n("DataPulseProvider: data for #"+t+" updated successfully, pending="+r._requestsPending)}).catch(function(e){--r._requestsPending,n("DataPulseProvider: data for #"+t+" updated with error="+c(e)+", pending="+r._requestsPending)})}(t)}},o.prototype._updateDataForSubscriber=function(t){var r=this,e=this._subscribers[t],s=parseInt((Date.now()/1e3).toString()),o=s-function(e,t){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}(e.resolution,10);return this._historyProvider.getBars(e.symbolInfo,e.resolution,o,s).then(function(e){r._onSubscriberDataReceived(t,e)})},o.prototype._onSubscriberDataReceived=function(e,t){if(this._subscribers.hasOwnProperty(e)){var r=t.bars;if(0!==r.length){var s=r[r.length-1],o=this._subscribers[e];if(!(null!==o.lastBarTime&&s.time<o.lastBarTime)){if(null!==o.lastBarTime&&s.time>o.lastBarTime){if(r.length<2)throw new Error("Not enough bars in history for proper pulse update. Need at least 2.");var i=r[r.length-2];o.listener(i)}o.lastBarTime=s.time,o.listener(s)}}}else n("DataPulseProvider: Data comes for already unsubscribed subscription #"+e)},o);function o(e,t){this._subscribers={},this._requestsPending=0,this._historyProvider=e,setInterval(this._updateData.bind(this),t)}var u=(l.prototype.subscribeQuotes=function(e,t,r,s){this._subscribers[s]={symbols:e,fastSymbols:t,listener:r},n("QuotesPulseProvider: subscribed quotes with #"+s)},l.prototype.unsubscribeQuotes=function(e){delete this._subscribers[e],n("QuotesPulseProvider: unsubscribed quotes with #"+e)},l.prototype._updateQuotes=function(s){var o=this;if(!(0<this._requestsPending)){var e=this;for(var t in this._subscribers)!function(t){e._requestsPending++;var r=e._subscribers[t];e._quotesProvider.getQuotes(1===s?r.fastSymbols:r.symbols).then(function(e){o._requestsPending--,o._subscribers.hasOwnProperty(t)&&(r.listener(e),n("QuotesPulseProvider: data for #"+t+" ("+s+") updated successfully, pending="+o._requestsPending))}).catch(function(e){o._requestsPending--,n("QuotesPulseProvider: data for #"+t+" ("+s+") updated with error="+c(e)+", pending="+o._requestsPending)})}(t)}},l);function l(e){this._subscribers={},this._requestsPending=0,this._quotesProvider=e,setInterval(this._updateQuotes.bind(this,1),1e4),setInterval(this._updateQuotes.bind(this,0),6e4)}function d(e,t,r,s){var o=e[t];return!Array.isArray(o)||s&&!Array.isArray(o[0])?o:o[r]}var h=(f.prototype.resolveSymbol=function(t){var r=this;return this._readyPromise.then(function(){var e=r._symbolsInfo[t];return void 0===e?Promise.reject("invalid symbol"):Promise.resolve(e)})},f.prototype.searchSymbols=function(a,u,c,s){var l=this;return this._readyPromise.then(function(){var i=[],n=0===a.length;a=a.toUpperCase();for(var e=0,t=l._symbolsList;e<t.length;e++)!function(e){var t,r,s,o=l._symbolsInfo[e];void 0!==o&&(0<c.length&&o.type!==c||u&&0<u.length&&o.exchange!==u||(r=o.name.toUpperCase().indexOf(a),s=o.description.toUpperCase().indexOf(a),(n||0<=r||0<=s)&&(i.some(function(e){return e.symbolInfo===o})||(t=0<=r?r:8e3+s,i.push({symbolInfo:o,weight:t})))))}(t[e]);var r=i.sort(function(e,t){return e.weight-t.weight}).slice(0,s).map(function(e){var t=e.symbolInfo;return{symbol:t.name,full_name:t.full_name,description:t.description,exchange:t.exchange,params:[],type:t.type,ticker:t.name}});return Promise.resolve(r)})},f.prototype._init=function(){for(var e=this,t=[],r={},s=0,o=this._exchangesList;s<o.length;s++){var i=o[s];r[i]||(r[i]=!0,t.push(this._requestExchangeData(i)))}return Promise.all(t).then(function(){e._symbolsList.sort(),n("SymbolsStorage: All exchanges data loaded")})},f.prototype._requestExchangeData=function(s){var o=this;return new Promise(function(t,r){o._requester.sendRequest(o._datafeedUrl,"symbol_info",{group:s}).then(function(e){try{o._onExchangeDataReceived(s,e)}catch(e){return void r(e)}t()}).catch(function(e){n("SymbolsStorage: Request data for exchange '"+s+"' failed, reason="+c(e)),t()})})},f.prototype._onExchangeDataReceived=function(t,r){var e=this,s=0;try{for(var o=r.symbol.length,i=void 0!==r.ticker;s<o;++s){var n=r.symbol[s],a=d(r,"exchange-listed",s),u=d(r,"exchange-traded",s),c=u+":"+n,l=i?d(r,"ticker",s):n,h={ticker:l,name:n,base_name:[a+":"+n],full_name:c,listed_exchange:a,exchange:u,description:d(r,"description",s),has_intraday:p(d(r,"has-intraday",s),!1),has_no_volume:p(d(r,"has-no-volume",s),!1),minmov:d(r,"minmovement",s)||d(r,"minmov",s)||0,minmove2:d(r,"minmove2",s)||d(r,"minmov2",s),fractional:d(r,"fractional",s),pricescale:d(r,"pricescale",s),type:d(r,"type",s),session:d(r,"session-regular",s),timezone:d(r,"timezone",s),supported_resolutions:p(d(r,"supported-resolutions",s,!0),e._datafeedSupportedResolutions),force_session_rebuild:d(r,"force-session-rebuild",s),has_daily:p(d(r,"has-daily",s),!0),intraday_multipliers:p(d(r,"intraday-multipliers",s,!0),["1","5","15","30","60"]),has_weekly_and_monthly:d(r,"has-weekly-and-monthly",s),has_empty_bars:d(r,"has-empty-bars",s),volume_precision:p(d(r,"volume-precision",s),0),format:"price"};e._symbolsInfo[l]=h,e._symbolsInfo[n]=h,e._symbolsInfo[c]=h,e._symbolsList.push(n)}}catch(e){throw new Error("SymbolsStorage: API error when processing exchange "+t+" symbol #"+s+" ("+r.symbol[s]+"): "+e.message)}},f);function f(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())})}function p(e,t){return void 0!==e?e:t}function _(e,t,r){var s=e[t];return Array.isArray(s)?s[r]:s}var m=(b.prototype.onReady=function(e){var t=this;this._configurationReadyPromise.then(function(){e(t._configuration)})},b.prototype.getQuotes=function(e,t,r){this._quotesProvider.getQuotes(e).then(t).catch(r)},b.prototype.subscribeQuotes=function(e,t,r,s){this._quotesPulseProvider.subscribeQuotes(e,t,r,s)},b.prototype.unsubscribeQuotes=function(e){this._quotesPulseProvider.unsubscribeQuotes(e)},b.prototype.calculateHistoryDepth=function(e,t,r){},b.prototype.getMarks=function(e,t,r,s,o){var i;this._configuration.supports_marks&&(i={symbol:e.ticker||"",from:t,to:r,resolution:o},this._send("marks",i).then(function(e){if(!Array.isArray(e)){for(var t=[],r=0;r<e.id.length;++r)t.push({id:_(e,"id",r),time:_(e,"time",r),color:_(e,"color",r),text:_(e,"text",r),label:_(e,"label",r),labelFontColor:_(e,"labelFontColor",r),minSize:_(e,"minSize",r)});e=t}s(e)}).catch(function(e){n("UdfCompatibleDatafeed: Request marks failed: "+c(e)),s([])}))},b.prototype.getTimescaleMarks=function(e,t,r,s,o){var i;this._configuration.supports_timescale_marks&&(i={symbol:e.ticker||"",from:t,to:r,resolution:o},this._send("timescale_marks",i).then(function(e){if(!Array.isArray(e)){for(var t=[],r=0;r<e.id.length;++r)t.push({id:_(e,"id",r),time:_(e,"time",r),color:_(e,"color",r),label:_(e,"label",r),tooltip:_(e,"tooltip",r)});e=t}s(e)}).catch(function(e){n("UdfCompatibleDatafeed: Request timescale marks failed: "+c(e)),s([])}))},b.prototype.getServerTime=function(r){this._configuration.supports_time&&this._send("time").then(function(e){var t=parseInt(e);isNaN(t)||r(t)}).catch(function(e){n("UdfCompatibleDatafeed: Fail to load server time, error="+c(e))})},b.prototype.searchSymbols=function(t,e,r,s){if(this._configuration.supports_search){var o={limit:30,query:t.toUpperCase(),type:r,exchange:e};this._send("search",o).then(function(e){return void 0!==e.s?(n("UdfCompatibleDatafeed: search symbols error="+e.errmsg),void s([])):void s(e)}).catch(function(e){n("UdfCompatibleDatafeed: Search symbols for '"+t+"' failed. Error="+c(e)),s([])})}else{if(null===this._symbolsStorage)throw new Error("UdfCompatibleDatafeed: inconsistent configuration (symbols storage)");this._symbolsStorage.searchSymbols(t,e,r,30).then(s).catch(s.bind(null,[]))}},b.prototype.resolveSymbol=function(e,t,r){n("Resolve requested");var s=Date.now();function o(e){n("Symbol resolved: "+(Date.now()-s)+"ms"),t(e)}if(this._configuration.supports_group_request){if(null===this._symbolsStorage)throw new Error("UdfCompatibleDatafeed: inconsistent configuration (symbols storage)");this._symbolsStorage.resolveSymbol(e).then(o).catch(r)}else{var i={symbol:e};this._send("symbols",i).then(function(e){void 0!==e.s?r("unknown_symbol"):o(e)}).catch(function(e){n("UdfCompatibleDatafeed: Error resolving symbol: "+c(e)),r("unknown_symbol")})}},b.prototype.getBars=function(e,t,r,s,o,i){this._historyProvider.getBars(e,t,r,s).then(function(e){o(e.bars,e.meta)}).catch(i)},b.prototype.subscribeBars=function(e,t,r,s,o){this._dataPulseProvider.subscribeBars(e,t,r,s)},b.prototype.unsubscribeBars=function(e){this._dataPulseProvider.unsubscribeBars(e)},b.prototype._requestConfiguration=function(){return this._send("config").catch(function(e){return n("UdfCompatibleDatafeed: Cannot get datafeed configuration - use default, error="+c(e)),null})},b.prototype._send=function(e,t){return this._requester.sendRequest(this._datafeedURL,e,t)},b.prototype._setupWithConfiguration=function(e){if(void 0===(this._configuration=e).exchanges&&(e.exchanges=[]),!e.supports_search&&!e.supports_group_request)throw new Error("Unsupported datafeed configuration. Must either support search, or support group request");!e.supports_group_request&&e.supports_search||(this._symbolsStorage=new h(this._datafeedURL,e.supported_resolutions||[],this._requester)),n("UdfCompatibleDatafeed: Initialized with "+JSON.stringify(e))},b);function b(e,t,r,s){var o=this;void 0===s&&(s=1e4),this._configuration=y(),this._symbolsStorage=null,this._datafeedURL=e,this._requester=r,this._historyProvider=new i(e,this._requester),this._quotesProvider=t,this._dataPulseProvider=new a(this._historyProvider,s),this._quotesPulseProvider=new u(this._quotesProvider),this._configurationReadyPromise=this._requestConfiguration().then(function(e){null===e&&(e=y()),o._setupWithConfiguration(e)})}function y(){return{supports_search:!1,supports_group_request:!0,supported_resolutions:["1","5","15","30","60","1D","1W","1M"],supports_marks:!1,supports_timescale_marks:!1}}var v=(g.prototype.getQuotes=function(e){var s=this;return new Promise(function(t,r){s._requester.sendRequest(s._datafeedUrl,"quotes",{symbols:e}).then(function(e){"ok"===e.s?t(e.d):r(e.errmsg)}).catch(function(e){var t=c(e);n("QuotesProvider: getQuotes failed, error="+t),r("network error: "+t)})})},g);function g(e,t){this._datafeedUrl=e,this._requester=t}var P=(q.prototype.sendRequest=function(e,t,r){var s;void 0!==r&&(0!==(s=Object.keys(r)).length&&(t+="?"),t+=s.map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(r[e].toString())}).join("&")),n("New request: "+t);var o={credentials:"same-origin"};return void 0!==this._headers&&(o.headers=this._headers),fetch(e+"/"+t,o).then(function(e){return e.text()}).then(function(e){return JSON.parse(e)})},q);function q(e){e&&(this._headers=e)}var w,D,S,x=(t(D=k,S=w=m),D.prototype=null===S?Object.create(S):(U.prototype=S.prototype,new U),k);function U(){this.constructor=D}function k(e,t){void 0===t&&(t=1e4);var r=new P,s=new v(e,r);return w.call(this,e,s,r,t)||this}e.UDFCompatibleDatafeed=x,Object.defineProperty(e,"__esModule",{value:!0})});