"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[26843],{89523:(e,t,s)=>{s.d(t,{BarBuilderBase:()=>o,SessionInfo:()=>a});var r=s(276536),i=s(239765),n=s(792646);class a{constructor(e,t,s,r){this.init(e,t,s,r),this._state={timezone:e,spec:t,holidays:s,corrections:r}}init(e,t,s,i){this.timezone=(0,r.get_timezone)(e),this.spec=new n.SessionsSpec(e,t,s,i)}state(){return this._state}static fromState(e){return new a(e.timezone,e.spec,e.holidays,e.corrections)}static wrap(e){const t=new a("Etc/UTC","24x7");return t.spec=e,t}static create(e,t,s,r){return new a(e,t,s,r)}}class o{alignTime(e){if(isNaN(e))return NaN;let t=this.indexOfBar(e);return t===i.SessionStage.POST_SESSION&&(this.moveTo(e),t=this.indexOfBar(e)),t<0?NaN:this.startOfBar(t)}}},313503:(e,t,s)=>{s.d(t,{getPeriodsBetweenDates:()=>x,newBarBuilder:()=>k});var r=s(276536),i=s(257253),n=s(462140),a=s(89523),o=s(239765);class _ extends a.BarBuilderBase{constructor(e,t){super(),this._sessionStartMs=-Number.MAX_VALUE,this._sessionEndMs=-Number.MAX_VALUE,this._periodSec=e,this._session=t}alignTimeIfPossible(e){const t=this.alignTime(e);return isNaN(t)?e:t}indexOfBar(e){return e=this._sessionEndMs?o.SessionStage.POST_SESSION:(0,n.toInt)((0,r.time_seconds_diff)(e,this._sessionStartMs)/this._periodSec)}startOfBar(e){if(e===o.SessionStage.PRE_SESSION){const e=(0,r.get_cal_from_unix_timestamp_ms)(this._session.timezone,this._sessionStartMs-1),t=this._session.spec.alignToNearestSessionEnd(e,-1);return(0,r.cal_to_utc)(this._session.timezone,t)}if(e===o.SessionStage.POST_SESSION)return this._sessionEndMs;if(e<0)throw new Error("Negative offset is not supported");return this._sessionStartMs+(0,r.time_seconds)(this._periodSec*e)}endOfBar(e){if(e<0)throw new Error("Index cannot be negative");const t=this.startOfBar(e)+1e3*this._periodSec;return t>this._sessionEndMs?this._sessionEndMs:t}isLastBar(e,t){return t>=this._sessionStartMs+(0,r.time_seconds)(this._periodSec*(e+1)-1)}moveTo(e){const t=this._session.timezone,s=(0,r.utc_to_cal)(t,e),i=this._session.spec.alignToSessionStart(s);this._sessionStartMs=(0,r.cal_to_utc)(t,s),(0,r.add_minutes)(s,i),this._sessionEndMs=(0,r.cal_to_utc)(t,s)}indexOfLastBarInSession(){return(0,n.toInt)((this._sessionEndMs-1-this._sessionStartMs)/1e3/this._periodSec)}moveNext(){this.moveTo(this._sessionEndMs)}static minutes(e,t){return new _(60*e,t)}static seconds(e,t){return new _(e,t)}}var d=s(650151),c=s(851553);const u=(0,r.get_timezone)("Etc/UTC");function S(e,t,s){const i=(0,r.clone)(t),n=e.businessDaysToCalendarDays(i,1);n>1&&(0,r.add_date)(i,n-1);const a=e.leftBorderOfDailyBar(i);if(null===a)throw new Error("Cannot calculate left border of daily bar");return(0,r.cal_to_utc)(s,a,!0)}class l{constructor(e,t){this.from=e,this.to=t}toString(){return`${this.from.toString()} - ${this.to.toString()}`}}class h extends a.BarBuilderBase{constructor(e,t,s,r,i=!1){super(),this._periodStart=-Number.MAX_VALUE,this._periodEnd=-Number.MAX_VALUE, this._periodLastBarStart=-Number.MAX_VALUE,this._periodStartDay=new c.BusinessDay(0,0,0),this._periodEndDay=new c.BusinessDay(0,0,0),this._period=s,this._sessionTgt=e,this._builder=r,this._useBusinessDays=i,i?((0,d.assert)(null===t,"useBusinessDays and sessionSrc are mutually exclusive arguments"),this._sessionSrc=new a.SessionInfo("Etc/UTC","24x7")):this._sessionSrc=t||e}builder(){return this._builder}alignTimeIfPossible(e){return this.tradingDayToSessionStart(e)}tradingDayToSessionStart(e){return this.moveTo(e),this.startOfBar(0)}indexOfBar(e){if(this._useBusinessDays){const t=c.BusinessDay.fromCalendar((0,r.get_cal_from_unix_timestamp_ms)(this._sessionSrc.timezone,e));return t.before(this._periodStartDay)?o.SessionStage.PRE_SESSION:this._periodEndDay.before(t)?o.SessionStage.POST_SESSION:0}return e=this._periodEnd?o.SessionStage.POST_SESSION:0}startOfBar(e){if(e===o.SessionStage.PRE_SESSION){const e=(0,r.get_cal_from_unix_timestamp_ms)(this._sessionTgt.timezone,this._periodStart-1),t=this._sessionTgt.spec.alignToNearestSessionEnd(e,-1);return(0,r.cal_to_utc)(this._sessionTgt.timezone,t)-1}return e===o.SessionStage.POST_SESSION||e>0?this._periodEnd:e===o.SessionStage.LASTBAR_SESSION?this._periodLastBarStart:this._periodStart}moveTo(e){let t=(0,r.get_cal_from_unix_timestamp_ms)(this._sessionSrc.timezone,e);t=this._sessionSrc.spec.correctTradingDay(t);const s=(0,r.get_year)(t),i=this._indexOfPeriodInYear(t),n=i+this._period,a=this._sessionTgt.spec,o=this._sessionTgt.timezone,_=this._builder.startOfPeriod(i,s);this._periodStart=S(a,_,o);const d=a.businessDaysToCalendarDays(_,1);d>1&&(0,r.add_date)(_,d-1),this._periodStartDay=c.BusinessDay.fromCalendar(_);let u=this._builder.startOfPeriod(n,s);this._periodEnd=S(a,u,o);const l=(0,r.clone)(u);for((0,r.add_date)(l,-1);a.isCalWeekEnd(l);)(0,r.add_date)(l,-1);this._periodEndDay=c.BusinessDay.fromCalendar(l),(0,r.add_date)(u,-1),u=function(e,t){const s=(0,r.clone)(t);for(;e.isCalWeekEnd(s);)(0,r.add_date)(s,-1);return s}(this._sessionTgt.spec,u),this._periodLastBarStart=S(a,u,o),(this._periodLastBarStart=this._periodLastBarStart}moveBarsForward(e,t){(0,d.assert)(t>0);const s=(0,r.get_cal_from_unix_timestamp_ms)(this._sessionTgt.timezone,e);let i=this._sessionTgt.spec.correctTradingDay(s);for(let e=0;e=0&&(i-=7),(0,n.toInt)((i+s)/7))}class O{indexOfPeriod(e){return(0,r.get_day_of_year)(e)-1}startOfPeriod(e,t){const s=(0,r.days_per_year)(t);return(0,r.get_cal)(u,t,r.JANUARY,1+Math.min(e,s))}}class y extends O{constructor(e){super(),this._sessionsSpec=e}indexOfPeriod(e){return super.indexOfPeriod(e)-function(e,t){const s=g(e,t),i=(0,r.get_cal)(u,(0,r.get_year)(t),r.JANUARY,1);(0,r.add_date)(i,7*s);const n=s*e.weekEndsCountForSingleSession()+e.holidaysFromYearStart(i),a=(0,r.get_day_of_year)(t)-(0,r.get_day_of_year)(i);return n+a-e.calendarDaysToBusinessDays(i,a)}(this._sessionsSpec,e)}startOfPeriod(e,t){const s=7-this._sessionsSpec.weekEndsCountForSingleSession(),i=Math.max(0,Math.trunc(e/s)-1),n=(0,r.get_cal)(u,t,r.JANUARY,1),a=(0,r.days_per_year)(t);if((0,r.add_date)(n,7*i),(e-=s*i-this._sessionsSpec.holidaysFromYearStart(n))>0){const t=this._sessionsSpec.businessDaysToCalendarDays(n,e);(0,r.add_date)(n,t)}let o=(0,r.get_day_of_year)(n)-1;return t<(0,r.get_year)(n)&&(o+=a),super.startOfPeriod(o,t)}}class p extends O{constructor(e){super(),this._sessionsSpec=e}indexOfPeriod(e){return super.indexOfPeriod(e)-this._sessionsSpec.daysOffFromYearStart(e)}startOfPeriod(e,t){const s=(0,r.get_cal)(u,t,r.JANUARY,1);(0,r.add_date)(s,e);const i=this._sessionsSpec.daysOffFromYearStart(s);(0,r.add_date)(s,i);const n=this._sessionsSpec.daysOffFromYearStart(s)-i;if(n>0){ const e=this._sessionsSpec.businessDaysToCalendarDays(s,n);(0,r.add_date)(s,e)}let a=(0,r.get_day_of_year)(s)-1;if(t<(0,r.get_year)(s)){a+=(0,r.days_per_year)(t)}return super.startOfPeriod(a,t)}}class m{constructor(e){this._builder=null,this._initialized=!1,this._session=e}indexOfPeriod(e){return this._getBuilder().indexOfPeriod(e)}startOfPeriod(e,t){return this._getBuilder().startOfPeriod(e,t)}_getBuilder(){return null!==this._builder&&this._initialized||(this._session.spec.hasWeekEnds()?this._builder=this._session.spec.hasHistoryCorrections()?new p(this._session.spec):new y(this._session.spec):this._builder=this._session.spec.hasHistoryCorrections()?new p(this._session.spec):new O,this._initialized=!0),this._builder}}class E{constructor(e){this._spec=e}indexOfPeriod(e){let t=g(this._spec,e);return 0===t&&e.getTime()(0,r.days_per_year)((0,r.get_year)(s))?this.startOfPeriod(0,t+1):((0,r.add_date)(s,n),s)}}class I{constructor(e){this._yearStartDataHash=new Map,this._spec=e}startOfPeriod(e,t){if(e<0){t--;const s=(0,r.get_cal)(u,t,r.DECEMBER,31,23,59,59),i=this.indexOfPeriod(s),n=-1*e,a=Math.trunc(i/n)*n;return this.startOfPeriod(a,t)}const s=this._spec.getWeekIndicesWithAdditionalWeekBars(t),i=this._getStartOfYearData(t,s),n=this._moveToWeekIndexAccountingAdditional(i.firstWeekIndex,s,e),a=7*(n-i.firstWeekIndex);let o=(0,r.clone)((0,d.ensureNotNull)(i.startOfFirstBarInYear));if((0,r.add_date)(o,a),(0,r.get_year)(o)>t){const e=t+1,s=this._spec.getWeekIndicesWithAdditionalWeekBars(e),r=this._getStartOfYearData(e,s);if(o.getTime()>=(0,d.ensureNotNull)(r.startOfFirstBarInYear).getTime())return this.startOfPeriod(0,e)}return o=this._calculateBarWeekStart(o,s,n,e),o}indexOfPeriod(e){const t=this._spec.getWeekIndex(e),s=this._spec.getWeekIndicesWithAdditionalWeekBars((0,r.get_year)(e)),i=this._getStartOfYearData((0,r.get_year)(e),s);if(e.getTime()<(0,d.ensureNotNull)(i.startOfFirstBarInYear).getTime())return-1;if(0===t&&I.isOnFirstCalendarWeekOfYear(e)||0!==t&&t===i.firstWeekIndex)return this._calculateLastWeek(e,t,s,i.firstWeekbarsCount)-1;let n=this._numberOfCalendarWeeks(e);return n+=i.firstWeekbarsCount-i.fullWeeksAdjustment,n+=this._calculateWeeksWithExtraBar(t,s,i.firstWeekIndex),n+=this._calculateLastWeek(e,t,s,I.fullWeekOfAdditionalBarsCount)-1,n}static isOnFirstCalendarWeekOfYear(e){if((0,r.get_day_of_year)(e)>r.LAST_DAY_OF_WEEK)return!1;const t=(0,r.get_cal)(u,(0,r.get_year)(e),r.JANUARY,1,0,0),s=(0,r.clone)(t);return(0,r.add_date)(s,r.LAST_DAY_OF_WEEK-(0,r.get_day_of_week)(t)),e.getTime()=r)break;r--}return r}_calculateBarWeekStart(e,t,s,i){ const n=this._getIndexOfWeekWithExtraBarIfExists(t,s);if(null===n){const t=this._spec.getEntriesForWeek(s).firstDayOfWeek()-(0,r.get_day_of_week)(e),i=(0,r.clone)(e);return(0,r.add_date)(i,t),i}const a=this._spec.getHistoryByIndex(n.entryIndex);if(this.indexOfPeriod((0,d.ensureNotNull)(a.getStartDay()))===i)return(0,r.clone)((0,d.ensureNotNull)(a.getStartDay()));const o=this._spec.getHistoryByIndex(n.entryIndex-1).getEntries().firstDayOfWeek()-(0,r.get_day_of_week)(e),_=(0,r.clone)(e);return(0,r.add_date)(_,o),_}_numberOfCalendarWeeks(e){const t=(0,r.get_day_of_year)(e),s=(0,r.get_day_of_week)(e);return Math.trunc((t-s)/7)}_getStartOfYearData(e,t){let s=this._yearStartDataHash.get(e);if(void 0!==s)return s;let i=(0,r.get_cal)(u,e,r.JANUARY,1,0,0),n=this._spec.getWeekIndex(i),a=0;for((0,r.get_day_of_week)(i)===r.FIRST_DAY_OF_WEEK&&(a=1),s=this._getYearStartDataFromWeek(t,n,i);null===s.startOfFirstBarInYear;)n++,a++,i=this._moveToNextCalendarWeekStart(i),s=this._getYearStartDataFromWeek(t,n,i);return s.fullWeeksAdjustment=a,this._yearStartDataHash.set(e,s),s}_moveToNextCalendarWeekStart(e){const t=(0,r.get_day_of_week)(e),s=(0,r.clone)(e);return(0,r.add_date)(s,r.LAST_DAY_OF_WEEK-t+1),s}_getYearStartDataFromWeek(e,t,s){const i=(0,r.get_day_of_week)(s);let n=null,a=0;const o=this._getIndexOfWeekWithExtraBarIfExists(e,t);if(null!==o){let e=this._spec.getHistoryByIndex(o.entryIndex-1).getEntries().firstDayOfWeek()-i;if(e>=0)n=(0,r.clone)(s),(0,r.add_date)(n,e),a=2;else{const t=this._spec.getHistoryByIndex(o.entryIndex);e=t.getEntries().firstDayOfWeek()-i,e>=0&&(n=t.getStartDay(),n&&(n=(0,r.clone)(n)),a=1)}}else{const e=this._spec.getEntriesForWeek(t),o=e.firstDayOfWeek()-i;o>=0&&(this._hasWorkingDays(e)||this._hasWorkingDaysNextWeek(t+1))&&(n=(0,r.clone)(s),(0,r.add_date)(n,o),a=1)}return{startOfFirstBarInYear:n,firstWeekIndex:t,firstWeekbarsCount:a,fullWeeksAdjustment:0}}_hasWorkingDays(e){if(0===e.entriesByDay().size)return!1;for(let t=e.firstDayOfWeek();t<=r.LAST_DAY_OF_WEEK;t++)if(void 0!==e.entriesByDay().get(t))return!0;return!1}_hasWorkingDaysNextWeek(e){const t=this._spec.getEntriesForWeek(e);for(let e=1;e=e)break;i.weekIndex>s&&r++}return r}_calculateLastWeek(e,t,s,i){const n=(0,r.get_day_of_week)(e),a=this._getIndexOfWeekWithExtraBarIfExists(s,t);if(null===a){return n-this._spec.getEntriesForWeek(t).firstDayOfWeek()>=0?1:0}const o=this._positionInsideWeekWithSeveralBars(a,n);return o===I.IsInNewSession?i:o===I.IsInMidSession?i-1:0}_getIndexOfWeekWithExtraBarIfExists(e,t){for(const s of e){if(s.weekIndex===t)return s;if(s.weekIndex>t)break}return null}_positionInsideWeekWithSeveralBars(e,t){let s=this._spec.getHistoryByIndex(e.entryIndex).getEntries().firstDayOfWeek()-t;if(s<=0)return I.IsInNewSession;return s=this._spec.getHistoryByIndex(e.entryIndex-1).getEntries().firstDayOfWeek()-t,s<=0?I.IsInMidSession:I.IsBeforeAnySession}}I.IsBeforeAnySession=-1, I.IsInMidSession=0,I.IsInNewSession=1,I.fullWeekOfAdditionalBarsCount=2;class T{constructor(e){this._builder=null,this._session=e}indexOfPeriod(e){return this._getBuilder().indexOfPeriod(e)}startOfPeriod(e,t){return this._getBuilder().startOfPeriod(e,t)}_getBuilder(){return null==this._builder&&(this._builder=this._session.spec.hasHistoryCorrections()?new I(this._session.spec):new E(this._session.spec)),this._builder}}class B{constructor(e){this._session=e}indexOfPeriod(e){return(0,r.get_month)(e)}startOfPeriod(e,t){if(e<0){const s=(0,n.toInt)((11-e)/12);t-=s,e+=12*s}else e>r.DECEMBER&&(t++,e=r.JANUARY);return(0,r.get_cal)(u,t,e,1)}}function k(e,t,s,r=!1){const n=i.Interval.parse(e),a=n.multiplier();return n.isMinutes()?_.minutes(a,t):n.isSeconds()?_.seconds(a,t):n.isTicks()?new _(1,t):n.isRange()?new _(60*a,t):new h(t,s??null,a,function(e,t){switch(e){case i.ResolutionKind.Days:return new m(t);case i.ResolutionKind.Weeks:return new T(t);case i.ResolutionKind.Months:return new B(t)}throw new Error(`Unknown dwm resolution: ${e}`)}(n.kind(),t),r)}function x(e,t,s,n,o,_,d){const c=i.Interval.parse(o+n);if(c.isMonths()){const e=new Date(_),t=new Date(d);let s=12*(t.getUTCFullYear()-e.getUTCFullYear());return s+=t.getUTCMonth()-e.getUTCMonth(),Math.ceil(s/c.multiplier())}const u=new a.SessionInfo("Etc/UTC",e,t,s),S=c.inMilliseconds();let l;if(c.isDWM())l=864e5;else{const e=u.spec.getWeekIndex((0,r.get_cal_from_unix_timestamp_ms)(u.timezone,d));l=60*u.spec.getEntriesForWeek(e).maxTradingDayLength()*1e3}let h=0;if(c.isWeeks())h=7;else{const e=u.spec.getWeekIndex((0,r.get_cal_from_unix_timestamp_ms)(u.timezone,d));h=7-u.spec.getEntriesForWeek(e).weekEndsCount()}const f=d-_,g=l/S,O=h*g;let y=f/864e5*g;y>=O&&(y=f/6048e5*O);return y%1<=Number.EPSILON*Math.ceil(y)?Math.round(y):Math.ceil(y)}},239765:(e,t,s)=>{var r;s.d(t,{SessionStage:()=>r}),function(e){e[e.PRE_SESSION=-1]="PRE_SESSION",e[e.POST_SESSION=-2]="POST_SESSION",e[e.LASTBAR_SESSION=-3]="LASTBAR_SESSION",e[e.LAST_SESSION_END=-4]="LAST_SESSION_END",e[e.FIRST_SESSION_START=-5]="FIRST_SESSION_START"}(r||(r={}))},196717:(e,t,s)=>{s.d(t,{extrapolateBarsFrontByCount:()=>n,extrapolateBarsFrontToTime:()=>i});var r=s(239765);function i(e,t,s,r,n=!1){if(t>s){const a=i(e,s,t,r,n);return a.count=-a.count,a}return a(e,t,1,((e,t)=>t>s||0!==r&&e>r),n)}function n(e,t,s,r=!1){const i=s<0?-1:1;return a(e,t,i,((e,t)=>e>=s*i),r)}function a(e,t,s,i,n){let a=0,o=t;e.moveTo(o);let _=0,d=Number.MAX_VALUE,c=!1,u=t;const S=[];for(;!i(a,o);){if(_>15)throw new Error("Internal error 0x10 while extrapolating.");const i=e.indexOfBar(o);if(i===r.SessionStage.PRE_SESSION&&1===s)o=e.startOfBar(0),e.moveTo(o);else if(i===r.SessionStage.PRE_SESSION&&-1===s)o=e.startOfBar(r.SessionStage.PRE_SESSION),e.moveTo(o);else if(i===r.SessionStage.POST_SESSION&&1===s)o=e.startOfBar(r.SessionStage.POST_SESSION),e.moveTo(o);else{if(i===r.SessionStage.POST_SESSION&&-1===s)throw new Error("Internal error 0x12 while extrapolating.");{const l=e.startOfBar(i);if(l>t&&s>0||t>l&&s<0){ if(c&&d===l)throw new Error("Internal error 0x11 while extrapolating.");c=!0,d=l,_=0,a++,u=l,n&&S.push(u)}if(0===i&&-1===s)o=l-1;else{o=e.startOfBar(i+s);const t=e.startOfBar(r.SessionStage.POST_SESSION);o>t&&(e.moveTo(t),o=e.startOfBar(0))}}}_++}return{time:u,times:S,count:a}}}}]);