@tradecanvas/core 1.43.0 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,6 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
|
|
|
18
18
|
cursor: pointer;
|
|
19
19
|
color: ${n?`#1fa874`:`#e8505b`};
|
|
20
20
|
transition: background 0.1s;
|
|
21
|
-
`,t.addEventListener(`mouseenter`,()=>{t.style.background=`#1f2630`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),s.appendChild(t)}n.appendChild(s),this.menuElement=s;let l=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!s.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,l),document.addEventListener(`keydown`,l),this.removeHandler=()=>{document.removeEventListener(`mousedown`,l),document.removeEventListener(`keydown`,l)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function Mp(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function Np(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var Pp=6,Fp=.12,Ip=[6,3],Lp=class{draft=null;dragStart=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=Mp(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(t,n,r=Pp){if(!this.draft)return null;let i=[`entry`,`sl`,`tp`],a=null,o=r;for(let r of i){let i=e.T(this.priceOf(r),n),s=Math.abs(i-t.y);s<=o&&(o=s,a=r)}return a}beginDrag(e,t,n){let r=this.hitTest(e,t,n);return r!==null&&this.beginDragOn(r)}beginDragOn(e){return this.draft?(this.dragging=e,this.dragStart=this.draft,!0):!1}cancelDrag(){this.dragging&&this.dragStart&&(this.draft=this.dragStart),this.dragging=null,this.dragStart=null}drag(t,n){if(!this.draft||!this.dragging)return!1;let r=e.M(t.y,n);return this.draft=zp(this.draft,this.dragging,r),!0}endDrag(){this.dragging=null,this.dragStart=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r){this.renderLines(e,t,n),rp(e,this.tags(t,n),t,n,[])}renderLines(t,n,r){let i=this.draft;if(!i)return;let{chartRect:a}=n,o=e.T(i.entry,n),s=e.T(i.stopLoss,n),c=e.T(i.takeProfit,n),{profit:l,loss:u}=Rp(r);t.save(),t.globalAlpha=Fp,t.fillStyle=l,t.fillRect(a.x,Math.min(o,c),a.width,Math.abs(c-o)),t.fillStyle=u,t.fillRect(a.x,Math.min(o,s),a.width,Math.abs(s-o)),t.globalAlpha=1,Ff(t,n,o,r.text,Ip),Ff(t,n,c,l,[]),Ff(t,n,s,u,[]),t.restore()}tags(t,n){let r=this.draft;if(!r)return[];let{profit:i,loss:a}=Rp(n),o=r.side===`buy`?1:-1,s=e=>{let t=r.entry===0?0:(e-r.entry)/r.entry*100*o;return`${t>=0?`+`:``}${t.toFixed(2)}%`};return[{y:e.T(r.entry,t),color:n.text,grab:{kind:`bracket`,handle:`entry`},cells:[{kind:`stamp`,text:r.side===`buy`?`Long`:`Short`},{kind:`text`,text:`${Np(r).toFixed(2)}R`}]},{y:e.T(r.takeProfit,t),color:i,grab:{kind:`bracket`,handle:`tp`},cells:[{kind:`stamp`,text:`TP`},{kind:`text`,text:s(r.takeProfit),color:i}]},{y:e.T(r.stopLoss,t),color:a,grab:{kind:`bracket`,handle:`sl`},cells:[{kind:`stamp`,text:`SL`},{kind:`text`,text:s(r.stopLoss),color:a}]}].filter(e=>q(e.y,t))}renderAxisBadges(e,t,n,r){for(let i of this.axisBadges(t,n,r))op(e,i.y,i.text,i.color,t,n)}axisBadges(n,r,i){let a=this.draft;if(!a)return[];let{profit:o,loss:s}=Rp(r),c=[];for(let[l,u]of[[a.takeProfit,o],[a.stopLoss,s],[a.entry,r.text]]){let r=e.T(l,n);q(r,n)&&c.push({y:r,text:(0,t.priceTagText)(l,n,i),color:u})}return c}};function Rp(e){return{profit:e.style?.trading.profit??e.candleUp,loss:e.style?.trading.loss??e.candleDown}}function zp(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function Bp(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Vp=6,Hp=[6,3],Up=class{draft=null;dragStart=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:Bp(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(t,n,r=Vp){return this.draft?Math.abs(e.T(this.draft.price,n)-t.y)<=r:!1}beginDrag(e,t,n){return this.hitTest(e,t,n)&&this.beginDragOn()}beginDragOn(){return this.draft?(this.dragging=!0,this.dragStart=this.draft,!0):!1}cancelDrag(){this.dragging&&this.dragStart&&(this.draft=this.dragStart),this.dragging=!1,this.dragStart=null}drag(t,n){return!this.draft||!this.dragging?!1:this.setPrice(e.M(t.y,n))}endDrag(){this.dragging=!1,this.dragStart=null}render(e,t,n,r,i){this.renderLines(e,t,n),rp(e,this.tags(t,n,r),t,n,[])}renderLines(t,n,r){let i=this.draft;i&&(t.save(),Ff(t,n,e.T(i.price,n),Wp(i.side,r),Hp),t.restore())}tags(t,n,r){let i=this.draft;if(!i)return[];let a=e.T(i.price,t);if(!q(a,t))return[];let o=Bp(i.side,i.price,r);return[{y:a,color:Wp(i.side,n),grab:{kind:`draft`},cells:[{kind:`stamp`,text:String(i.quantity)},{kind:`text`,text:dp({side:i.side,type:o})}]}]}renderAxisBadges(e,t,n,r){for(let i of this.axisBadges(t,n,r))op(e,i.y,i.text,i.color,t,n)}axisBadges(n,r,i){let a=this.draft;if(!a)return[];let o=e.T(a.price,n);return q(o,n)?[{y:o,text:(0,t.priceTagText)(a.price,n,i),color:Wp(a.side,r)}]:[]}};function Wp(e,t){return e===`buy`?t.style?.trading.buy??t.candleUp:t.style?.trading.sell??t.candleDown}var Gp=2;function Kp(e,t){return e.type===t.type?e.type===`cancelOrder`?e.orderId===t.orderId:e.type===`removeStop`?e.positionId===t.positionId&&e.which===t.which:e.positionId===t.positionId:!1}function qp(e,t,n=Gp){let r=(e,n)=>t.x>=e.x-n&&t.x<=e.x+e.size+n&&t.y>=e.y-n&&t.y<=e.y+e.size+n;for(let t=e.length-1;t>=0;t--)if(r(e[t],0))return e[t];let i=null,a=1/0;for(let o of e){if(!r(o,n))continue;let e=Math.hypot(t.x-(o.x+o.size/2),t.y-(o.y+o.size/2));e<a&&(a=e,i=o)}return i}var Jp=5,Yp=7,Xp=2;function Zp(e,n){let r=n.data;return r&&r.length>0?e/(0,t.barTimeUnit)(r):e}function Qp(t,n,r,i){if(n.length===0)return;let{chartRect:a}=r,o=i.orderColors?.buy??`#1fa874`,s=i.orderColors?.sell??`#e8505b`;t.lineWidth=1.5;for(let i of n){let n=e.O(Zp(i.time,r),r),c=e.T(i.price,r);if(n<a.x||n>a.x+a.width||c<a.y||c>a.y+a.height)continue;let l=i.side===`buy`,u=l?c+Xp:c-Xp,d=l?u+Yp:u-Yp;t.beginPath(),t.moveTo(n,u),t.lineTo(n-Jp,d),t.lineTo(n+Jp,d),t.closePath();let f=l?o:s;!i.reason||i.reason===`order`?(t.fillStyle=f,t.fill()):(t.strokeStyle=f,t.stroke())}}var $p=1e3,em=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new hp;positionRenderer=new Dp;depthOverlay=new Op;dragHandler;contextMenu=new jp;bracket=new Lp;orderDraft=new Up;buttons=[];tagBoxes=[];grabOffset=0;fills=[];realisedPnl=0;requestRender=null;eventCallback=null;container=null;constructor(e){this.config={...t.DEFAULT_TRADING_CONFIG,...e},this.dragHandler=new Ap(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}getCurrentPrice(){return this.currentPrice}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}addFill(e){this.fills=[...this.fills.slice(-($p-1)),e],this.realisedPnl+=e.pnl??0,this.requestRender?.()}setFills(e){this.fills=e.slice(-$p),this.realisedPnl=e.reduce((e,t)=>e+(t.pnl??0),0),this.requestRender?.()}getRealisedPnl(){return this.realisedPnl}getFills(){return[...this.fills]}armed=null;isOverButton(e){return this.config.enabled&&qp(this.buttons,e)!==null}runButton(e){switch(e.type){case`cancelOrder`:this.eventCallback?.(`orderCancel`,{orderId:e.orderId});break;case`closePosition`:this.eventCallback?.(`positionClose`,{positionId:e.positionId});break;case`reversePosition`:this.eventCallback?.(`positionReverse`,{positionId:e.positionId});break;case`removeStop`:this.eventCallback?.(`positionModify`,{positionId:e.positionId,[e.which]:null});break}}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:Np(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}isOverDraggableLine(t,n,r=8){if(!this.config.enabled)return!1;if(Qf(this.tagBoxes,t.x,t.y)&&!qp(this.buttons,t))return!0;let i=i=>{if(i===void 0)return!1;let a=e.T(i,n);return q(a,n)&&Math.abs(t.y-a)<=r};for(let e of this.orders)if(e.draggable!==!1&&i(e.price))return!0;for(let e of this.positions)if(i(e.stopLoss)||i(e.takeProfit))return!0;return!1}onPointerDown(e,t,n){if(!this.config.enabled)return!1;let r=qp(this.buttons,e,n?.button),i=r?null:Qf(this.tagBoxes,e.x,e.y);return i&&this.grabTag(i,e)||(this.grabOffset=0,this.bracket.isActive()&&this.bracket.beginDrag(e,t,n?.handle))||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t,n?.handle)?(this.requestRender?.(),!0):r?(this.armed=r.action,!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,n?.order??8)}grabTag(e,t){this.grabOffset=e.lineY-t.y;let n=e.grab;switch(n.kind){case`bracket`:return this.bracket.beginDragOn(n.handle);case`draft`:return this.orderDraft.beginDragOn();case`order`:{let t=this.orders.find(e=>e.id===n.orderId);return t!==void 0&&this.dragHandler.beginOrder(t,e.lineY)}case`stop`:{let t=this.positions.find(e=>e.id===n.positionId);return t!==void 0&&this.dragHandler.beginStop(t,n.which,e.lineY)}}}onPointerMove(e,t){if(this.armed)return!0;let n=this.grabOffset===0?e:{x:e.x,y:Pf(e.y+this.grabOffset,t)};if(this.bracket.isDragging()){let e=this.bracket.drag(n,t);return e&&this.requestRender?.(),e}if(this.orderDraft.isDragging()){let e=this.orderDraft.drag(n,t);return e&&this.requestRender?.(),e}if(!this.dragHandler.isActive())return!1;let r=this.dragHandler.onPointerMove(n,t);return r&&this.requestRender?.(),r}onPointerUp(e){if(this.grabOffset=0,this.armed){let t=this.armed;this.armed=null;let n=e?qp(this.buttons,e):null;return n&&Kp(n.action,t)&&this.runButton(t),!0}if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let t=this.dragHandler.onPointerUp();return t?(t.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:t.id,newPrice:t.newPrice,previousPrice:t.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:t.id,[t.sourceType]:t.newPrice}),this.requestRender?.(),!0):!1}cancelPointer(){this.grabOffset=0;let e=!1;return this.armed&&(this.armed=null,e=!0),this.bracket.isDragging()&&(this.bracket.cancelDrag(),e=!0),this.orderDraft.isDragging()&&(this.orderDraft.cancelDrag(),e=!0),this.dragHandler.cancel()&&(e=!0),e&&this.requestRender?.(),e}onContextMenu(n,r){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let i=e.M(n.y,r);return this.contextMenu.show(n,i,this.container,this.config,e=>(0,t.priceTagText)(e,r,this.config.pricePrecision)),!0}render(e,t,n){if(this.buttons=[],this.tagBoxes=[],!this.config.enabled)return;let{chartRect:r}=t;e.save();try{e.beginPath(),e.rect(r.x,r.y,r.width,r.height),e.clip(),this.renderInPlot(e,t,n)}finally{e.restore()}}renderInPlot(e,t,n){let r=Zs(this.config,n);this.depthData&&this.depthOverlay.render(e,this.depthData,t,r),r.fillMarks!==!1&&Qp(e,this.fills,t,r);let i=this.dragHandler.getDragState();this.positionRenderer.renderLines(e,this.positions,this.currentPrice,t,r,i),this.orderRenderer.renderLines(e,this.orders,t,r,i),this.bracket.renderLines(e,t,n),this.orderDraft.renderLines(e,t,n),rp(e,[...this.bracket.tags(t,n),...this.orderDraft.tags(t,n,this.currentPrice),...this.positionRenderer.tags(this.positions,this.currentPrice,t,r,i),...this.orderRenderer.tags(this.orders,t,r,i)],t,n,this.buttons,this.tagBoxes)}renderAxisBadges(e,t,n){if(this.config.enabled)for(let r of ap(this.axisBadges(t,n),t))op(e,r.at,r.text,r.color,t,n)}axisBadges(e,t){let n=Zs(this.config,t);return[...this.positionRenderer.axisBadges(this.positions,e,n,this.dragHandler.getDragState()),...this.orderRenderer.axisBadges(this.orders,e,n,this.dragHandler.getDragState()),...this.bracket.axisBadges(e,t,this.config.pricePrecision),...this.orderDraft.axisBadges(e,t,this.config.pricePrecision)]}axisTagYs(e,n=t.DARK_THEME){return this.config.enabled?ap(this.axisBadges(e,n),e).map(e=>e.at):[]}destroy(){this.contextMenu.destroy()}},tm=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}axisTagYs(e,t){return this.manager.axisTagYs(e,t)}},nm=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;markTime;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e,t){this.markPrice=e,this.markTime=t!==void 0&&Number.isFinite(t)?t:void 0,this.checkPendingOrders(),this.checkStops()}fillTime(){return this.markTime??Date.now()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:im(e.type),draggable:!0,stopLoss:e.stopLoss,takeProfit:e.takeProfit,timeInForce:e.timeInForce};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){let t=(e,t)=>e===void 0?t:e??void 0;this.positions=this.positions.map(n=>n.id===e.positionId?{...n,stopLoss:t(e.stopLoss,n.stopLoss),takeProfit:t(e.takeProfit,n.takeProfit)}:n),this.emit(`positions`,this.positions)}async closePosition(e){let t=this.positions.find(t=>t.id===e.positionId);t&&(this.close(t,this.markPrice||t.entryPrice,`close`),this.emit(`positions`,this.positions))}async reversePosition(e){let t=this.positions.find(t=>t.id===e.positionId);if(!t)return;let n=this.markPrice||t.entryPrice;this.close(t,n,`reverse`);let r=t.quantity-(t.closedQuantity??0),i={id:this.nextId(`ord`),side:rm(t.side),type:`market`,price:n,quantity:r};this.fill(i,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity,stopLoss:e.stopLoss,takeProfit:e.takeProfit};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:this.fillTime(),positionId:n.id,reason:`order`};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}close(e,t,n){this.positions=this.positions.filter(t=>t.id!==e.id);let r=e.quantity-(e.closedQuantity??0),i=e.side===`buy`?1:-1;this.emit(`fill`,{orderId:this.nextId(`ord`),side:rm(e.side),price:t,quantity:r,time:this.fillTime(),positionId:e.id,reason:n,pnl:(t-e.entryPrice)*r*i})}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=!1;for(let t of[...this.positions]){let n=t.stopLoss!==void 0&&(t.side===`buy`?this.markPrice<=t.stopLoss:this.markPrice>=t.stopLoss),r=t.takeProfit!==void 0&&(t.side===`buy`?this.markPrice>=t.takeProfit:this.markPrice<=t.takeProfit);!n&&!r||(this.close(t,n?t.stopLoss:t.takeProfit,n?`stopLoss`:`takeProfit`),e=!0)}e&&this.emit(`positions`,this.positions)}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function rm(e){return e===`buy`?`sell`:`buy`}function im(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var am=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},om=class extends am{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(e,n=1e3){super(),this.timeframeMs=(0,t.timeframeToMs)(e),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(e){this.timeframeMs=(0,t.timeframeToMs)(e),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return this.timeframeMs>0?Math.floor(e/this.timeframeMs)*this.timeframeMs:e}},sm=class extends am{config;attempt=0;timer=null;active=!1;constructor(e){super(),this.config={...t.DEFAULT_RECONNECT,...e}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.cancel(),this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},cm=20,lm=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=null;locale=`en-US`;tag=null;setLocale(e){this.locale=e}setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}isVisible(){return this.visible}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}getTag(){return this.tag}render(n,r,i){this.tag=null;let a=i.style?.lastPrice;if(!this.visible||this.price===null||a?.visible===!1)return;let o=e.T(this.price,r),{chartRect:s}=r;if(o<s.y||o>s.y+s.height)return;let c=this.previousClose===null||this.price>=this.previousClose?a?.up??i.candleUp??`#1fa874`:a?.down??i.candleDown??`#e8505b`,l=Date.now()<this.flashUntil,u=a?.width??1;n.setLineDash((0,t.lineDash)(a?.style??`solid`,[4,3],u)),n.strokeStyle=c,n.lineWidth=u,n.globalAlpha=l?1:.7,n.beginPath(),n.moveTo(s.x,Math.round(o)+.5),n.lineTo(s.x+s.width,Math.round(o)+.5),n.stroke(),n.setLineDash([]),n.globalAlpha=1;let d=s.x+s.width+1,f=this.pricePrecision??(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max),p=r.formatPrice?r.formatPrice(this.price):(0,t.formatPrice)(this.price,f,this.locale);n.font=`bold 11px ${i.font.family}`;let m=n.measureText(p).width,h=r.priceAxisWidth??t.PRICE_AXIS_WIDTH,g=Math.min(m+12,h-2);n.fillStyle=c,E(n,d,o-cm/2,g,cm,i),this.tag={x:d,y:o-cm/2,width:g,height:cm,color:c};let _=d-5;n.beginPath(),n.moveTo(_,o),n.lineTo(_+5,o-5),n.lineTo(_+5,o+5),n.closePath(),n.fill(),n.fillStyle=A(c),n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(p,d+5,o)}},um=1e3,dm=10,fm=1440,pm=[`tick`,`barClose`,`snapshot`,`connectionChange`,`error`,`symbolInfo`],mm=new WeakMap;function hm(e){if(e instanceof bm||!e.supportedTimeframes?.length)return e;let t=mm.get(e);return t||(t=new bm(e,e.supportedTimeframes),mm.set(e,t)),t}function gm(e,n){if(n.includes(e))return e;let r=(0,t.pickBaseTimeframe)(e,n);return r&&Math.ceil((0,t.timeframeToMs)(e)/(0,t.timeframeToMs)(r))<=1440?r:null}function _m(e,n){if((0,t.tickBarCount)(n)!==null)return typeof e.fetchTrades==`function`&&typeof e.subscribeTrades==`function`;let r=e.supportedTimeframes;return!r?.length||gm(n,r)!==null}function vm(e,n){let r=(0,t.parseTimeframe)(n);if(r?.unit===`M`){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth()+r.count,1)}return e+(0,t.timeframeToMs)(n)}function ym(e,t){let n=t[0],r={time:e,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume};for(let e=1;e<t.length;e++){let n=t[e];n.high>r.high&&(r.high=n.high),n.low<r.low&&(r.low=n.low),r.close=n.close,r.volume+=n.volume}return r}var bm=class{name;fetchHistoryBefore;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;unsubscribe=[];live=null;bucket=null;parts=new Map;tail=null;generation=0;constructor(e,t){this.inner=e,this.baseTimeframes=t,this.name=e.name,e.fetchHistoryBefore&&(this.fetchHistoryBefore=(e,t,n,r)=>this.historyBefore(e,t,n,r)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),e.fetchTrades&&(this.fetchTrades=e.fetchTrades.bind(e)),e.subscribeTrades&&(this.subscribeTrades=e.subscribeTrades.bind(e)),this.listen(`bar`,e=>this.onBar(e));for(let e of pm)this.listen(e,t=>this.emit(e,t.data))}baseFor(e){let t=gm(e,this.baseTimeframes);if(!t)throw RangeError(`${this.name} cannot serve the ${e} timeframe`);return t}connect(e){let t=this.baseFor(e.timeframe);this.generation++,this.resetBucket(),this.live=t===e.timeframe?null:{symbol:e.symbol,target:e.timeframe,base:t},this.live&&this.resumeFromHistory(this.live.symbol,this.live.target),this.inner.connect({...e,timeframe:t})}disconnect(){this.generation++,this.inner.disconnect(),this.resetBucket(),this.live=null}getConnectionState(){return this.inner.getConnectionState()}async fetchHistory(e,t,n=500){let r=this.baseFor(t);if(r===t)return this.inner.fetchHistory(e,t,n);let i=this.generation,a=this.baseBarsFor(t,r,n),o=await this.inner.fetchHistory(e,r,Math.min(a,um)),s=await this.extendBack(e,r,o,a,i);return this.rememberTail(e,t,s),this.toTarget(s,t,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.generation++;for(let e of this.unsubscribe)e();this.unsubscribe.length=0,this.listeners.clear(),this.inner.dispose()}async historyBefore(e,t,n,r){let i=this.inner.fetchHistoryBefore.bind(this.inner),a=this.baseFor(t);if(a===t)return i(e,t,n,r);let o=this.generation,s=this.baseBarsFor(t,a,r),c=await i(e,a,n,Math.min(s,um)),l=await this.extendBack(e,a,c.filter(e=>e.time<n),s,o,1);return this.toTarget(l,t,r)}baseBarsFor(e,n,r){return(r+1)*Math.ceil((0,t.timeframeToMs)(e)/(0,t.timeframeToMs)(n))}async extendBack(e,t,n,r,i,a=1){let o=this.inner.fetchHistoryBefore?.bind(this.inner),s=n,c=a;for(;o&&s.length>0&&s.length<r&&c<10&&i===this.generation;){let n=s[0].time,i=await o(e,t,n,Math.min(r-s.length,um));c++;let a=i.filter(e=>e.time<n);if(a.length===0)break;s=a.concat(s)}return s}toTarget(e,n,r){if(e.length===0)return[];let i=(0,t.resampleBars)(e,n);return i.length>1&&i[0].time!==e[0].time&&i.shift(),i.length>r?i.slice(i.length-r):i}rememberTail(e,n,r){if(r.length===0)return;let i=(0,t.timeframeBucketStart)(r[r.length-1].time,n),a=r.length;for(;a>0&&(0,t.timeframeBucketStart)(r[a-1].time,n)===i;)a--;this.tail={symbol:e,target:n,bucket:i,bars:r.slice(a)}}resumeFromHistory(e,t){let n=this.tail;if(!(!n||n.symbol!==e||n.target!==t)){this.bucket=n.bucket;for(let e of n.bars)this.parts.set(e.time,e)}}onBar(e){let n=this.live;if(!n){this.emit(`bar`,e.data);return}let{bar:r,closed:i}=e.data,a=(0,t.timeframeBucketStart)(r.time,n.target);if(this.bucket!==null&&a<this.bucket)return;if(this.bucket!==null&&a>this.bucket){let e=this.composed();e&&this.emit(`bar`,{bar:e,closed:!0}),this.resetBucket()}this.bucket=a,this.parts.set(r.time,r);let o=this.composed();if(!o)return;let s=i&&(0,t.timeframeBucketStart)(vm(r.time,n.base),n.target)!==a;this.emit(`bar`,{bar:o,closed:s}),s&&(this.resetBucket(),this.bucket=(0,t.timeframeBucketStart)(vm(r.time,n.base),n.target))}composed(){if(this.bucket===null||this.parts.size===0)return null;let e=[...this.parts.values()].sort((e,t)=>e.time-t.time);return ym(this.bucket,e)}resetBucket(){this.bucket=null,this.parts=new Map}listen(e,t){let n=e=>t(e);this.inner.on(e,n),this.unsubscribe.push(()=>this.inner.off(e,n))}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},xm=1e3,Sm=15e3,Cm=[`tick`,`bar`,`barClose`,`snapshot`,`connectionChange`,`error`,`symbolInfo`],wm=class{bar=null;count=0;lastTime=-1/0;constructor(e){this.tradesPerBar=e}push(e){let t=[],n=!1;for(let r of e){if(this.bar)this.bar={...this.bar,high:Math.max(this.bar.high,r.price),low:Math.min(this.bar.low,r.price),close:r.price,volume:this.bar.volume+r.volume};else{let e=Math.max(r.time,this.lastTime+1);this.lastTime=e,this.bar={time:e,open:r.price,high:r.price,low:r.price,close:r.price,volume:r.volume},this.count=0}this.count++,n=!0,this.count>=this.tradesPerBar&&(t.push({bar:this.bar,closed:!0}),this.bar=null,n=!1)}return n&&this.bar&&t.push({bar:this.bar,closed:!1}),t}build(e){return this.bar=null,this.count=0,this.lastTime=-1/0,this.push(e).map(e=>e.bar)}},Tm=class{name;supportedTimeframes;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;tick=null;stopTrades=null;keepAlive=null;tickMode=!1;state=`disconnected`;constructor(e){this.inner=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes,e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),this.fetchTrades=e.fetchTrades.bind(e),this.subscribeTrades=e.subscribeTrades.bind(e);for(let t of Cm)e.on(t,e=>{this.tickMode||this.emit(t,e.data)})}async fetchHistory(e,n,r){let i=(0,t.tickBarCount)(n);if(i===null)return this.inner.fetchHistory(e,n,r);let a=(await this.inner.fetchTrades(e,xm)).filter(km).sort((e,t)=>e.time-t.time),o=new wm(i),s=o.build(a);return this.tick={symbol:e,builder:o,after:a.length?a[a.length-1].time:-1/0},r!==void 0&&r>0?s.slice(-r):s}fetchHistoryBefore(e,n,r,i){return(0,t.tickBarCount)(n)!==null||!this.inner.fetchHistoryBefore?Promise.resolve([]):this.inner.fetchHistoryBefore(e,n,r,i)}connect(e){this.disconnect();let n=(0,t.tickBarCount)(e.timeframe);if(n===null){this.tickMode=!1,this.inner.connect(e);return}this.tickMode=!0;let r=this.tick?.symbol===e.symbol?this.tick:{symbol:e.symbol,builder:new wm(n),after:-1/0};this.tick=r,this.stopTrades=this.inner.subscribeTrades(e.symbol,e=>{let t=e.filter(e=>km(e)&&e.time>=r.after);for(let{bar:e,closed:n}of r.builder.push(t))this.emit(`bar`,{bar:e,closed:n}),this.emit(`tick`,{time:e.time,price:e.close,volume:e.volume})}),this.state=`connected`,this.emit(`connectionChange`,`connected`),this.keepAlive=setInterval(()=>this.emit(`connectionChange`,`connected`),Sm)}disconnect(){this.tickMode?(this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.state=`disconnected`):this.inner.disconnect()}getConnectionState(){return this.tickMode?this.state:this.inner.getConnectionState()}dispose(){this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.listeners.clear(),this.inner.dispose()}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},Em=new WeakMap;function Dm(e){if(e instanceof Tm||!Om(e))return e;let t=Em.get(e);return t||(t=new Tm(e),Em.set(e,t)),t}function Om(e){return typeof e.fetchTrades==`function`&&typeof e.subscribeTrades==`function`}function km(e){return Number.isFinite(e?.time)&&Number.isFinite(e?.price)&&Number.isFinite(e?.volume)}var Am=2e4,jm=class extends am{config=null;adapter=null;aggregator=null;reconnector;priceLine=new lm;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;connectSeq=0;constructor(){super(),this.reconnector=new sm,this.wireReconnector()}async connect(e){this.disconnect();let n=Dm(hm(e.adapter));this.config={...t.DEFAULT_STREAM_CONFIG,...e,adapter:n},this.adapter=n,this.aggregator=new om(e.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new sm(e.reconnect??t.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.connectSeq++,this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!this.config||!this.adapter)return;let e=++this.connectSeq,{symbol:t,timeframe:n}=this.config;this.setState(`connecting`);try{let r=await this.adapter.fetchHistory(t,n,this.config.historyLimit??500);if(e!==this.connectSeq||!this.adapter)return;r.length>0&&(this.previousClose=r[r.length-1].close,this.updatePrice(r[r.length-1].close)),this.emit(`snapshot`,r),this.adapter.connect({symbol:t,timeframe:n}),this.startHeartbeat()}catch(t){if(e!==this.connectSeq)return;let n=t instanceof Error?t.message:String(t);this.emit(`error`,{message:n,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),(t.bid!==void 0||t.ask!==void 0)&&this.emit(`quote`,{bid:t.bid,ask:t.ask}),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i));let a=e=>{e?.data&&typeof e.data==`object`&&this.emit(`symbolInfo`,e.data)};try{e.on(`symbolInfo`,a),this.unsubscribers.push(()=>e.off(`symbolInfo`,a))}catch{}}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}wake(e){!this.adapter||!this.config||this.state===`connecting`||this.state===`disconnected`||this.state===`connected`&&e===`visible`&&Date.now()-this.lastMessageTime<=Am||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.doConnect())}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Mm=class extends am{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Nm(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Fm(e[1]),r=Fm(e[2]),i=Fm(e[3]),a=Fm(e[4]),o=Fm(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Pm(e){if(!Im(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Fm(e.o),r=Fm(e.h),i=Fm(e.l),a=Fm(e.c),o=Fm(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function Fm(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Im(e){return typeof e==`object`&&!!e}function J(e){let t=typeof e==`string`?Number(e):e;return typeof t==`number`&&Number.isFinite(t)?t:void 0}function Lm(e){let n=e&&typeof e==`object`&&`data`in e?e.data:e;if(!n||typeof n!=`object`)return null;let r=n;return r.e===`24hrMiniTicker`?(0,t.readQuote)({symbol:r.s,last:J(r.c),open:J(r.o),high:J(r.h),low:J(r.l),volume:J(r.v),time:J(r.E)}):null}function Rm(e){if(!e||typeof e!=`object`)return null;let n=e;return(0,t.readQuote)({symbol:n.symbol,last:J(n.lastPrice),change:J(n.priceChange),changePercent:J(n.priceChangePercent),open:J(n.openPrice),high:J(n.highPrice),low:J(n.lowPrice),prevClose:J(n.prevClosePrice),volume:J(n.volume),bid:J(n.bidPrice),ask:J(n.askPrice),time:J(n.closeTime)})}function zm(e){if(!e||typeof e!=`object`)return null;let t=e,n=J(t.T),r=J(t.p),i=J(t.q);return n!==void 0&&r!==void 0&&i!==void 0?{time:n,price:r,volume:i}:null}var Bm={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},Vm=1e3,Hm=200,Um=[`USDT`,`USDC`,`FDUSD`,`BTC`,`ETH`,`BNB`,`EUR`,`TRY`,`BRL`,`JPY`];function Wm(e){let t=e.currency?Um.indexOf(e.currency):-1;return t<0?0:40-t*3}function Gm(e){if(typeof e.symbol!=`string`||e.status!==`TRADING`)return null;let n=typeof e.baseAsset==`string`?e.baseAsset:``,r=typeof e.quoteAsset==`string`?e.quoteAsset:``,i=Array.isArray(e.filters)?e.filters.find(e=>typeof e==`object`&&!!e&&e.filterType===`PRICE_FILTER`&&typeof e.tickSize==`string`):void 0,a={symbol:e.symbol,description:n&&r?`${n} / ${r}`:e.symbol,exchange:`Binance`,type:`crypto`};return i&&(a.pricePrecision=(0,t.stepDecimals)(i.tickSize),a.minTick=Number(i.tickSize)),a.timezone=`UTC`,r&&(a.currency=r),a}function Km(e){let t=e?.symbols;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=Gm(e);t&&n.push(t)}return n}var qm=class{name=`binance`;supportedTimeframes=Object.keys(Bm);ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;symbolList=null;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){if(this.ws){let e=this.ws;e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n=500){return this.fetchKlines(e,t,n,``)}async searchSymbols(e,n){return(0,t.rankSymbols)(await this.loadSymbols(),e,n?.limit??50,Wm)}async resolveSymbol(e){if(this.symbolList){let t=(await this.symbolList.catch(()=>null))?.find(t=>t.symbol===e);if(t)return t}let t=await fetch(`${this.restBase}/exchangeInfo?symbol=${encodeURIComponent(e)}`);return t.ok?Km(await t.json())[0]??null:null}loadSymbols(){return this.symbolList||(this.symbolList=(async()=>{let e=await fetch(`${this.restBase}/exchangeInfo`);if(!e.ok)throw Error(`Binance REST error: ${e.status}`);return Km(await e.json())})(),this.symbolList.catch(()=>{this.symbolList=null})),this.symbolList}subscribeQuotes(e,t){let n=[...new Set(e.map(e=>e.trim().toUpperCase()))].filter(e=>/^[A-Z0-9]{2,30}$/.test(e)).slice(0,Hm);if(n.length===0)return()=>{};let r=!1,i=null,a=null,o=0,s=new Set,c=new AbortController;(async()=>{let e=await fetch(`${this.restBase}/ticker/24hr?symbols=${encodeURIComponent(JSON.stringify(n))}`,{signal:c.signal});if(e.ok)return e.json();let t=await fetch(`${this.restBase}/ticker/24hr`,{signal:c.signal});if(!t.ok)return[];let r=await t.json(),i=new Set(n);return Array.isArray(r)?r.filter(e=>i.has(e?.symbol)):[]})().then(e=>{if(r||!Array.isArray(e))return;let n=e.map(Rm).filter(e=>e!==null&&!s.has(e.symbol));n.length>0&&t(n)}).catch(()=>{});let l=this.wsBase.replace(/\/ws\/?$/,``),u=()=>{if(!r){try{i=new WebSocket(`${l}/stream?streams=${n.map(e=>`${e.toLowerCase()}@miniTicker`).join(`/`)}`)}catch{d();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=Lm(n);!i||r||(s.add(i.symbol),t([i]))},i.onclose=()=>{i=null,d()}}},d=()=>{r||(a=setTimeout(u,Math.min(3e4,1e3*2**o++)))};return u(),()=>{r=!0,c.abort(),a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=await fetch(`${this.restBase}/aggTrades?symbol=${encodeURIComponent(e.toUpperCase())}&limit=${n}`);if(!r.ok)throw Error(`Binance aggTrades ${r.status}`);let i=await r.json();return Array.isArray(i)?i.map(zm).filter(e=>e!==null):[]}subscribeTrades(e,t){let n=`${e.trim().toLowerCase()}@aggTrade`;if(!/^[a-z0-9]{2,30}@aggTrade$/.test(n))return()=>{};let r=!1,i=null,a=null,o=0,s=()=>{if(!r){try{i=new WebSocket(`${this.wsBase}/${n}`)}catch{c();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=zm(n);i&&!r&&t([i])},i.onclose=()=>{i=null,c()}}},c=()=>{r||(a=setTimeout(s,Math.min(3e4,1e3*2**o++)))};return s(),()=>{r=!0,a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}fetchHistoryBefore(e,t,n,r=500){return this.fetchKlines(e,t,Math.min(r,Vm),`&endTime=${Math.floor(n)-1}`)}async fetchKlines(e,t,n,r){let i=Bm[t]??`15m`,a=`${this.restBase}/klines?symbol=${e}&interval=${i}&limit=${n}${r}`,o=await fetch(a);if(!o.ok)throw Error(`Binance REST error: ${o.status}`);let s=await o.json();if(!Array.isArray(s))return[];let c=[];for(let e of s){let t=Nm(e);t&&c.push(t)}return c}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Bm[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Pm(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Jm=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;oldestOpen=new Map;forming=null;formingTimeframe=null;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}subscribeQuotes(e,t){let n=[...new Set(e)].map(e=>{let t=this.options.basePrice*(.5+Ym(e)%1e3/1e3);return{symbol:e,open:t,last:t,high:t,low:t,volume:0}});if(n.length===0)return()=>{};let r=this.options.volatility/100,i=()=>t(n.map(e=>({symbol:e.symbol,last:e.last,open:e.open,high:e.high,low:e.low,volume:e.volume,change:e.last-e.open,changePercent:(e.last-e.open)/e.open*100,time:Date.now()})));i();let a=setInterval(()=>{for(let e of n)e.last=Math.max(e.open*.01,e.last*(1+(Math.random()-.5)*r)),e.high=Math.max(e.high,e.last),e.low=Math.min(e.low,e.last),e.volume+=Math.random()*100;i()},this.options.tickInterval);return()=>clearInterval(a)}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=Date.now(),i=this.options.volatility/1e3,a=this.options.basePrice*(.5+Ym(e)%1e3/1e3),o=[];for(let e=n-1;e>=0;e--)a=Math.max(a*.5,a*(1+(Math.random()-.5)*i)),o.push({time:r-e*1e3,price:a,volume:Math.random()*5});return o}subscribeTrades(e,t){let n=this.options.volatility/1e3,r=this.options.basePrice*(.5+Ym(e)%1e3/1e3),i=setInterval(()=>{let e=[];for(let t=0;t<3;t++)r=Math.max(r*.5,r*(1+(Math.random()-.5)*n)),e.push({time:Date.now(),price:r,volume:Math.random()*5});t(e)},this.options.tickInterval);return()=>clearInterval(i)}async fetchHistory(e,t,n){let r=this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize);return r.length>0&&this.oldestOpen.set(e,r[0].open),this.forming=r.length>0?{...r[r.length-1]}:null,this.formingTimeframe=t,r}async fetchHistoryBefore(e,n,r,i){let a=(0,t.timeframeToMs)(n),o=this.options.volatility/100,s=Array(Math.max(0,i)),c=this.oldestOpen.get(e)??this.options.basePrice;for(let e=0;e<i;e++){let t=c/(1+(Math.random()-.52)*o),n=Math.max(t,c)+Math.random()*c*o*.3,l=Math.max(0,Math.min(t,c)-Math.random()*c*o*.3),u=Math.floor(1e4+Math.random()*1e5);s[i-1-e]={time:r-(e+1)*a,open:t,high:n,low:l,close:c,volume:u},c=t}return this.oldestOpen.set(e,c),s}async searchSymbols(e,n){return(0,t.rankSymbols)(this.options.symbols??[],e,n?.limit??50)}async resolveSymbol(e){return this.options.symbols?.find(t=>t.symbol===e)??null}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(e,n){let r=[],i=(0,t.timeframeToMs)(e),a=Math.floor(Date.now()/i)*i,o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=a-e*i,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let e=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let e=this.options.volatility/100,t=(Math.random()-.48)*this.currentPrice*e*.3;this.currentPrice+=t;let n=Date.now(),r=this.tickBar(n,t,Math.floor(100+Math.random()*5e3));this.emitEvent(`bar`,{bar:r,closed:!1}),this.emitEvent(`tick`,{time:n,price:this.currentPrice,volume:r.volume})},e)}tickBar(e,n,r){let i=this.config.timeframe,a=(0,t.timeframeToMs)(i),o=Math.floor(e/a)*a,s=this.currentPrice,c=this.formingTimeframe===i?this.forming:null,l=Math.abs(n)*.2,u;if(c&&c.time===o)u={time:o,open:c.open,high:Math.max(c.high,s+l),low:Math.min(c.low,s-l),close:s,volume:c.volume+r};else{let e=c?.close??s-n;u={time:o,open:e,high:Math.max(e,s)+l,low:Math.min(e,s)-l,close:s,volume:r}}return this.forming=u,this.formingTimeframe=i,{...u}}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Ym(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return t}var Xm=class{name;supportedTimeframes;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}let t=this.ws;t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,t.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Zm=class{name;supportedTimeframes;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Y(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Qm(e){return typeof e==`object`&&!!e}var $m={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function eh(e){return $m[e]??3600}var th=class extends Zm{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,supportedTimeframes:Object.keys($m),intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>nh(t,e,n)})}};async function nh(e,t,n){let r=`${e}/products/${t}/candles?granularity=${eh(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return rh(await i.json())}function rh(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=ih(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function ih(e){if(!Array.isArray(e)||e.length<6)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var ah={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function oh(e){return ah[e]??`1`}var sh=class extends Xm{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${oh(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${oh(e.timeframe)}.${e.symbol}`]}),supportedTimeframes:Object.keys(ah),parseMessage:ch,fetchHistory:(e,n,i)=>lh(t,r,e,n,i),fetchHistoryBefore:(e,n,i,a)=>lh(t,r,e,n,a,Math.floor(i)-1)})}};function ch(e){if(!Qm(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Qm(n))return null;let r=Y(n.start),i=Y(n.open),a=Y(n.high),o=Y(n.low),s=Y(n.close),c=Y(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function lh(e,t,n,r,i,a){let o=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${oh(r)}&limit=${Math.min(Math.max(i,1),1e3)}${a===void 0?``:`&end=${a}`}`,s=await fetch(o);if(!s.ok)throw Error(`Bybit REST error: ${s.status}`);return uh(await s.json())}function uh(e){if(!Qm(e)||!Qm(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=dh(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function dh(e){if(!Array.isArray(e)||e.length<6)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var fh={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function ph(e){return fh[e]??1}var mh=class extends Xm{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ph(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ph(e.timeframe)}}),supportedTimeframes:Object.keys(fh),parseMessage:hh,fetchHistory:(e,n)=>gh(t,e,n)})}};function hh(e){if(!Qm(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Qm(n))return null;let r=Y(n.open),i=Y(n.high),a=Y(n.low),o=Y(n.close),s=Y(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function gh(e,t,n){let r=ph(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return _h(await o.json())}function _h(e){if(!Qm(e)||!Qm(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=vh(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function vh(e){if(!Array.isArray(e)||e.length<7)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var yh={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12,fontFamily:null},bh=class{config={...yh};symbol=``;timeframe=``;hoverBar=null;hoverPrev=null;indicators=[];statusText=null;exchange=``;drawnHeight=null;locale=`en-US`;pricePrecision=null;setConfig(e){Object.assign(this.config,e),this.drawnHeight=null}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}setSymbol(e){this.symbol=e,this.drawnHeight=null}setTimeframe(e){this.timeframe=e,this.drawnHeight=null}setChartType(e){}setHoverBar(e,t=null){this.hoverBar=e,this.hoverPrev=e?t:null}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e,this.drawnHeight=null}setExchange(e){this.exchange=e,this.drawnHeight=null}title(){return this.config.showSymbol?[this.symbol,this.timeframe,this.exchange].filter(Boolean).join(` · `):``}titleCells(e,t,n,r,i){let a=[],o=this.title();if(o){let i=`600 ${t}px ${n}`;e.font=i,a.push({label:``,labelWidth:0,value:o,width:e.measureText(o).width,color:r,font:i})}if(this.statusText){let r=`${t}px ${n}`;e.font=r,a.push({label:``,labelWidth:0,value:this.statusText,width:e.measureText(this.statusText).width,color:i,font:r})}return a}priceCells(e,n,r,i,a,o,s,c){let l=`${o}px ${s}`;e.font=l;let u=i.close>=i.open,d=this.pricePrecision??(0,t.autoPricePrecision)(n.priceRange.min,n.priceRange.max),f=e=>n.formatPrice?.(e)??(0,t.formatPrice)(e,d,this.locale),p=[{label:`O`,value:f(i.open),color:c},{label:`H`,value:f(i.high),color:c},{label:`L`,value:f(i.low),color:c},{label:`C`,value:f(i.close),color:u?r.candleUp:r.candleDown}];if(this.config.showChange){let e=i.close-a.close,n=a.close===0?0:e/a.close*100,o=e>=0?`+`:``,s=(0,t.formatPrice)(n,2,this.locale);p.push({label:``,value:`${o}${f(e)} (${o}${s}%)`,color:e>=0?r.candleUp:r.candleDown})}return p.map(t=>({...t,labelWidth:t.label?e.measureText(t.label+` `).width:0,width:Th(e,t.value),font:l}))}getHeight(){if(!this.config.visible||this.config.position!==`top-left`)return 0;if(this.drawnHeight!==null)return this.drawnHeight;let e=this.config.fontSize,t=xh;return(this.config.showOHLC||this.title()||this.statusText)&&(t+=e+Ch),this.config.showVolume&&(t+=e+2),t}render(e,t,n,r){if(!this.config.visible||r.length===0)return;let i=this.hoverBar??r[r.length-1],a=this.hoverBar?this.hoverPrev??i:r.length>1?r[r.length-2]:i,{chartRect:o}=t,s=this.config.fontSize,c=this.config.fontFamily??n.font.family,l=n.style?.legend.text??n.text,u=n.style?.legend.label??n.textSecondary,d=this.config.position===`top-left`,f=d?o.x+Sh:o.x+o.width-Sh,p=o.y+xh;e.textAlign=d?`left`:`right`,e.textBaseline=`top`;let m=this.titleCells(e,s,c,l,u);if(this.config.showOHLC&&m.push(...this.priceCells(e,t,n,i,a,s,c,l)),m.length>0){e.font=`${s}px ${c}`;let t=e.measureText(` `).width;for(let n of wh(m,t,o.width-2*Sh)){let r=n.reduce((e,n)=>e+n.labelWidth+n.width+t,-t),i=d?f:f-r;e.textAlign=`left`;for(let r of n)e.font=r.font,r.label&&(e.fillStyle=u,e.fillText(r.label,i,p),i+=r.labelWidth),e.fillStyle=r.color,e.fillText(r.value,i,p),i+=r.width+t;p+=s+Ch}e.textAlign=d?`left`:`right`}if(this.config.showVolume){e.font=`${s}px ${c}`,e.fillStyle=u;let t=i.volume>=1e6?`${(i.volume/1e6).toFixed(2)}M`:i.volume>=1e3?`${(i.volume/1e3).toFixed(2)}K`:i.volume.toFixed(0);e.fillText(`Vol ${t}`,f,p),p+=s+2}if(this.drawnHeight=d?p-o.y:null,this.indicators.length>0){e.font=`${s}px ${c}`;let t=e.measureText(` `).width,n=this.indicators.map(t=>{let n=`${t.name} ${t.value}`;return{entry:n,color:t.color,width:Th(e,n)}}),r=n.reduce((e,n)=>e+n.width+t,-t),i=d?f:f-r;e.textAlign=`left`;for(let{entry:r,color:a,width:o}of n)e.fillStyle=a,e.fillText(r,i,p),i+=o+t}}},xh=6,Sh=8,Ch=3;function wh(e,t,n){let r=[],i=[],a=0;for(let o of e){let e=o.labelWidth+o.width;i.length>0&&a+t+e>n&&(r.push(i),i=[],a=0),a+=(i.length>0?t:0)+e,i.push(o)}return i.length>0&&r.push(i),r}function Th(e,t){let n=t.replace(/\d/g,`0`);return Math.max(e.measureText(t).width,e.measureText(n.replace(/[-−]/g,`+`)).width,e.measureText(n.replace(/\+/g,`-`)).width)}var Eh=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},Dh=class{config=null;setConfig(e){this.config=e}isVisible(){return!!this.config?.text}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=n.style?.watermark.color??this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},Oh={solid:null,dashed:[6,4],dotted:[2,3]},kh=6,Ah=8;function jh(e,t){let n=[...e].sort((e,t)=>t.rank-e.rank||e.px-t.px),r=[],i=[];for(let e of n){let n=0,a=r.length;for(;n<a;){let t=n+a>>1;r[t]<e.px?n=t+1:a=t}n>0&&e.px-r[n-1]<t||n<r.length&&r[n]-e.px<t||(r.splice(n,0,e.px),i.push(e))}return i.sort((e,t)=>e.px-t.px)}var Mh=class{config={visible:!1};cachedBreaksTyped=[];cachedMedianStep=0;cacheValid=!1;lastDataLength=0;locale=`en-US`;tz=null;setConfig(e){Object.assign(this.config,e)}setLocale(e){this.locale=e}setTimezone(e){e!==this.tz&&(this.tz=e,this.invalidateCache())}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(e){if(e.length<2)return[];if(this.cacheValid&&e.length===this.lastDataLength)return this.cachedBreaksTyped;let n=[],r=(0,t.barTimeUnit)(e),i=(0,t.timeParts)(e[0].time*r,this.tz);for(let a=1;a<e.length;a++){let o=e[a].time*r,s=(0,t.timeParts)(o,this.tz);if(s.year!==i.year)n.push({idx:a,kind:`year`,time:o,year:s.year});else if(s.month!==i.month)n.push({idx:a,kind:`month`,time:o,year:s.year});else if(s.day!==i.day){let e=new Date(Date.UTC(s.year,s.month-1,s.day)).getUTCDay()===1;n.push({idx:a,kind:e?`week`:`day`,time:o,year:s.year})}i=s}return this.lastDataLength=e.length,this.cachedBreaksTyped=n,this.cachedMedianStep=Fh(e),this.cacheValid=!0,n}render(e,t,n,r){this.renderLines(e,t,n,r),this.renderLabels(e,t,n,r)}renderLines(e,t,n,r){let i=this.lineMarks(t,r,n);if(i.length===0)return;let{chartRect:a}=t,o=this.look(n),s=Oh[o.style];e.save(),s&&e.setLineDash(s),e.strokeStyle=o.color;for(let t of i)e.globalAlpha=t.alpha,e.lineWidth=t.width,e.beginPath(),e.moveTo(t.px,a.y),e.lineTo(t.px,a.y+a.height),e.stroke();e.restore()}renderLabels(e,t,n,r){let i=this.lineMarks(t,r,n).filter(e=>e.label!==null);if(i.length===0)return;let{chartRect:a}=t;e.save(),e.font=`600 11px ${n.font.family}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillStyle=n.textSecondary;let o=[],s=[...i].sort((e,t)=>t.rank-e.rank||e.px-t.px);for(let t of s){let n=t.px+4,r=n+e.measureText(t.label).width;o.some(e=>n<e.right+Ah&&r+Ah>e.left)||(o.push({left:n,right:r}),e.globalAlpha=Math.min(1,t.alpha+.35),e.fillText(t.label,n,a.y+4))}e.restore()}lineRects(e,t,n){let r=this.lineMarks(e,n,t);if(r.length===0)return[];let{color:i,style:a}=this.look(t),o=Oh[a]??void 0,{y:s,height:c}=e.chartRect;return r.map(e=>({x:e.px-e.width/2,y:s,width:e.width,height:c,color:i,alpha:e.alpha,...o?{dash:o}:{}}))}look(e){let t=e.style?.sessionBreaks;return{color:t?.color??this.config.color??e.axisLine,style:t?.style??this.config.lineStyle??`dashed`,width:t?.width??this.config.lineWidth??1}}lineMarks(e,t,n){return jh(this.marks(e,t,n),kh)}marks(n,r,i){if(!this.config.visible||r.length<2)return[];let a=this.computeBreaksTyped(r);if(a.length===0||this.cachedMedianStep>=1380*60*1e3)return[];let{chartRect:o}=n,s=this.look(i).width,c=[];for(let r of a){let i=e.b(r.idx,n)-(n.barWidth+n.barSpacing)/2;if(i<o.x-1||i>o.x+o.width+1)continue;let a=Math.round(i)+.5,l=.25,u=s,d=null,f=3;r.kind===`day`?(l=.22,f=0):r.kind===`week`?(l=.34,f=1,d=(0,t.zonedDateFormatter)(this.locale,Nh,this.tz)(r.time)):r.kind===`month`?(l=.5,f=2,u=s+.5,d=(0,t.zonedDateFormatter)(this.locale,Ph,this.tz)(r.time)):(l=.7,u=s+1,d=String(r.year)),c.push({px:a,width:u,alpha:l,label:d,rank:f})}return c}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[],this.cachedMedianStep=0,this.cacheValid=!1}},Nh={month:`short`,day:`numeric`},Ph={month:`short`,year:`numeric`};function Fh(e){if(e.length<2)return 0;let n=Math.min(50,e.length-1),r=(0,t.barTimeUnit)(e),i=[];for(let t=1;t<=n;t++)i.push((e[t].time-e[t-1].time)*r);return i.sort((e,t)=>e-t),i[Math.floor(i.length/2)]}var Ih=864e5;function Lh(e,t){let n={...e,...t};return t.tzOffsetMinutes!==void 0&&t.timeZone===void 0&&delete n.timeZone,n.windows?n.windows=n.windows.map(e=>({...e})):delete n.windows,n}function Rh(e,t){let n=((e+t*6e4)%Ih+Ih)%Ih;return Math.floor(n/6e4)}function zh(e,t,n){return t===n?!0:t<n?e>=t&&e<n:e>=t||e<n}function Bh(e,n){let r=Rh(e,n.timeZone?(0,t.zoneOffsetMinutes)(n.timeZone,e):n.tzOffsetMinutes??0);return n.windows&&n.windows.length>0?n.windows.some(e=>zh(r,e.startMinute,e.endMinute)):zh(r,n.startMinute,n.endMinute)}var Vh={startMinute:570,endMinute:960,tzOffsetMinutes:-300,timeZone:`America/New_York`},Hh=class{visible=!1;config={...Vh};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){this.config=Lh(this.config,e)}replaceConfig(e){this.config=Lh(e,{})}getConfig(){return{...this.config,windows:this.config.windows?.map(e=>({...e}))}}render(e,t,n,r){let i=this.rects(t,n,r);if(i.length!==0){e.save(),e.fillStyle=i[0].color;for(let t of i)e.fillRect(t.x,t.y,t.width,t.height);e.restore()}}rects(t,n,r){if(!this.visible||t.length===0)return[];let{chartRect:i}=n,{from:a,to:o}=n.visibleRange,s=Math.max(0,a),c=Math.min(o,t.length-1);if(c<s)return[];let l=n.barWidth+n.barSpacing,u=r.name===`light`?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`,d=[],f=-1,p=(t,r)=>{let a=e.b(t,n)-l/2,o=e.b(r,n)+l/2;d.push({x:a,y:i.y,width:o-a,height:i.height,color:u,alpha:1})};for(let e=s;e<=c;e++){let n=!Bh(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}return f!==-1&&p(f,c),d}},Uh=[2,3],Wh=16,Gh=class{highLow=!1;quote=null;quoteShown=!0;priceText=null;setPriceText(e){this.priceText=e}setQuoteShown(e){this.quoteShown=e}setHighLow(e){this.highLow=e}isHighLowVisible(){return this.highLow}setBidAsk(e){this.quote=e?{...e}:null}getBidAsk(){return this.quote?{...this.quote}:null}levels(e,t){let n=[];if(this.highLow){let r=Math.max(0,t.visibleRange.from),i=Math.min(e.length-1,t.visibleRange.to),a=-1/0,o=1/0;for(let t=r;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);Number.isFinite(a)&&n.push({kind:`high`,price:a}),Number.isFinite(o)&&n.push({kind:`low`,price:o})}let{bid:r,ask:i}=(this.quoteShown?this.quote:null)??{};return r!==void 0&&Number.isFinite(r)&&n.push({kind:`bid`,price:r}),i!==void 0&&Number.isFinite(i)&&n.push({kind:`ask`,price:i}),n}render(t,n,r,i){let{chartRect:a}=n;t.save(),t.setLineDash(Uh),t.lineWidth=1;for(let o of this.levels(i,n)){let i=Math.round(e.T(o.price,n))+.5;i<a.y||i>a.y+a.height||(t.strokeStyle=Kh(o.kind,r),t.beginPath(),t.moveTo(a.x,i),t.lineTo(a.x+a.width,i),t.stroke())}t.restore()}renderAxisTags(n,r,i,a){let{chartRect:o}=r,s=o.x+o.width+1,c=(r.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2,l=(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max);n.save(),n.font=`${i.font.sizeSmall}px ${i.font.family}`,n.textBaseline=`middle`,n.textAlign=`left`;for(let u of this.levels(a,r)){let a=e.T(u.price,r);if(a<o.y||a>o.y+o.height)continue;n.fillStyle=Kh(u.kind,i),E(n,s,a-Wh/2,c,Wh,i),n.fillStyle=i.background;let d=r.formatPrice?.(u.price)??this.priceText?.(u.price)??(0,t.formatPrice)(u.price,l);n.fillText(d,s+5,a)}n.restore()}};function Kh(e,t){switch(e){case`bid`:return t.candleUp;case`ask`:return t.candleDown;default:return t.style?.highLow.color??t.textSecondary}}var qh=12,Jh=3,Yh=500,Xh=2,Zh=[`movesUp`,`movesDown`];function Qh(e){return e.channel===`price`&&!e.drawingId&&!e.target&&!Zh.includes(e.condition)}function $h(e,t,n,r){switch(r){case`crossingUp`:return e!==void 0&&e<n&&t>=n;case`crossingDown`:return e!==void 0&&e>n&&t<=n;case`crossing`:return e!==void 0&&(e<n&&t>=n||e>n&&t<=n);case`greaterThan`:return t>n;case`lessThan`:return t<n;default:return!1}}var eg=[`crossing`,`crossingUp`,`crossingDown`];function tg(e,t,n){let r=e<0&&t>=0,i=e>0&&t<=0;return n===`crossingUp`?r:n===`crossingDown`?i:r||i}var ng=1,rg=2**31-1,ig=class extends am{alerts=[];lastValues=new Map;drawingSides=new Map;drawingLevels=null;requestRender=null;pricePrecision=null;barTime=null;expiryTimer=null;history=new Map;lastDiffs=new Map;setBarTime(e){this.barTime=e}setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a,o={}){let s=ag(t,i,o),c=`tc_alert_${ng++}`,l={id:c,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a,...s};return this.alerts.push(l),s.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`added`,l),this.requestRender?.(),c}setDrawingLevels(e){this.drawingLevels=e}addDrawingAlert(e,t=`crossing`,n,r=!1,i){if(!eg.includes(t))throw RangeError(`An alert on a drawing takes a crossing condition, not "${t}"`);let a=`tc_alert_${ng++}`,o={id:a,price:this.drawingLevels?.(e)?.[0]??NaN,condition:t,message:n,triggered:!1,repeating:r,channel:`price`,label:i,drawingId:e};return this.alerts.push(o),this.emit(`added`,o),a}removeDrawingAlerts(e){for(let t of this.alerts.filter(t=>t.drawingId===e))this.removeAlert(t.id)}takeDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId===e);for(let e of t)this.removeAlert(e.id);return t.map(e=>({...e}))}restoreAlerts(e){for(let t of e){if(this.alerts.some(e=>e.id===t.id))continue;let e={...t};this.alerts.push(e),this.emit(`added`,e)}this.scheduleExpiry(),this.requestRender?.()}pruneDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId!==void 0&&!e.has(t.drawingId));for(let e of t)this.removeAlert(e.id);return t.length}removeAlert(e){this.drawingSides.delete(e),this.lastDiffs.delete(e);let t=this.alerts.some(t=>t.id===e&&t.expiresAt!==void 0);this.alerts=this.alerts.filter(t=>t.id!==e),t&&this.scheduleExpiry(),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(t,n,r=6){let{chartRect:i}=n;if(t.y<i.y||t.y>i.y+i.height)return null;let a=null,o=r;for(let r of this.alerts){if(!Qh(r))continue;let i=Math.abs(e.T(r.price,n)-t.y);i<=o&&(o=i,a=r)}return a}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,n.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.lastDiffs.clear(),this.drawingSides.clear(),this.scheduleExpiry(),this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e),this.checkDrawingAlerts(e)}checkDrawings(e){this.checkDrawingAlerts(e)}expire(){let e=Date.now(),t=this.alerts.filter(t=>!t.expired&&t.expiresAt!==void 0&&e>=t.expiresAt&&!(t.triggered&&!t.repeating));if(t.length!==0){for(let e of t)e.expired=!0;try{for(let e of t)this.emit(`expired`,{...e}),this.emit(`updated`,{...e})}finally{this.requestRender?.(),this.scheduleExpiry()}}}scheduleExpiry(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null;let e=Math.min(...this.alerts.filter(e=>!e.expired&&e.expiresAt!==void 0&&!(e.triggered&&!e.repeating)).map(e=>e.expiresAt));if(!Number.isFinite(e))return;let t=Math.min(Math.max(0,e-Date.now()),rg);this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.expire(),this.expiryTimer||this.scheduleExpiry()},t)}dispose(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}checkDrawingAlerts(e){if(!(!this.drawingLevels||!Number.isFinite(e)))for(let t of this.alerts){if(!t.drawingId||t.expired)continue;let n=this.drawingLevels(t.drawingId);if(!n||n.length===0){this.drawingSides.delete(t.id);continue}t.price=n[0];let r=n.map(t=>Math.sign(e-t)),i=this.drawingSides.get(t.id);this.drawingSides.set(t.id,r),!(!i||i.length!==r.length)&&(r.some((e,n)=>tg(i[n],e,t.condition))?t.triggered||(t.triggered=!0,this.emit(`triggered`,{...t})):t.repeating&&(t.triggered=!1))}}checkChannel(e,t){this.checkChannels(new Map([[e,t]]))}checkChannels(e,t={}){let n=(e instanceof Map?[...e.entries()]:Object.entries(e)).filter(([,e])=>Number.isFinite(e));if(n.length===0)return;this.expire();let r=new Map,i=new Map;for(let[e,t]of n){r.set(e,this.lastValues.get(e));let n=this.recordBar(e,t);n&&i.set(e,n),this.lastValues.set(e,t)}for(let e of this.alerts){if(e.drawingId||e.expired)continue;let n=r.has(e.channel),a=e.target!==void 0&&r.has(e.target);if(!n&&!a||e.target!==void 0&&t.together&&!(n&&a))continue;let o;if(e.onBarClose){let t=i.get(e.channel)??(e.target?i.get(e.target):void 0);if(!t)continue;o=this.closedBarMet(e,t)}else if(e.target)o=this.targetMet(e);else if(Zh.includes(e.condition)){if(!n)continue;o=this.moveMet(e,this.history.get(e.channel)??[])}else{let t=r.get(e.channel);if(!n||t===void 0)continue;o=$h(t,this.lastValues.get(e.channel),e.price,e.condition)}this.settle(e,o)}}settle(e,t){t?e.triggered||(e.triggered=!0,this.emit(`triggered`,{...e})):e.repeating&&(e.triggered=!1)}targetMet(e){let t=this.lastValues.get(e.channel),n=e.target?this.lastValues.get(e.target):void 0;if(t===void 0||n===void 0)return!1;let r=t-n,i=this.lastDiffs.get(e.id);return this.lastDiffs.set(e.id,r),e.price=n,$h(i,r,0,e.condition)}moveMet(e,t,n=t.length){let r=e.bars??1,i=t.slice(Math.max(0,n-r),n);if(i.length<2||e.percent===void 0)return!1;let a=i[i.length-1].value,o=i.map(e=>e.value);if(e.condition===`movesUp`){let t=Math.min(...o);return t!==0&&(a-t)/Math.abs(t)*100>=e.percent}let s=Math.max(...o);return s!==0&&(s-a)/Math.abs(s)*100>=e.percent}closedBarMet(e,t){let n=this.history.get(e.channel)??[],r=n.findIndex(e=>e.time===t.time);if(r<0)return!1;if(Zh.includes(e.condition))return this.moveMet(e,n,r+1);let i=(e,t)=>{let r=this.history.get(e)??[],i=n[t]?.time;return i===void 0?void 0:r.find(e=>e.time===i)?.value},a=n[r].value,o=r>0?n[r-1].value:void 0,s=e.price;if(e.target){let t=i(e.target,r),n=r>0?i(e.target,r-1):void 0;if(t===void 0)return!1;a-=t,o=o!==void 0&&n!==void 0?o-n:void 0,s=0,e.price=t}return $h(o,a,s,e.condition)}recordBar(e,t){let n=this.barTime;if(n===null)return null;let r=this.history.get(e)??[],i=r[r.length-1];if(i&&n<i.time)return r=r.filter(e=>e.time<n),r.push({time:n,value:t}),this.history.set(e,r),null;if(i&&i.time===n)return r[r.length-1]={time:n,value:t},null;i=r[r.length-1],r.push({time:n,value:t});let a=Math.min(502,Math.max(3,...this.alerts.map(e=>(e.bars??1)+2)));return r.length>a&&r.splice(0,r.length-a),this.history.set(e,r),i?{channel:e,time:i.time}:null}clearLastValues(){this.lastValues.clear(),this.drawingSides.clear(),this.history.clear(),this.lastDiffs.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label,drawingId:e.drawingId,target:e.target,percent:e.percent,bars:e.bars,onBarClose:e.onBarClose,expiresAt:e.expiresAt,expired:e.expired}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n){if(typeof e.drawingId==`string`&&e.condition&&!e.triggered){eg.includes(e.condition)&&this.addDrawingAlert(e.drawingId,e.condition,e.message,e.repeating??!1,e.label);continue}if(!e.condition||e.triggered||e.expired)continue;let t=og(e),n=!t.target&&!Zh.includes(e.condition),r=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:NaN;if(!(n&&Number.isNaN(r)))try{this.addAlert(r,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label,t)}catch{}}}catch{}}render(n,r,i){let{chartRect:a}=r;for(let o of this.alerts){if(!Qh(o))continue;let s=e.T(o.price,r);if(s<a.y||s>a.y+a.height)continue;let c=o.expired?`#8a93a3`:o.triggered?`#f2a93b`:`#4c8dff`;n.setLineDash([2,6]),n.strokeStyle=c,n.lineWidth=1,n.beginPath(),n.moveTo(a.x,Math.round(s)+.5),n.lineTo(a.x+a.width,Math.round(s)+.5),n.stroke(),n.setLineDash([]),n.font=`10px ${i.font.family}`,n.fillStyle=c,n.textBaseline=`bottom`,n.textAlign=`right`;let l=`${(0,t.priceTagText)(o.price,r,this.pricePrecision??void 0)}${o.message?` - ${o.message}`:``}`,u=a.x+a.width-4;n.fillText(l,u,s-2);let d=u-n.measureText(l).width-Jh-qh;d>=a.x&&Jf(n,t.UI_ICONS.bell,d,s-2-qh,qh,c)}}};function ag(e,t,n){let r={},i=Zh.includes(e);if(n.target!==void 0){if(i)throw RangeError(`An alert on a move takes no other line`);if(n.target===t)throw RangeError(`An alert can’t compare a line with itself`);r.target=n.target}if(i){let{percent:e,bars:t}=n;if(e===void 0||!Number.isFinite(e)||e<=0)throw RangeError(`An alert on a move needs a percent above 0`);if(t===void 0||!Number.isInteger(t)||t<2||t>500)throw RangeError(`An alert on a move needs 2 to 500 bars`);r.percent=e,r.bars=t}return n.onBarClose&&(r.onBarClose=!0),n.expiresAt!==void 0&&Number.isFinite(n.expiresAt)&&(r.expiresAt=n.expiresAt),r}function og(e){let t={};return typeof e.target==`string`&&e.target&&(t.target=e.target),typeof e.percent==`number`&&Number.isFinite(e.percent)&&(t.percent=e.percent),typeof e.bars==`number`&&Number.isInteger(e.bars)&&(t.bars=e.bars),e.onBarClose===!0&&(t.onBarClose=!0),typeof e.expiresAt==`number`&&Number.isFinite(e.expiresAt)&&(t.expiresAt=e.expiresAt),t}var sg=16,cg=()=>typeof requestAnimationFrame==`function`&&!(typeof document<`u`&&document.hidden),lg={now:()=>typeof performance<`u`?performance.now():Date.now(),frame:e=>cg()?{raf:requestAnimationFrame(e)}:{timeout:setTimeout(e,sg)},cancel:e=>{let t=e;t.raf!==void 0&&cancelAnimationFrame(t.raf),t.timeout!==void 0&&clearTimeout(t.timeout)}},ug=class extends am{data=[];cursor=-1;timer=null;frameHandle=null;run=0;state=`stopped`;config={speed:1,interval:500};paceMs=null;constructor(e=lg){super(),this.clock=e}load(e){this.stop(),this.data=e,this.cursor=-1}play(e){if(this.data.length===0)return;if(e){let{startIndex:t,paused:n,duration:r,...i}=e;this.config={...this.config,...i};let a=t===void 0?null:this.clamp(t);if(n){this.clearTimer(),this.seekTo(a??Math.max(0,this.cursor)),this.setPace(r),this.setState(`paused`);return}a!==null&&(this.cursor=a-1),this.setPace(r)}if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`);return}this.clearTimer();let t=this.paceMs??this.config.interval/this.config.speed;if(!(t>0)||!Number.isFinite(t)){this.setState(`paused`);return}this.setState(`playing`),t<sg||this.paceMs!==null?this.runFrames(t):this.timer=setInterval(()=>this.advance(1),t)}pause(){this.clearTimer(),this.setState(`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.clearTimer(),this.cursor=-1,this.setState(`stopped`)}seekTo(e){this.data.length!==0&&(this.cursor=this.clamp(e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}))}setSpeed(e){this.config={...this.config,speed:e},this.paceMs=null,this.state===`playing`&&this.play()}getState(){return this.state}isAtEnd(){return this.data.length>0&&this.cursor>=this.data.length-1}getProgress(){let e=this.data.length;return{current:Math.max(0,this.cursor),total:e,percent:e>0?(this.cursor+1)/e*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}setPace(e){this.paceMs=e!==void 0&&e>0&&Number.isFinite(e)?e/Math.max(1,this.data.length-1-this.cursor):null}runFrames(e){let t=this.run,n=this.clock.now(),r=0,i=()=>{if(t!==this.run||this.state!==`playing`)return;this.frameHandle=null;let a=this.clock.now();r+=Math.min(50,Math.max(0,a-n)),n=a;let o=Math.floor(r/e);try{o>0&&(r-=o*e,this.advance(o))}finally{t===this.run&&this.state===`playing`&&this.frameHandle===null&&(this.frameHandle=this.clock.frame(i))}};this.frameHandle=this.clock.frame(i)}advance(e){if(this.isAtEnd()){this.finish();return}this.cursor=Math.min(this.data.length-1,this.cursor+e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}),this.isAtEnd()&&this.finish()}finish(){this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0)}clamp(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.floor(e),this.data.length-1)):0}clearTimer(){this.run++,this.timer&&=(clearInterval(this.timer),null),this.frameHandle!==null&&(this.clock.cancel(this.frameHandle),this.frameHandle=null)}setState(e){this.state!==e&&(this.state=e,this.emit(`stateChange`,e))}},dg=64,fg=3,pg=3;function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function mg(e){return Array.isArray(e)?e:[]}function hg(e,t){return typeof e==`string`?e:t}function gg(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function _g(e){if(!X(e)||typeof e.id!=`string`||typeof e.type!=`string`||!Array.isArray(e.anchors)||e.anchors.length===0||e.anchors.length>vg||!X(e.style))return null;let n=[];for(let t of e.anchors){if(!X(t)||typeof t.time!=`number`||typeof t.price!=`number`||!Number.isFinite(t.time)||!Number.isFinite(t.price))return null;n.push({time:t.time,price:t.price})}let r=(0,t.sanitizeDrawingStyle)(e.style);return r.color===void 0||r.lineWidth===void 0?null:{id:e.id,type:e.type,anchors:n,style:{lineStyle:`solid`,...r,color:r.color,lineWidth:r.lineWidth},visible:typeof e.visible==`boolean`?e.visible:!0,locked:typeof e.locked==`boolean`?e.locked:!1,options:X(e.options)?e.options:void 0,intervals:nn(e.intervals)??void 0,group:xg(e.group),meta:X(e.meta)?e.meta:void 0}}var vg=5e3,yg=64,bg=80;function xg(e){if(!(!X(e)||typeof e.id!=`string`||typeof e.name!=`string`)&&!(e.id===``||e.id.length>yg))return{id:e.id,name:e.name.slice(0,bg)}}function Sg(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function Cg(e){if(!X(e))return;let n={},r=mg(e.colors).filter(e=>typeof e==`string`);r.length>0&&(n.colors=r);let i=mg(e.lineWidths).filter(e=>typeof e==`number`&&Number.isFinite(e)&&e>0);i.length>0&&(n.lineWidths=i),typeof e.opacity==`number`&&Number.isFinite(e.opacity)&&(n.opacity=Math.min(1,Math.max(0,e.opacity)));let a=(0,t.readIndicatorPlotStyles)(e.plots);return a&&(n.plots=a),Object.keys(n).length>0?n:void 0}var wg=[`crossingUp`,`crossingDown`,`crossing`,`greaterThan`,`lessThan`,`movesUp`,`movesDown`];function Tg(e){if(!X(e)||typeof e.id!=`string`)return null;let t=typeof e.drawingId==`string`?e.drawingId:void 0,n=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:null,r=wg.find(t=>t===e.condition)??`crossing`,i=og(e),a=i.target!==void 0||r===`movesUp`||r===`movesDown`;return n===null&&!t&&!a?null:{id:e.id,price:n??NaN,drawingId:t,condition:r,message:typeof e.message==`string`?e.message:void 0,triggered:e.triggered===!0,repeating:e.repeating===!0,channel:hg(e.channel,`price`),label:typeof e.label==`string`?e.label:void 0,...i,...e.expired===!0?{expired:!0}:{}}}function Eg(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}var Dg=4e3;function Og(e){if(!X(e))return;let n={},r=[];for(let[i,a]of Object.entries(e)){let e=(0,t.readChartStyleOverrides)(a);r.push(...e.rejected);let o=Object.fromEntries(Object.entries(e.overrides).filter(([,e])=>e!==null));Object.keys(o).length>0&&(n[i.slice(0,dg)]=o)}return r.length>0&&console.warn(`Saved style overrides left out: ${[...new Set(r)].join(`, `)}`),n}function kg(e){if(!X(e))return Ag();typeof e.version==`number`&&e.version>pg&&console.warn(`Chart state from a newer version (${e.version}); loading what this version understands.`);let n=X(e.viewport)?e.viewport:{},r=[];for(let n of mg(e.indicators))X(n)&&(typeof n.id!=`string`||typeof n.instanceId!=`string`||X(n.params)&&r.push({id:n.id,instanceId:n.instanceId,params:n.params,position:typeof n.position==`string`?n.position:void 0,style:Cg(n.style),visible:typeof n.visible==`boolean`?n.visible:void 0,levels:Array.isArray(n.levels)?n.levels.filter(e=>typeof e==`number`&&Number.isFinite(e)):void 0,pane:typeof n.pane==`string`?n.pane:void 0,scale:n.scale===`left`?`left`:void 0,intervals:nn(n.intervals)??void 0,paneStyle:(0,t.readPaneStyle)(n.paneStyle)??void 0,paneSize:typeof n.paneSize==`number`&&Number.isFinite(n.paneSize)&&n.paneSize>0?Math.min(n.paneSize,Dg):void 0,paneOrder:typeof n.paneOrder==`number`&&Number.isInteger(n.paneOrder)&&n.paneOrder>=0?n.paneOrder:void 0,paneCollapsed:n.paneCollapsed===!0?!0:void 0,paneMaximized:n.paneMaximized===!0?!0:void 0,paneLog:n.paneLog===!0?!0:void 0,paneInvert:n.paneInvert===!0?!0:void 0,panePercent:n.panePercent===!0?!0:void 0}));let i=[];for(let t of mg(e.drawings)){let e=_g(t);e&&i.push(e)}let a=[];for(let t of mg(e.orders)){let e=Sg(t);e&&a.push(e)}let o=[];for(let t of mg(e.positions)){let e=Eg(t);e&&o.push(e)}let s=[];for(let t of mg(e.alerts)){let e=Tg(t);e&&s.push(e)}let c=Og(e.overrides);return{version:typeof e.version==`number`&&Array.isArray(e.indicators)?e.version:1,timestamp:gg(e.timestamp,Date.now()),symbol:typeof e.symbol==`string`?e.symbol:void 0,timeframe:typeof e.timeframe==`string`?e.timeframe:void 0,chartType:hg(e.chartType,`candlestick`),...e.chartTypeOptions===void 0?{}:{chartTypeOptions:(0,t.readChartTypeOptions)(e.chartTypeOptions)},viewport:{barWidth:gg(n.barWidth,8),barSpacing:gg(n.barSpacing,2),offset:gg(n.offset,0)},theme:typeof e.theme==`string`?e.theme:void 0,...c?{overrides:c}:{},locale:typeof e.locale==`string`?e.locale:void 0,indicators:r,drawings:i,orders:a,positions:o,alerts:s}}function Ag(){return{version:1,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var jg=class{static capture(e,t){return{version:e.getIndicators?pg:1,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,...t?.chartTypeOptions&&Object.keys(t.chartTypeOptions).length>0?{chartTypeOptions:t.chartTypeOptions}:{},symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,...e.getOverrides&&Object.keys(e.getOverrides()).length>0?{overrides:e.getOverrides()}:{},indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return kg(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},Mg=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0,this.onChange?.()}last(){return this.undoStack[this.undoStack.length-1]??null}dropLast(){this.undoStack.pop()&&(this.redoStack.length=0,this.onChange?.())}replaceLast(e){if(this.undoStack.length===0){this.push(e);return}this.undoStack[this.undoStack.length-1]=e,this.redoStack.length=0,this.onChange?.()}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},Ng=[`Time`,`Open`,`High`,`Low`,`Close`,`Volume`];function Pg(e,n){return new Date((0,t.normalizeBarTime)(e,n)).toISOString()}function Fg(e){let t=/^[=+\-@\t\r]/.test(e)&&!/^-?\d/.test(e)?`'${e}`:e;return/[",\r\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var Ig=e=>e==null||!Number.isFinite(e)?``:String(e),Lg=class{static toCSV(e,n=[]){let r=[...Ng,...n.map(e=>Fg(e.name))].join(`,`),i=(0,t.barTimeUnit)(e);return[r,...e.map((e,t)=>[Pg(e.time,i),e.open,e.high,e.low,e.close,e.volume,...n.map(e=>Ig(e.values[t]))].join(`,`))].join(`
|
|
21
|
+
`,t.addEventListener(`mouseenter`,()=>{t.style.background=`#1f2630`}),t.addEventListener(`mouseleave`,()=>{t.style.background=`transparent`}),t.addEventListener(`click`,()=>{this.onItemSelect?.(e.intent),this.hide()}),s.appendChild(t)}n.appendChild(s),this.menuElement=s;let l=e=>{(e instanceof KeyboardEvent&&e.key===`Escape`||e instanceof MouseEvent&&!s.contains(e.target))&&this.hide()};document.addEventListener(`mousedown`,l),document.addEventListener(`keydown`,l),this.removeHandler=()=>{document.removeEventListener(`mousedown`,l),document.removeEventListener(`keydown`,l)}}hide(){this.menuElement?.remove(),this.menuElement=null,this.removeHandler?.(),this.removeHandler=null}destroy(){this.hide(),this.onItemSelect=null}};function Mp(e,t,n={}){let r=Math.max(Math.abs(t)*(n.riskFraction??.01),1e-8),i=r*(n.riskReward??2);return e===`buy`?{side:e,entry:t,stopLoss:t-r,takeProfit:t+i}:{side:e,entry:t,stopLoss:t+r,takeProfit:t-i}}function Np(e){let t=Math.abs(e.entry-e.stopLoss);return t===0?0:Math.abs(e.takeProfit-e.entry)/t}var Pp=6,Fp=.12,Ip=[6,3],Lp=class{draft=null;dragStart=null;dragging=null;defaults;constructor(e={}){this.defaults=e}start(e,t){this.draft=Mp(e,t,this.defaults),this.dragging=null}cancel(){this.draft=null,this.dragging=null}isActive(){return this.draft!==null}getDraft(){return this.draft?{...this.draft}:null}hitTest(t,n,r=Pp){if(!this.draft)return null;let i=[`entry`,`sl`,`tp`],a=null,o=r;for(let r of i){let i=e.T(this.priceOf(r),n),s=Math.abs(i-t.y);s<=o&&(o=s,a=r)}return a}beginDrag(e,t,n){let r=this.hitTest(e,t,n);return r!==null&&this.beginDragOn(r)}beginDragOn(e){return this.draft?(this.dragging=e,this.dragStart=this.draft,!0):!1}cancelDrag(){this.dragging&&this.dragStart&&(this.draft=this.dragStart),this.dragging=null,this.dragStart=null}drag(t,n){if(!this.draft||!this.dragging)return!1;let r=e.M(t.y,n);return this.draft=zp(this.draft,this.dragging,r),!0}endDrag(){this.dragging=null,this.dragStart=null}isDragging(){return this.dragging!==null}priceOf(e){let t=this.draft;return e===`entry`?t.entry:e===`sl`?t.stopLoss:t.takeProfit}render(e,t,n,r){this.renderLines(e,t,n),rp(e,this.tags(t,n),t,n,[])}renderLines(t,n,r){let i=this.draft;if(!i)return;let{chartRect:a}=n,o=e.T(i.entry,n),s=e.T(i.stopLoss,n),c=e.T(i.takeProfit,n),{profit:l,loss:u}=Rp(r);t.save(),t.globalAlpha=Fp,t.fillStyle=l,t.fillRect(a.x,Math.min(o,c),a.width,Math.abs(c-o)),t.fillStyle=u,t.fillRect(a.x,Math.min(o,s),a.width,Math.abs(s-o)),t.globalAlpha=1,Ff(t,n,o,r.text,Ip),Ff(t,n,c,l,[]),Ff(t,n,s,u,[]),t.restore()}tags(t,n){let r=this.draft;if(!r)return[];let{profit:i,loss:a}=Rp(n),o=r.side===`buy`?1:-1,s=e=>{let t=r.entry===0?0:(e-r.entry)/r.entry*100*o;return`${t>=0?`+`:``}${t.toFixed(2)}%`};return[{y:e.T(r.entry,t),color:n.text,grab:{kind:`bracket`,handle:`entry`},cells:[{kind:`stamp`,text:r.side===`buy`?`Long`:`Short`},{kind:`text`,text:`${Np(r).toFixed(2)}R`}]},{y:e.T(r.takeProfit,t),color:i,grab:{kind:`bracket`,handle:`tp`},cells:[{kind:`stamp`,text:`TP`},{kind:`text`,text:s(r.takeProfit),color:i}]},{y:e.T(r.stopLoss,t),color:a,grab:{kind:`bracket`,handle:`sl`},cells:[{kind:`stamp`,text:`SL`},{kind:`text`,text:s(r.stopLoss),color:a}]}].filter(e=>q(e.y,t))}renderAxisBadges(e,t,n,r){for(let i of this.axisBadges(t,n,r))op(e,i.y,i.text,i.color,t,n)}axisBadges(n,r,i){let a=this.draft;if(!a)return[];let{profit:o,loss:s}=Rp(r),c=[];for(let[l,u]of[[a.takeProfit,o],[a.stopLoss,s],[a.entry,r.text]]){let r=e.T(l,n);q(r,n)&&c.push({y:r,text:(0,t.priceTagText)(l,n,i),color:u})}return c}};function Rp(e){return{profit:e.style?.trading.profit??e.candleUp,loss:e.style?.trading.loss??e.candleDown}}function zp(e,t,n){let r=e.side===`buy`;if(t===`entry`){let t=n-e.entry;return{side:e.side,entry:n,stopLoss:e.stopLoss+t,takeProfit:e.takeProfit+t}}if(t===`sl`){let t=r?Math.min(n,e.entry):Math.max(n,e.entry);return{...e,stopLoss:t}}let i=r?Math.max(n,e.entry):Math.min(n,e.entry);return{...e,takeProfit:i}}function Bp(e,t,n){return n==null?`limit`:e===`buy`?t<=n?`limit`:`stop`:t>=n?`limit`:`stop`}var Vp=6,Hp=[6,3],Up=class{draft=null;dragStart=null;dragging=!1;start(e,t,n=1){this.draft={side:e,price:t,quantity:n},this.dragging=!1}cancel(){this.draft=null,this.dragging=!1}isActive(){return this.draft!==null}isDragging(){return this.dragging}getDraft(){return this.draft?{...this.draft}:null}setPrice(e){return this.draft?(this.draft={...this.draft,price:e},!0):!1}toIntent(e){return this.draft?{side:this.draft.side,type:Bp(this.draft.side,this.draft.price,e),price:this.draft.price,quantity:this.draft.quantity}:null}hitTest(t,n,r=Vp){return this.draft?Math.abs(e.T(this.draft.price,n)-t.y)<=r:!1}beginDrag(e,t,n){return this.hitTest(e,t,n)&&this.beginDragOn()}beginDragOn(){return this.draft?(this.dragging=!0,this.dragStart=this.draft,!0):!1}cancelDrag(){this.dragging&&this.dragStart&&(this.draft=this.dragStart),this.dragging=!1,this.dragStart=null}drag(t,n){return!this.draft||!this.dragging?!1:this.setPrice(e.M(t.y,n))}endDrag(){this.dragging=!1,this.dragStart=null}render(e,t,n,r,i){this.renderLines(e,t,n),rp(e,this.tags(t,n,r),t,n,[])}renderLines(t,n,r){let i=this.draft;i&&(t.save(),Ff(t,n,e.T(i.price,n),Wp(i.side,r),Hp),t.restore())}tags(t,n,r){let i=this.draft;if(!i)return[];let a=e.T(i.price,t);if(!q(a,t))return[];let o=Bp(i.side,i.price,r);return[{y:a,color:Wp(i.side,n),grab:{kind:`draft`},cells:[{kind:`stamp`,text:String(i.quantity)},{kind:`text`,text:dp({side:i.side,type:o})}]}]}renderAxisBadges(e,t,n,r){for(let i of this.axisBadges(t,n,r))op(e,i.y,i.text,i.color,t,n)}axisBadges(n,r,i){let a=this.draft;if(!a)return[];let o=e.T(a.price,n);return q(o,n)?[{y:o,text:(0,t.priceTagText)(a.price,n,i),color:Wp(a.side,r)}]:[]}};function Wp(e,t){return e===`buy`?t.style?.trading.buy??t.candleUp:t.style?.trading.sell??t.candleDown}var Gp=2;function Kp(e,t){return e.type===t.type?e.type===`cancelOrder`?e.orderId===t.orderId:e.type===`removeStop`?e.positionId===t.positionId&&e.which===t.which:e.positionId===t.positionId:!1}function qp(e,t,n=Gp){let r=(e,n)=>t.x>=e.x-n&&t.x<=e.x+e.size+n&&t.y>=e.y-n&&t.y<=e.y+e.size+n;for(let t=e.length-1;t>=0;t--)if(r(e[t],0))return e[t];let i=null,a=1/0;for(let o of e){if(!r(o,n))continue;let e=Math.hypot(t.x-(o.x+o.size/2),t.y-(o.y+o.size/2));e<a&&(a=e,i=o)}return i}var Jp=5,Yp=7,Xp=2;function Zp(e,n){let r=n.data;return r&&r.length>0?e/(0,t.barTimeUnit)(r):e}function Qp(t,n,r,i){if(n.length===0)return;let{chartRect:a}=r,o=i.orderColors?.buy??`#1fa874`,s=i.orderColors?.sell??`#e8505b`;t.lineWidth=1.5;for(let i of n){let n=e.O(Zp(i.time,r),r),c=e.T(i.price,r);if(n<a.x||n>a.x+a.width||c<a.y||c>a.y+a.height)continue;let l=i.side===`buy`,u=l?c+Xp:c-Xp,d=l?u+Yp:u-Yp;t.beginPath(),t.moveTo(n,u),t.lineTo(n-Jp,d),t.lineTo(n+Jp,d),t.closePath();let f=l?o:s;!i.reason||i.reason===`order`?(t.fillStyle=f,t.fill()):(t.strokeStyle=f,t.stroke())}}var $p=1e3,em=class{orders=[];positions=[];depthData=null;currentPrice=null;config;orderRenderer=new hp;positionRenderer=new Dp;depthOverlay=new Op;dragHandler;contextMenu=new jp;bracket=new Lp;orderDraft=new Up;buttons=[];tagBoxes=[];grabOffset=0;fills=[];realisedPnl=0;requestRender=null;eventCallback=null;container=null;constructor(e){this.config={...t.DEFAULT_TRADING_CONFIG,...e},this.dragHandler=new Ap(this.config.dragThreshold),this.contextMenu.onItemSelect=e=>{this.eventCallback?.(`orderPlace`,e)}}setContainer(e){this.container=e}setRequestRender(e){this.requestRender=e}setEventCallback(e){this.eventCallback=e}setOrders(e){this.orders=e,this.requestRender?.()}setPositions(e){this.positions=e,this.requestRender?.()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}getCurrentPrice(){return this.currentPrice}setDepthData(e){this.depthData=e,this.requestRender?.()}setCurrentPrice(e){this.currentPrice=e,this.requestRender?.()}setConfig(e){Object.assign(this.config,e),this.requestRender?.()}addFill(e){this.fills=[...this.fills.slice(-($p-1)),e],this.realisedPnl+=e.pnl??0,this.requestRender?.()}setFills(e){this.fills=e.slice(-$p),this.realisedPnl=e.reduce((e,t)=>e+(t.pnl??0),0),this.requestRender?.()}getRealisedPnl(){return this.realisedPnl}getFills(){return[...this.fills]}armed=null;isOverButton(e){return this.config.enabled&&qp(this.buttons,e)!==null}runButton(e){switch(e.type){case`cancelOrder`:this.eventCallback?.(`orderCancel`,{orderId:e.orderId});break;case`closePosition`:this.eventCallback?.(`positionClose`,{positionId:e.positionId});break;case`reversePosition`:this.eventCallback?.(`positionReverse`,{positionId:e.positionId});break;case`removeStop`:this.eventCallback?.(`positionModify`,{positionId:e.positionId,[e.which]:null});break}}startBracket(e,t){this.bracket.start(e,t),this.requestRender?.()}cancelBracket(){this.bracket.isActive()&&(this.bracket.cancel(),this.requestRender?.())}confirmBracket(){let e=this.bracket.getDraft();return e?(this.eventCallback?.(`bracketPlace`,{side:e.side,entry:e.entry,stopLoss:e.stopLoss,takeProfit:e.takeProfit,riskReward:Np(e)}),this.bracket.cancel(),this.requestRender?.(),!0):!1}isBracketActive(){return this.bracket.isActive()}startOrderDraft(e,t){this.orderDraft.start(e,t),this.requestRender?.()}cancelOrderDraft(){this.orderDraft.isActive()&&(this.orderDraft.cancel(),this.requestRender?.())}confirmOrderDraft(){let e=this.orderDraft.toIntent(this.currentPrice);return e?(this.eventCallback?.(`orderPlace`,e),this.orderDraft.cancel(),this.requestRender?.(),!0):!1}isOrderDraftActive(){return this.orderDraft.isActive()}isOverDraggableLine(t,n,r=8){if(!this.config.enabled)return!1;if(Qf(this.tagBoxes,t.x,t.y)&&!qp(this.buttons,t))return!0;let i=i=>{if(i===void 0)return!1;let a=e.T(i,n);return q(a,n)&&Math.abs(t.y-a)<=r};for(let e of this.orders)if(e.draggable!==!1&&i(e.price))return!0;for(let e of this.positions)if(i(e.stopLoss)||i(e.takeProfit))return!0;return!1}onPointerDown(e,t,n){if(!this.config.enabled)return!1;let r=qp(this.buttons,e,n?.button),i=r?null:Qf(this.tagBoxes,e.x,e.y);return i&&this.grabTag(i,e)||(this.grabOffset=0,this.bracket.isActive()&&this.bracket.beginDrag(e,t,n?.handle))||this.orderDraft.isActive()&&this.orderDraft.beginDrag(e,t,n?.handle)?(this.requestRender?.(),!0):r?(this.armed=r.action,!0):this.dragHandler.onPointerDown(e,this.orders,this.positions,t,n?.order??8)}grabTag(e,t){this.grabOffset=e.lineY-t.y;let n=e.grab;switch(n.kind){case`bracket`:return this.bracket.beginDragOn(n.handle);case`draft`:return this.orderDraft.beginDragOn();case`order`:{let t=this.orders.find(e=>e.id===n.orderId);return t!==void 0&&this.dragHandler.beginOrder(t,e.lineY)}case`stop`:{let t=this.positions.find(e=>e.id===n.positionId);return t!==void 0&&this.dragHandler.beginStop(t,n.which,e.lineY)}}}onPointerMove(e,t){if(this.armed)return!0;let n=this.grabOffset===0?e:{x:e.x,y:Pf(e.y+this.grabOffset,t)};if(this.bracket.isDragging()){let e=this.bracket.drag(n,t);return e&&this.requestRender?.(),e}if(this.orderDraft.isDragging()){let e=this.orderDraft.drag(n,t);return e&&this.requestRender?.(),e}if(!this.dragHandler.isActive())return!1;let r=this.dragHandler.onPointerMove(n,t);return r&&this.requestRender?.(),r}onPointerUp(e){if(this.grabOffset=0,this.armed){let t=this.armed;this.armed=null;let n=e?qp(this.buttons,e):null;return n&&Kp(n.action,t)&&this.runButton(t),!0}if(this.bracket.isDragging())return this.bracket.endDrag(),this.requestRender?.(),!0;if(this.orderDraft.isDragging())return this.orderDraft.endDrag(),this.requestRender?.(),!0;let t=this.dragHandler.onPointerUp();return t?(t.sourceType===`order`?this.eventCallback?.(`orderModify`,{orderId:t.id,newPrice:t.newPrice,previousPrice:t.previousPrice}):this.eventCallback?.(`positionModify`,{positionId:t.id,[t.sourceType]:t.newPrice}),this.requestRender?.(),!0):!1}cancelPointer(){this.grabOffset=0;let e=!1;return this.armed&&(this.armed=null,e=!0),this.bracket.isDragging()&&(this.bracket.cancelDrag(),e=!0),this.orderDraft.isDragging()&&(this.orderDraft.cancelDrag(),e=!0),this.dragHandler.cancel()&&(e=!0),e&&this.requestRender?.(),e}onContextMenu(n,r){if(!this.config.enabled||!this.config.contextMenu?.enabled||!this.container)return!1;let i=e.M(n.y,r);return this.contextMenu.show(n,i,this.container,this.config,e=>(0,t.priceTagText)(e,r,this.config.pricePrecision)),!0}render(e,t,n){if(this.buttons=[],this.tagBoxes=[],!this.config.enabled)return;let{chartRect:r}=t;e.save();try{e.beginPath(),e.rect(r.x,r.y,r.width,r.height),e.clip(),this.renderInPlot(e,t,n)}finally{e.restore()}}renderInPlot(e,t,n){let r=Zs(this.config,n);this.depthData&&this.depthOverlay.render(e,this.depthData,t,r),r.fillMarks!==!1&&Qp(e,this.fills,t,r);let i=this.dragHandler.getDragState();this.positionRenderer.renderLines(e,this.positions,this.currentPrice,t,r,i),this.orderRenderer.renderLines(e,this.orders,t,r,i),this.bracket.renderLines(e,t,n),this.orderDraft.renderLines(e,t,n),rp(e,[...this.bracket.tags(t,n),...this.orderDraft.tags(t,n,this.currentPrice),...this.positionRenderer.tags(this.positions,this.currentPrice,t,r,i),...this.orderRenderer.tags(this.orders,t,r,i)],t,n,this.buttons,this.tagBoxes)}renderAxisBadges(e,t,n){if(this.config.enabled)for(let r of ap(this.axisBadges(t,n),t))op(e,r.at,r.text,r.color,t,n)}axisBadges(e,t){let n=Zs(this.config,t);return[...this.positionRenderer.axisBadges(this.positions,e,n,this.dragHandler.getDragState()),...this.orderRenderer.axisBadges(this.orders,e,n,this.dragHandler.getDragState()),...this.bracket.axisBadges(e,t,this.config.pricePrecision),...this.orderDraft.axisBadges(e,t,this.config.pricePrecision)]}axisTagYs(e,n=t.DARK_THEME){return this.config.enabled?ap(this.axisBadges(e,n),e).map(e=>e.at):[]}destroy(){this.contextMenu.destroy()}},tm=class{constructor(e){this.manager=e}render(e,t,n){this.manager.render(e,t,n)}renderAxisBadges(e,t,n){this.manager.renderAxisBadges(e,t,n)}axisTagYs(e,t){return this.manager.axisTagYs(e,t)}},nm=class{name=`paper`;state=`disconnected`;listeners=new Map;orders=[];positions=[];markPrice;markTime;seq=0;constructor(e={}){this.markPrice=e.markPrice??0}connect(e){this.state=`connected`,this.emit(`connectionChange`,this.state),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}disconnect(){this.state=`disconnected`,this.emit(`connectionChange`,this.state)}getConnectionState(){return this.state}setMarkPrice(e,t){this.markPrice=e,this.markTime=t!==void 0&&Number.isFinite(t)?t:void 0,this.checkPendingOrders(),this.checkStops()}fillTime(){return this.markTime??Date.now()}getOrders(){return[...this.orders]}getPositions(){return[...this.positions]}async placeOrder(e){let t={id:this.nextId(`ord`),side:e.side,type:e.type,price:e.price,stopPrice:e.stopPrice,quantity:e.quantity??1,label:e.type===`market`?void 0:im(e.type),draggable:!0,stopLoss:e.stopLoss,takeProfit:e.takeProfit,timeInForce:e.timeInForce};return e.type===`market`?this.fill(t,this.markPrice||e.price):(this.orders=[...this.orders,t],this.emit(`orders`,this.orders)),t}async modifyOrder(e){this.orders=this.orders.map(t=>t.id===e.orderId?{...t,price:e.newPrice}:t),this.emit(`orders`,this.orders)}async cancelOrder(e){this.orders=this.orders.filter(t=>t.id!==e.orderId),this.emit(`orders`,this.orders)}async modifyPosition(e){let t=(e,t)=>e===void 0?t:e??void 0;this.positions=this.positions.map(n=>n.id===e.positionId?{...n,stopLoss:t(e.stopLoss,n.stopLoss),takeProfit:t(e.takeProfit,n.takeProfit)}:n),this.emit(`positions`,this.positions)}async closePosition(e){let t=this.positions.find(t=>t.id===e.positionId);t&&(this.close(t,this.markPrice||t.entryPrice,`close`),this.emit(`positions`,this.positions))}async reversePosition(e){let t=this.positions.find(t=>t.id===e.positionId);if(!t)return;let n=this.markPrice||t.entryPrice;this.close(t,n,`reverse`);let r=t.quantity-(t.closedQuantity??0),i={id:this.nextId(`ord`),side:rm(t.side),type:`market`,price:n,quantity:r};this.fill(i,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear(),this.orders=[],this.positions=[]}fill(e,t){this.orders=this.orders.filter(t=>t.id!==e.id);let n={id:this.nextId(`pos`),side:e.side,entryPrice:t,quantity:e.quantity,stopLoss:e.stopLoss,takeProfit:e.takeProfit};this.positions=[...this.positions,n];let r={orderId:e.id,side:e.side,price:t,quantity:e.quantity,time:this.fillTime(),positionId:n.id,reason:`order`};this.emit(`fill`,r),this.emit(`orders`,this.orders),this.emit(`positions`,this.positions)}close(e,t,n){this.positions=this.positions.filter(t=>t.id!==e.id);let r=e.quantity-(e.closedQuantity??0),i=e.side===`buy`?1:-1;this.emit(`fill`,{orderId:this.nextId(`ord`),side:rm(e.side),price:t,quantity:r,time:this.fillTime(),positionId:e.id,reason:n,pnl:(t-e.entryPrice)*r*i})}checkPendingOrders(){let e=this.orders.filter(e=>this.isTriggered(e));for(let t of e)this.fill(t,t.type===`limit`?t.price:t.stopPrice??t.price)}isTriggered(e){if(e.type===`limit`)return e.side===`buy`?this.markPrice<=e.price:this.markPrice>=e.price;if(e.type===`stop`||e.type===`stopLimit`){let t=e.stopPrice??e.price;return e.side===`buy`?this.markPrice>=t:this.markPrice<=t}return!1}checkStops(){let e=!1;for(let t of[...this.positions]){let n=t.stopLoss!==void 0&&(t.side===`buy`?this.markPrice<=t.stopLoss:this.markPrice>=t.stopLoss),r=t.takeProfit!==void 0&&(t.side===`buy`?this.markPrice>=t.takeProfit:this.markPrice<=t.takeProfit);!n&&!r||(this.close(t,n?t.stopLoss:t.takeProfit,n?`stopLoss`:`takeProfit`),e=!0)}e&&this.emit(`positions`,this.positions)}nextId(e){return`${e}-${++this.seq}`}emit(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function rm(e){return e===`buy`?`sell`:`buy`}function im(e){switch(e){case`stop`:return`STOP`;case`stopLimit`:return`STOP LIMIT`;default:return`LIMIT`}}var am=class{listeners=new Map;on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let e of n)e(t)}removeAllListeners(){this.listeners.clear()}},om=class extends am{currentBar=null;timeframeMs;tickRing;ringHead=0;ringCount=0;ringCapacity;constructor(e,n=1e3){super(),this.timeframeMs=(0,t.timeframeToMs)(e),this.ringCapacity=n,this.tickRing=Array(n)}setTimeframe(e){this.timeframeMs=(0,t.timeframeToMs)(e),this.currentBar=null,this.ringHead=0,this.ringCount=0}processTick(e){let t=(this.ringHead+this.ringCount)%this.ringCapacity;this.tickRing[t]=e,this.ringCount<this.ringCapacity?this.ringCount++:this.ringHead=(this.ringHead+1)%this.ringCapacity;let n=this.alignToTimeframe(e.time);!this.currentBar||this.currentBar.time!==n?(this.currentBar&&(this.currentBar.closed=!0,this.emit(`barClose`,this.currentBar)),this.currentBar={time:n,open:e.price,high:e.price,low:e.price,close:e.price,volume:e.volume,closed:!1,tickCount:1}):(this.currentBar.high=Math.max(this.currentBar.high,e.price),this.currentBar.low=Math.min(this.currentBar.low,e.price),this.currentBar.close=e.price,this.currentBar.volume+=e.volume,this.currentBar.tickCount++),this.emit(`bar`,this.currentBar)}processBar(e,t){if(t&&this.currentBar&&this.currentBar.time===e.time)this.currentBar={...e,closed:!0,tickCount:this.currentBar.tickCount+1},this.emit(`barClose`,this.currentBar),this.currentBar=null;else if(!t)this.currentBar={...e,closed:!1,tickCount:(this.currentBar?.tickCount??0)+1},this.emit(`bar`,this.currentBar);else{let t={...e,closed:!0,tickCount:1};this.emit(`barClose`,t),this.currentBar=null}}getCurrentBar(){return this.currentBar?{...this.currentBar}:null}getTickBuffer(){let e=Array(this.ringCount);for(let t=0;t<this.ringCount;t++)e[t]=this.tickRing[(this.ringHead+t)%this.ringCapacity];return e}reset(){this.currentBar=null,this.ringHead=0,this.ringCount=0}alignToTimeframe(e){return this.timeframeMs>0?Math.floor(e/this.timeframeMs)*this.timeframeMs:e}},sm=class extends am{config;attempt=0;timer=null;active=!1;constructor(e){super(),this.config={...t.DEFAULT_RECONNECT,...e}}schedule(e){if(!this.config.enabled||!this.active)return;if(this.cancel(),this.attempt++,this.attempt>this.config.maxRetries){this.emit(`giveUp`,{attempts:this.attempt-1}),this.active=!1;return}let t=this.computeDelay();this.emit(`attempt`,{attempt:this.attempt,delay:t}),this.timer=setTimeout(()=>{this.timer=null,this.active&&e()},t)}onConnected(){this.attempt=0,this.cancel(),this.emit(`success`,void 0)}start(){this.active=!0}stop(){this.active=!1,this.cancel(),this.attempt=0}cancel(){this.timer&&=(clearTimeout(this.timer),null)}getAttempt(){return this.attempt}isActive(){return this.active}computeDelay(){let e=this.config.baseDelay,t=this.config.backoffMultiplier**(this.attempt-1),n=Math.min(e*t,this.config.maxDelay),r=n*.25*(Math.random()*2-1);return Math.max(0,Math.round(n+r))}},cm=20,lm=class{price=null;previousClose=null;visible=!0;flashUntil=0;pricePrecision=null;locale=`en-US`;tag=null;setLocale(e){this.locale=e}setPrice(e,t){this.price!==null&&e!==this.price&&(this.flashUntil=Date.now()+300),this.previousClose=t??this.price??e,this.price=e}setVisible(e){this.visible=e}isVisible(){return this.visible}setPricePrecision(e){this.pricePrecision=e}getPrice(){return this.price}getTag(){return this.tag}render(n,r,i){this.tag=null;let a=i.style?.lastPrice;if(!this.visible||this.price===null||a?.visible===!1)return;let o=e.T(this.price,r),{chartRect:s}=r;if(o<s.y||o>s.y+s.height)return;let c=this.previousClose===null||this.price>=this.previousClose?a?.up??i.candleUp??`#1fa874`:a?.down??i.candleDown??`#e8505b`,l=Date.now()<this.flashUntil,u=a?.width??1;n.setLineDash((0,t.lineDash)(a?.style??`solid`,[4,3],u)),n.strokeStyle=c,n.lineWidth=u,n.globalAlpha=l?1:.7,n.beginPath(),n.moveTo(s.x,Math.round(o)+.5),n.lineTo(s.x+s.width,Math.round(o)+.5),n.stroke(),n.setLineDash([]),n.globalAlpha=1;let d=s.x+s.width+1,f=this.pricePrecision??(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max),p=r.formatPrice?r.formatPrice(this.price):(0,t.formatPrice)(this.price,f,this.locale);n.font=`bold 11px ${i.font.family}`;let m=n.measureText(p).width,h=r.priceAxisWidth??t.PRICE_AXIS_WIDTH,g=Math.min(m+12,h-2);n.fillStyle=c,E(n,d,o-cm/2,g,cm,i),this.tag={x:d,y:o-cm/2,width:g,height:cm,color:c};let _=d-5;n.beginPath(),n.moveTo(_,o),n.lineTo(_+5,o-5),n.lineTo(_+5,o+5),n.closePath(),n.fill(),n.fillStyle=A(c),n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(p,d+5,o)}},um=1e3,dm=10,fm=1440,pm=[`tick`,`barClose`,`snapshot`,`connectionChange`,`error`,`symbolInfo`],mm=new WeakMap;function hm(e){if(e instanceof bm||!e.supportedTimeframes?.length)return e;let t=mm.get(e);return t||(t=new bm(e,e.supportedTimeframes),mm.set(e,t)),t}function gm(e,n){if(n.includes(e))return e;let r=(0,t.pickBaseTimeframe)(e,n);return r&&Math.ceil((0,t.timeframeToMs)(e)/(0,t.timeframeToMs)(r))<=1440?r:null}function _m(e,n){if((0,t.tickBarCount)(n)!==null)return typeof e.fetchTrades==`function`&&typeof e.subscribeTrades==`function`;let r=e.supportedTimeframes;return!r?.length||gm(n,r)!==null}function vm(e,n){let r=(0,t.parseTimeframe)(n);if(r?.unit===`M`){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth()+r.count,1)}return e+(0,t.timeframeToMs)(n)}function ym(e,t){let n=t[0],r={time:e,open:n.open,high:n.high,low:n.low,close:n.close,volume:n.volume};for(let e=1;e<t.length;e++){let n=t[e];n.high>r.high&&(r.high=n.high),n.low<r.low&&(r.low=n.low),r.close=n.close,r.volume+=n.volume}return r}var bm=class{name;fetchHistoryBefore;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;unsubscribe=[];live=null;bucket=null;parts=new Map;tail=null;generation=0;constructor(e,t){this.inner=e,this.baseTimeframes=t,this.name=e.name,e.fetchHistoryBefore&&(this.fetchHistoryBefore=(e,t,n,r)=>this.historyBefore(e,t,n,r)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),e.fetchTrades&&(this.fetchTrades=e.fetchTrades.bind(e)),e.subscribeTrades&&(this.subscribeTrades=e.subscribeTrades.bind(e)),this.listen(`bar`,e=>this.onBar(e));for(let e of pm)this.listen(e,t=>this.emit(e,t.data))}baseFor(e){let t=gm(e,this.baseTimeframes);if(!t)throw RangeError(`${this.name} cannot serve the ${e} timeframe`);return t}connect(e){let t=this.baseFor(e.timeframe);this.generation++,this.resetBucket(),this.live=t===e.timeframe?null:{symbol:e.symbol,target:e.timeframe,base:t},this.live&&this.resumeFromHistory(this.live.symbol,this.live.target),this.inner.connect({...e,timeframe:t})}disconnect(){this.generation++,this.inner.disconnect(),this.resetBucket(),this.live=null}getConnectionState(){return this.inner.getConnectionState()}async fetchHistory(e,t,n=500){let r=this.baseFor(t);if(r===t)return this.inner.fetchHistory(e,t,n);let i=this.generation,a=this.baseBarsFor(t,r,n),o=await this.inner.fetchHistory(e,r,Math.min(a,um)),s=await this.extendBack(e,r,o,a,i);return this.rememberTail(e,t,s),this.toTarget(s,t,n)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.generation++;for(let e of this.unsubscribe)e();this.unsubscribe.length=0,this.listeners.clear(),this.inner.dispose()}async historyBefore(e,t,n,r){let i=this.inner.fetchHistoryBefore.bind(this.inner),a=this.baseFor(t);if(a===t)return i(e,t,n,r);let o=this.generation,s=this.baseBarsFor(t,a,r),c=await i(e,a,n,Math.min(s,um)),l=await this.extendBack(e,a,c.filter(e=>e.time<n),s,o,1);return this.toTarget(l,t,r)}baseBarsFor(e,n,r){return(r+1)*Math.ceil((0,t.timeframeToMs)(e)/(0,t.timeframeToMs)(n))}async extendBack(e,t,n,r,i,a=1){let o=this.inner.fetchHistoryBefore?.bind(this.inner),s=n,c=a;for(;o&&s.length>0&&s.length<r&&c<10&&i===this.generation;){let n=s[0].time,i=await o(e,t,n,Math.min(r-s.length,um));c++;let a=i.filter(e=>e.time<n);if(a.length===0)break;s=a.concat(s)}return s}toTarget(e,n,r){if(e.length===0)return[];let i=(0,t.resampleBars)(e,n);return i.length>1&&i[0].time!==e[0].time&&i.shift(),i.length>r?i.slice(i.length-r):i}rememberTail(e,n,r){if(r.length===0)return;let i=(0,t.timeframeBucketStart)(r[r.length-1].time,n),a=r.length;for(;a>0&&(0,t.timeframeBucketStart)(r[a-1].time,n)===i;)a--;this.tail={symbol:e,target:n,bucket:i,bars:r.slice(a)}}resumeFromHistory(e,t){let n=this.tail;if(!(!n||n.symbol!==e||n.target!==t)){this.bucket=n.bucket;for(let e of n.bars)this.parts.set(e.time,e)}}onBar(e){let n=this.live;if(!n){this.emit(`bar`,e.data);return}let{bar:r,closed:i}=e.data,a=(0,t.timeframeBucketStart)(r.time,n.target);if(this.bucket!==null&&a<this.bucket)return;if(this.bucket!==null&&a>this.bucket){let e=this.composed();e&&this.emit(`bar`,{bar:e,closed:!0}),this.resetBucket()}this.bucket=a,this.parts.set(r.time,r);let o=this.composed();if(!o)return;let s=i&&(0,t.timeframeBucketStart)(vm(r.time,n.base),n.target)!==a;this.emit(`bar`,{bar:o,closed:s}),s&&(this.resetBucket(),this.bucket=(0,t.timeframeBucketStart)(vm(r.time,n.base),n.target))}composed(){if(this.bucket===null||this.parts.size===0)return null;let e=[...this.parts.values()].sort((e,t)=>e.time-t.time);return ym(this.bucket,e)}resetBucket(){this.bucket=null,this.parts=new Map}listen(e,t){let n=e=>t(e);this.inner.on(e,n),this.unsubscribe.push(()=>this.inner.off(e,n))}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},xm=1e3,Sm=15e3,Cm=[`tick`,`bar`,`barClose`,`snapshot`,`connectionChange`,`error`,`symbolInfo`],wm=class{bar=null;count=0;lastTime=-1/0;constructor(e){this.tradesPerBar=e}push(e){let t=[],n=!1;for(let r of e){if(this.bar)this.bar={...this.bar,high:Math.max(this.bar.high,r.price),low:Math.min(this.bar.low,r.price),close:r.price,volume:this.bar.volume+r.volume};else{let e=Math.max(r.time,this.lastTime+1);this.lastTime=e,this.bar={time:e,open:r.price,high:r.price,low:r.price,close:r.price,volume:r.volume},this.count=0}this.count++,n=!0,this.count>=this.tradesPerBar&&(t.push({bar:this.bar,closed:!0}),this.bar=null,n=!1)}return n&&this.bar&&t.push({bar:this.bar,closed:!1}),t}build(e){return this.bar=null,this.count=0,this.lastTime=-1/0,this.push(e).map(e=>e.bar)}},Tm=class{name;supportedTimeframes;searchSymbols;resolveSymbol;subscribeQuotes;fetchNews;fetchTrades;subscribeTrades;listeners=new Map;tick=null;stopTrades=null;keepAlive=null;tickMode=!1;state=`disconnected`;constructor(e){this.inner=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes,e.searchSymbols&&(this.searchSymbols=e.searchSymbols.bind(e)),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol.bind(e)),e.subscribeQuotes&&(this.subscribeQuotes=e.subscribeQuotes.bind(e)),e.fetchNews&&(this.fetchNews=e.fetchNews.bind(e)),this.fetchTrades=e.fetchTrades.bind(e),this.subscribeTrades=e.subscribeTrades.bind(e);for(let t of Cm)e.on(t,e=>{this.tickMode||this.emit(t,e.data)})}async fetchHistory(e,n,r){let i=(0,t.tickBarCount)(n);if(i===null)return this.inner.fetchHistory(e,n,r);let a=(await this.inner.fetchTrades(e,xm)).filter(km).sort((e,t)=>e.time-t.time),o=new wm(i),s=o.build(a);return this.tick={symbol:e,builder:o,after:a.length?a[a.length-1].time:-1/0},r!==void 0&&r>0?s.slice(-r):s}fetchHistoryBefore(e,n,r,i){return(0,t.tickBarCount)(n)!==null||!this.inner.fetchHistoryBefore?Promise.resolve([]):this.inner.fetchHistoryBefore(e,n,r,i)}connect(e){this.disconnect();let n=(0,t.tickBarCount)(e.timeframe);if(n===null){this.tickMode=!1,this.inner.connect(e);return}this.tickMode=!0;let r=this.tick?.symbol===e.symbol?this.tick:{symbol:e.symbol,builder:new wm(n),after:-1/0};this.tick=r,this.stopTrades=this.inner.subscribeTrades(e.symbol,e=>{let t=e.filter(e=>km(e)&&e.time>=r.after);for(let{bar:e,closed:n}of r.builder.push(t))this.emit(`bar`,{bar:e,closed:n}),this.emit(`tick`,{time:e.time,price:e.close,volume:e.volume})}),this.state=`connected`,this.emit(`connectionChange`,`connected`),this.keepAlive=setInterval(()=>this.emit(`connectionChange`,`connected`),Sm)}disconnect(){this.tickMode?(this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.state=`disconnected`):this.inner.disconnect()}getConnectionState(){return this.tickMode?this.state:this.inner.getConnectionState()}dispose(){this.stopTrades?.(),this.stopTrades=null,this.keepAlive&&clearInterval(this.keepAlive),this.keepAlive=null,this.listeners.clear(),this.inner.dispose()}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,t){let n=this.listeners.get(e);if(!n)return;let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}},Em=new WeakMap;function Dm(e){if(e instanceof Tm||!Om(e))return e;let t=Em.get(e);return t||(t=new Tm(e),Em.set(e,t)),t}function Om(e){return typeof e.fetchTrades==`function`&&typeof e.subscribeTrades==`function`}function km(e){return Number.isFinite(e?.time)&&Number.isFinite(e?.price)&&Number.isFinite(e?.volume)}var Am=2e4,jm=class extends am{config=null;adapter=null;aggregator=null;reconnector;priceLine=new lm;state=`disconnected`;lastPrice=null;previousClose=null;unsubscribers=[];heartbeatTimer=null;lastMessageTime=0;connectSeq=0;constructor(){super(),this.reconnector=new sm,this.wireReconnector()}async connect(e){this.disconnect();let n=Dm(hm(e.adapter));this.config={...t.DEFAULT_STREAM_CONFIG,...e,adapter:n},this.adapter=n,this.aggregator=new om(e.timeframe),this.reconnector.removeAllListeners(),this.reconnector.stop(),this.reconnector=new sm(e.reconnect??t.DEFAULT_RECONNECT),this.wireReconnector(),this.aggregator.on(`bar`,e=>{this.emit(`barUpdate`,e),this.updatePrice(e.close)}),this.aggregator.on(`barClose`,e=>{this.previousClose=e.close,this.emit(`barClose`,e)}),this.wireAdapter(),this.reconnector.start(),await this.doConnect()}disconnect(){this.connectSeq++,this.reconnector.stop(),this.stopHeartbeat();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.adapter&&=(this.adapter.disconnect(),null),this.aggregator?.reset(),this.aggregator?.removeAllListeners(),this.aggregator=null,this.config=null,this.lastPrice=null,this.previousClose=null,this.setState(`disconnected`)}async switchTo(e,t){!this.config||!this.adapter||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.aggregator?.reset(),this.aggregator?.setTimeframe(t),this.lastPrice=null,this.previousClose=null,this.config.symbol=e,this.config.timeframe=t,await this.doConnect())}getConnectionState(){return this.state}getConnectionInfo(){return{state:this.state,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}}getLastPrice(){return this.lastPrice}async doConnect(){if(!this.config||!this.adapter)return;let e=++this.connectSeq,{symbol:t,timeframe:n}=this.config;this.setState(`connecting`);try{let r=await this.adapter.fetchHistory(t,n,this.config.historyLimit??500);if(e!==this.connectSeq||!this.adapter)return;r.length>0&&(this.previousClose=r[r.length-1].close,this.updatePrice(r[r.length-1].close)),this.emit(`snapshot`,r),this.adapter.connect({symbol:t,timeframe:n}),this.startHeartbeat()}catch(t){if(e!==this.connectSeq)return;let n=t instanceof Error?t.message:String(t);this.emit(`error`,{message:n,code:`CONNECT_FAILED`}),this.setState(`error`),this.reconnector.schedule(()=>this.doConnect())}}wireReconnector(){this.reconnector.on(`attempt`,({attempt:e,delay:t})=>{this.setState(`reconnecting`),this.emit(`connectionChange`,{state:`reconnecting`,reconnectAttempt:e,lastMessageTime:this.lastMessageTime})}),this.reconnector.on(`giveUp`,({attempts:e})=>{this.setState(`error`),this.emit(`error`,{message:`Reconnection failed after ${e} attempts`,code:`RECONNECT_EXHAUSTED`})})}wireAdapter(){if(!this.adapter)return;let e=this.adapter,t=e=>{let t=e.data;this.lastMessageTime=Date.now(),t===`connected`?(this.reconnector.onConnected(),this.setState(`connected`)):(t===`disconnected`||t===`error`)&&this.reconnector.schedule(()=>this.doConnect())};e.on(`connectionChange`,t),this.unsubscribers.push(()=>e.off(`connectionChange`,t));let n=e=>{this.lastMessageTime=Date.now();let t=e.data;this.emit(`tick`,t),(t.bid!==void 0||t.ask!==void 0)&&this.emit(`quote`,{bid:t.bid,ask:t.ask}),this.config?.aggregateTicks&&this.aggregator?this.aggregator.processTick(t):this.updatePrice(t.price)};e.on(`tick`,n),this.unsubscribers.push(()=>e.off(`tick`,n));let r=e=>{this.lastMessageTime=Date.now();let{bar:t,closed:n}=e.data;this.aggregator&&this.aggregator.processBar(t,n)};e.on(`bar`,r),this.unsubscribers.push(()=>e.off(`bar`,r));let i=e=>{this.emit(`error`,{message:e.data?.message??`Adapter error`})};e.on(`error`,i),this.unsubscribers.push(()=>e.off(`error`,i));let a=e=>{e?.data&&typeof e.data==`object`&&this.emit(`symbolInfo`,e.data)};try{e.on(`symbolInfo`,a),this.unsubscribers.push(()=>e.off(`symbolInfo`,a))}catch{}}updatePrice(e){e!==this.lastPrice&&(this.lastPrice=e,this.priceLine.setPrice(e,this.previousClose??void 0),this.emit(`priceChange`,{price:e,previousClose:this.previousClose}))}setState(e){this.state!==e&&(this.state=e,this.emit(`connectionChange`,{state:e,reconnectAttempt:this.reconnector.getAttempt(),lastMessageTime:this.lastMessageTime}))}wake(e){!this.adapter||!this.config||this.state===`connecting`||this.state===`disconnected`||this.state===`connected`&&e===`visible`&&Date.now()-this.lastMessageTime<=Am||(this.reconnector.stop(),this.adapter.disconnect(),this.reconnector.start(),this.doConnect())}startHeartbeat(){this.stopHeartbeat(),this.heartbeatTimer=setInterval(()=>{Date.now()-this.lastMessageTime>6e4&&this.state===`connected`&&(this.emit(`error`,{message:`Heartbeat timeout`,code:`HEARTBEAT_TIMEOUT`}),this.adapter?.disconnect(),this.reconnector.schedule(()=>this.doConnect()))},3e4)}stopHeartbeat(){this.heartbeatTimer&&=(clearInterval(this.heartbeatTimer),null)}dispose(){this.disconnect(),this.removeAllListeners()}},Mm=class extends am{data;speed;index;status=`idle`;timer=null;constructor(e){if(super(),e.data.length===0)throw Error(`ReplayController requires non-empty data`);this.data=e.data,this.speed=Math.max(.01,e.speed??1),this.index=Math.max(0,Math.min(e.startIndex??0,e.data.length)),e.autoStart&&this.start()}getStatus(){return this.status}getIndex(){return this.index}getTotal(){return this.data.length}getPrefix(){return this.data.slice(0,this.index)}start(){if(this.status!==`playing`){if(this.index>=this.data.length){this.transition(`finished`);return}this.transition(`playing`),this.scheduleNext()}}pause(){this.status===`playing`&&(this.clearTimer(),this.transition(`paused`))}resume(){this.status===`paused`&&this.start()}stop(){this.clearTimer(),this.index=0,this.transition(`idle`)}step(e=1){if(!(e<=0)){this.clearTimer();for(let t=0;t<e;t++)if(!this.emitNext())return;this.status!==`finished`&&this.transition(`paused`)}}seek(e){let t=Math.max(0,Math.min(e,this.data.length));this.clearTimer(),this.index=t;let n=t>=this.data.length?`finished`:`paused`;this.transition(n)}setSpeed(e){this.speed=Math.max(.01,e),this.status===`playing`&&(this.clearTimer(),this.scheduleNext())}destroy(){this.clearTimer(),this.removeAllListeners()}scheduleNext(){let e=1e3/this.speed;this.timer=setTimeout(()=>{this.timer=null,this.status===`playing`&&this.emitNext()&&this.scheduleNext()},e)}emitNext(){if(this.index>=this.data.length)return this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1;let e=this.data[this.index],t=this.index;return this.index++,this.emit(`bar`,{bar:e,index:t,total:this.data.length}),this.index>=this.data.length?(this.transition(`finished`),this.emit(`finished`,{total:this.data.length}),!1):!0}clearTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}transition(e){this.status!==e&&(this.status=e,this.emit(`stateChange`,{status:e,index:this.index,total:this.data.length}))}};function Nm(e){if(!Array.isArray(e)||e.length<6)return null;let t=e[0];if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Fm(e[1]),r=Fm(e[2]),i=Fm(e[3]),a=Fm(e[4]),o=Fm(e[5]);return n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}function Pm(e){if(!Im(e))return null;let t=e.t;if(typeof t!=`number`||!Number.isFinite(t))return null;let n=Fm(e.o),r=Fm(e.h),i=Fm(e.l),a=Fm(e.c),o=Fm(e.v);if(n===null||r===null||i===null||a===null||o===null)return null;let s=typeof e.x==`boolean`?e.x:!1;return{bar:{time:t,open:n,high:r,low:i,close:a,volume:o},closed:s}}function Fm(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Im(e){return typeof e==`object`&&!!e}function J(e){let t=typeof e==`string`?Number(e):e;return typeof t==`number`&&Number.isFinite(t)?t:void 0}function Lm(e){let n=e&&typeof e==`object`&&`data`in e?e.data:e;if(!n||typeof n!=`object`)return null;let r=n;return r.e===`24hrMiniTicker`?(0,t.readQuote)({symbol:r.s,last:J(r.c),open:J(r.o),high:J(r.h),low:J(r.l),volume:J(r.v),time:J(r.E)}):null}function Rm(e){if(!e||typeof e!=`object`)return null;let n=e;return(0,t.readQuote)({symbol:n.symbol,last:J(n.lastPrice),change:J(n.priceChange),changePercent:J(n.priceChangePercent),open:J(n.openPrice),high:J(n.highPrice),low:J(n.lowPrice),prevClose:J(n.prevClosePrice),volume:J(n.volume),bid:J(n.bidPrice),ask:J(n.askPrice),time:J(n.closeTime)})}function zm(e){if(!e||typeof e!=`object`)return null;let t=e,n=J(t.T),r=J(t.p),i=J(t.q);return n!==void 0&&r!==void 0&&i!==void 0?{time:n,price:r,volume:i}:null}var Bm={"1s":`1s`,"1m":`1m`,"3m":`3m`,"5m":`5m`,"15m":`15m`,"30m":`30m`,"1h":`1h`,"2h":`2h`,"4h":`4h`,"6h":`6h`,"8h":`8h`,"12h":`12h`,"1d":`1d`,"3d":`3d`,"1w":`1w`,"1M":`1M`},Vm=1e3,Hm=200,Um=[`USDT`,`USDC`,`FDUSD`,`BTC`,`ETH`,`BNB`,`EUR`,`TRY`,`BRL`,`JPY`];function Wm(e){let t=e.currency?Um.indexOf(e.currency):-1;return t<0?0:40-t*3}function Gm(e){if(typeof e.symbol!=`string`||e.status!==`TRADING`)return null;let n=typeof e.baseAsset==`string`?e.baseAsset:``,r=typeof e.quoteAsset==`string`?e.quoteAsset:``,i=Array.isArray(e.filters)?e.filters.find(e=>typeof e==`object`&&!!e&&e.filterType===`PRICE_FILTER`&&typeof e.tickSize==`string`):void 0,a={symbol:e.symbol,description:n&&r?`${n} / ${r}`:e.symbol,exchange:`Binance`,type:`crypto`};return i&&(a.pricePrecision=(0,t.stepDecimals)(i.tickSize),a.minTick=Number(i.tickSize)),a.timezone=`UTC`,r&&(a.currency=r),a}function Km(e){let t=e?.symbols;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=Gm(e);t&&n.push(t)}return n}var qm=class{name=`binance`;supportedTimeframes=Object.keys(Bm);ws=null;state=`disconnected`;listeners=new Map;config=null;restBase;wsBase;symbolList=null;constructor(e){this.restBase=e?.restBase??`https://api.binance.com/api/v3`,this.wsBase=e?.wsBase??`wss://stream.binance.com:9443/ws`}connect(e){this.config=e,this.connectWs()}disconnect(){if(this.ws){let e=this.ws;e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n=500){return this.fetchKlines(e,t,n,``)}async searchSymbols(e,n){return(0,t.rankSymbols)(await this.loadSymbols(),e,n?.limit??50,Wm)}async resolveSymbol(e){if(this.symbolList){let t=(await this.symbolList.catch(()=>null))?.find(t=>t.symbol===e);if(t)return t}let t=await fetch(`${this.restBase}/exchangeInfo?symbol=${encodeURIComponent(e)}`);return t.ok?Km(await t.json())[0]??null:null}loadSymbols(){return this.symbolList||(this.symbolList=(async()=>{let e=await fetch(`${this.restBase}/exchangeInfo`);if(!e.ok)throw Error(`Binance REST error: ${e.status}`);return Km(await e.json())})(),this.symbolList.catch(()=>{this.symbolList=null})),this.symbolList}subscribeQuotes(e,t){let n=[...new Set(e.map(e=>e.trim().toUpperCase()))].filter(e=>/^[A-Z0-9]{2,30}$/.test(e)).slice(0,Hm);if(n.length===0)return()=>{};let r=!1,i=null,a=null,o=0,s=new Set,c=new AbortController;(async()=>{let e=await fetch(`${this.restBase}/ticker/24hr?symbols=${encodeURIComponent(JSON.stringify(n))}`,{signal:c.signal});if(e.ok)return e.json();let t=await fetch(`${this.restBase}/ticker/24hr`,{signal:c.signal});if(!t.ok)return[];let r=await t.json(),i=new Set(n);return Array.isArray(r)?r.filter(e=>i.has(e?.symbol)):[]})().then(e=>{if(r||!Array.isArray(e))return;let n=e.map(Rm).filter(e=>e!==null&&!s.has(e.symbol));n.length>0&&t(n)}).catch(()=>{});let l=this.wsBase.replace(/\/ws\/?$/,``),u=()=>{if(!r){try{i=new WebSocket(`${l}/stream?streams=${n.map(e=>`${e.toLowerCase()}@miniTicker`).join(`/`)}`)}catch{d();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=Lm(n);!i||r||(s.add(i.symbol),t([i]))},i.onclose=()=>{i=null,d()}}},d=()=>{r||(a=setTimeout(u,Math.min(3e4,1e3*2**o++)))};return u(),()=>{r=!0,c.abort(),a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=await fetch(`${this.restBase}/aggTrades?symbol=${encodeURIComponent(e.toUpperCase())}&limit=${n}`);if(!r.ok)throw Error(`Binance aggTrades ${r.status}`);let i=await r.json();return Array.isArray(i)?i.map(zm).filter(e=>e!==null):[]}subscribeTrades(e,t){let n=`${e.trim().toLowerCase()}@aggTrade`;if(!/^[a-z0-9]{2,30}@aggTrade$/.test(n))return()=>{};let r=!1,i=null,a=null,o=0,s=()=>{if(!r){try{i=new WebSocket(`${this.wsBase}/${n}`)}catch{c();return}i.onopen=()=>{o=0},i.onmessage=e=>{let n;try{n=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}let i=zm(n);i&&!r&&t([i])},i.onclose=()=>{i=null,c()}}},c=()=>{r||(a=setTimeout(s,Math.min(3e4,1e3*2**o++)))};return s(),()=>{r=!0,a&&clearTimeout(a),i&&=(i.onopen=null,i.onmessage=null,i.onclose=null,i.close(),null)}}fetchHistoryBefore(e,t,n,r=500){return this.fetchKlines(e,t,Math.min(r,Vm),`&endTime=${Math.floor(n)-1}`)}async fetchKlines(e,t,n,r){let i=Bm[t]??`15m`,a=`${this.restBase}/klines?symbol=${e}&interval=${i}&limit=${n}${r}`,o=await fetch(a);if(!o.ok)throw Error(`Binance REST error: ${o.status}`);let s=await o.json();if(!Array.isArray(s))return[];let c=[];for(let e of s){let t=Nm(e);t&&c.push(t)}return c}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}connectWs(){if(!this.config)return;let e=`${this.config.symbol.toLowerCase()}@kline_${Bm[this.config.timeframe]??`15m`}`,t=`${this.wsBase}/${e}`;this.setState(`connecting`);try{this.ws=new WebSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws.onopen=()=>{this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`)},this.ws.onmessage=e=>{let t;try{t=JSON.parse(typeof e.data==`string`?e.data:``)}catch{return}typeof t==`object`&&t&&t.e===`kline`&&this.handleKline(t.k)},this.ws.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},this.ws.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}handleKline(e){let t=Pm(e);if(!t)return;let{bar:n,closed:r}=t;this.emitEvent(`bar`,{bar:n,closed:r}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume})}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Jm=class{name=`mock`;state=`disconnected`;listeners=new Map;config=null;options;tickTimer=null;currentPrice;oldestOpen=new Map;forming=null;formingTimeframe=null;constructor(e){this.options={basePrice:100,volatility:1.5,tickInterval:2e3,historySize:500,...e},this.currentPrice=this.options.basePrice}connect(e){this.config=e,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startTicking()}disconnect(){this.stopTicking(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}subscribeQuotes(e,t){let n=[...new Set(e)].map(e=>{let t=this.options.basePrice*(.5+Ym(e)%1e3/1e3);return{symbol:e,open:t,last:t,high:t,low:t,volume:0}});if(n.length===0)return()=>{};let r=this.options.volatility/100,i=()=>t(n.map(e=>({symbol:e.symbol,last:e.last,open:e.open,high:e.high,low:e.low,volume:e.volume,change:e.last-e.open,changePercent:(e.last-e.open)/e.open*100,time:Date.now()})));i();let a=setInterval(()=>{for(let e of n)e.last=Math.max(e.open*.01,e.last*(1+(Math.random()-.5)*r)),e.high=Math.max(e.high,e.last),e.low=Math.min(e.low,e.last),e.volume+=Math.random()*100;i()},this.options.tickInterval);return()=>clearInterval(a)}async fetchTrades(e,t=1e3){let n=Math.max(1,Math.min(1e3,Math.floor(t))),r=Date.now(),i=this.options.volatility/1e3,a=this.options.basePrice*(.5+Ym(e)%1e3/1e3),o=[];for(let e=n-1;e>=0;e--)a=Math.max(a*.5,a*(1+(Math.random()-.5)*i)),o.push({time:r-e*1e3,price:a,volume:Math.random()*5});return o}subscribeTrades(e,t){let n=this.options.volatility/1e3,r=this.options.basePrice*(.5+Ym(e)%1e3/1e3),i=setInterval(()=>{let e=[];for(let t=0;t<3;t++)r=Math.max(r*.5,r*(1+(Math.random()-.5)*n)),e.push({time:Date.now(),price:r,volume:Math.random()*5});t(e)},this.options.tickInterval);return()=>clearInterval(i)}async fetchHistory(e,t,n){let r=this.options.historyGenerator?this.options.historyGenerator(e,t,n??this.options.historySize):this.generateHistory(t,n??this.options.historySize);return r.length>0&&this.oldestOpen.set(e,r[0].open),this.forming=r.length>0?{...r[r.length-1]}:null,this.formingTimeframe=t,r}async fetchHistoryBefore(e,n,r,i){let a=(0,t.timeframeToMs)(n),o=this.options.volatility/100,s=Array(Math.max(0,i)),c=this.oldestOpen.get(e)??this.options.basePrice;for(let e=0;e<i;e++){let t=c/(1+(Math.random()-.52)*o),n=Math.max(t,c)+Math.random()*c*o*.3,l=Math.max(0,Math.min(t,c)-Math.random()*c*o*.3),u=Math.floor(1e4+Math.random()*1e5);s[i-1-e]={time:r-(e+1)*a,open:t,high:n,low:l,close:c,volume:u},c=t}return this.oldestOpen.set(e,c),s}async searchSymbols(e,n){return(0,t.rankSymbols)(this.options.symbols??[],e,n?.limit??50)}async resolveSymbol(e){return this.options.symbols?.find(t=>t.symbol===e)??null}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}generateHistory(e,n){let r=[],i=(0,t.timeframeToMs)(e),a=Math.floor(Date.now()/i)*i,o=this.options.basePrice,s=this.options.volatility/100;for(let e=n-1;e>=0;e--){let t=a-e*i,n=(Math.random()-.48)*o*s,c=o;o+=n;let l=Math.max(c,o)+Math.random()*o*s*.3,u=Math.min(c,o)-Math.random()*o*s*.3,d=Math.floor(1e4+Math.random()*1e5);r.push({time:t,open:c,high:l,low:u,close:o,volume:d})}return this.currentPrice=o,r}startTicking(){this.stopTicking();let e=this.options.tickInterval??2e3;this.tickTimer=setInterval(()=>{if(this.state!==`connected`||!this.config)return;let e=this.options.volatility/100,t=(Math.random()-.48)*this.currentPrice*e*.3;this.currentPrice+=t;let n=Date.now(),r=this.tickBar(n,t,Math.floor(100+Math.random()*5e3));this.emitEvent(`bar`,{bar:r,closed:!1}),this.emitEvent(`tick`,{time:n,price:this.currentPrice,volume:r.volume})},e)}tickBar(e,n,r){let i=this.config.timeframe,a=(0,t.timeframeToMs)(i),o=Math.floor(e/a)*a,s=this.currentPrice,c=this.formingTimeframe===i?this.forming:null,l=Math.abs(n)*.2,u;if(c&&c.time===o)u={time:o,open:c.open,high:Math.max(c.high,s+l),low:Math.min(c.low,s-l),close:s,volume:c.volume+r};else{let e=c?.close??s-n;u={time:o,open:e,high:Math.max(e,s)+l,low:Math.min(e,s)-l,close:s,volume:r}}return this.forming=u,this.formingTimeframe=i,{...u}}stopTicking(){this.tickTimer&&=(clearInterval(this.tickTimer),null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Ym(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return t}var Xm=class{name;supportedTimeframes;ws=null;state=`disconnected`;config=null;listeners=new Map;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.openSocket()}disconnect(){let e=this.config;if(this.ws){if(this.opts.unsubscribeMessage&&e)try{this.sendMessage(this.opts.unsubscribeMessage(e))}catch{}let t=this.ws;t.onopen=null,t.onmessage=null,t.onerror=null,t.onclose=null,t.close(),this.ws=null}this.setState(`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchHistory(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}openSocket(){let e=this.config;if(!e)return;let t=this.opts.wsUrl(e);this.setState(`connecting`);let n;try{n=this.createSocket(t)}catch{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket creation failed`}),this.emitEvent(`connectionChange`,`error`);return}this.ws=n,n.onopen=()=>{if(this.setState(`connected`),this.emitEvent(`connectionChange`,`connected`),this.opts.subscribeMessage)try{this.sendMessage(this.opts.subscribeMessage(e))}catch{}},n.onmessage=t=>{let n=this.decode(t.data);if(n===void 0)return;let r;try{r=this.opts.parseMessage(n,e)}catch{return}r&&(r.bar&&this.emitEvent(`bar`,{bar:r.bar,closed:r.closed??!1}),r.tick?this.emitEvent(`tick`,r.tick):r.bar&&this.emitEvent(`tick`,{time:Date.now(),price:r.bar.close,volume:r.bar.volume}))},n.onerror=()=>{this.setState(`error`),this.emitEvent(`error`,{message:`WebSocket error`})},n.onclose=()=>{this.setState(`disconnected`),this.emitEvent(`connectionChange`,`disconnected`)}}sendMessage(e){e===void 0||!this.ws||this.ws.send(typeof e==`string`?e:JSON.stringify(e))}decode(e){if(this.opts.decode)try{return this.opts.decode(e)}catch{return}if(typeof e==`string`)try{return JSON.parse(e)}catch{return}return e}createSocket(e){if(this.opts.socketFactory)return this.opts.socketFactory(e);let t=globalThis.WebSocket;if(!t)throw Error(`No WebSocket implementation available`);return new t(e)}setState(e){this.state=e}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}},Zm=class{name;supportedTimeframes;state=`disconnected`;listeners=new Map;config=null;timer=null;lastBarTime=0;opts;fetchHistoryBefore;searchSymbols;resolveSymbol;constructor(e){this.opts=e,this.name=e.name,this.supportedTimeframes=e.supportedTimeframes;let t=e.fetchHistoryBefore;t&&(this.fetchHistoryBefore=(e,n,r,i)=>t(e,n,r,i)),e.searchSymbols&&(this.searchSymbols=e.searchSymbols),e.resolveSymbol&&(this.resolveSymbol=e.resolveSymbol)}connect(e){this.config=e,this.lastBarTime=0,this.state=`connected`,this.emitEvent(`connectionChange`,`connected`),this.startPolling()}disconnect(){this.stopPolling(),this.state=`disconnected`,this.emitEvent(`connectionChange`,`disconnected`)}getConnectionState(){return this.state}fetchHistory(e,t,n){return this.opts.fetchBars(e,t,n??this.opts.defaultHistoryLimit??500)}on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}dispose(){this.disconnect(),this.listeners.clear()}async poll(){let e=this.config;if(!e||this.state!==`connected`)return;let t;try{t=await this.opts.fetchBars(e.symbol,e.timeframe,this.opts.pollLimit??2)}catch(e){this.emitEvent(`error`,{message:`Poll failed`,cause:e});return}if(t.length===0)return;let n=t[t.length-1];if(this.lastBarTime>0&&n.time>this.lastBarTime){let e=t.find(e=>e.time===this.lastBarTime);e&&this.emitEvent(`bar`,{bar:e,closed:!0})}this.emitEvent(`bar`,{bar:n,closed:!1}),this.emitEvent(`tick`,{time:Date.now(),price:n.close,volume:n.volume}),this.lastBarTime=n.time}startPolling(){this.stopPolling(),this.poll();let e=this.opts.setInterval??((e,t)=>setInterval(e,t));this.timer=e(()=>{this.poll()},this.opts.intervalMs??5e3)}stopPolling(){this.timer!==null&&((this.opts.clearInterval??(e=>clearInterval(e)))(this.timer),this.timer=null)}emitEvent(e,t){let n=this.listeners.get(e);if(n){let r={type:e,data:t,timestamp:Date.now()};for(let e of n)e(r)}}};function Y(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=parseFloat(e);return Number.isFinite(t)?t:null}return null}function Qm(e){return typeof e==`object`&&!!e}var $m={"1m":60,"5m":300,"15m":900,"1h":3600,"6h":21600,"1d":86400};function eh(e){return $m[e]??3600}var th=class extends Zm{constructor(e={}){let t=e.restBase??`https://api.exchange.coinbase.com`;super({name:`coinbase`,supportedTimeframes:Object.keys($m),intervalMs:e.intervalMs??5e3,pollLimit:2,fetchBars:(e,n)=>nh(t,e,n)})}};async function nh(e,t,n){let r=`${e}/products/${t}/candles?granularity=${eh(n)}`,i=await fetch(r);if(!i.ok)throw Error(`Coinbase REST error: ${i.status}`);return rh(await i.json())}function rh(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=ih(n);e&&t.push(e)}return t.sort((e,t)=>e.time-t.time),t}function ih(e){if(!Array.isArray(e)||e.length<6)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:i,high:r,low:n,close:a,volume:o}}var ah={"1m":`1`,"3m":`3`,"5m":`5`,"15m":`15`,"30m":`30`,"1h":`60`,"2h":`120`,"4h":`240`,"6h":`360`,"12h":`720`,"1d":`D`,"1w":`W`,"1M":`M`};function oh(e){return ah[e]??`1`}var sh=class extends Xm{constructor(e={}){let t=e.restBase??`https://api.bybit.com`,n=e.wsBase??`wss://stream.bybit.com/v5/public/spot`,r=e.category??`spot`;super({name:`bybit`,wsUrl:()=>n,subscribeMessage:e=>({op:`subscribe`,args:[`kline.${oh(e.timeframe)}.${e.symbol}`]}),unsubscribeMessage:e=>({op:`unsubscribe`,args:[`kline.${oh(e.timeframe)}.${e.symbol}`]}),supportedTimeframes:Object.keys(ah),parseMessage:ch,fetchHistory:(e,n,i)=>lh(t,r,e,n,i),fetchHistoryBefore:(e,n,i,a)=>lh(t,r,e,n,a,Math.floor(i)-1)})}};function ch(e){if(!Qm(e)||typeof e.topic!=`string`||!e.topic.startsWith(`kline.`))return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Qm(n))return null;let r=Y(n.start),i=Y(n.open),a=Y(n.high),o=Y(n.low),s=Y(n.close),c=Y(n.volume);if(r===null||i===null||a===null||o===null||s===null||c===null)return null;let l=typeof n.confirm==`boolean`?n.confirm:!1;return{bar:{time:r,open:i,high:a,low:o,close:s,volume:c},closed:l}}async function lh(e,t,n,r,i,a){let o=`${e}/v5/market/kline?category=${t}&symbol=${n}&interval=${oh(r)}&limit=${Math.min(Math.max(i,1),1e3)}${a===void 0?``:`&end=${a}`}`,s=await fetch(o);if(!s.ok)throw Error(`Bybit REST error: ${s.status}`);return uh(await s.json())}function uh(e){if(!Qm(e)||!Qm(e.result))return[];let t=e.result.list;if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=dh(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function dh(e){if(!Array.isArray(e)||e.length<6)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[5]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t,open:n,high:r,low:i,close:a,volume:o}}var fh={"1m":1,"5m":5,"15m":15,"30m":30,"1h":60,"4h":240,"1d":1440,"1w":10080};function ph(e){return fh[e]??1}var mh=class extends Xm{constructor(e={}){let t=e.restBase??`https://api.kraken.com`,n=e.wsBase??`wss://ws.kraken.com/v2`;super({name:`kraken`,wsUrl:()=>n,subscribeMessage:e=>({method:`subscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ph(e.timeframe)}}),unsubscribeMessage:e=>({method:`unsubscribe`,params:{channel:`ohlc`,symbol:[e.symbol],interval:ph(e.timeframe)}}),supportedTimeframes:Object.keys(fh),parseMessage:hh,fetchHistory:(e,n)=>gh(t,e,n)})}};function hh(e){if(!Qm(e)||e.channel!==`ohlc`)return null;let t=e.data;if(!Array.isArray(t)||t.length===0)return null;let n=t[t.length-1];if(!Qm(n))return null;let r=Y(n.open),i=Y(n.high),a=Y(n.low),o=Y(n.close),s=Y(n.volume),c=typeof n.interval_begin==`string`?Date.parse(n.interval_begin):NaN;return r===null||i===null||a===null||o===null||s===null||!Number.isFinite(c)?null:{bar:{time:c,open:r,high:i,low:a,close:o,volume:s},closed:!1}}async function gh(e,t,n){let r=ph(n),i=t.replace(`/`,``),a=`${e}/0/public/OHLC?pair=${encodeURIComponent(i)}&interval=${r}`,o=await fetch(a);if(!o.ok)throw Error(`Kraken REST error: ${o.status}`);return _h(await o.json())}function _h(e){if(!Qm(e)||!Qm(e.result))return[];let t=null;for(let[n,r]of Object.entries(e.result))if(n!==`last`&&Array.isArray(r)){t=r;break}if(!Array.isArray(t))return[];let n=[];for(let e of t){let t=vh(e);t&&n.push(t)}return n.sort((e,t)=>e.time-t.time),n}function vh(e){if(!Array.isArray(e)||e.length<7)return null;let t=Y(e[0]),n=Y(e[1]),r=Y(e[2]),i=Y(e[3]),a=Y(e[4]),o=Y(e[6]);return t===null||n===null||r===null||i===null||a===null||o===null?null:{time:t*1e3,open:n,high:r,low:i,close:a,volume:o}}var yh={visible:!0,showSymbol:!0,showOHLC:!0,showChange:!0,showVolume:!0,position:`top-left`,fontSize:12,fontFamily:null},bh=class{config={...yh};symbol=``;timeframe=``;hoverBar=null;hoverPrev=null;indicators=[];statusText=null;exchange=``;drawnHeight=null;locale=`en-US`;pricePrecision=null;setConfig(e){Object.assign(this.config,e),this.drawnHeight=null}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}setSymbol(e){this.symbol=e,this.drawnHeight=null}setTimeframe(e){this.timeframe=e,this.drawnHeight=null}setChartType(e){}setHoverBar(e,t=null){this.hoverBar=e,this.hoverPrev=e?t:null}setIndicatorValues(e){this.indicators=e}setStatusText(e){this.statusText=e,this.drawnHeight=null}setExchange(e){this.exchange=e,this.drawnHeight=null}title(){return this.config.showSymbol?[this.symbol,this.timeframe,this.exchange].filter(Boolean).join(` · `):``}titleCells(e,t,n,r,i){let a=[],o=this.title();if(o){let i=`600 ${t}px ${n}`;e.font=i,a.push({label:``,labelWidth:0,value:o,width:e.measureText(o).width,color:r,font:i})}if(this.statusText){let r=`${t}px ${n}`;e.font=r,a.push({label:``,labelWidth:0,value:this.statusText,width:e.measureText(this.statusText).width,color:i,font:r})}return a}priceCells(e,n,r,i,a,o,s,c){let l=`${o}px ${s}`;e.font=l;let u=i.close>=i.open,d=this.pricePrecision??(0,t.autoPricePrecision)(n.priceRange.min,n.priceRange.max),f=e=>n.formatPrice?.(e)??(0,t.formatPrice)(e,d,this.locale),p=[{label:`O`,value:f(i.open),color:c},{label:`H`,value:f(i.high),color:c},{label:`L`,value:f(i.low),color:c},{label:`C`,value:f(i.close),color:u?r.candleUp:r.candleDown}];if(this.config.showChange){let e=i.close-a.close,n=a.close===0?0:e/a.close*100,o=e>=0?`+`:``,s=(0,t.formatPrice)(n,2,this.locale);p.push({label:``,value:`${o}${f(e)} (${o}${s}%)`,color:e>=0?r.candleUp:r.candleDown})}return p.map(t=>({...t,labelWidth:t.label?e.measureText(t.label+` `).width:0,width:Th(e,t.value),font:l}))}getHeight(){if(!this.config.visible||this.config.position!==`top-left`)return 0;if(this.drawnHeight!==null)return this.drawnHeight;let e=this.config.fontSize,t=xh;return(this.config.showOHLC||this.title()||this.statusText)&&(t+=e+Ch),this.config.showVolume&&(t+=e+2),t}render(e,t,n,r){if(!this.config.visible||r.length===0)return;let i=this.hoverBar??r[r.length-1],a=this.hoverBar?this.hoverPrev??i:r.length>1?r[r.length-2]:i,{chartRect:o}=t,s=this.config.fontSize,c=this.config.fontFamily??n.font.family,l=n.style?.legend.text??n.text,u=n.style?.legend.label??n.textSecondary,d=this.config.position===`top-left`,f=d?o.x+Sh:o.x+o.width-Sh,p=o.y+xh;e.textAlign=d?`left`:`right`,e.textBaseline=`top`;let m=this.titleCells(e,s,c,l,u);if(this.config.showOHLC&&m.push(...this.priceCells(e,t,n,i,a,s,c,l)),m.length>0){e.font=`${s}px ${c}`;let t=e.measureText(` `).width;for(let n of wh(m,t,o.width-2*Sh)){let r=n.reduce((e,n)=>e+n.labelWidth+n.width+t,-t),i=d?f:f-r;e.textAlign=`left`;for(let r of n)e.font=r.font,r.label&&(e.fillStyle=u,e.fillText(r.label,i,p),i+=r.labelWidth),e.fillStyle=r.color,e.fillText(r.value,i,p),i+=r.width+t;p+=s+Ch}e.textAlign=d?`left`:`right`}if(this.config.showVolume){e.font=`${s}px ${c}`,e.fillStyle=u;let t=i.volume>=1e6?`${(i.volume/1e6).toFixed(2)}M`:i.volume>=1e3?`${(i.volume/1e3).toFixed(2)}K`:i.volume.toFixed(0);e.fillText(`Vol ${t}`,f,p),p+=s+2}if(this.drawnHeight=d?p-o.y:null,this.indicators.length>0){e.font=`${s}px ${c}`;let t=e.measureText(` `).width,n=this.indicators.map(t=>{let n=`${t.name} ${t.value}`;return{entry:n,color:t.color,width:Th(e,n)}}),r=n.reduce((e,n)=>e+n.width+t,-t),i=d?f:f-r;e.textAlign=`left`;for(let{entry:r,color:a,width:o}of n)e.fillStyle=a,e.fillText(r,i,p),i+=o+t}}},xh=6,Sh=8,Ch=3;function wh(e,t,n){let r=[],i=[],a=0;for(let o of e){let e=o.labelWidth+o.width;i.length>0&&a+t+e>n&&(r.push(i),i=[],a=0),a+=(i.length>0?t:0)+e,i.push(o)}return i.length>0&&r.push(i),r}function Th(e,t){let n=t.replace(/\d/g,`0`);return Math.max(e.measureText(t).width,e.measureText(n.replace(/[-−]/g,`+`)).width,e.measureText(n.replace(/\+/g,`-`)).width)}var Eh=class{static toDataURL(e,t){let n=e.querySelectorAll(`canvas`);if(n.length===0)return``;let r=n[0],i=r.width,a=r.height,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);t&&(s.fillStyle=t,s.fillRect(0,0,i,a));let c=Array.from(n).sort((e,t)=>(parseInt(e.style.zIndex)||0)-(parseInt(t.style.zIndex)||0));for(let e of c)s.drawImage(e,0,0);return o.toDataURL(`image/png`)}static async toBlob(e,t){let n=this.toDataURL(e,t);return n?(await fetch(n)).blob():null}static download(e,t=`chart.png`,n){let r=this.toDataURL(e,n);if(!r)return;let i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i)}},Dh=class{config=null;setConfig(e){this.config=e}isVisible(){return!!this.config?.text}render(e,t,n){if(!this.config?.text)return;let{chartRect:r}=t,i=this.config.fontSize??48,a=n.style?.watermark.color??this.config.color??n.textSecondary;e.save(),e.globalAlpha=.07,e.font=`bold ${i}px ${n.font.family}`,e.fillStyle=a,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(this.config.text,r.x+r.width/2,r.y+r.height/2),e.restore()}},Oh={solid:null,dashed:[6,4],dotted:[2,3]},kh=6,Ah=8;function jh(e,t){let n=[...e].sort((e,t)=>t.rank-e.rank||e.px-t.px),r=[],i=[];for(let e of n){let n=0,a=r.length;for(;n<a;){let t=n+a>>1;r[t]<e.px?n=t+1:a=t}n>0&&e.px-r[n-1]<t||n<r.length&&r[n]-e.px<t||(r.splice(n,0,e.px),i.push(e))}return i.sort((e,t)=>e.px-t.px)}var Mh=class{config={visible:!1};cachedBreaksTyped=[];cachedMedianStep=0;cacheValid=!1;lastDataLength=0;locale=`en-US`;tz=null;setConfig(e){Object.assign(this.config,e)}setLocale(e){this.locale=e}setTimezone(e){e!==this.tz&&(this.tz=e,this.invalidateCache())}isVisible(){return this.config.visible}setVisible(e){this.config.visible=e}computeBreaksTyped(e){if(e.length<2)return[];if(this.cacheValid&&e.length===this.lastDataLength)return this.cachedBreaksTyped;let n=[],r=(0,t.barTimeUnit)(e),i=(0,t.timeParts)(e[0].time*r,this.tz);for(let a=1;a<e.length;a++){let o=e[a].time*r,s=(0,t.timeParts)(o,this.tz);if(s.year!==i.year)n.push({idx:a,kind:`year`,time:o,year:s.year});else if(s.month!==i.month)n.push({idx:a,kind:`month`,time:o,year:s.year});else if(s.day!==i.day){let e=new Date(Date.UTC(s.year,s.month-1,s.day)).getUTCDay()===1;n.push({idx:a,kind:e?`week`:`day`,time:o,year:s.year})}i=s}return this.lastDataLength=e.length,this.cachedBreaksTyped=n,this.cachedMedianStep=Fh(e),this.cacheValid=!0,n}render(e,t,n,r){this.renderLines(e,t,n,r),this.renderLabels(e,t,n,r)}renderLines(e,t,n,r){let i=this.lineMarks(t,r,n);if(i.length===0)return;let{chartRect:a}=t,o=this.look(n),s=Oh[o.style];e.save(),s&&e.setLineDash(s),e.strokeStyle=o.color;for(let t of i)e.globalAlpha=t.alpha,e.lineWidth=t.width,e.beginPath(),e.moveTo(t.px,a.y),e.lineTo(t.px,a.y+a.height),e.stroke();e.restore()}renderLabels(e,t,n,r){let i=this.lineMarks(t,r,n).filter(e=>e.label!==null);if(i.length===0)return;let{chartRect:a}=t;e.save(),e.font=`600 11px ${n.font.family}`,e.textBaseline=`top`,e.textAlign=`left`,e.fillStyle=n.textSecondary;let o=[],s=[...i].sort((e,t)=>t.rank-e.rank||e.px-t.px);for(let t of s){let n=t.px+4,r=n+e.measureText(t.label).width;o.some(e=>n<e.right+Ah&&r+Ah>e.left)||(o.push({left:n,right:r}),e.globalAlpha=Math.min(1,t.alpha+.35),e.fillText(t.label,n,a.y+4))}e.restore()}lineRects(e,t,n){let r=this.lineMarks(e,n,t);if(r.length===0)return[];let{color:i,style:a}=this.look(t),o=Oh[a]??void 0,{y:s,height:c}=e.chartRect;return r.map(e=>({x:e.px-e.width/2,y:s,width:e.width,height:c,color:i,alpha:e.alpha,...o?{dash:o}:{}}))}look(e){let t=e.style?.sessionBreaks;return{color:t?.color??this.config.color??e.axisLine,style:t?.style??this.config.lineStyle??`dashed`,width:t?.width??this.config.lineWidth??1}}lineMarks(e,t,n){return jh(this.marks(e,t,n),kh)}marks(n,r,i){if(!this.config.visible||r.length<2)return[];let a=this.computeBreaksTyped(r);if(a.length===0||this.cachedMedianStep>=1380*60*1e3)return[];let{chartRect:o}=n,s=this.look(i).width,c=[];for(let r of a){let i=e.b(r.idx,n)-(n.barWidth+n.barSpacing)/2;if(i<o.x-1||i>o.x+o.width+1)continue;let a=Math.round(i)+.5,l=.25,u=s,d=null,f=3;r.kind===`day`?(l=.22,f=0):r.kind===`week`?(l=.34,f=1,d=(0,t.zonedDateFormatter)(this.locale,Nh,this.tz)(r.time)):r.kind===`month`?(l=.5,f=2,u=s+.5,d=(0,t.zonedDateFormatter)(this.locale,Ph,this.tz)(r.time)):(l=.7,u=s+1,d=String(r.year)),c.push({px:a,width:u,alpha:l,label:d,rank:f})}return c}invalidateCache(){this.lastDataLength=0,this.cachedBreaksTyped=[],this.cachedMedianStep=0,this.cacheValid=!1}},Nh={month:`short`,day:`numeric`},Ph={month:`short`,year:`numeric`};function Fh(e){if(e.length<2)return 0;let n=Math.min(50,e.length-1),r=(0,t.barTimeUnit)(e),i=[];for(let t=1;t<=n;t++)i.push((e[t].time-e[t-1].time)*r);return i.sort((e,t)=>e-t),i[Math.floor(i.length/2)]}var Ih=864e5;function Lh(e,t){let n={...e,...t};return t.tzOffsetMinutes!==void 0&&t.timeZone===void 0&&delete n.timeZone,n.windows?n.windows=n.windows.map(e=>({...e})):delete n.windows,n}function Rh(e,t){let n=((e+t*6e4)%Ih+Ih)%Ih;return Math.floor(n/6e4)}function zh(e,t,n){return t===n?!0:t<n?e>=t&&e<n:e>=t||e<n}function Bh(e,n){let r=Rh(e,n.timeZone?(0,t.zoneOffsetMinutes)(n.timeZone,e):n.tzOffsetMinutes??0);return n.windows&&n.windows.length>0?n.windows.some(e=>zh(r,e.startMinute,e.endMinute)):zh(r,n.startMinute,n.endMinute)}var Vh={startMinute:570,endMinute:960,tzOffsetMinutes:-300,timeZone:`America/New_York`},Hh=class{visible=!1;config={...Vh};setVisible(e){this.visible=e}isVisible(){return this.visible}setConfig(e){this.config=Lh(this.config,e)}replaceConfig(e){this.config=Lh(e,{})}getConfig(){return{...this.config,windows:this.config.windows?.map(e=>({...e}))}}render(e,t,n,r){let i=this.rects(t,n,r);if(i.length!==0){e.save(),e.fillStyle=i[0].color;for(let t of i)e.fillRect(t.x,t.y,t.width,t.height);e.restore()}}rects(t,n,r){if(!this.visible||t.length===0)return[];let{chartRect:i}=n,{from:a,to:o}=n.visibleRange,s=Math.max(0,a),c=Math.min(o,t.length-1);if(c<s)return[];let l=n.barWidth+n.barSpacing,u=r.name===`light`?`rgba(0,0,0,0.045)`:`rgba(0,0,0,0.28)`,d=[],f=-1,p=(t,r)=>{let a=e.b(t,n)-l/2,o=e.b(r,n)+l/2;d.push({x:a,y:i.y,width:o-a,height:i.height,color:u,alpha:1})};for(let e=s;e<=c;e++){let n=!Bh(t[e].time,this.config);n&&f===-1?f=e:!n&&f!==-1&&(p(f,e-1),f=-1)}return f!==-1&&p(f,c),d}},Uh=[2,3],Wh=16,Gh=class{highLow=!1;quote=null;quoteShown=!0;priceText=null;setPriceText(e){this.priceText=e}setQuoteShown(e){this.quoteShown=e}setHighLow(e){this.highLow=e}isHighLowVisible(){return this.highLow}setBidAsk(e){this.quote=e?{...e}:null}getBidAsk(){return this.quote?{...this.quote}:null}levels(e,t){let n=[];if(this.highLow){let r=Math.max(0,t.visibleRange.from),i=Math.min(e.length-1,t.visibleRange.to),a=-1/0,o=1/0;for(let t=r;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);Number.isFinite(a)&&n.push({kind:`high`,price:a}),Number.isFinite(o)&&n.push({kind:`low`,price:o})}let{bid:r,ask:i}=(this.quoteShown?this.quote:null)??{};return r!==void 0&&Number.isFinite(r)&&n.push({kind:`bid`,price:r}),i!==void 0&&Number.isFinite(i)&&n.push({kind:`ask`,price:i}),n}render(t,n,r,i){let{chartRect:a}=n;t.save(),t.setLineDash(Uh),t.lineWidth=1;for(let o of this.levels(i,n)){let i=Math.round(e.T(o.price,n))+.5;i<a.y||i>a.y+a.height||(t.strokeStyle=Kh(o.kind,r),t.beginPath(),t.moveTo(a.x,i),t.lineTo(a.x+a.width,i),t.stroke())}t.restore()}renderAxisTags(n,r,i,a){let{chartRect:o}=r,s=o.x+o.width+1,c=(r.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2,l=(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max);n.save(),n.font=`${i.font.sizeSmall}px ${i.font.family}`,n.textBaseline=`middle`,n.textAlign=`left`;for(let u of this.levels(a,r)){let a=e.T(u.price,r);if(a<o.y||a>o.y+o.height)continue;n.fillStyle=Kh(u.kind,i),E(n,s,a-Wh/2,c,Wh,i),n.fillStyle=i.background;let d=r.formatPrice?.(u.price)??this.priceText?.(u.price)??(0,t.formatPrice)(u.price,l);n.fillText(d,s+5,a)}n.restore()}};function Kh(e,t){switch(e){case`bid`:return t.candleUp;case`ask`:return t.candleDown;default:return t.style?.highLow.color??t.textSecondary}}var qh=12,Jh=3,Yh=500,Xh=2,Zh=[`movesUp`,`movesDown`];function Qh(e){return e.channel===`price`&&!e.drawingId&&!e.target&&!Zh.includes(e.condition)}function $h(e,t,n,r){switch(r){case`crossingUp`:return e!==void 0&&e<n&&t>=n;case`crossingDown`:return e!==void 0&&e>n&&t<=n;case`crossing`:return e!==void 0&&(e<n&&t>=n||e>n&&t<=n);case`greaterThan`:return t>n;case`lessThan`:return t<n;default:return!1}}var eg=[`crossing`,`crossingUp`,`crossingDown`];function tg(e,t,n){let r=e<0&&t>=0,i=e>0&&t<=0;return n===`crossingUp`?r:n===`crossingDown`?i:r||i}var ng=1,rg=2**31-1,ig=class extends am{alerts=[];lastValues=new Map;drawingSides=new Map;drawingLevels=null;requestRender=null;pricePrecision=null;barTime=null;expiryTimer=null;history=new Map;lastDiffs=new Map;setBarTime(e){this.barTime=e}setRequestRender(e){this.requestRender=e}setPricePrecision(e){this.pricePrecision=e}addAlert(e,t=`crossing`,n,r=!1,i=`price`,a,o={}){let s=ag(t,i,o),c=`tc_alert_${ng++}`,l={id:c,price:e,condition:t,message:n,triggered:!1,repeating:r,channel:i,label:a,...s};return this.alerts.push(l),s.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`added`,l),this.requestRender?.(),c}setDrawingLevels(e){this.drawingLevels=e}addDrawingAlert(e,t=`crossing`,n,r=!1,i){if(!eg.includes(t))throw RangeError(`An alert on a drawing takes a crossing condition, not "${t}"`);let a=`tc_alert_${ng++}`,o={id:a,price:this.drawingLevels?.(e)?.[0]??NaN,condition:t,message:n,triggered:!1,repeating:r,channel:`price`,label:i,drawingId:e};return this.alerts.push(o),this.emit(`added`,o),a}removeDrawingAlerts(e){for(let t of this.alerts.filter(t=>t.drawingId===e))this.removeAlert(t.id)}takeDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId===e);for(let e of t)this.removeAlert(e.id);return t.map(e=>({...e}))}restoreAlerts(e){for(let t of e){if(this.alerts.some(e=>e.id===t.id))continue;let e={...t};this.alerts.push(e),this.emit(`added`,e)}this.scheduleExpiry(),this.requestRender?.()}pruneDrawingAlerts(e){let t=this.alerts.filter(t=>t.drawingId!==void 0&&!e.has(t.drawingId));for(let e of t)this.removeAlert(e.id);return t.length}removeAlert(e){this.drawingSides.delete(e),this.lastDiffs.delete(e);let t=this.alerts.some(t=>t.id===e&&t.expiresAt!==void 0);this.alerts=this.alerts.filter(t=>t.id!==e),t&&this.scheduleExpiry(),this.emit(`removed`,e),this.requestRender?.()}getAlerts(){return[...this.alerts]}getAlertAtPoint(t,n,r=6){let{chartRect:i}=n;if(t.y<i.y||t.y>i.y+i.height)return null;let a=null,o=r;for(let r of this.alerts){if(!Qh(r))continue;let i=Math.abs(e.T(r.price,n)-t.y);i<=o&&(o=i,a=r)}return a}updateAlertPrice(e,t){let n=this.alerts.find(t=>t.id===e);!n||!Number.isFinite(t)||(n.price=t,n.triggered=!1,n.expiresAt!==void 0&&this.scheduleExpiry(),this.emit(`updated`,{...n}),this.requestRender?.())}clearAlerts(){this.alerts=[],this.lastDiffs.clear(),this.drawingSides.clear(),this.scheduleExpiry(),this.requestRender?.()}checkPrice(e){this.checkChannel(`price`,e),this.checkDrawingAlerts(e)}checkDrawings(e){this.checkDrawingAlerts(e)}expire(){let e=Date.now(),t=this.alerts.filter(t=>!t.expired&&t.expiresAt!==void 0&&e>=t.expiresAt&&!(t.triggered&&!t.repeating));if(t.length!==0){for(let e of t)e.expired=!0;try{for(let e of t)this.emit(`expired`,{...e}),this.emit(`updated`,{...e})}finally{this.requestRender?.(),this.scheduleExpiry()}}}scheduleExpiry(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null;let e=Math.min(...this.alerts.filter(e=>!e.expired&&e.expiresAt!==void 0&&!(e.triggered&&!e.repeating)).map(e=>e.expiresAt));if(!Number.isFinite(e))return;let t=Math.min(Math.max(0,e-Date.now()),rg);this.expiryTimer=setTimeout(()=>{this.expiryTimer=null,this.expire(),this.expiryTimer||this.scheduleExpiry()},t)}dispose(){this.expiryTimer&&clearTimeout(this.expiryTimer),this.expiryTimer=null}checkDrawingAlerts(e){if(!(!this.drawingLevels||!Number.isFinite(e)))for(let t of this.alerts){if(!t.drawingId||t.expired)continue;let n=this.drawingLevels(t.drawingId);if(!n||n.length===0){this.drawingSides.delete(t.id);continue}t.price=n[0];let r=n.map(t=>Math.sign(e-t)),i=this.drawingSides.get(t.id);this.drawingSides.set(t.id,r),!(!i||i.length!==r.length)&&(r.some((e,n)=>tg(i[n],e,t.condition))?t.triggered||(t.triggered=!0,this.emit(`triggered`,{...t})):t.repeating&&(t.triggered=!1))}}checkChannel(e,t){this.checkChannels(new Map([[e,t]]))}checkChannels(e,t={}){let n=(e instanceof Map?[...e.entries()]:Object.entries(e)).filter(([,e])=>Number.isFinite(e));if(n.length===0)return;this.expire();let r=new Map,i=new Map;for(let[e,t]of n){r.set(e,this.lastValues.get(e));let n=this.recordBar(e,t);n&&i.set(e,n),this.lastValues.set(e,t)}for(let e of this.alerts){if(e.drawingId||e.expired)continue;let n=r.has(e.channel),a=e.target!==void 0&&r.has(e.target);if(!n&&!a||e.target!==void 0&&t.together&&!(n&&a))continue;let o;if(e.onBarClose){let t=i.get(e.channel)??(e.target?i.get(e.target):void 0);if(!t)continue;o=this.closedBarMet(e,t)}else if(e.target)o=this.targetMet(e);else if(Zh.includes(e.condition)){if(!n)continue;o=this.moveMet(e,this.history.get(e.channel)??[])}else{let t=r.get(e.channel);if(!n||t===void 0)continue;o=$h(t,this.lastValues.get(e.channel),e.price,e.condition)}this.settle(e,o)}}settle(e,t){t?e.triggered||(e.triggered=!0,this.emit(`triggered`,{...e})):e.repeating&&(e.triggered=!1)}targetMet(e){let t=this.lastValues.get(e.channel),n=e.target?this.lastValues.get(e.target):void 0;if(t===void 0||n===void 0)return!1;let r=t-n,i=this.lastDiffs.get(e.id);return this.lastDiffs.set(e.id,r),e.price=n,$h(i,r,0,e.condition)}moveMet(e,t,n=t.length){let r=e.bars??1,i=t.slice(Math.max(0,n-r),n);if(i.length<2||e.percent===void 0)return!1;let a=i[i.length-1].value,o=i.map(e=>e.value);if(e.condition===`movesUp`){let t=Math.min(...o);return t!==0&&(a-t)/Math.abs(t)*100>=e.percent}let s=Math.max(...o);return s!==0&&(s-a)/Math.abs(s)*100>=e.percent}closedBarMet(e,t){let n=this.history.get(e.channel)??[],r=n.findIndex(e=>e.time===t.time);if(r<0)return!1;if(Zh.includes(e.condition))return this.moveMet(e,n,r+1);let i=(e,t)=>{let r=this.history.get(e)??[],i=n[t]?.time;return i===void 0?void 0:r.find(e=>e.time===i)?.value},a=n[r].value,o=r>0?n[r-1].value:void 0,s=e.price;if(e.target){let t=i(e.target,r),n=r>0?i(e.target,r-1):void 0;if(t===void 0)return!1;a-=t,o=o!==void 0&&n!==void 0?o-n:void 0,s=0,e.price=t}return $h(o,a,s,e.condition)}recordBar(e,t){let n=this.barTime;if(n===null)return null;let r=this.history.get(e)??[],i=r[r.length-1];if(i&&n<i.time)return r=r.filter(e=>e.time<n),r.push({time:n,value:t}),this.history.set(e,r),null;if(i&&i.time===n)return r[r.length-1]={time:n,value:t},null;i=r[r.length-1],r.push({time:n,value:t});let a=Math.min(502,Math.max(3,...this.alerts.map(e=>(e.bars??1)+2)));return r.length>a&&r.splice(0,r.length-a),this.history.set(e,r),i?{channel:e,time:i.time}:null}seedLastValue(e,t){Number.isFinite(t)&&this.lastValues.set(e,t)}clearLastValues(){this.lastValues.clear(),this.drawingSides.clear(),this.history.clear(),this.lastDiffs.clear()}saveToStorage(e){try{let t=this.alerts.map(e=>({id:e.id,price:e.price,condition:e.condition,message:e.message,triggered:e.triggered,repeating:e.repeating,channel:e.channel,label:e.label,drawingId:e.drawingId,target:e.target,percent:e.percent,bars:e.bars,onBarClose:e.onBarClose,expiresAt:e.expiresAt,expired:e.expired}));localStorage.setItem(e,JSON.stringify(t))}catch{}}loadFromStorage(e){try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);if(!Array.isArray(n))return;for(let e of n){if(typeof e.drawingId==`string`&&e.condition&&!e.triggered){eg.includes(e.condition)&&this.addDrawingAlert(e.drawingId,e.condition,e.message,e.repeating??!1,e.label);continue}if(!e.condition||e.triggered||e.expired)continue;let t=og(e),n=!t.target&&!Zh.includes(e.condition),r=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:NaN;if(!(n&&Number.isNaN(r)))try{this.addAlert(r,e.condition,e.message,e.repeating??!1,e.channel??`price`,e.label,t)}catch{}}}catch{}}render(n,r,i){let{chartRect:a}=r;for(let o of this.alerts){if(!Qh(o))continue;let s=e.T(o.price,r);if(s<a.y||s>a.y+a.height)continue;let c=o.expired?`#8a93a3`:o.triggered?`#f2a93b`:`#4c8dff`;n.setLineDash([2,6]),n.strokeStyle=c,n.lineWidth=1,n.beginPath(),n.moveTo(a.x,Math.round(s)+.5),n.lineTo(a.x+a.width,Math.round(s)+.5),n.stroke(),n.setLineDash([]),n.font=`10px ${i.font.family}`,n.fillStyle=c,n.textBaseline=`bottom`,n.textAlign=`right`;let l=`${(0,t.priceTagText)(o.price,r,this.pricePrecision??void 0)}${o.message?` - ${o.message}`:``}`,u=a.x+a.width-4;n.fillText(l,u,s-2);let d=u-n.measureText(l).width-Jh-qh;d>=a.x&&Jf(n,t.UI_ICONS.bell,d,s-2-qh,qh,c)}}};function ag(e,t,n){let r={},i=Zh.includes(e);if(n.target!==void 0){if(i)throw RangeError(`An alert on a move takes no other line`);if(n.target===t)throw RangeError(`An alert can’t compare a line with itself`);r.target=n.target}if(i){let{percent:e,bars:t}=n;if(e===void 0||!Number.isFinite(e)||e<=0)throw RangeError(`An alert on a move needs a percent above 0`);if(t===void 0||!Number.isInteger(t)||t<2||t>500)throw RangeError(`An alert on a move needs 2 to 500 bars`);r.percent=e,r.bars=t}return n.onBarClose&&(r.onBarClose=!0),n.expiresAt!==void 0&&Number.isFinite(n.expiresAt)&&(r.expiresAt=n.expiresAt),r}function og(e){let t={};return typeof e.target==`string`&&e.target&&(t.target=e.target),typeof e.percent==`number`&&Number.isFinite(e.percent)&&(t.percent=e.percent),typeof e.bars==`number`&&Number.isInteger(e.bars)&&(t.bars=e.bars),e.onBarClose===!0&&(t.onBarClose=!0),typeof e.expiresAt==`number`&&Number.isFinite(e.expiresAt)&&(t.expiresAt=e.expiresAt),t}var sg=16,cg=()=>typeof requestAnimationFrame==`function`&&!(typeof document<`u`&&document.hidden),lg={now:()=>typeof performance<`u`?performance.now():Date.now(),frame:e=>cg()?{raf:requestAnimationFrame(e)}:{timeout:setTimeout(e,sg)},cancel:e=>{let t=e;t.raf!==void 0&&cancelAnimationFrame(t.raf),t.timeout!==void 0&&clearTimeout(t.timeout)}},ug=class extends am{data=[];cursor=-1;timer=null;frameHandle=null;run=0;state=`stopped`;config={speed:1,interval:500};paceMs=null;constructor(e=lg){super(),this.clock=e}load(e){this.stop(),this.data=e,this.cursor=-1}play(e){if(this.data.length===0)return;if(e){let{startIndex:t,paused:n,duration:r,...i}=e;this.config={...this.config,...i};let a=t===void 0?null:this.clamp(t);if(n){this.clearTimer(),this.seekTo(a??Math.max(0,this.cursor)),this.setPace(r),this.setState(`paused`);return}a!==null&&(this.cursor=a-1),this.setPace(r)}if(this.isAtEnd()){this.clearTimer(),this.setState(`paused`);return}this.clearTimer();let t=this.paceMs??this.config.interval/this.config.speed;if(!(t>0)||!Number.isFinite(t)){this.setState(`paused`);return}this.setState(`playing`),t<sg||this.paceMs!==null?this.runFrames(t):this.timer=setInterval(()=>this.advance(1),t)}pause(){this.clearTimer(),this.setState(`paused`)}resume(){this.state===`paused`&&this.play()}stop(){this.clearTimer(),this.cursor=-1,this.setState(`stopped`)}seekTo(e){this.data.length!==0&&(this.cursor=this.clamp(e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}))}setSpeed(e){this.config={...this.config,speed:e},this.paceMs=null,this.state===`playing`&&this.play()}getState(){return this.state}isAtEnd(){return this.data.length>0&&this.cursor>=this.data.length-1}getProgress(){let e=this.data.length;return{current:Math.max(0,this.cursor),total:e,percent:e>0?(this.cursor+1)/e*100:0}}dispose(){this.stop(),this.removeAllListeners(),this.data=[]}setPace(e){this.paceMs=e!==void 0&&e>0&&Number.isFinite(e)?e/Math.max(1,this.data.length-1-this.cursor):null}runFrames(e){let t=this.run,n=this.clock.now(),r=0,i=()=>{if(t!==this.run||this.state!==`playing`)return;this.frameHandle=null;let a=this.clock.now();r+=Math.min(50,Math.max(0,a-n)),n=a;let o=Math.floor(r/e);try{o>0&&(r-=o*e,this.advance(o))}finally{t===this.run&&this.state===`playing`&&this.frameHandle===null&&(this.frameHandle=this.clock.frame(i))}};this.frameHandle=this.clock.frame(i)}advance(e){if(this.isAtEnd()){this.finish();return}this.cursor=Math.min(this.data.length-1,this.cursor+e),this.emit(`bar`,{bar:this.data[this.cursor],index:this.cursor,total:this.data.length}),this.isAtEnd()&&this.finish()}finish(){this.clearTimer(),this.setState(`paused`),this.emit(`complete`,void 0)}clamp(e){return Number.isFinite(e)?Math.max(0,Math.min(Math.floor(e),this.data.length-1)):0}clearTimer(){this.run++,this.timer&&=(clearInterval(this.timer),null),this.frameHandle!==null&&(this.clock.cancel(this.frameHandle),this.frameHandle=null)}setState(e){this.state!==e&&(this.state=e,this.emit(`stateChange`,e))}},dg=64,fg=3,pg=3;function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function mg(e){return Array.isArray(e)?e:[]}function hg(e,t){return typeof e==`string`?e:t}function gg(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function _g(e){if(!X(e)||typeof e.id!=`string`||typeof e.type!=`string`||!Array.isArray(e.anchors)||e.anchors.length===0||e.anchors.length>vg||!X(e.style))return null;let n=[];for(let t of e.anchors){if(!X(t)||typeof t.time!=`number`||typeof t.price!=`number`||!Number.isFinite(t.time)||!Number.isFinite(t.price))return null;n.push({time:t.time,price:t.price})}let r=(0,t.sanitizeDrawingStyle)(e.style);return r.color===void 0||r.lineWidth===void 0?null:{id:e.id,type:e.type,anchors:n,style:{lineStyle:`solid`,...r,color:r.color,lineWidth:r.lineWidth},visible:typeof e.visible==`boolean`?e.visible:!0,locked:typeof e.locked==`boolean`?e.locked:!1,options:X(e.options)?e.options:void 0,intervals:nn(e.intervals)??void 0,group:xg(e.group),meta:X(e.meta)?e.meta:void 0}}var vg=5e3,yg=64,bg=80;function xg(e){if(!(!X(e)||typeof e.id!=`string`||typeof e.name!=`string`)&&!(e.id===``||e.id.length>yg))return{id:e.id,name:e.name.slice(0,bg)}}function Sg(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.type!=`string`||typeof e.price!=`number`||typeof e.quantity!=`number`?null:e}function Cg(e){if(!X(e))return;let n={},r=mg(e.colors).filter(e=>typeof e==`string`);r.length>0&&(n.colors=r);let i=mg(e.lineWidths).filter(e=>typeof e==`number`&&Number.isFinite(e)&&e>0);i.length>0&&(n.lineWidths=i),typeof e.opacity==`number`&&Number.isFinite(e.opacity)&&(n.opacity=Math.min(1,Math.max(0,e.opacity)));let a=(0,t.readIndicatorPlotStyles)(e.plots);return a&&(n.plots=a),Object.keys(n).length>0?n:void 0}var wg=[`crossingUp`,`crossingDown`,`crossing`,`greaterThan`,`lessThan`,`movesUp`,`movesDown`];function Tg(e){if(!X(e)||typeof e.id!=`string`)return null;let t=typeof e.drawingId==`string`?e.drawingId:void 0,n=typeof e.price==`number`&&Number.isFinite(e.price)?e.price:null,r=wg.find(t=>t===e.condition)??`crossing`,i=og(e),a=i.target!==void 0||r===`movesUp`||r===`movesDown`;return n===null&&!t&&!a?null:{id:e.id,price:n??NaN,drawingId:t,condition:r,message:typeof e.message==`string`?e.message:void 0,triggered:e.triggered===!0,repeating:e.repeating===!0,channel:hg(e.channel,`price`),label:typeof e.label==`string`?e.label:void 0,...i,...e.expired===!0?{expired:!0}:{}}}function Eg(e){return!X(e)||typeof e.id!=`string`||typeof e.side!=`string`||typeof e.entryPrice!=`number`||typeof e.quantity!=`number`?null:e}var Dg=4e3;function Og(e){if(!X(e))return;let n={},r=[];for(let[i,a]of Object.entries(e)){let e=(0,t.readChartStyleOverrides)(a);r.push(...e.rejected);let o=Object.fromEntries(Object.entries(e.overrides).filter(([,e])=>e!==null));Object.keys(o).length>0&&(n[i.slice(0,dg)]=o)}return r.length>0&&console.warn(`Saved style overrides left out: ${[...new Set(r)].join(`, `)}`),n}function kg(e){if(!X(e))return Ag();typeof e.version==`number`&&e.version>pg&&console.warn(`Chart state from a newer version (${e.version}); loading what this version understands.`);let n=X(e.viewport)?e.viewport:{},r=[];for(let n of mg(e.indicators))X(n)&&(typeof n.id!=`string`||typeof n.instanceId!=`string`||X(n.params)&&r.push({id:n.id,instanceId:n.instanceId,params:n.params,position:typeof n.position==`string`?n.position:void 0,style:Cg(n.style),visible:typeof n.visible==`boolean`?n.visible:void 0,levels:Array.isArray(n.levels)?n.levels.filter(e=>typeof e==`number`&&Number.isFinite(e)):void 0,pane:typeof n.pane==`string`?n.pane:void 0,scale:n.scale===`left`?`left`:void 0,intervals:nn(n.intervals)??void 0,paneStyle:(0,t.readPaneStyle)(n.paneStyle)??void 0,paneSize:typeof n.paneSize==`number`&&Number.isFinite(n.paneSize)&&n.paneSize>0?Math.min(n.paneSize,Dg):void 0,paneOrder:typeof n.paneOrder==`number`&&Number.isInteger(n.paneOrder)&&n.paneOrder>=0?n.paneOrder:void 0,paneCollapsed:n.paneCollapsed===!0?!0:void 0,paneMaximized:n.paneMaximized===!0?!0:void 0,paneLog:n.paneLog===!0?!0:void 0,paneInvert:n.paneInvert===!0?!0:void 0,panePercent:n.panePercent===!0?!0:void 0}));let i=[];for(let t of mg(e.drawings)){let e=_g(t);e&&i.push(e)}let a=[];for(let t of mg(e.orders)){let e=Sg(t);e&&a.push(e)}let o=[];for(let t of mg(e.positions)){let e=Eg(t);e&&o.push(e)}let s=[];for(let t of mg(e.alerts)){let e=Tg(t);e&&s.push(e)}let c=Og(e.overrides);return{version:typeof e.version==`number`&&Array.isArray(e.indicators)?e.version:1,timestamp:gg(e.timestamp,Date.now()),symbol:typeof e.symbol==`string`?e.symbol:void 0,timeframe:typeof e.timeframe==`string`?e.timeframe:void 0,chartType:hg(e.chartType,`candlestick`),...e.chartTypeOptions===void 0?{}:{chartTypeOptions:(0,t.readChartTypeOptions)(e.chartTypeOptions)},viewport:{barWidth:gg(n.barWidth,8),barSpacing:gg(n.barSpacing,2),offset:gg(n.offset,0)},theme:typeof e.theme==`string`?e.theme:void 0,...c?{overrides:c}:{},locale:typeof e.locale==`string`?e.locale:void 0,indicators:r,drawings:i,orders:a,positions:o,alerts:s}}function Ag(){return{version:1,timestamp:Date.now(),chartType:`candlestick`,viewport:{barWidth:8,barSpacing:2,offset:0},indicators:[],drawings:[],orders:[],positions:[],alerts:[]}}var jg=class{static capture(e,t){return{version:e.getIndicators?pg:1,timestamp:Date.now(),chartType:t?.chartType??`candlestick`,...t?.chartTypeOptions&&Object.keys(t.chartTypeOptions).length>0?{chartTypeOptions:t.chartTypeOptions}:{},symbol:t?.symbol,timeframe:t?.timeframe,viewport:{barWidth:8,barSpacing:2,offset:0},theme:e.getTheme().name,...e.getOverrides&&Object.keys(e.getOverrides()).length>0?{overrides:e.getOverrides()}:{},indicators:e.getIndicators?.()??[],drawings:e.getDrawings(),orders:e.getOrders?.()??[],positions:e.getPositions?.()??[],alerts:e.getAlerts?.()??[]}}static serialize(e){return JSON.stringify(e)}static deserialize(e){return kg(JSON.parse(e))}static saveToStorage(e,t){localStorage.setItem(e,this.serialize(t))}static loadFromStorage(e){let t=localStorage.getItem(e);return t?this.deserialize(t):null}static downloadFile(e,t=`tc-chart-state.json`){let n=new Blob([this.serialize(e)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}static loadFromFile(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async()=>{let r=n.files?.[0];if(!r){t(Error(`No file selected`));return}let i=await r.text();e(this.deserialize(i))},n.click()})}},Mg=class{undoStack=[];redoStack=[];maxHistory=50;onChange=null;setOnChange(e){this.onChange=e}push(e){this.undoStack.push(e),this.undoStack.length>this.maxHistory&&this.undoStack.shift(),this.redoStack.length=0,this.onChange?.()}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undo(){let e=this.undoStack.pop();return e?(this.redoStack.push(e),this.onChange?.(),e):null}redo(){let e=this.redoStack.pop();return e?(this.undoStack.push(e),this.onChange?.(),e):null}clear(){this.undoStack.length=0,this.redoStack.length=0,this.onChange?.()}last(){return this.undoStack[this.undoStack.length-1]??null}dropLast(){this.undoStack.pop()&&(this.redoStack.length=0,this.onChange?.())}replaceLast(e){if(this.undoStack.length===0){this.push(e);return}this.undoStack[this.undoStack.length-1]=e,this.redoStack.length=0,this.onChange?.()}getState(){return{canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoCount:this.undoStack.length,redoCount:this.redoStack.length}}},Ng=[`Time`,`Open`,`High`,`Low`,`Close`,`Volume`];function Pg(e,n){return new Date((0,t.normalizeBarTime)(e,n)).toISOString()}function Fg(e){let t=/^[=+\-@\t\r]/.test(e)&&!/^-?\d/.test(e)?`'${e}`:e;return/[",\r\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t}var Ig=e=>e==null||!Number.isFinite(e)?``:String(e),Lg=class{static toCSV(e,n=[]){let r=[...Ng,...n.map(e=>Fg(e.name))].join(`,`),i=(0,t.barTimeUnit)(e);return[r,...e.map((e,t)=>[Pg(e.time,i),e.open,e.high,e.low,e.close,e.volume,...n.map(e=>Ig(e.values[t]))].join(`,`))].join(`
|
|
22
22
|
`)}static toJSON(e,n=[]){let r=(0,t.barTimeUnit)(e);return JSON.stringify(e.map((e,t)=>{let i={time:Pg(e.time,r),open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume};for(let e of n){let n=e.values[t];i[e.name]=n==null||!Number.isFinite(n)?null:n}return i}),null,2)}static download(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}};function Rg(e,t,n=-1/0){return t===null?e:e.filter(e=>e.time>=n&&e.time<t)}function zg(e,t,n=-1/0){return t===null?e:e.filter(e=>e.entryTime>=n&&e.entryTime<t).map(e=>{if(e.exitTime===void 0||e.exitTime<t)return e;let{exitTime:n,exitPrice:r,pnl:i,pnlPercent:a,...o}=e;return o})}var Bg=1,Vg=3,Hg=class extends am{markers=[];style={...t.DEFAULT_SIGNAL_STYLE};requestRender=null;dataGetter=null;revealUntil=null;revealFrom=-1/0;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addMarker(e){let t=e.id??`tc_signal_${Bg++}`,n={...e,id:t};return this.markers.push(n),this.emit(`added`,n),this.requestRender?.(),t}removeMarker(e){this.markers=this.markers.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getMarkers(){return[...this.markers]}clearMarkers(){this.markers=[],this.emit(`cleared`,void 0),this.requestRender?.()}setMarkers(e){this.markers=[...e],this.requestRender?.()}setRevealUntil(e,t=-1/0){e===this.revealUntil&&t===this.revealFrom||(this.revealUntil=e,this.revealFrom=t,this.requestRender?.())}shownMarkers(){return[...Rg(this.markers,this.revealUntil,this.revealFrom)]}markerAt(t,n){let r=this.dataGetter?.();if(!r||r.length===0)return null;let{chartRect:i}=n;if(t.x<i.x||t.x>i.x+i.width||t.y<i.y||t.y>i.y+i.height)return null;let a=this.style.arrowSize??12,o=Rg(this.markers,this.revealUntil,this.revealFrom);for(let i=o.length-1;i>=0;i--){let s=o[i],c=e.b(e.k(s.time,r),n),l=e.T(s.price,n),u=a*Math.max(.6,Math.min(1,s.confidence)),d=s.direction===`long`?l-u:(s.direction,l-u*.4),f=s.direction===`long`?l+u*.4:s.direction===`short`?l+u:l+u*.4;if(Math.abs(t.x-c)<=u*.6+Vg&&t.y>=d-Vg&&t.y<=f+Vg)return s}return null}render(t,n,r){let i=this.dataGetter?.(),a=Rg(this.markers,this.revealUntil,this.revealFrom);if(!i||i.length===0||a.length===0)return;let{chartRect:o}=n,s=Qs(this.style,r),c=s.arrowSize??12;t.save(),t.beginPath(),t.rect(o.x,o.y,o.width,o.height),t.clip();for(let l of a){let a=e.b(e.k(l.time,i),n),u=e.T(l.price,n);if(a<o.x-c||a>o.x+o.width+c||u<o.y-c||u>o.y+o.height+c)continue;let d=this.resolveColor(l,s),f=c*Math.max(.6,Math.min(1,l.confidence));if(this.renderArrow(t,a,u,l.direction,f,d),s.showLabel&&l.label){t.font=`10px ${r.font.family}`,t.fillStyle=d,t.textAlign=`center`,t.textBaseline=l.direction===`long`?`top`:`bottom`;let e=l.direction===`long`?u+f+3:u-f-3;t.fillText(l.label,a,e)}if(s.showConfidence&&l.confidence<1){t.font=`9px ${r.font.family}`,t.fillStyle=d,t.globalAlpha=.7,t.textAlign=`center`,t.textBaseline=l.direction===`long`?`top`:`bottom`;let e=l.direction===`long`?u+f+(l.label?14:3):u-f-(l.label?14:3);t.fillText(`${Math.round(l.confidence*100)}%`,a,e),t.globalAlpha=1}}t.restore()}resolveColor(e,t){if(e.color)return e.color;if(t.sourceColors?.[e.source])return t.sourceColors[e.source];switch(e.direction){case`long`:return t.longColor??`#1fa874`;case`short`:return t.shortColor??`#e8505b`;default:return t.neutralColor??`#9E9E9E`}}renderArrow(e,t,n,r,i,a){e.fillStyle=a,e.beginPath(),r===`long`?(e.moveTo(t,n-i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n+i*.4),e.lineTo(t+i*.2,n+i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):r===`short`?(e.moveTo(t,n+i),e.lineTo(t-i*.6,n),e.lineTo(t-i*.2,n),e.lineTo(t-i*.2,n-i*.4),e.lineTo(t+i*.2,n-i*.4),e.lineTo(t+i*.2,n),e.lineTo(t+i*.6,n)):e.arc(t,n,i*.4,0,Math.PI*2),e.closePath(),e.fill()}},Ug=12,Wg=1,Gg=class extends am{zones=[];style={...t.DEFAULT_TRADE_ZONE_STYLE};requestRender=null;dataGetter=null;revealUntil=null;revealFrom=-1/0;pricePrecision=null;setRequestRender(e){this.requestRender=e}setDataGetter(e){this.dataGetter=e}setPricePrecision(e){this.pricePrecision=e}setStyle(e){this.style={...this.style,...e},this.requestRender?.()}getStyle(){return{...this.style}}addZone(e){let t=e.id??`tc_zone_${Wg++}`,n={...e,id:t};return this.zones.push(n),this.emit(`added`,n),this.requestRender?.(),t}updateZone(e,t){let n=this.zones.findIndex(t=>t.id===e);n!==-1&&(this.zones[n]={...this.zones[n],...t},this.requestRender?.())}removeZone(e){this.zones=this.zones.filter(t=>t.id!==e),this.emit(`removed`,e),this.requestRender?.()}getZones(){return[...this.zones]}clearZones(){this.zones=[],this.emit(`cleared`,void 0),this.requestRender?.()}setZones(e){this.zones=[...e],this.requestRender?.()}setRevealUntil(e,t=-1/0){e===this.revealUntil&&t===this.revealFrom||(this.revealUntil=e,this.revealFrom=t,this.requestRender?.())}shownZones(){return[...zg(this.zones,this.revealUntil,this.revealFrom)]}render(e,t,n){let r=this.dataGetter?.(),i=zg(this.zones,this.revealUntil,this.revealFrom);if(!r||r.length===0||i.length===0)return;let{chartRect:a}=t,o=$s(this.style,n);e.save(),e.beginPath(),e.rect(a.x,a.y,a.width,a.height),e.clip();for(let a of i)this.renderZone(e,a,r,t,n,o);e.restore()}renderZone(n,r,i,a,o,s){let{chartRect:c}=a,l=e.k(r.entryTime,i),u=r.exitTime==null?i.length-1:e.k(r.exitTime,i),d=e.b(l,a),f=e.b(u,a),p=Math.max(c.x,Math.min(d,f)),m=Math.min(c.x+c.width,Math.max(d,f));if(m-p<1)return;let h=e.T(r.entryPrice,a),g=r.exitPrice==null?e.T(r.entryPrice,a):e.T(r.exitPrice,a),_=Math.min(h,g),v=Math.max(Math.max(h,g)-_,2),y=r.exitTime==null,b=r.pnl==null?r.direction===`long`?(r.exitPrice??r.entryPrice)>=r.entryPrice:(r.exitPrice??r.entryPrice)<=r.entryPrice:r.pnl>=0,x=y?s.activeColor??`#4c8dff`:b?s.profitColor??`#1fa874`:s.lossColor??`#e8505b`;n.fillStyle=x,n.globalAlpha=s.fillOpacity??.12,n.fillRect(p,_,m-p,v),n.globalAlpha=1;let S=s.borderWidth??1;if(n.strokeStyle=x,n.lineWidth=S,n.setLineDash([]),n.beginPath(),n.moveTo(p,Math.round(h)+.5),n.lineTo(m,Math.round(h)+.5),n.stroke(),!y&&r.exitPrice!=null&&(n.setLineDash([3,3]),n.beginPath(),n.moveTo(p,Math.round(g)+.5),n.lineTo(m,Math.round(g)+.5),n.stroke(),n.setLineDash([])),Jf(n,r.direction===`long`?t.UI_ICONS.trendingUp:t.UI_ICONS.trendingDown,p+4,h-3-Ug,Ug,x),n.font=`bold 10px ${o.font.family}`,n.fillStyle=x,n.textBaseline=`bottom`,n.textAlign=`left`,n.fillText((0,t.priceTagText)(r.entryPrice,a,this.pricePrecision??void 0),p+4+Ug+3,h-3),s.showPnl&&!y&&r.pnl!=null){let e=r.pnl>=0?`+`:``,t=r.pnlPercent==null?`${e}${r.pnl.toFixed(2)}`:`${e}${r.pnl.toFixed(2)} (${e}${r.pnlPercent.toFixed(2)}%)`;n.font=`bold 10px ${o.font.family}`,n.fillStyle=x,n.textBaseline=`top`,n.textAlign=`right`;let i=n.measureText(t).width+8,a=m-i-2,s=_+2;n.globalAlpha=.85,n.fillStyle=o.background,E(n,a,s,i,14,o),n.globalAlpha=1,n.fillStyle=x,n.fillText(t,m-4,s+1)}s.showLabel&&r.label&&(n.font=`9px ${o.font.family}`,n.fillStyle=x,n.globalAlpha=.8,n.textBaseline=`top`,n.textAlign=`left`,n.fillText(r.label,p+4,h+3),n.globalAlpha=1)}},Kg=class{active=!1;startBar=0;startPrice=0;endBar=0;endPrice=0;startTime=null;endTime=null;isActive(){return this.active}begin(t,n,r){let i=Math.round(e.A(t.x,n)),a=e.M(t.y,n);this.startBar=i,this.startPrice=a,this.endBar=i,this.endPrice=a,this.startTime=qg(i,r),this.endTime=this.startTime,this.active=!0}update(t,n,r){if(!this.active)return;let i=Math.round(e.A(t.x,n));this.endBar=i,this.endPrice=e.M(t.y,n),this.endTime=qg(i,r)}end(){this.active=!1}render(t,n,r){if(!this.active)return;let i=e.b(this.startBar,n),a=e.b(this.endBar,n),o=e.T(this.startPrice,n),s=e.T(this.endPrice,n),c=Math.min(i,a),l=Math.max(i,a),u=Math.min(o,s),d=Math.max(o,s),f=l-c,p=d-u,m=this.endPrice>=this.startPrice?r.candleUp:r.candleDown,h=$g(m,.14);t.save();let{chartRect:g}=n;t.beginPath(),t.rect(g.x,g.y,g.width,g.height),t.clip(),t.fillStyle=h,t.fillRect(c,u,f,p),t.strokeStyle=m,t.lineWidth=1,t.setLineDash([4,3]),t.strokeRect(c+.5,u+.5,f,p),t.setLineDash([]),t.strokeStyle=m,t.lineWidth=1.5,t.beginPath(),t.moveTo(i,o),t.lineTo(a,s),t.stroke(),Xg(t,i,o,m),Xg(t,a,s,m),t.restore();let _=Math.abs(this.endBar-this.startBar),v=this.endPrice-this.startPrice,y=this.startPrice===0?0:v/this.startPrice*100,b=this.startTime!==null&&this.endTime!==null?Yg(Math.abs(this.endTime-this.startTime)):null,x=[],S=v>0?`+`:v<0?`−`:``,C=Math.abs(v);x.push(`${S}${n.formatPrice?.(C)??Jg(C)} (${S}${Math.abs(y).toFixed(2)}%)`),x.push(`${_} bars${b?` · `+b:``}`),t.save(),Zg(t,a,s,x,m,r),t.restore()}};function qg(e,n){return e<0||e>=n.length?null:n[e].time*(0,t.barTimeUnit)(n)}function Jg(e){return e>=1e3?e.toFixed(2):e>=1?e.toFixed(4):e.toPrecision(4)}function Yg(e){let t=e/1e3;if(t<60)return`${t.toFixed(0)}s`;let n=t/60;if(n<60)return`${n.toFixed(1)}m`;let r=n/60;if(r<24)return`${r.toFixed(1)}h`;let i=r/24;if(i<30)return`${i.toFixed(1)}d`;let a=i/30;return a<12?`${a.toFixed(1)}mo`:`${(i/365).toFixed(1)}y`}function Xg(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t,n,3.5,0,Math.PI*2),e.fill(),e.fillStyle=`#fff`,e.beginPath(),e.arc(t,n,1.5,0,Math.PI*2),e.fill()}function Zg(e,t,n,r,i,a){e.font=`600 11px ${a.font.family}`;let o=0;for(let t of r){let n=e.measureText(t).width;n>o&&(o=n)}let s=Math.ceil(o)+16,c=r.length*14+12,l=t+8,u=n+8,d=e.canvas.clientWidth||e.canvas.width;l+s>d-4&&(l=t-s-8),l<4&&(l=4),e.fillStyle=a.background,e.globalAlpha=.96,Qg(e,l,u,s,c,6),e.fill(),e.globalAlpha=1,e.strokeStyle=i,e.lineWidth=1,Qg(e,l+.5,u+.5,s-1,c-1,6),e.stroke(),e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<r.length;t++)e.fillStyle=t===0?i:a.textSecondary,e.fillText(r[t],l+8,u+6+t*14)}function Qg(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function $g(e,t){if(e.startsWith(`#`)){let n=0,r=0,i=0;return e.length===4?(n=parseInt(e[1]+e[1],16),r=parseInt(e[2]+e[2],16),i=parseInt(e[3]+e[3],16)):e.length>=7&&(n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16)),`rgba(${n},${r},${i},${t})`}if(e.startsWith(`rgb`)){let n=e.match(/[\d.]+/g);if(n&&n.length>=3)return`rgba(${n[0]},${n[1]},${n[2]},${t})`}return e}var e_=6,t_=class{start=null;current=null;isActive(){return this.start!==null}begin(e){this.start=e,this.current=e}update(e){this.start&&(this.current=e)}end(){let e=this.start,t=this.current;if(this.cancel(),!e||!t)return null;let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y);return{x0:n,y0:i,x1:r,y1:a,isClick:r-n<6&&a-i<6}}cancel(){this.start=null,this.current=null}render(e,t,n){if(!this.start||!this.current)return;let{chartRect:r}=t,i=e=>Math.max(r.x,Math.min(r.x+r.width,e)),a=e=>Math.max(r.y,Math.min(r.y+r.height,e)),o=i(Math.min(this.start.x,this.current.x)),s=i(Math.max(this.start.x,this.current.x)),c=a(Math.min(this.start.y,this.current.y)),l=a(Math.max(this.start.y,this.current.y));e.save(),e.fillStyle=n.crosshair,e.globalAlpha=.1,e.fillRect(o,c,s-o,l-c),e.globalAlpha=.8,e.strokeStyle=n.crosshair,e.lineWidth=1,e.setLineDash([4,3]),e.strokeRect(Math.round(o)+.5,Math.round(c)+.5,Math.round(s-o),Math.round(l-c)),e.restore()}},n_={linear:e=>e,easeOutCubic:e=>1-(1-e)**3,easeOutQuart:e=>1-(1-e)**4,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeOutExpo:e=>e===1?1:1-2**(-10*e),easeOutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,spring:e=>1-Math.E**(-6*e)*Math.cos(8*e)},r_=class{animations=new Map;frameId=0;running=!1;animate(e,t){this.animations.set(e,{startTime:-1,duration:t.duration,easing:t.easing??n_.easeOutCubic,onUpdate:t.onUpdate,onComplete:t.onComplete}),this.running||(this.running=!0,this.tick())}cancel(e){this.animations.delete(e),this.animations.size===0&&this.stop()}cancelAll(){this.animations.clear(),this.stop()}isAnimating(e){return e?this.animations.has(e):this.animations.size>0}tick(){this.frameId=requestAnimationFrame(e=>{let t=[];for(let[n,r]of this.animations){r.startTime<0&&(r.startTime=e);let i=e-r.startTime,a=Math.min(1,i/r.duration),o=r.easing(a);r.onUpdate(o),a>=1&&(r.onComplete?.(),t.push(n))}for(let e of t)this.animations.delete(e);this.animations.size>0?this.tick():this.running=!1})}stop(){this.frameId&&=(cancelAnimationFrame(this.frameId),0),this.running=!1}dispose(){this.cancelAll()}};function i_(e){return!e||e===`dark`?t.DARK_THEME:e===`light`?t.LIGHT_THEME:e}var a_=class{canvas;ctx;container;theme;width=0;height=0;dpr=1;frameId=null;resizeObserver;constructor(e,t){this.container=e,this.theme=i_(t),this.canvas=document.createElement(`canvas`),this.canvas.style.width=`100%`,this.canvas.style.height=`100%`,this.canvas.style.display=`block`,this.canvas.setAttribute(`role`,`img`),e.appendChild(this.canvas),this.ctx=this.canvas.getContext(`2d`),this.dpr=o(),this.updateSize(),this.resizeObserver=new ResizeObserver(()=>{this.updateSize(),this.requestRender()}),this.resizeObserver.observe(e)}updateSize(){this.dpr=o();let e=this.container.getBoundingClientRect();this.width=e.width||this.container.clientWidth,this.height=e.height||this.container.clientHeight,this.canvas.width=Math.max(1,Math.floor(this.width*this.dpr)),this.canvas.height=Math.max(1,Math.floor(this.height*this.dpr))}requestRender(){this.frameId===null&&(this.frameId=requestAnimationFrame(()=>{this.frameId=null,(this.width===0||this.height===0)&&this.updateSize(),!(this.width===0||this.height===0)&&(this.ctx.save(),this.ctx.scale(this.dpr,this.dpr),this.ctx.clearRect(0,0,this.width,this.height),this.renderChart(this.ctx,this.width,this.height,this.theme),this.ctx.restore())}))}setLabel(e){this.canvas.setAttribute(`aria-label`,e)}setTheme(e){this.theme=i_(e),this.requestRender()}destroy(){this.frameId!==null&&cancelAnimationFrame(this.frameId),this.resizeObserver.disconnect(),this.canvas.width=0,this.canvas.height=0,this.canvas.remove()}},o_=class{pos=null;canvas;onUpdate;handleMove;handleLeave;constructor(e,t){this.canvas=e,this.onUpdate=t,this.handleMove=t=>{let n=e.getBoundingClientRect();this.pos={x:t.clientX-n.left,y:t.clientY-n.top},this.onUpdate()},this.handleLeave=()=>{this.pos=null,this.onUpdate()},e.addEventListener(`pointermove`,this.handleMove),e.addEventListener(`pointerleave`,this.handleLeave)}getPosition(){return this.pos}isActive(){return this.pos!==null}drawCrosshair(e,t,n,r){this.pos&&(e.save(),e.strokeStyle=r,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(this.pos.x,0),e.lineTo(this.pos.x,n),e.stroke(),e.beginPath(),e.moveTo(0,this.pos.y),e.lineTo(t,this.pos.y),e.stroke(),e.restore())}destroy(){this.canvas.removeEventListener(`pointermove`,this.handleMove),this.canvas.removeEventListener(`pointerleave`,this.handleLeave)}};function s_(e,t,n,r,i){let{data:a,mode:o=`area`,lineWidth:s=1.5,showLastPoint:c=!1,showMinMax:l=!1}=r;if(a.length<2||t<=0||n<=0)return;let u=r.color??i.lineColor,d=r.fillColor??u,f=t-4,p=n-4,m=1/0,h=-1/0,g=0,_=0;for(let e=0;e<a.length;e++)a[e]<m&&(m=a[e],g=e),a[e]>h&&(h=a[e],_=e);let v=h-m||1,y=e=>2+e/(a.length-1)*f,b=e=>2+p-(e-m)/v*p;if(o===`area`){let t=e.createLinearGradient(0,2,0,n-2);t.addColorStop(0,d+(d.startsWith(`#`)?`40`:``)),t.addColorStop(1,`transparent`),e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));e.lineTo(y(a.length-1),n-2),e.lineTo(y(0),n-2),e.closePath(),e.fillStyle=t,e.fill()}e.beginPath(),e.moveTo(y(0),b(a[0]));for(let t=1;t<a.length;t++)e.lineTo(y(t),b(a[t]));if(e.strokeStyle=u,e.lineWidth=s,e.lineJoin=`round`,e.stroke(),c){let t=r.lastPointColor??u,n=y(a.length-1),i=b(a[a.length-1]);e.beginPath(),e.arc(n,i,3,0,Math.PI*2),e.fillStyle=t,e.fill()}if(l){let t=r.minPointColor??i.candleDown,n=r.maxPointColor??i.candleUp;e.beginPath(),e.arc(y(g),b(m),2.5,0,Math.PI*2),e.fillStyle=t,e.fill(),e.beginPath(),e.arc(y(_),b(h),2.5,0,Math.PI*2),e.fillStyle=n,e.fill()}}var c_=50,l_=60,u_=20,d_=.2;function f_(e){let t=[...e].sort((e,t)=>t.price-e.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function p_(e){let t=[...e].sort((e,t)=>e.price-t.price),n=[],r=0;for(let e of t)r+=e.volume,n.push({price:e.price,cumulativeVolume:r});return n}function m_(e,t){return{left:c_,right:e-l_,top:u_,bottom:t-u_,plotWidth:e-c_-l_,plotHeight:t-u_*2}}function h_(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function g_(e,n,r,i,a,o,s,c){let{left:l,right:u,top:d,bottom:f,plotWidth:p,plotHeight:m}=n;e.save(),e.strokeStyle=o.grid,e.lineWidth=.5,e.fillStyle=o.axisLabel,e.font=`${o.font.sizeSmall}px ${o.font.family}`;let h=(0,t.computeTickStep)(0,a,5);for(let t=0;t<=a;t+=h){let n=f-t/a*m;e.beginPath(),e.moveTo(l,n),e.lineTo(u,n),e.stroke(),e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(c(t),l-4,n)}let g=i-r,_=(0,t.computeTickStep)(r,i,6),v=Math.ceil(r/_)*_;for(let t=v;t<=i;t+=_){let n=l+(t-r)/g*p;e.beginPath(),e.moveTo(n,d),e.lineTo(n,f),e.stroke(),e.textAlign=`center`,e.textBaseline=`top`,e.fillText(s(t),n,f+4)}e.restore()}function __(e,t,n,r,i,a,o,s,c){if(t.length===0)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-e/a*f;if(e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}else{e.moveTo(p(t[0].price),u);for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);e.lineTo(r,i),n<t.length-1&&e.lineTo(p(t[n+1].price),i)}e.lineTo(p(t[t.length-1].price),u)}if(e.closePath(),e.fillStyle=o,e.fill(),e.beginPath(),c===`bid`){e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=0;n<t.length;n++){let r=p(t[n].price),i=m(t[n].cumulativeVolume);n>0&&e.lineTo(r,m(t[n-1].cumulativeVolume)),e.lineTo(r,i)}}else{e.moveTo(p(t[0].price),m(t[0].cumulativeVolume));for(let n=1;n<t.length;n++){let r=m(t[n-1].cumulativeVolume),i=p(t[n].price),a=m(t[n].cumulativeVolume);e.lineTo(i,r),e.lineTo(i,a)}}e.strokeStyle=s,e.lineWidth=1.5,e.stroke()}function v_(e,t,n,r,i,a,o,s,c){let{left:l,top:u,bottom:d,plotWidth:f}=r,p=l+(t-i)/a*f;if(e.save(),e.strokeStyle=o.textSecondary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(p,u),e.lineTo(p,d),e.stroke(),e.restore(),s){let t=`Spread: ${c(n)}`;e.save(),e.font=`${o.font.sizeSmall}px ${o.font.family}`,e.fillStyle=o.textSecondary,e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t,p,u-2),e.restore()}}function y_(e,t,n,r,i,a,o,s,c,l,u){let{left:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=i,g=t.x;if(g<d||g>i.right)return;let _=a+(g-d)/m*o,v=0,y=``;if(n.length>0&&_<=n[0].price){y=`Bid`;for(let e of n)if(_<=e.price)v=e.cumulativeVolume;else break}if(r.length>0&&_>=r[0].price){y=`Ask`;for(let e of r)if(_>=e.price)v=e.cumulativeVolume;else break}if(e.save(),e.strokeStyle=c.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(g,f),e.lineTo(g,p),e.stroke(),v>0){let t=p-v/s*h;e.beginPath(),e.moveTo(d,t),e.lineTo(i.right,t),e.stroke()}e.restore();let b=[`Price: ${l(_)}`,y?`${y} Vol: ${u(v)}`:``].filter(Boolean);e.save(),e.font=`${c.font.sizeSmall}px ${c.font.family}`;let x=Math.max(...b.map(t=>e.measureText(t).width))+16,S=b.length*(c.font.sizeSmall+4)+12,C=g+10,w=t.y-S/2;C+x>i.right&&(C=g-x-10),w<f&&(w=f),w+S>p&&(w=p-S),e.fillStyle=c.axisLabelBackground,e.globalAlpha=.9,e.fillRect(C,w,x,S),e.globalAlpha=1,e.fillStyle=c.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<b.length;t++)e.fillText(b[t],C+8,w+6+t*(c.font.sizeSmall+4));e.restore()}function b_(e){return e.toFixed(2)}function x_(e){return e>=1e6?(e/1e6).toFixed(2)+`M`:e>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(0)}function S_(e,t,n,r,i,a){let{data:o}=r;if(o.bids.length===0&&o.asks.length===0||t<=0||n<=0)return;let s=r.bidColor??i.candleUp,c=r.askColor??i.candleDown,l=r.bidFillColor??s+`40`,u=r.askFillColor??c+`40`,d=r.midPriceLine!==!1,f=r.spreadLabel!==!1,p=r.priceFormat??b_,m=r.volumeFormat??x_,h=f_(o.bids),g=p_(o.asks),_=h.length>0?h[0].price:0,v=g.length>0?g[0].price:0,y=h.length>0&&g.length>0?(_+v)/2:_||v,b=g.length>0&&h.length>0?v-_:0,x=h.length>0?h[h.length-1].price:y,S=g.length>0?g[g.length-1].price:y,C=Math.max(y-x,S-y)*(1+d_),w=y-C,T=y+C,E=T-w,D=h.length>0?h[h.length-1].cumulativeVolume:0,O=g.length>0?g[g.length-1].cumulativeVolume:0,k=Math.max(D,O)||1,A=m_(t,n);h_(e,t,n,i.background),g_(e,A,w,T,k,i,p,m),__(e,h,A,w,E,k,l,s,`bid`),__(e,g,A,w,E,k,u,c,`ask`),d&&v_(e,y,b,A,w,E,i,f,p),a&&y_(e,a,h,g,A,w,E,k,i,p,m)}var C_=70,w_=30,T_=20,E_=20,D_=.05;function O_(e,t){return{left:C_,right:e-T_,top:E_,bottom:t-w_,plotWidth:e-C_-T_,plotHeight:t-E_-w_}}function k_(e,t){let n=1/0,r=-1/0;for(let t of e)t.value<n&&(n=t.value),t.value>r&&(r=t.value);if(t)for(let e of t)e.value<n&&(n=e.value),e.value>r&&(r=e.value);let i=(r-n)*D_;return{valMin:n-i,valMax:r+i}}function A_(e){let t=[],n=-1/0;for(let r of e)r.value>n&&(n=r.value),t.push(n);return t}function j_(e){let t=864e5;if(365.25*t,e<7*t){let e=new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`});return t=>e.format(new Date(t))}if(e<315576e5){let e=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`});return t=>e.format(new Date(t))}let n=new Intl.DateTimeFormat(void 0,{month:`short`,year:`numeric`});return e=>n.format(new Date(e))}function M_(e){return Math.abs(e)>=1e6?(e/1e6).toFixed(2)+`M`:Math.abs(e)>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function N_(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function P_(e,n,r,i,a,o,s,c,l){let{left:u,right:d,top:f,bottom:p,plotWidth:m,plotHeight:h}=n;e.save(),e.strokeStyle=s.grid,e.lineWidth=.5,e.fillStyle=s.axisLabel,e.font=`${s.font.sizeSmall}px ${s.font.family}`;let g=(0,t.computeTickStep)(r,i,6),_=Math.ceil(r/g)*g;for(let t=_;t<=i;t+=g){let n=p-(t-r)/(i-r)*h;e.beginPath(),e.moveTo(u,n),e.lineTo(d,n),e.stroke(),e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(c(t),u-6,n)}let v=o-a,y=(0,t.computeTickStep)(a,o,6),b=Math.ceil(a/y)*y;for(let t=b;t<=o;t+=y){let n=u+(t-a)/v*m;e.beginPath(),e.moveTo(n,f),e.lineTo(n,p),e.stroke(),e.textAlign=`center`,e.textBaseline=`top`,e.fillText(l(t),n,p+4)}e.restore()}function F_(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=n,p=e=>l+(e-r)/i*d,m=e=>u-(e-a)/o*f;e.save(),e.beginPath(),e.moveTo(p(t[0].time),m(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(p(t[n].time),m(t[n].value));e.strokeStyle=s,e.lineWidth=c,e.lineJoin=`round`,e.stroke(),e.restore()}function I_(e,t,n,r,i,a,o,s){if(t.length<2)return;let{left:c,bottom:l,plotWidth:u,plotHeight:d}=n,f=e=>c+(e-r)/i*u,p=e=>l-(e-a)/o*d,m=e.createLinearGradient(0,n.top,0,l);m.addColorStop(0,s+`40`),m.addColorStop(1,`transparent`),e.save(),e.beginPath(),e.moveTo(f(t[0].time),p(t[0].value));for(let n=1;n<t.length;n++)e.lineTo(f(t[n].time),p(t[n].value));e.lineTo(f(t[t.length-1].time),l),e.lineTo(f(t[0].time),l),e.closePath(),e.fillStyle=m,e.fill(),e.restore()}function L_(e,t,n,r,i,a,o,s,c){if(t.length<2)return;let{left:l,bottom:u,plotWidth:d,plotHeight:f}=r,p=e=>l+(e-i)/a*d,m=e=>u-(e-o)/s*f;e.save(),e.fillStyle=c,e.beginPath(),e.moveTo(p(t[0].time),m(n[0]));for(let r=1;r<t.length;r++)e.lineTo(p(t[r].time),m(n[r]));for(let n=t.length-1;n>=0;n--)e.lineTo(p(t[n].time),m(t[n].value));e.closePath(),e.fill(),e.restore()}function R_(e,t,n,r,i,a,o,s,c,l){if(t.length===0)return;let{left:u,bottom:d,plotWidth:f,plotHeight:p}=n,m=t[t.length-1],h=u+(m.time-r)/i*f,g=d-(m.value-a)/o*p;e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`,e.fillStyle=c,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(s,h+4,g),e.restore()}function z_(e,t,n,r,i,a,o,s,c,l,u,d){let{left:f,top:p,bottom:m,plotWidth:h,plotHeight:g}=i,_=t.x;if(_<f||_>i.right)return;e.save(),e.strokeStyle=l.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(_,p),e.lineTo(_,m),e.stroke(),e.restore();let v=a+(_-f)/h*o,y=0,b=1/0;for(let e=0;e<n.length;e++){let t=Math.abs(n[e].time-v);t<b&&(b=t,y=e)}let x=n[y],S=[u(x.time),`Value: ${d(x.value)}`];r&&r.length>y&&S.push(`Benchmark: ${d(r[y].value)}`);let C=f+(x.time-a)/o*h,w=m-(x.value-s)/c*g;e.beginPath(),e.arc(C,w,3,0,Math.PI*2),e.fillStyle=l.lineColor,e.fill(),e.save(),e.font=`${l.font.sizeSmall}px ${l.font.family}`;let T=Math.max(...S.map(t=>e.measureText(t).width))+16,E=S.length*(l.font.sizeSmall+4)+12,D=_+10,O=t.y-E/2;D+T>i.right&&(D=_-T-10),O<p&&(O=p),O+E>m&&(O=m-E),e.fillStyle=l.axisLabelBackground,e.globalAlpha=.9,e.fillRect(D,O,T,E),e.globalAlpha=1,e.fillStyle=l.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<S.length;t++)e.fillText(S[t],D+8,O+6+t*(l.font.sizeSmall+4));e.restore()}function B_(e,t,n,r,i,a){let{data:o}=r;if(o.length<2||t<=0||n<=0)return;let s=r.lineColor??i.lineColor,c=r.lineWidth??1.5,l=r.drawdown===!0,u=r.drawdownColor??i.candleDown+`30`,d=r.fillArea===!0,f=r.benchmark,p=r.benchmarkColor??i.textSecondary,m=r.benchmarkLabel??`Benchmark`,h=r.valueFormat??M_,{valMin:g,valMax:_}=k_(o,f),v=_-g||1,y=o[0].time,b=o[o.length-1].time,x=b-y||1,S=r.timeFormat??j_(x),C=O_(t,n);N_(e,t,n,i.background),P_(e,C,g,_,y,b,i,h,S),l&&L_(e,o,A_(o),C,y,x,g,v,u),d&&I_(e,o,C,y,x,g,v,s),F_(e,o,C,y,x,g,v,s,c),f&&f.length>=2&&(F_(e,f,C,y,x,g,v,p,1),R_(e,f,C,y,x,g,v,m,p,i)),a&&z_(e,a,o,f,C,y,x,g,v,i,S,h)}function V_(e,t,n){if(e.length===0)return[];let r=e.length,i=Math.ceil(Math.sqrt(r)),a=Math.ceil(r/i),o=t.width/i,s=t.height/a,c=[];for(let a=0;a<r;a++){let r=a%i,l=Math.floor(a/i);c.push({id:e[a].id,rect:{x:t.x+r*o+n,y:t.y+l*s+n,width:Math.max(0,o-n*2),height:Math.max(0,s-n*2)}})}return c}function H_(e,t){let n=e.reduce((e,t)=>e+t,0);if(n===0||t===0)return 1/0;let r=0;for(let i of e){let e=n/t,a=i/e,o=e>a?e/a:a/e;o>r&&(r=o)}return r}function U_(e,t,n,r,i,a){let o=r?n.height:n.width,s=e.reduce((e,t)=>e+t,0),c=o>0?s/o:0,l=0;for(let o=0;o<e.length;o++){let s=c>0?e[o]/c:0,u;u=r?{x:n.x+i,y:n.y+l+i,width:Math.max(0,c-i*2),height:Math.max(0,s-i*2)}:{x:n.x+l+i,y:n.y+i,width:Math.max(0,s-i*2),height:Math.max(0,c-i*2)},a.push({id:t[o],rect:u}),l+=s}}function W_(e,t,n,r,i){if(e.length===0)return;let a=n.width>=n.height,o=a?n.height:n.width;if(e.length===1){U_(e,t,n,a,r,i);return}let s=[],c=[],l=0;for(;l<e.length;){let u=[...s,e[l]];if(s.length===0||H_(u,o)<=H_(s,o))s.push(e[l]),c.push(t[l]),l++;else{U_(s,c,n,a,r,i);let u=s.reduce((e,t)=>e+t,0),d=o>0?u/o:0;n=a?{x:n.x+d,y:n.y,width:n.width-d,height:n.height}:{x:n.x,y:n.y+d,width:n.width,height:n.height-d},W_(e.slice(l),t.slice(l),n,r,i);return}}s.length>0&&U_(s,c,n,a,r,i)}function G_(e,t,n){if(e.length===0)return[];let r=[...e].sort((e,t)=>t.weight-e.weight),i=r.reduce((e,t)=>e+Math.max(0,t.weight),0);if(i===0)return[];let a=t.width*t.height,o=r.map(e=>Math.max(0,e.weight)/i*a),s=r.map(e=>e.id),c=[];return W_(o,s,{...t},n,c),c}var K_=2,q_=18;function J_(e,t,n,r=18){let i=new Map;for(let t of e){if(!(t.weight>0))continue;let e=t.group??``,n=i.get(e);n?n.push(t):i.set(e,[t])}let a=[...i.keys()],o=G_(a.map((e,t)=>({id:String(t),weight:i.get(e).reduce((e,t)=>e+t.weight,0)})),t,0),s=[],c=[];for(let e of o){let t=a[Number(e.id)],o=i.get(t),l=o.reduce((e,t)=>e+t.weight,0),u=o.reduce((e,t)=>e+(Number.isFinite(t.value)?t.value*t.weight:0),0),d=e.rect,f=t!==``&&d.height>=r*2.5&&d.width>=40?r:0,p={x:d.x+K_/2,y:d.y+K_/2+f,width:Math.max(0,d.width-K_),height:Math.max(0,d.height-K_-f)};s.push({name:t,rect:{...d},header:f,value:l>0?u/l:0,count:o.length}),c.push(...G_(o,p,n))}return{groups:s,cells:c}}var Y_=10,X_=6,Z_=16,Q_=18,$_=8,ev=16,tv=15,nv={min:0,max:1,step:.2,ticks:[0,.2,.4,.6,.8,1]};function rv(e){for(let t=0;t<=tv;t++){let n=e*10**t,r=Math.round(n);if(r!==0&&Math.abs(r-n)<1e-9*Math.abs(n))return t}return tv}var iv=(e,t)=>{let n=Number(e.toFixed(t));return n===0?0:n};function av(e,t,n=5){let r=Math.min(e,t),i=Math.max(e,t);if((!Number.isFinite(r)||!Number.isFinite(i))&&(r=0,i=1),r===i){let e=Math.abs(r)||1;r-=e/2,i+=e/2}let a=(i/2-r/2)/Math.max(1,n)*2;if(!Number.isFinite(a)||a<=0)return nv;let o=10**Math.floor(Math.log10(a)),s=a/o,c=(s<=1?1:s<=2?2:s<=2.5?2.5:s<=5?5:10)*o;if(!Number.isFinite(c)||c<=0)return nv;let l=rv(c),u=Math.floor(r/c+1e-9),d=Math.ceil(i/c-1e-9),f=[];for(let e=u;e<=d;e++)f.push(iv(e*c,l));return f.length<2||!f.every(Number.isFinite)?nv:{min:f[0],max:f[f.length-1],step:iv(c,l),ticks:f}}function Z(e,t,n,r,i=!1){let a=e.max===e.min?.5:(t-e.min)/(e.max-e.min);return i?n+r*(1-a):n+r*a}var ov=new Intl.NumberFormat(void 0,{maximumFractionDigits:2}),sv=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function cv(e){return Math.abs(e)>=1e4?sv.format(e):ov.format(e)}function Q(e){let t=rv(e.step),n=new Intl.NumberFormat(void 0,{minimumFractionDigits:t,maximumFractionDigits:t});if(Math.max(Math.abs(e.min),Math.abs(e.max))>=1e4&&e.step%1e3==0){let t=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:2}),n=e.ticks.map(e=>t.format(e));if(new Set(n).size===n.length)return e=>t.format(e)}return e=>n.format(e)}function lv(e,n){return n??t.TC_SERIES_COLORS[e%t.TC_SERIES_COLORS.length]}function $(e,t,n=``){return`${n?`${n} `:``}${t}px ${e.font.family}`}function uv(e,t){return(n,r=11)=>(e.font=$(t,r),e.measureText(n).width)}function dv(e,t,n,r=!1){let i=[],a=0,o=0;for(let s of e){let e=Y_+X_+n(s.label,11);a>0&&(r||a+e>t)&&(o++,a=0),i.push({...s,x:a,y:o*Q_}),a+=e+Z_}let s=e.length===0?0:o+1;return{items:i,rows:s,height:s*Q_}}function fv(e,t,n,r,i){e.save(),e.font=$(i,11),e.textBaseline=`middle`,e.textAlign=`left`;for(let a of t.items){let t=r+a.y+Q_/2;e.fillStyle=a.color,e.fillRect(n+a.x,t-Y_/2,Y_,Y_),e.fillStyle=i.textSecondary,e.fillText(a.label,n+a.x+Y_+X_,t)}e.restore()}function pv(e,n,r,i,a){if(n.length===0)return;e.save();let o=n.some(e=>e.color)?Y_+X_:0,s=0;for(let t of n)e.font=$(a,11,t.bold?`600`:``),s=Math.max(s,e.measureText(t.text).width);let c=s+o+$_*2,l=n.length*ev+$_*2-4,u=r.x+14,d=r.y+14;u+c>i.x+i.width&&(u=r.x-14-c),d+l>i.y+i.height&&(d=r.y-14-l),u=Math.max(i.x,u),d=Math.max(i.y,d),e.fillStyle=(0,t.withAlpha)(a.axisLabelBackground,.94),e.strokeStyle=a.grid,e.lineWidth=1,e.beginPath(),typeof e.roundRect==`function`?e.roundRect(u,d,c,l,6):e.rect(u,d,c,l),e.fill(),e.stroke(),e.textBaseline=`middle`,e.textAlign=`left`,n.forEach((t,n)=>{let r=d+$_+n*ev+ev/2-2;t.color&&(e.fillStyle=t.color,e.fillRect(u+$_,r-4,8,8)),e.font=$(a,11,t.bold?`600`:``),e.fillStyle=t.bold?a.text:a.textSecondary,e.fillText(t.text,u+$_+o,r)}),e.restore()}function mv(e,t,n,r,i,a){e.save(),e.font=$(i,11),e.fillStyle=i.axisLabel,e.strokeStyle=i.grid,e.lineWidth=1;for(let i of n.ticks)if(r===`vertical`){let r=Math.round(Z(n,i,t.y,t.height,!0))+.5;e.beginPath(),e.moveTo(t.x,r),e.lineTo(t.x+t.width,r),e.stroke(),e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(a(i),t.x-6,r)}else{let r=Math.round(Z(n,i,t.x,t.width))+.5;e.beginPath(),e.moveTo(r,t.y),e.lineTo(r,t.y+t.height),e.stroke(),e.textAlign=`center`,e.textBaseline=`top`,e.fillText(a(i),r,t.y+t.height+6)}e.restore()}function hv(e,t,n,r=11){if(n(e,r)<=t)return e;let i=e;for(;i.length>1&&n(`${i}…`,r)>t;)i=i.slice(0,-1);return i.length>1?`${i}…`:``}function gv(e){return(e>=0?`+`:``)+e.toFixed(2)+`%`}function _v(e){return e.label}function vv(e,n){let r=n.min??-5,i=n.max??5;if(e<=r)return n.negative;if(e>=i)return n.positive;if(e<0){let i=1-e/r;return(0,t.lerpColor)(n.negative,n.zero,i)}let a=e/i;return(0,t.lerpColor)(n.zero,n.positive,a)}function yv(e,t,n,r,i,a){let o=Math.min(a,r/2,i/2);e.beginPath(),e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function bv(e,t,n,r,i,a,o,s,c,l,u){if(i<40||a<30)return;let d=n+i/2,f=r+a/2;if(e.save(),e.shadowColor=`rgba(0,0,0,0.6)`,e.shadowBlur=2,e.fillStyle=`#FFFFFF`,e.textAlign=`center`,s){let n=l(t),r=Math.min(o.font.sizeMedium,i/n.length*1.5,a/4);e.font=`bold `+Math.max(8,r)+`px `+o.font.family,e.textBaseline=c?`bottom`:`middle`,e.fillText(n,d,c?f-1:f,i-8)}if(c){let n=u(t.value),r=Math.min(o.font.sizeSmall,i/n.length*1.5,a/4);e.font=Math.max(7,r)+`px `+o.font.family,e.textBaseline=s?`top`:`middle`,e.fillText(n,d,s?f+1:f,i-8)}e.restore()}function xv(e,t,n,r,i,a,o,s){let c=[o(t),s(t.value)];if(t.meta)for(let[e,n]of Object.entries(t.meta))c.push(e+`: `+String(n));e.save(),e.font=a.font.sizeSmall+`px `+a.font.family;let l=Math.max(...c.map(t=>e.measureText(t).width))+16,u=a.font.sizeSmall+4,d=c.length*u+12,f=n.x+14,p=n.y-d/2;f+l>r&&(f=n.x-l-14),p<0&&(p=0),p+d>i&&(p=i-d),e.fillStyle=a.axisLabelBackground,e.globalAlpha=.92,yv(e,f,p,l,d,4),e.fill(),e.globalAlpha=1,e.fillStyle=a.text,e.textBaseline=`top`,e.textAlign=`left`;for(let t=0;t<c.length;t++)e.fillText(c[t],f+8,p+6+t*u);e.restore()}function Sv(e,t,n,r,i,a,o,s,c=[]){if(r.length===0||i.length===0||t<=0||n<=0)return null;let l=a.colorScale,u={negative:l?.negative??`#e8505b`,zero:l?.zero??`#424242`,positive:l?.positive??`#1fa874`,min:l?.min,max:l?.max},d=a.cellRadius??4,f=a.showLabels!==!1,p=a.showValues!==!1,m=a.valueFormat??gv,h=a.labelFormat??_v,g=new Map;for(let e of r)g.set(e.id,e);let _=null,v=null;if(s)for(let e of i){let{x:t,y:n,width:r,height:i}=e.rect;if(s.x>=t&&s.x<=t+r&&s.y>=n&&s.y<=n+i){_=e.id;let t=g.get(e.id);t&&(v={cell:t,rect:e});break}}e.fillStyle=o.background,e.fillRect(0,0,t,n);for(let t of i){let n=g.get(t.id);if(!n)continue;let{x:r,y:i,width:a,height:s}=t.rect;if(a<=0||s<=0)continue;let c=vv(n.value,u);yv(e,r,i,a,s,d),e.fillStyle=c,e.fill(),bv(e,n,r,i,a,s,o,f,p,h,m),t.id===_&&(yv(e,r,i,a,s,d),e.strokeStyle=`#FFFFFF`,e.lineWidth=1.5,e.stroke())}let y=s&&!v?c.find(e=>e.header>0&&Cv(e,s)):void 0;return wv(e,c,o,m,y),v&&s?xv(e,v.cell,s,t,n,o,h,m):y&&s&&xv(e,{id:``,label:y.name,value:y.value},s,t,n,o,e=>e.label,m),v}function Cv(e,t){let n=e.rect;return t.x>=n.x&&t.x<=n.x+n.width&&t.y>=n.y&&t.y<=n.y+e.header}function wv(e,t,n,r,i){if(t.length===0)return;e.save(),e.textBaseline=`middle`;let a=n.font.sizeSmall,o=t=>e.measureText(t).width;for(let s of t){if(s.header<=0)continue;let{x:t,y:c,width:l}=s.rect,u=c+s.header/2+1;e.font=a+`px `+n.font.family;let d=r(s.value),f=o(d),p=l>=f*2+24;p&&(e.textAlign=`right`,e.fillStyle=s.value<0?n.candleDown:s.value>0?n.candleUp:n.textSecondary,e.fillText(d,t+l-5,u)),e.font=`600 `+a+`px `+n.font.family,e.textAlign=`left`,e.fillStyle=s===i?n.text:n.textSecondary;let m=l-10-(p?f+8:0),h=hv(s.name,m,e=>o(e),a);h&&e.fillText(h,t+5,u)}e.restore()}var Tv=60,Ev=12,Dv=24,Ov=40,kv=.7,Av=1;function jv(e){return e.type?e.type:e.value>0?`positive`:e.value<0?`negative`:`subtotal`}function Mv(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:e.toFixed(2)}function Nv(e,t){return{left:Tv,right:e-Ev,top:Dv,bottom:t-Ov,plotWidth:e-Tv-Ev,plotHeight:t-Dv-Ov}}function Pv(e,t,n,r,i){let a=Array(e.length),o=Array(e.length),s=t.plotWidth/e.length,c=s*n,l=(s-c)/2,{left:u,bottom:d,plotHeight:f}=t,p=0;for(let t=0;t<e.length;t++){let n=e[t],m=jv(n),h,g;m===`total`||m===`subtotal`?(h=0,g=n.value,p=n.value):(h=p,g=p+n.value,p=g);let _=Math.min(h,g),v=Math.max(h,g),y=d-(_-r)/i*f,b=d-(v-r)/i*f,x=Math.min(y,b),S=Math.max(Math.abs(b-y),Av),C=u+t*s,w=C+l;a[t]={label:n.label,value:n.value,start:h,end:g,type:m,rectX:w,rectY:x,rectW:c,rectH:S,slotX:C,slotW:s},o[t]=p}return{bars:a,cumulatives:o}}function Fv(e){if(e.length===0)return{valMin:0,valMax:1};let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=jv(a),s,c;o===`total`||o===`subtotal`?(s=0,c=a.value,r=a.value):(s=r,c=r+a.value,r=c),s<t&&(t=s),c<t&&(t=c),s>n&&(n=s),c>n&&(n=c)}let i=(n-t||1)*.1;return{valMin:t-i,valMax:n+i}}function Iv(e,t,n,r){e.fillStyle=r,e.fillRect(0,0,t,n)}function Lv(e,n,r,i,a,o){let{left:s,right:c,top:l,bottom:u,plotHeight:d}=n,f=i-r||1;e.strokeStyle=a.grid,e.lineWidth=.5,e.fillStyle=a.axisLabel,e.font=`${a.font.sizeSmall}px ${a.font.family}`,e.textAlign=`right`,e.textBaseline=`middle`;let p=(0,t.computeTickStep)(r,i,5),m=Math.ceil(r/p)*p;e.beginPath();for(let t=m;t<=i;t+=p){let n=Math.round(u-(t-r)/f*d)+.5;n<l||n>u||(e.moveTo(s,n),e.lineTo(c,n))}e.stroke();for(let t=m;t<=i;t+=p){let n=u-(t-r)/f*d;n<l-1||n>u+1||e.fillText(o(t),s-6,n)}if(r<0&&i>0){let t=Math.round(u-(0-r)/f*d)+.5;e.strokeStyle=a.axisLine,e.lineWidth=1,e.beginPath(),e.moveTo(s,t),e.lineTo(c,t),e.stroke()}}function Rv(e,t,n){let r=[`positive`,`negative`,`total`,`subtotal`];for(let i=0;i<r.length;i++){let a=r[i],o=n[a],s=!1;e.beginPath();for(let n=0;n<t.length;n++){let r=t[n];if(r.type!==a)continue;let i=Math.round(r.rectX),o=Math.round(r.rectY),c=Math.round(r.rectW),l=Math.round(r.rectH);e.rect(i,o,c,l),s=!0}s&&(e.fillStyle=o,e.fill())}}function zv(e,t,n,r,i,a,o){if(o===`none`||t.length<2)return;let{bottom:s,plotHeight:c}=n;e.strokeStyle=a,e.lineWidth=1,o===`dashed`?e.setLineDash([4,4]):e.setLineDash([]),e.beginPath();for(let n=0;n<t.length-1;n++){let a=t[n],o=t[n+1],l=a.end,u=Math.round(s-(l-r)/i*c)+.5,d=Math.round(a.rectX+a.rectW),f=Math.round(o.rectX);f<=d||(e.moveTo(d,u),e.lineTo(f,u))}e.stroke(),e.setLineDash([])}function Bv(e,t,n,r,i,a){e.fillStyle=r.text,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`;for(let r=0;r<t.length;r++){let o=t[r],s;s=o.type===`total`||o.type===`subtotal`?i(o.value):a?`${o.value>=0?`+`:``}${i(o.value)}`:i(n[r]);let c=o.rectX+o.rectW/2;o.end<o.start?(e.textBaseline=`top`,e.fillText(s,c,o.rectY+o.rectH+4)):(e.textBaseline=`bottom`,e.fillText(s,c,o.rectY-4))}}function Vv(e,t,n,r,i){e.fillStyle=r.axisLabel,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textAlign=`center`,e.textBaseline=`top`;let a=n.bottom+6,o=t.length>0?t[0].slotW-4:0,s=!1;for(let n=0;n<t.length;n++)if(e.measureText(i(t[n].label)).width>o){s=!0;break}if(!s){for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.fillText(i(r.label),o,a)}return}e.save(),e.textAlign=`right`,e.textBaseline=`middle`;for(let n=0;n<t.length;n++){let r=t[n],o=r.slotX+r.slotW/2;e.setTransform(1,0,0,1,o,a+4),e.rotate(-Math.PI/4),e.fillText(i(r.label),0,0)}e.setTransform(1,0,0,1,0,0),e.restore()}function Hv(e,t,n){if(t<n.left||t>n.right)return null;for(let n=0;n<e.length;n++){let r=e[n];if(t>=r.slotX&&t<=r.slotX+r.slotW)return n}return null}function Uv(e,t,n,r,i,a,o,s){let c=t[r],l=n[r],u=Math.round(c.slotX+c.slotW/2)+.5;e.strokeStyle=o.crosshair,e.lineWidth=.5,e.setLineDash([4,4]),e.beginPath(),e.moveTo(u,a.top),e.lineTo(u,a.bottom),e.stroke(),e.setLineDash([]);let d=[c.label,`Value: ${c.value>=0&&(c.type===`positive`||c.type===`negative`)?`+`:``}${s(c.value)}`,`Total: ${s(l)}`];e.font=`${o.font.sizeSmall}px ${o.font.family}`;let f=0;for(let t=0;t<d.length;t++){let n=e.measureText(d[t]).width;n>f&&(f=n)}let p=f+16,m=d.length*(o.font.sizeSmall+4)+12,h=i.x+10,g=i.y-m/2;h+p>a.right&&(h=i.x-p-10),g<a.top&&(g=a.top),g+m>a.bottom&&(g=a.bottom-m),e.fillStyle=o.axisLabelBackground,e.globalAlpha=.9,e.fillRect(h,g,p,m),e.globalAlpha=1,e.fillStyle=o.text,e.textAlign=`left`,e.textBaseline=`top`;let _=o.font.sizeSmall+4;for(let t=0;t<d.length;t++)e.fillText(d[t],h+8,g+6+t*_)}function Wv(e,t,n,r,i,a){let{data:o}=r;if(!o||o.length===0||t<=0||n<=0)return{hitBar:null};let s=r.positiveColor??i.candleUp,c=r.negativeColor??i.candleDown,l=r.totalColor??i.lineColor,u=r.subtotalColor??i.textSecondary,d=r.connectorColor??i.textSecondary,f=r.connectorStyle??`dashed`,p=r.barWidth??kv,m=r.showValues!==!1,h=r.showDelta!==!1,g=r.valueFormat??Mv,_=r.labelFormat??(e=>e),{valMin:v,valMax:y}=Fv(o),b=y-v||1,x=Nv(t,n),{bars:S,cumulatives:C}=Pv(o,x,p,v,b);Iv(e,t,n,i.background),Lv(e,x,v,y,i,g),zv(e,S,x,v,b,d,f),Rv(e,S,{positive:s,negative:c,total:l,subtotal:u}),m&&Bv(e,S,C,i,g,h),Vv(e,S,x,i,_);let w=a?Hv(S,a.x,x):null;return a&&w!==null&&Uv(e,S,C,w,a,x,i,g),{hitBar:w}}var Gv=Math.PI/180,Kv=150,qv=240,Jv=90,Yv=.14,Xv=1.6*Gv,Zv=.22,Qv=8,$v=18,ey=16,ty=6.5,ny=20,ry=5,iy=28;function ay(e,t,n){return e<t?t:e>n?n:e}function oy(e){let t=Math.abs(e);return t>=1e6?(e/1e6).toFixed(2)+`M`:t>=1e3?(e/1e3).toFixed(1)+`K`:Number.isInteger(e)?e.toFixed(0):e.toFixed(1)}function sy(e){let t=Number.isFinite(e.startAngle)?e.startAngle:Kv,n=(Number.isFinite(e.endAngle)?e.endAngle:t+qv)-t;return n<=0&&(n=(n%360+360)%360||360),n=ay(n,Jv,360),{start:(t%360+360)%360*Gv,sweep:n*Gv}}function cy(e,t){let n=Math.min(Math.cos(e),Math.cos(t)),r=Math.max(Math.cos(e),Math.cos(t)),i=Math.min(Math.sin(e),Math.sin(t)),a=Math.max(Math.sin(e),Math.sin(t));for(let o=Math.ceil(e/(Math.PI/2));Math.PI/2*o<=t;o++){let e=Math.PI/2*o;n=Math.min(n,Math.cos(e)),r=Math.max(r,Math.cos(e)),i=Math.min(i,Math.sin(e)),a=Math.max(a,Math.sin(e))}return{minX:n,maxX:r,minY:i,maxY:a}}function ly(e){if(e.showZoneLabels!==!0||!e.zones)return 0;let t=e.zones.reduce((e,t)=>Math.max(e,t.label?.length??0),0);return t>0?t*ty+12:0}function uy(e,t,n){let r=Number.isFinite(n.min)?n.min:0,i=Number.isFinite(n.max)?n.max:100;i-r>Math.abs(r)*1e-9||(i=r+Math.max(1,Math.abs(r)*1e-6));let{start:a,sweep:o}=sy(n),s=a,c=a+o,l=ay(n.thickness??Yv,.04,.5),u=cy(s,c),d=Math.max(u.maxY,.18),f=ly(n),p=f>0?ey:0,m=Math.max(1,e-2*Qv-2*f),h=Math.max(1,t-2*Qv-$v-p),g=1+l/2,_=Math.max(8,Math.min(m/((u.maxX-u.minX)*g),h/((d-u.minY)*g))),v=_*l,y=(d-u.minY)*_*g+$v+p,b=e/2-(u.maxX+u.minX)/2*_,x=(t-y)/2+p-u.minY*_*g,S=_-v/2,C=Math.max(11,Math.round(S*.46)),w=u.maxY>.3?x-C*.12:x-C*.55,T=Math.max(Math.sin(s),Math.sin(c)),E=T>.2?x+T*_+v/2+2:1/0,D=Math.min(t-Qv,E);return{cx:b,cy:x,radius:_,thickness:v,startAngle:s,endAngle:c,min:r,max:i,valueY:w,valueSize:C,textBottom:D}}function dy(e,t){let n=Number.isFinite(e)?ay((e-t.min)/(t.max-t.min),0,1):0;return t.startAngle+(t.endAngle-t.startAngle)*n}function fy(e,t){if(!t||!Number.isFinite(e))return;let n;for(let r of t)e>=r.from&&e<=r.to&&(n=r);return n}function py(e,t,n){let r=(t??[]).map(t=>({a0:dy(t.from,e),a1:dy(t.to,e),color:t.color,track:!1})).filter(e=>e.a1>e.a0).sort((e,t)=>e.a0-t.a0),i=[],a=e.startAngle;for(let e of r)e.a1<=a||(e.a0>a+1e-9&&i.push({a0:a,a1:e.a0,color:n,track:!0}),i.push({...e,a0:Math.max(e.a0,a)}),a=e.a1);return a<e.endAngle-1e-9&&i.push({a0:a,a1:e.endAngle,color:n,track:!0}),i}function my(e,t,n,r,i){r<=n||(e.beginPath(),e.arc(t.cx,t.cy,t.radius,n,r,!1),e.lineWidth=t.thickness,e.lineCap=`butt`,e.strokeStyle=i,e.stroke())}function hy(e,t,n,r,i,a){let o=t.cx+Math.cos(n)*t.radius,s=t.cy+Math.sin(n)*t.radius,c=a===`start`?n-Math.PI:n;e.globalAlpha=i,e.beginPath(),e.arc(o,s,t.thickness/2,c,c+(i>=1?Math.PI*2:Math.PI),!1),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1}function gy(e,t,n,r,i,a){let o=py(t,n,i),s=o.some(e=>!e.track);o.forEach((n,i)=>{let a=i>0&&!n.track&&!o[i-1].track?Xv/2:0,s=i<o.length-1&&!n.track&&!o[i+1].track?Xv/2:0,c=n.a0+a,l=n.a1-s;if(n.track){my(e,t,c,l,n.color);return}e.globalAlpha=Zv,my(e,t,c,l,n.color),e.globalAlpha=1,my(e,t,c,Math.min(l,r),n.color)}),s||my(e,t,t.startAngle,r,a);let c=r>t.startAngle+1e-9,l=r>=t.endAngle-1e-9,u=(e,t)=>e.track?[!s&&t?a:i,1]:[e.color,t?1:Zv],[d,f]=u(o[0],c),[p,m]=u(o[o.length-1],l);hy(e,t,t.startAngle,d,f,`start`),hy(e,t,t.endAngle,p,m,`end`)}function _y(e,t,n){let r=t.radius-t.thickness/2;if(r<iy)return;let i=Math.max(4,t.thickness*.45);e.strokeStyle=n,e.lineCap=`butt`;for(let n=0;n<=ny;n++){let a=n%ry===0,o=t.startAngle+(t.endAngle-t.startAngle)*n/ny,s=r-i,c=s-(a?Math.max(6,t.thickness*.55):Math.max(3,t.thickness*.3));e.globalAlpha=a?.55:.3,e.lineWidth=a?1.5:1,e.beginPath(),e.moveTo(t.cx+Math.cos(o)*s,t.cy+Math.sin(o)*s),e.lineTo(t.cx+Math.cos(o)*c,t.cy+Math.sin(o)*c),e.stroke()}e.globalAlpha=1}function vy(e,t,n,r,i){let a=t.cx+Math.cos(n)*t.radius,o=t.cy+Math.sin(n)*t.radius;e.beginPath(),e.arc(a,o,t.thickness*.78,0,Math.PI*2),e.fillStyle=r,e.fill(),e.lineWidth=Math.max(2,t.thickness*.32),e.strokeStyle=i,e.stroke()}function yy(e,t,n,r,i){let a=Math.cos(n),o=Math.sin(n),s=t.radius-t.thickness*.9,c=Math.max(6,t.thickness*.6),l=Math.max(1.5,t.thickness*.14);e.beginPath(),e.moveTo(t.cx+a*s,t.cy+o*s),e.lineTo(t.cx-o*l-a*c,t.cy+a*l-o*c),e.lineTo(t.cx+o*l-a*c,t.cy-a*l-o*c),e.closePath(),e.fillStyle=r,e.fill(),e.beginPath(),e.arc(t.cx,t.cy,Math.max(4,t.thickness*.42),0,Math.PI*2),e.fill(),e.lineWidth=2,e.strokeStyle=i,e.stroke()}function by(e,t,n,r,i,a,o){e.font=`${n} ${r}px ${i}`;let s=e.measureText(t).width;if(s<=a)return r;let c=Math.floor(r*a/s);return c<o?0:(e.font=`${n} ${c}px ${i}`,c)}function xy(e,t,n,r,i,a,o){let s=a.font.family,c=(t.radius-t.thickness/2)*1.3,l=a.font.sizeSmall;e.textAlign=`center`,e.textBaseline=`middle`;let u=by(e,n,`600`,t.valueSize,s,c,l);if(u===0)return;let d=o?Math.min(t.cy+u*.8,t.textBottom-u/2):t.valueY;e.fillStyle=a.text,e.fillText(n,t.cx,d);let f=Math.max(l,Math.round(u*.26));if(i?.label&&!o){let n=i.label.toUpperCase();by(e,n,`600`,f,s,c*.9,l)>0&&(e.fillStyle=i.color,e.fillText(n,t.cx,d-u*.78))}if(r){let n=d+u*.72;n+f/2<=t.textBottom&&by(e,r,`400`,f,s,c,l)>0&&(e.fillStyle=a.textSecondary,e.fillText(r,t.cx,n))}}function Sy(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall+1}px ${r.font.family}`;let i=t.thickness/2+6;for(let[r,a]of[[t.startAngle,t.min],[t.endAngle,t.max]]){let o=Math.cos(r),s=Math.sin(r),c=t.cx+o*t.radius,l=t.cy+s*t.radius;s>.2?(e.textAlign=`center`,e.textBaseline=`top`,e.fillText(n(a),c,l+i)):(e.textAlign=o<-.2?`right`:o>.2?`left`:`center`,e.textBaseline=s<-.2?`bottom`:`middle`,e.fillText(n(a),c+o*i,l+s*i))}}function Cy(e,t,n,r){e.fillStyle=r.textSecondary,e.font=`${r.font.sizeSmall}px ${r.font.family}`,e.textBaseline=`middle`;let i=t.radius+t.thickness/2+8;for(let r of n){if(!r.label)continue;let n=dy((ay(r.from,t.min,t.max)+ay(r.to,t.min,t.max))/2,t),a=Math.cos(n);e.textAlign=a<-.2?`right`:a>.2?`left`:`center`,e.fillText(r.label,t.cx+a*i,t.cy+Math.sin(n)*i)}}function wy(e,t,n,r,i,a){if(t<=0||n<=0)return;let o=uy(t,n,r),s=Number.isFinite(a),c=s?ay(a,o.min,o.max):o.min,l=dy(c,o),u=s?fy(c,r.zones):void 0,d=r.pointer===`needle`,f=r.valueFormat??oy,p=u?.color??r.needleColor??i.lineColor;e.save(),e.fillStyle=i.background,e.fillRect(0,0,t,n),gy(e,o,r.zones,l,r.trackColor??i.grid,p),_y(e,o,i.textSecondary),s&&(d?yy(e,o,l,r.needleColor??i.text,i.background):vy(e,o,l,p,i.background)),r.showValue!==!1&&xy(e,o,s?f(c):`—`,r.label,u,i,d),Sy(e,o,f,i),r.showZoneLabels===!0&&r.zones?.length&&Cy(e,o,r.zones,i),e.restore()}var Ty=12,Ey=.72,Dy=20,Oy=.35;function ky(e){let t=0,n=0,r=e.mode===`stacked`;return e.categories.forEach((i,a)=>{let o=0,s=0;for(let i of e.series){let e=i.values[a];Number.isFinite(e)&&(r?e>=0?o+=e:s+=e:(n=Math.max(n,e),t=Math.min(t,e)))}n=Math.max(n,o),t=Math.min(t,s)}),[t,n]}function Ay(e,t){let n=e.colorBySign;return n?n===!0?{positive:t.candleUp,negative:t.candleDown}:n:null}function jy(e,t,n,r,i){let a=e.orientation===`horizontal`,o=e.legend??e.series.length>1?dv(e.series.map((e,t)=>({label:e.name,color:lv(t,e.color)})),t-Ty*2,i):null,s=Ty+(o?o.height+6:0),[c,l]=ky(e),u=av(c,l,a?Math.max(2,Math.floor(t/110)):5),d=e.valueFormat??Q(u),f=Math.max(0,...u.ticks.map(e=>i(d(e),11))),p;if(a){let r=Ty+Math.min(t*Oy,Math.max(0,...e.categories.map(e=>i(e,11))))+8;p={x:r,y:s,width:Math.max(1,t-r-Ty-f/2),height:Math.max(1,n-s-Ty-Dy)}}else{let e=Ty+f+8;p={x:e,y:s,width:Math.max(1,t-e-Ty),height:Math.max(1,n-s-Ty-Dy)}}let m=Math.max(1,e.categories.length),h=a?p.y:p.x,g=(a?p.height:p.width)/m,_=g*Ey,v=e.mode===`stacked`,y=v?_:_/Math.max(1,e.series.length),b=e=>a?Z(u,e,p.x,p.width):Z(u,e,p.y,p.height,!0),x=b(0),S=Ay(e,r),C=Array(m).fill(0),w=Array(m).fill(0),T=[];return e.series.forEach((t,n)=>{e.categories.forEach((e,r)=>{let i=t.values[r];if(!Number.isFinite(i))return;let o=0;v&&(o=i>=0?C[r]:w[r],i>=0?C[r]+=i:w[r]+=i);let s=b(o),c=b(o+i),l=h+r*g+(g-_)/2+(v?0:n*y),u=S?i>=0?S.positive:S.negative:lv(n,t.color),d=Math.min(s,c),f=Math.abs(c-s);T.push(a?{x:d,y:l,width:f,height:y,category:e,series:t.name,value:i,index:r,color:u}:{x:l,y:d,width:y,height:f,category:e,series:t.name,value:i,index:r,color:u})})}),{plot:p,scale:u,orientation:a?`horizontal`:`vertical`,zero:x,bars:T,bandStart:h,band:g,legend:o,legendY:Ty}}function My(e,t,n){for(let r of e.bars)if(t>=r.x-2&&t<=r.x+r.width+2&&n>=r.y-2&&n<=r.y+r.height+2)return r;return null}function Ny(e,t,n,r){let{plot:i}=e;if(t<i.x||t>i.x+i.width||n<i.y||n>i.y+i.height)return-1;let a=e.orientation===`horizontal`?n:t,o=Math.floor((a-e.bandStart)/e.band);return o>=0&&o<r?o:-1}function Py(e,n,r,i,a,o,s=jy(i,n,r,a,uv(e,a))){let c=uv(e,a),l=i.valueFormat??cv,{plot:u,orientation:d}=s,f=d===`horizontal`;e.fillStyle=a.background,e.fillRect(0,0,n,r),s.legend&&fv(e,s.legend,Ty,s.legendY,a),mv(e,u,s.scale,f?`horizontal`:`vertical`,a,i.valueFormat??Q(s.scale));let p=o&&i.crosshair!==!1?Ny(s,o.x,o.y,i.categories.length):-1;if(p>=0){e.fillStyle=(0,t.withAlpha)(a.crosshair,.08);let n=s.bandStart+p*s.band;f?e.fillRect(u.x,n,u.width,s.band):e.fillRect(n,u.y,s.band,u.height)}for(let t of s.bars)e.fillStyle=t.color,e.fillRect(t.x,t.y,Math.max(t.width,+!!f),Math.max(t.height,+!f));e.strokeStyle=a.axisLine,e.lineWidth=1,e.beginPath();let m=Math.round(s.zero)+.5;if(f?(e.moveTo(m,u.y),e.lineTo(m,u.y+u.height)):(e.moveTo(u.x,m),e.lineTo(u.x+u.width,m)),e.stroke(),Fy(e,i.categories,s,a,c),i.showValues&&Iy(e,s,a,l,i.mode===`stacked`),p>=0&&o){let t=[{text:i.categories[p],bold:!0}];for(let e of s.bars)e.index===p&&t.push({text:`${e.series}: ${l(e.value)}`,color:e.color});pv(e,t,o,{x:0,y:0,width:n,height:r},a)}return s}function Fy(e,t,n,r,i){let{plot:a}=n;e.save(),e.font=$(r,11),e.fillStyle=r.axisLabel;let o=Math.max(0,...t.map(e=>i(e,11))),s=n.orientation===`vertical`?Math.max(1,Math.ceil((o+8)/Math.max(1,n.band))):1;t.forEach((t,r)=>{if(r%s!==0)return;let o=n.bandStart+(r+.5)*n.band;n.orientation===`horizontal`?(e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(hv(t,a.x-Ty-8,i),a.x-8,o)):(e.textAlign=`center`,e.textBaseline=`top`,e.fillText(hv(t,n.band*s-4,i),o,a.y+a.height+6))}),e.restore()}function Iy(e,t,n,r,i){e.save(),e.font=$(n,10),e.fillStyle=n.textSecondary;for(let n of t.bars){let a=r(n.value);if(t.orientation===`horizontal`){e.textBaseline=`middle`;let t=n.y+n.height/2;i?(e.textAlign=`center`,e.measureText(a).width<n.width-4&&e.fillText(a,n.x+n.width/2,t)):n.value>=0?(e.textAlign=`left`,e.fillText(a,n.x+n.width+4,t)):(e.textAlign=`right`,e.fillText(a,n.x-4,t))}else{e.textAlign=`center`;let t=n.x+n.width/2;i?(e.textBaseline=`middle`,n.height>13&&e.measureText(a).width<n.width&&e.fillText(a,t,n.y+n.height/2)):n.value>=0?(e.textBaseline=`bottom`,e.fillText(a,t,n.y-3)):(e.textBaseline=`top`,e.fillText(a,t,n.y+n.height+3))}}e.restore()}var Ly=12,Ry=-Math.PI/2,zy=Math.PI*2,By=5,Vy=1.4,Hy=18,Uy=new Intl.NumberFormat(void 0,{style:`percent`,maximumFractionDigits:1});function Wy(e,t,n,r,i){let a=e.data.filter(e=>Number.isFinite(e.value)&&e.value>0),o=a.reduce((e,t)=>e+t.value,0),s=a.map((e,t)=>({label:`${e.label} ${Uy.format(e.value/o)}`,color:lv(t,e.color)})),c=e.legend!==!1&&a.length>0,l=c&&t>=n*Vy&&a.length*Hy<=n-Ly*2,u=l?Math.min(t*.4,Math.max(...s.map(e=>i(e.label,11)))+16):t-Ly*2,d=c?dv(s,u,i,l):null,f=l?t-u-Ly*3:t-Ly*2,p=l?n-Ly*2:n-Ly*3-(d?.height??0),m=Math.max(0,Math.min(f,p)/2-By),h=Ly+f/2,g=Ly+p/2,_=e.innerRadius,v=Math.min(.95,Math.max(0,_!==void 0&&Number.isFinite(_)?_:.6)),y=Ry,b=a.map((e,t)=>{let n=e.value/o,r=y;return y+=n*zy,{label:e.label,value:e.value,share:n,start:r,end:y,color:lv(t,e.color),slice:e}});return{cx:h,cy:g,radius:m,inner:m*v,total:o,slices:b,legend:d,legendX:l?t-u-Ly:Ly,legendY:l?Math.max(Ly,g-(d?.height??0)/2):Ly*2+p}}function Gy(e,t,n){let r=t-e.cx,i=n-e.cy,a=Math.hypot(r,i);if(a<e.inner||a>e.radius+By)return null;let o=Math.atan2(i,r);for(;o<Ry;)o+=zy;return e.slices.find(e=>o>=e.start&&o<e.end)??null}function Ky(e,t,n,r,i,a,o=Wy(r,t,n,i,uv(e,i))){let s=uv(e,i),c=r.valueFormat??cv;e.fillStyle=i.background,e.fillRect(0,0,t,n);let l=a&&r.crosshair!==!1?Gy(o,a.x,a.y):null,{cx:u,cy:d,radius:f,inner:p}=o;for(let t of o.slices){let n=(t.start+t.end)/2,r=t===l?By:0,a=u+Math.cos(n)*r,s=d+Math.sin(n)*r;e.beginPath(),e.arc(a,s,f,t.start,t.end),p>0?e.arc(a,s,p,t.end,t.start,!0):e.lineTo(a,s),e.closePath(),e.fillStyle=t.color,e.fill(),o.slices.length>1&&(e.strokeStyle=i.background,e.lineWidth=1.5,e.stroke())}return r.showLabels!==!1&&qy(e,o,i),Jy(e,o,r,i,s),o.legend&&fv(e,o.legend,o.legendX,o.legendY,i),l&&a&&pv(e,[{text:l.label,bold:!0,color:l.color},{text:`${c(l.value)} · ${Uy.format(l.share)}`}],a,{x:0,y:0,width:t,height:n},i),o}function qy(e,t,n){let{cx:r,cy:i,radius:a,inner:o}=t,s=o>0?(a+o)/2:a*.62;e.save(),e.font=$(n,11,`600`),e.textAlign=`center`,e.textBaseline=`middle`,e.fillStyle=`#fff`;for(let n of t.slices){let t=Uy.format(n.share);if((n.end-n.start)*s<e.measureText(t).width+8||o>0&&a-o<15)continue;let c=(n.start+n.end)/2;e.fillText(t,r+Math.cos(c)*s,i+Math.sin(c)*s)}e.restore()}function Jy(e,t,n,r,i){if(t.inner<=0||!n.centerLabel&&!n.centerValue)return;let a=t.inner*1.6;if(e.save(),e.textAlign=`center`,e.textBaseline=`middle`,n.centerValue){let o=Math.max(12,Math.min(28,t.inner*.42));e.font=$(r,o,`600`),e.fillStyle=r.text,e.fillText(hv(n.centerValue,a,i,o),t.cx,t.cy+(n.centerLabel?o*.35:0))}n.centerLabel&&(e.font=$(r,11),e.fillStyle=r.textSecondary,e.fillText(hv(n.centerLabel,a,i),t.cx,t.cy-(n.centerValue?11*1.1:0))),e.restore()}var Yy=12,Xy=5,Zy=3,Qy=18,$y=20,eb=6;function tb(e,n,r,i,a){let o=1/0,s=-1/0,c=1/0,l=-1/0,u=0;for(let t of e.series)for(let e of t.points)!Number.isFinite(e.x)||!Number.isFinite(e.y)||(e.x<o&&(o=e.x),e.x>s&&(s=e.x),e.y<c&&(c=e.y),e.y>l&&(l=e.y),e.size!==void 0&&Number.isFinite(e.size)&&e.size>u&&(u=e.size));let d=e.maxRadius??24,f=d+eb,p=(e,t,n)=>{if(e>t)return[0,1];let r=(t-e)*f/Math.max(1,n-f*2);return[e>=0?Math.max(0,e-r):e-r,t<=0?Math.min(0,t+r):t+r]},m=av(...p(o,s,n*.8),Math.max(2,Math.floor(n/110))),h=av(...p(c,l,r*.7),5),g=e.xFormat??Q(m),_=e.yFormat??Q(h),v=e.legend??e.series.length>1?dv(e.series.map((e,t)=>({label:e.name,color:lv(t,e.color)})),n-Yy*2,a):null,y=Yy+(v?v.height+6:0),b=Math.max(0,...h.ticks.map(e=>a(_(e),11))),x=Yy+(e.yLabel?Qy:0)+b+8,S=Yy+$y+(e.xLabel?Qy:0),C=a(g(m.max),11)/2,w={x,y,width:Math.max(1,n-x-Yy-C),height:Math.max(1,r-y-S)},T=[];return e.series.forEach((e,n)=>{let r=lv(n,e.color),i=(0,t.withAlpha)(r,.55),a=(0,t.withAlpha)(r,.85);for(let t of e.points){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))continue;let n=t.size!==void 0&&Number.isFinite(t.size)&&t.size>0&&u>0?Math.max(Zy,d*Math.sqrt(t.size/u)):Xy;T.push({px:Z(m,t.x,w.x,w.width),py:Z(h,t.y,w.y,w.height,!0),r:n,color:r,fill:i,hoverFill:a,series:e.name,label:t.label,point:t})}}),{plot:w,xScale:m,yScale:h,points:T,drawOrder:T.map((e,t)=>t).sort((e,t)=>T[t].r-T[e].r),legend:v}}function nb(e,t,n){let r=null,i=1/0;for(let a of e.points){let e=Math.hypot(a.px-t,a.py-n);e<=a.r+eb&&e<i&&(r=a,i=e)}return r}function rb(e,t,n,r,i,a,o=tb(r,t,n,i,uv(e,i))){let{plot:s,xScale:c,yScale:l}=o,u=r.xFormat??Q(c),d=r.yFormat??Q(l);e.fillStyle=i.background,e.fillRect(0,0,t,n),o.legend&&fv(e,o.legend,Yy,Yy,i),mv(e,s,l,`vertical`,i,d),mv(e,s,c,`horizontal`,i,u),r.zeroLines!==!1&&ib(e,o,i),ab(e,o,r,i);let f=a&&r.crosshair!==!1?nb(o,a.x,a.y):null;e.save(),e.beginPath(),e.rect(s.x,s.y,s.width,s.height),e.clip();for(let t of o.drawOrder){let n=o.points[t];e.beginPath(),e.arc(n.px,n.py,n===f?n.r+2:n.r,0,Math.PI*2),e.fillStyle=n===f?n.hoverFill:n.fill,e.fill(),e.strokeStyle=n.color,e.lineWidth=1,e.stroke()}if(e.restore(),r.showLabels){e.save(),e.font=$(i,10),e.fillStyle=i.textSecondary,e.textAlign=`left`,e.textBaseline=`middle`;for(let t of o.points)t.label&&e.fillText(t.label,t.px+t.r+4,t.py);e.restore()}if(f&&a){let o=[{text:f.label??f.series,bold:!0,color:f.color}];f.label&&r.series.length>1&&o.push({text:f.series}),o.push({text:`${r.xLabel??`x`}: ${(r.xFormat??cv)(f.point.x)}`}),o.push({text:`${r.yLabel??`y`}: ${(r.yFormat??cv)(f.point.y)}`}),f.point.size!==void 0&&o.push({text:cv(f.point.size)}),pv(e,o,a,{x:0,y:0,width:t,height:n},i)}return o}function ib(e,t,n){let{plot:r,xScale:i,yScale:a}=t;if(e.save(),e.strokeStyle=n.axisLine,e.lineWidth=1,e.beginPath(),i.min<0&&i.max>0){let t=Math.round(Z(i,0,r.x,r.width))+.5;e.moveTo(t,r.y),e.lineTo(t,r.y+r.height)}if(a.min<0&&a.max>0){let t=Math.round(Z(a,0,r.y,r.height,!0))+.5;e.moveTo(r.x,t),e.lineTo(r.x+r.width,t)}e.stroke(),e.restore()}function ab(e,t,n,r){let{plot:i}=t;e.save(),e.font=$(r,11,`600`),e.fillStyle=r.textSecondary,e.textAlign=`center`,n.xLabel&&(e.textBaseline=`bottom`,e.fillText(n.xLabel,i.x+i.width/2,i.y+i.height+$y+Qy)),n.yLabel&&(e.translate(Yy+11/2,i.y+i.height/2),e.rotate(-Math.PI/2),e.textBaseline=`middle`,e.fillText(n.yLabel,0,0)),e.restore()}var ob=1e-9,sb=1e3,cb=e=>{let t=Number(e.toPrecision(12));return t===0?0:t};function lb(e,t={}){let n=e.filter(e=>Number.isFinite(e));if(n.length===0)return[];let r=1/0,i=-1/0;for(let e of n)e<r&&(r=e),e>i&&(i=e);if(r===i)return[{from:r,to:i,count:n.length}];let a=t.binWidth;if(a!==void 0&&a>0&&Number.isFinite(a)){let e=Math.floor(r/a+ob),t=Math.max(e,Math.ceil(i/a-ob)-1)-e+1;if(t<=1e3){let r=Array.from({length:t},(t,n)=>({from:cb((e+n)*a),to:cb((e+n+1)*a),count:0}));for(let i of n)r[Math.min(t-1,Math.floor(i/a+ob)-e)].count++;return r}}let o=t.bins,s=typeof o==`number`&&Number.isFinite(o)&&o>=1?Math.min(sb,Math.floor(o)):Math.min(sb,Math.ceil(Math.log2(n.length))+1),c=(i-r)/s,l=Array.from({length:s},(e,t)=>({from:cb(r+t*c),to:cb(t===s-1?i:r+(t+1)*c),count:0}));for(let e of n)l[Math.min(s-1,Math.floor((e-r)/c+ob))].count++;return l}var ub=12,db=20,fb=16;function pb(e,n,r){return n.colorBySign?(e.from+e.to)/2<0?r.candleDown:r.candleUp:n.color??t.TC_SERIES_COLORS[0]}function mb(e,t,n,r,i){let a=lb(e.values,{bins:e.bins,binWidth:e.binWidth}),o=a.length>0?a[0].from:0,s=a.length>0?a[a.length-1].to:1,c=(e.markers??[]).map(e=>e.value).filter(e=>Number.isFinite(e)),l=av(Math.min(o,...c),Math.max(s,...c),Math.max(2,Math.floor(t/110))),u=0;for(let e of a)e.count>u&&(u=e.count);let d=av(0,Math.max(4,u),4),f=e.valueFormat??Q(l),p=Math.max(0,...d.ticks.map(e=>i(Q(d)(e),11))),m=ub+(c.length>0?fb:0),h=ub+p+8,g=ub+i(f(l.max),11)/2,_={x:h,y:m,width:Math.max(1,t-h-g),height:Math.max(1,n-m-ub-db)};return{plot:_,xScale:l,yScale:d,bars:a.map(t=>{let n=Z(l,t.from,_.x,_.width),i=t.to>t.from?Z(l,t.to,_.x,_.width):n+_.width/10,a=Z(d,t.count,_.y,_.height,!0);return{x:n,y:a,width:Math.max(1,i-n),height:_.y+_.height-a,bin:t,color:pb(t,e,r)}}),total:a.reduce((e,t)=>e+t.count,0)}}function hb(e,t,n){let{plot:r}=e;return n<r.y||n>r.y+r.height?null:e.bars.find(e=>t>=e.x&&t<e.x+e.width)??null}var gb=new Intl.NumberFormat(void 0,{style:`percent`,maximumFractionDigits:1});function _b(e,n,r,i,a,o,s=mb(i,n,r,a,uv(e,a))){let c=i.valueFormat??cv,{plot:l}=s;e.fillStyle=a.background,e.fillRect(0,0,n,r),mv(e,l,s.yScale,`vertical`,a,Q(s.yScale)),mv(e,l,s.xScale,`horizontal`,a,i.valueFormat??Q(s.xScale));let u=o&&i.crosshair!==!1?hb(s,o.x,o.y):null;for(let n of s.bars)e.fillStyle=n===u?n.color:(0,t.withAlpha)(n.color,.75),e.fillRect(n.x+(n.width>3?.5:0),n.y,Math.max(1,n.width-+(n.width>3)),n.height);if(vb(e,s,i,a,c),u&&o){let{bin:t}=u;pv(e,[{text:t.to>t.from?`${c(t.from)} – ${c(t.to)}`:c(t.from),bold:!0,color:u.color},{text:`${cv(t.count)} · ${gb.format(s.total>0?t.count/s.total:0)}`}],o,{x:0,y:0,width:n,height:r},a)}return s}function vb(e,t,n,r,i){let{plot:a}=t;e.save(),e.font=$(r,10),e.textAlign=`center`,e.textBaseline=`bottom`;let o=[];for(let s of n.markers??[]){if(!Number.isFinite(s.value))continue;let n=Math.round(Z(t.xScale,s.value,a.x,a.width))+.5,c=s.color??r.text;e.strokeStyle=c,e.setLineDash([4,3]),e.lineWidth=1,e.beginPath(),e.moveTo(n,a.y),e.lineTo(n,a.y+a.height),e.stroke(),e.setLineDash([]),e.fillStyle=c;let l=s.label?`${s.label} ${i(s.value)}`:i(s.value),u=e.measureText(l).width/2+4,d=0;for(;o.some(e=>e.row===d&&n-u<e.to&&n+u>e.from);)d++;o.push({from:n-u,to:n+u,row:d}),e.fillText(l,n,a.y-3+d*14)}e.restore()}var yb=8,bb=32,xb=new Map;function Sb(e){let t=xb.get(e);return t===void 0&&(t=Cb(e),xb.size>512&&xb.clear(),xb.set(e,t)),t}function Cb(e){let t=e.trim(),n=t.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(n){let e=n[1];return e.length<=4&&(e=[...e.slice(0,3)].map(e=>e+e).join(``)),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let r=t.match(/^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i);return r?[Number(r[1]),Number(r[2]),Number(r[3])]:null}function wb(e,t,n){let r=Sb(e),i=Sb(t);if(!r||!i)return n<.5?e:t;let a=e=>Math.round(r[e]+(i[e]-r[e])*n);return`rgb(${a(0)},${a(1)},${a(2)})`}function Tb(e,t,n){let r=1/0,i=-1/0;for(let t of e)Number.isFinite(t)&&(t<r&&(r=t),t>i&&(i=t));let a=0,o=1;if(r<=i){let e=Math.max(Math.abs(r),Math.abs(i))||1;a=r<0?-e:0,o=r<0?e:i||1}return{negative:n?.negative??t.candleDown,zero:n?.zero??wb(t.background,t.text,.14),positive:n?.positive??t.candleUp,min:n?.min!==void 0&&Number.isFinite(n.min)?n.min:a,max:n?.max!==void 0&&Number.isFinite(n.max)?n.max:o}}function Eb(e,t){return!Number.isFinite(e)||e===0?wb(t.zero,t.zero,0):e<0?wb(t.zero,t.negative,t.min<0?Math.min(1,e/t.min):1):wb(t.zero,t.positive,t.max>0?Math.min(1,e/t.max):1)}var Db=`#11151b`,Ob=.0076;function kb(e){let t=Sb(e);if(!t)return`#ffffff`;let[n,r,i]=t.map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}),a=.2126*n+.7152*r+.0722*i;return(a+.05)/(Ob+.05)>1.05/(a+.05)?Db:`#ffffff`}function Ab(e,t,n,r,i){let a=Math.min(180,t.width);if(a<40||!(n.max>n.min))return;let{x:o,y:s}=t,c=n.max-n.min;e.save();for(let t=0;t<bb;t++){let r=(t+.5)/bb;e.fillStyle=Eb(n.min+c*r,n),e.fillRect(o+a*t/bb,s,a/bb+.5,yb)}e.font=$(i,10),e.fillStyle=i.textSecondary,e.textBaseline=`top`;let l=s+yb+4;e.textAlign=`left`,e.fillText(r(n.min),o,l),e.textAlign=`right`,e.fillText(r(n.max),o+a,l);let u=o+a*-n.min/c;n.min<0&&n.max>0&&u-o>28&&o+a-u>28&&(e.textAlign=`center`,e.fillText(r(0),u,l)),e.restore()}var jb=864e5,Mb=3,Nb=12,Pb=16,Fb=10,Ib=28,Lb=6;function Rb(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return null;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])],a=Date.UTC(n,r-1,i),o=new Date(a);return o.getUTCFullYear()!==n||o.getUTCMonth()!==r-1||o.getUTCDate()!==i?null:Math.round(a/jb)}function zb(e){return new Date(e*jb).toISOString().slice(0,10)}var Bb=e=>((e+4)%7+7)%7;function Vb(e,t){let n=e.from===void 0?null:Rb(e.from),r=e.to===void 0?null:Rb(e.to);if(n===null||r===null){let e=1/0,i=-1/0;for(let n of t.keys())n<e&&(e=n),n>i&&(i=n);n??=Number.isFinite(e)?e:null,r??=Number.isFinite(i)?i:null}if(n===null||r===null||n>r)return null;let i=new Date(r*jb).getUTCFullYear()-10+1;return[Math.max(n,Math.round(Date.UTC(i,0,1)/jb)),r]}function Hb(e,t,n){let r=[],i=e;for(;i<=t;){let e=new Date(i*jb).getUTCFullYear(),a=Math.min(t,Math.round(Date.UTC(e,11,31)/jb)),o=i-n(i);r.push({year:e,first:i,last:a,origin:o,weeks:Math.floor((a-o)/7)+1}),i=a+1}return r}var Ub=new Map;function Wb(e){let t=e??``,n=Ub.get(t);if(!n){try{n={month:new Intl.DateTimeFormat(e,{month:`short`,timeZone:`UTC`}),weekday:new Intl.DateTimeFormat(e,{weekday:`short`,timeZone:`UTC`}),long:new Intl.DateTimeFormat(e,{dateStyle:`full`,timeZone:`UTC`})}}catch{n=Wb(void 0)}Ub.set(t,n)}return n}function Gb(e,t,n,r,i){let a=new Map;for(let t of e.data){let e=Rb(t.date);e!==null&&Number.isFinite(t.value)&&a.set(e,t)}let o=Wb(e.locale),s=e.dateFormat??(e=>o.long.format(new Date(`${e}T00:00:00Z`))),c=e.weekdays===5,l=e=>!c||Bb(e)>=1&&Bb(e)<=5,u=Vb(e,a),d=t-Nb*2,f=e.legend===!1?0:28,p=c?5:7,m=c?1:e.weekStart??1,h=e=>(Bb(e)-m+7)%7,g=u?Hb(u[0],u[1],h):[],_=e=>n-Nb*2-f-e*Pb-(e-1)*Fb;for(;g.length>1&&_(g.length)/(g.length*p)<Mb;)g=g.slice(1);let v=[];for(let[e,t]of a)g.length>0&&e>=g[0].first&&e<=g[g.length-1].last&&l(e)&&v.push(t.value);let y=Tb(v,r,e.colorScale),b={cells:[],months:[],weekdays:[],years:[],scale:y,bar:null,pitch:0,formatDate:s};if(g.length===0||d<=0||_(g.length)<=0)return b;let x=g.length>1,S=g.map(e=>String(e.year)),C=Array.from({length:p},(e,t)=>o.weekday.format(new Date((3+m+t)*jb))),w=Nb+Math.max(...C.map(e=>i(e,10)),...x?S.map(e=>i(e,11)):[0])+Lb,T=Math.max(...g.map(e=>e.weeks)),E=Math.min(Ib,(t-w-Nb)/T,_(g.length)/(g.length*p));if(!(E>0))return b;let D=E-(E>=6?Math.max(1,Math.round(E*.12)):0),O=T*E,k=w+Math.max(0,(t-w-Nb-O)/2),A={...b,pitch:E},ee=Nb;for(let[e,n]of g.entries()){let r=ee+Pb;x&&A.years.push({label:S[e],x:k-Lb,y:ee});let s=-1,c=-1/0;for(let e=n.first;e<=n.last;e++){if(!l(e))continue;let u=k+Math.floor((e-n.origin)/7)*E,d=r+h(e)*E,f=a.get(e);A.cells.push({x:u,y:d,size:D,date:zb(e),day:f,color:f&&Number.isFinite(f.value)?Eb(f.value,y):null});let p=new Date(e*jb).getUTCMonth();if(p!==s){s=p;let n=o.month.format(new Date(e*jb)),r=u+i(n,10);u>=c&&r<=t&&(A.months.push({label:n,x:u,y:ee}),c=r+4)}}if(E>=8){let e=E>=13?1:2;for(let t=0;t<p;t+=e)A.weekdays.push({label:C[t],x:k-Lb,y:r+t*E+D/2})}ee=r+p*E+Fb}return f>0&&(A.bar={x:k,y:ee-Fb+8,width:Math.min(O,t-k-Nb),height:f-8}),A}function Kb(e,t,n){for(let r of e.cells)if(t>=r.x&&t<r.x+e.pitch&&n>=r.y&&n<r.y+e.pitch)return r;return null}function qb(e,n,r,i,a,o,s=Gb(i,n,r,a,uv(e,a))){let c=i.valueFormat??cv;e.fillStyle=a.background,e.fillRect(0,0,n,r);let l=o&&i.crosshair!==!1?Kb(s,o.x,o.y):null,u=(0,t.withAlpha)(a.textSecondary,.12),d=s.pitch>=10?2:0;e.save();for(let t of s.cells)e.fillStyle=t.color??u,e.beginPath(),d>0&&typeof e.roundRect==`function`?e.roundRect(t.x,t.y,t.size,t.size,d):e.rect(t.x,t.y,t.size,t.size),e.fill();l&&(e.strokeStyle=a.text,e.lineWidth=1.5,e.strokeRect(l.x-.75,l.y-.75,l.size+1.5,l.size+1.5)),e.fillStyle=a.textSecondary,e.font=$(a,10),e.textAlign=`left`,e.textBaseline=`top`;for(let t of s.months)e.fillText(t.label,t.x,t.y);e.textAlign=`right`,e.textBaseline=`middle`;for(let t of s.weekdays)e.fillText(t.label,t.x,t.y);e.font=$(a,11,`600`),e.fillStyle=a.text,e.textBaseline=`top`;for(let t of s.years)e.fillText(t.label,t.x,t.y);if(e.restore(),s.bar&&Ab(e,s.bar,s.scale,c,a),l&&o){let t=[{text:s.formatDate(l.date),bold:!0,color:l.color??void 0}];if(l.day){t.push({text:c(l.day.value)});for(let[e,n]of Object.entries(l.day.meta??{}))t.push({text:`${e}: ${String(n)}`})}else t.push({text:`–`});pv(e,t,o,{x:0,y:0,width:n,height:r},a)}return s}var Jb=12,Yb=6,Xb=72,Zb=Math.PI/4,Qb=Math.sin(Zb);function $b(e){let t=e.length,n=Array.from({length:t},()=>Array(t).fill(NaN));for(let r=0;r<t;r++)for(let i=r;i<t;i++){let t=ex(e[r],e[i],r===i);n[r][i]=t,n[i][r]=t}return n}function ex(e,t,n){let r=Math.min(e.length,t.length),i=0,a=0,o=0;for(let n=0;n<r;n++)Number.isFinite(e[n])&&Number.isFinite(t[n])&&(i++,a+=e[n],o+=t[n]);if(i<3)return NaN;let s=a/i,c=o/i,l=0,u=0,d=0;for(let n=0;n<r;n++){if(!Number.isFinite(e[n])||!Number.isFinite(t[n]))continue;let r=e[n]-s,i=t[n]-c;l+=r*i,u+=r*r,d+=i*i}return u===0||d===0?NaN:n?1:Math.max(-1,Math.min(1,l/Math.sqrt(u*d)))}var tx=e=>e.toFixed(2);function nx(e,t,n,r){return!t||!e?!0:e===`lower`?r<=n:r>=n}function rx(e,t,n,r,i){let a=e.rows.slice(0,200),o=(e.columns??e.rows).slice(0,200),s=e.columns===void 0||e.columns.length===e.rows.length&&e.columns.every((t,n)=>t===e.rows[n]),c=[];for(let t=0;t<a.length;t++)for(let n=0;n<o.length;n++){let r=e.values[t]?.[n];Number.isFinite(r)&&nx(e.triangle,s,t,n)&&c.push(r)}let l=Tb(c,r,e.colorScale),u={cells:[],rowLabels:[],columnLabels:[],grid:{x:0,y:0,width:0,height:0},pitch:0,scale:l,bar:null,at:[]};if(a.length===0||o.length===0||t<=0||n<=0)return u;let d=Math.min(t*.3,Math.max(...a.map(e=>i(e,11)))),f=Math.max(...o.map(e=>i(e,11))),p=e.legend===!1?0:28,m=Jb+d+Yb,h=t-m-Jb,g=e=>Math.min(Xb,h/o.length,(n-e-Jb-p)/a.length),_=Jb+11+Yb,v=g(_),y=f>v-4,b=f;if(y&&(b=Math.min(f,n*.33/Qb),_=Jb+b*Qb+11,v=g(_)),!(v>0))return u;let x=v-+(v>=8),S=m+Math.max(0,(h-o.length*v)/2);y&&(b=Math.max(0,Math.min(b,(S+x/2-2-11*Qb/2)/Qb))),u.grid={x:S,y:_,width:o.length*v,height:a.length*v},u.pitch=v;let C=e.valueFormat??tx,w=e.showValues!==!1,T=Math.max(8,Math.min(11,v/3));for(let t=0;t<a.length;t++){u.at.push([]);for(let n=0;n<o.length;n++){let r=e.values[t]?.[n];if(!Number.isFinite(r)||!nx(e.triangle,s,t,n))continue;let c=Eb(r,l),d=w?C(r):``,f=w&&v>=18&&i(d,T)<=v-4,p={x:S+n*v,y:_+t*v,size:x,cell:{row:a[t],column:o[n],value:r,rowIndex:t,columnIndex:n},color:c,text:f?d:null,textColor:kb(c)};u.cells.push(p),u.at[t][n]=p}}let E=Math.max(1,Math.ceil(11/v)),D=Math.max(1,Math.ceil(11/(y?v*Qb:v)));for(let e=0;e<a.length;e+=E)u.rowLabels.push({text:hv(a[e],d,i),index:e,x:S-Yb,y:_+e*v+x/2});for(let e=0;e<o.length;e+=D)u.columnLabels.push({text:hv(o[e],b,i),index:e,x:S+e*v+x/2,y:_-Yb,rotated:y});return p>0&&(u.bar={x:S,y:_+a.length*v+8,width:Math.min(u.grid.width,t-S-Jb),height:p-8}),u}function ix(e,t,n){let{grid:r,pitch:i}=e;return i<=0||t<r.x||n<r.y||t>=r.x+r.width||n>=r.y+r.height?null:e.at[Math.floor((n-r.y)/i)]?.[Math.floor((t-r.x)/i)]??null}function ax(e,t,n,r,i,a,o=rx(r,t,n,i,uv(e,i))){let s=r.valueFormat??tx;e.fillStyle=i.background,e.fillRect(0,0,t,n);let c=a&&r.crosshair!==!1?ix(o,a.x,a.y):null;e.save();let l=Math.max(8,Math.min(11,o.pitch/3));e.textAlign=`center`,e.textBaseline=`middle`,e.font=$(i,l);for(let t of o.cells)e.fillStyle=t.color,e.fillRect(t.x,t.y,t.size,t.size),t.text&&(e.fillStyle=t.textColor,e.fillText(t.text,t.x+t.size/2,t.y+t.size/2));c&&(e.strokeStyle=i.text,e.lineWidth=1.5,e.strokeRect(c.x+.75,c.y+.75,c.size-1.5,c.size-1.5)),e.font=$(i,11),e.fillStyle=i.textSecondary,e.textAlign=`right`;for(let t of o.rowLabels)e.fillStyle=c&&c.cell.rowIndex===t.index?i.text:i.textSecondary,e.fillText(t.text,t.x,t.y);for(let t of o.columnLabels)e.fillStyle=c&&c.cell.columnIndex===t.index?i.text:i.textSecondary,t.rotated?(e.save(),e.translate(t.x,t.y),e.rotate(Zb),e.textAlign=`right`,e.fillText(t.text,0,0),e.restore()):(e.textAlign=`center`,e.textBaseline=`bottom`,e.fillText(t.text,t.x,t.y),e.textBaseline=`middle`);if(e.restore(),o.bar&&Ab(e,o.bar,o.scale,s,i),c&&a){let{cell:r}=c;pv(e,[{text:`${r.row} × ${r.column}`,bold:!0,color:c.color},{text:s(r.value)}],a,{x:0,y:0,width:t,height:n},i)}return o}var ox=12,sx=18,cx=20,lx=10,ux=.2,dx=2e3,fx=1e-9;function px(e,t,n=1/0){let r=Number.isFinite(t)?Math.max(1,Math.floor(t)):25,i=[],a=Math.max(r-1,e.length-(Number.isFinite(n)?Math.max(1,Math.floor(n)):e.length));for(let t=a;t<e.length;t++){let n=0,a=0;for(let i=t-r+1;i<=t;i++)n+=e[i].volume,a+=e[i].close;i.push({time:e[t].time,volume:n/r,price:a/r})}return i}var mx=(e,t)=>t-e>fx*Math.max(Math.abs(e),Math.abs(t));function hx(e){if(e.length<2)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e)t=Math.min(t,a.volume),n=Math.max(n,a.volume),r=Math.min(r,a.price),i=Math.max(i,a.price);let a=e[e.length-2],o=e[e.length-1],s=mx(t,n)?(o.volume-a.volume)/(n-t):0,c=mx(r,i)?(o.price-a.price)/(i-r):0;if(Math.abs(s)<1e-6&&Math.abs(c)<1e-6)return null;let l=(Math.atan2(c,s)+2*Math.PI)%(2*Math.PI);return Math.round(l/(Math.PI/4))%8+1}function gx(e,n,r,i,a){let o=px(e.data,e.period??25,_x(e)),s=1/0,c=-1/0,l=1/0,u=-1/0;for(let e of o)s=Math.min(s,e.volume),c=Math.max(c,e.volume),l=Math.min(l,e.price),u=Math.max(u,e.price);o.length>0&&!mx(s,c)&&(c=s),o.length>0&&!mx(l,u)&&(u=l);let d=av(o.length>0?s:0,o.length>0?c:1,Math.max(2,Math.floor(n/110))),f=av(o.length>0?l:0,o.length>0?u:1,Math.max(2,Math.floor(r/60))),p=e.priceFormat??Q(f),m=e.volumeFormat??Q(d),h=ox+Math.max(0,...f.ticks.map(e=>a(p(e),11)))+8+(e.yLabel?sx:0),g=ox+a(m(d.max),11)/2,_=ox,v=ox+cx+(e.xLabel?sx:0),y={x:h,y:_,width:Math.max(1,n-h-g),height:Math.max(1,r-_-v)},b=Math.max(1,o.length-1);return{plot:y,xScale:d,yScale:f,points:o.map((e,t)=>({px:Z(d,e.volume,y.x,y.width),py:Z(f,e.price,y.y,y.height,!0),alpha:ux+(1-ux)*t/b,point:e})),phase:hx(o),color:e.color??t.TC_SERIES_COLORS[0]}}function _x(e){let t=e.points??60;return Number.isFinite(t)?Math.min(dx,Math.max(2,Math.floor(t))):60}function vx(e,t,n){let r=null,i=lx*lx;for(let a=e.points.length-1;a>=0;a--){let o=e.points[a],s=(o.px-t)**2+(o.py-n)**2;s<i&&(r=o,i=s)}return r}var yx=new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`});function bx(e,n,r,i,a,o,s=gx(i,n,r,a,uv(e,a))){let{plot:c,points:l,color:u}=s,d=i.timeFormat??(e=>yx.format(new Date(e))),f=i.priceFormat??cv,p=i.volumeFormat??cv;e.fillStyle=a.background,e.fillRect(0,0,n,r),mv(e,c,s.yScale,`vertical`,a,i.priceFormat??Q(s.yScale)),mv(e,c,s.xScale,`horizontal`,a,i.volumeFormat??Q(s.xScale)),xx(e,c,i,a),e.save(),e.lineWidth=1.5,e.lineJoin=`round`;for(let n=1;n<l.length;n++)e.strokeStyle=(0,t.withAlpha)(u,l[n].alpha),e.beginPath(),e.moveTo(l[n-1].px,l[n-1].py),e.lineTo(l[n].px,l[n].py),e.stroke();for(let n of l)e.fillStyle=(0,t.withAlpha)(u,n.alpha),e.beginPath(),e.arc(n.px,n.py,2,0,Math.PI*2),e.fill();let m=l[l.length-1];m&&(e.fillStyle=u,e.strokeStyle=a.background,e.lineWidth=2,e.beginPath(),e.arc(m.px,m.py,5,0,Math.PI*2),e.fill(),e.stroke()),e.restore();let h=o&&i.crosshair!==!1?vx(s,o.x,o.y):null;return h&&o&&(e.save(),e.strokeStyle=a.text,e.lineWidth=1.5,e.beginPath(),e.arc(h.px,h.py,5,0,Math.PI*2),e.stroke(),e.restore(),pv(e,[{text:d(h.point.time),bold:!0,color:u},{text:`${i.yLabel??`Price`}: ${f(h.point.price)}`},{text:`${i.xLabel??`Volume`}: ${p(h.point.volume)}`}],o,{x:0,y:0,width:n,height:r},a)),s}function xx(e,t,n,r){e.save(),e.font=$(r,11),e.fillStyle=r.textSecondary,e.textAlign=`center`,n.xLabel&&(e.textBaseline=`bottom`,e.fillText(n.xLabel,t.x+t.width/2,t.y+t.height+cx+sx)),n.yLabel&&(e.translate(ox+4,t.y+t.height/2),e.rotate(-Math.PI/2),e.textBaseline=`middle`,e.fillText(n.yLabel,0,0)),e.restore()}exports.ABCDPatternTool=Vu,exports.ADXIndicator=Xn,exports.ALMAIndicator=ui,exports.ATRIndicator=Yn,exports.AXIS_LABEL_HEIGHT=O,exports.AcceleratorOscillatorIndicator=Rr,exports.AccumulationDistributionIndicator=Kr,exports.AccumulativeSwingIndexIndicator=to,exports.AdvanceDeclineIndicator=ro,exports.AlertDragHandler=ms,exports.AlertManager=ig,exports.AlligatorIndicator=Fn,exports.AnchoredVWAPIndicator=En,exports.AnchoredVWAPTool=vu,exports.Animator=r_,exports.ArcTool=rf,exports.AreaRenderer=Pe,exports.AroonIndicator=tr,exports.ArrowMarkTool=Rd,exports.ArrowTool=pu,exports.AverageDayRangeIndicator=Ii,exports.AveragePriceIndicator=Wi,exports.AwesomeOscillatorIndicator=Wn,exports.AxisDragHandler=ps,exports.BalanceOfPowerIndicator=Cr,exports.BarCountdown=le,exports.BarRenderer=Fe,exports.BarsPatternTool=Mf,exports.BaseFinanceChart=a_,exports.BaselineRenderer=Re,exports.BinanceAdapter=qm,exports.BollingerBandWidthIndicator=Ci,exports.BollingerBandsIndicator=hn,exports.BollingerPercentBIndicator=Si,exports.BracketTool=Lp,exports.BrushTool=Xd,exports.BybitAdapter=sh,exports.CANDLE_PATTERNS=ja,exports.CCIIndicator=$n,exports.CMFIndicator=ir,exports.COUNTDOWN_HEIGHT=ce,exports.CalloutTool=Ad,exports.CandlestickRenderer=oe,exports.CanvasLayer=n,exports.ChaikinOscillatorIndicator=Gn,exports.ChaikinVolatilityIndicator=jr,exports.ChandeKrollStopIndicator=yi,exports.ChandeMomentumIndicator=Tr,exports.ChandelierExitIndicator=Pn,exports.ChartLegend=bh,exports.ChartStateManager=jg,exports.ChopZoneIndicator=so,exports.ChoppinessIndexIndicator=sr,exports.CircleTool=Gu,exports.CoinbaseAdapter=th,exports.CompareRenderer=bt,exports.CompareSymbolIndicator=wo,exports.ConnorsRSIIndicator=dr,exports.CoppockIndicator=pr,exports.CorrelationCoefficientIndicator=ko,exports.CorrelationLogIndicator=Ao,exports.CrossLineTool=Ou,exports.CrosshairHandler=_s,exports.CrosshairTooltip=Ls,exports.CurrentPriceLine=lm,exports.CurveTool=nf,exports.CyclicLinesTool=td,exports.CypherPatternTool=Wu,exports.DEFAULT_LEGEND_CONFIG=yh,exports.DEFAULT_MAX_PIXEL_RATIO=a,exports.DEFAULT_MAX_WEBGL_CHARTS=e.t,exports.DEFAULT_SESSION_HOURS=Vh,exports.DEMAIndicator=ci,exports.DENSE_BAR_WIDTH=e.u,exports.DOUBLE_TAP_MS=Wo,exports.DOUBLE_TAP_PX=Go,exports.DPRManager=s,exports.DataExporter=Lg,exports.DateAndPriceRangeTool=Zu,exports.DateRangeTool=lu,exports.DepthHeatmapBuffer=gt,exports.DepthHeatmapRenderer=_t,exports.DepthOverlay=Op,exports.DetrendedPriceOscillatorIndicator=Sr,exports.DisparityIndexIndicator=Vr,exports.DonchianChannelIndicator=xn,exports.DrawingBase=G,exports.DrawingManager=cl,exports.DrawingRenderer=ul,exports.EMAIndicator=mn,exports.EaseOfMovementIndicator=Or,exports.Easing=n_,exports.ElderRayIndicator=_r,exports.ElliottCorrectionTool=iu,exports.ElliottDoubleComboTool=ou,exports.ElliottImpulseTool=ru,exports.ElliottTriangleTool=au,exports.ElliottTripleComboTool=su,exports.ElliottWaveTool=nu,exports.EllipseTool=ql,exports.Emitter=am,exports.EnvelopeIndicator=zn,exports.EquivolumeRenderer=Ue,exports.EventBus=qs,exports.ExtendedLineTool=Il,exports.FibArcsTool=gf,exports.FibChannelTool=Pu,exports.FibCirclesTool=hf,exports.FibExtensionTool=Gl,exports.FibRetracementTool=Ul,exports.FibSpeedResistanceFanTool=Ru,exports.FibSpiralTool=yf,exports.FibTimeZonesTool=xu,exports.FibWedgeTool=_f,exports.FinanceCrosshair=o_,exports.FisherTransformIndicator=xr,exports.FlagTool=Fd,exports.ForceIndexIndicator=ur,exports.ForecastTool=Af,exports.GROUP_HEADER=q_,exports.GannBoxTool=_u,exports.GannFanTool=hu,exports.GannSquareTool=bf,exports.GridRenderer=e.o,exports.GuppyMMAIndicator=Vi,exports.HLCAreaRenderer=Ge,exports.HammingMAIndicator=Ja,exports.HeadAndShouldersTool=Hu,exports.HiLoRenderer=Xe,exports.HighlighterTool=Zd,exports.HistoricalVolatilityIndicator=Ti,exports.HollowCandleRenderer=Ie,exports.HorizontalLineTool=Ml,exports.HorizontalRayTool=Nl,exports.HullMAIndicator=kn,exports.ICON_GLYPHS=zd,exports.INDICATOR_CATEGORIES=_o,exports.INTERVAL_LIMITS=Qt,exports.INTERVAL_UNITS=Zt,exports.IchimokuIndicator=_n,exports.IconTool=Vd,exports.IndicatorBase=P,exports.IndicatorEngine=ln,exports.IndicatorValueMap=F,exports.IndicatorWorkerHost=xo,exports.InfoLineTool=Au,exports.InteractionManager=ts,exports.KAMAIndicator=di,exports.KSTIndicator=mr,exports.KagiRenderer=Be,exports.KeltnerChannelIndicator=bn,exports.KeyboardHandler=Ds,exports.KlingerIndicator=br,exports.KrakenAdapter=mh,exports.LSMAIndicator=fi,exports.LayerManager=r,exports.LineRenderer=Ne,exports.LineWithMarkersRenderer=qe,exports.LinearRegressionChannelIndicator=On,exports.LinearRegressionSlopeIndicator=Pi,exports.MACDIndicator=qn,exports.MAChannelIndicator=Wa,exports.MACrossIndicator=gi,exports.MADoubleIndicator=Qa,exports.MARibbonIndicator=Hi,exports.MATripleIndicator=$a,exports.MAX_ALERT_BARS=Yh,exports.MAX_BASE_RATIO=fm,exports.MAX_BASE_REQUESTS=dm,exports.MFIIndicator=er,exports.MIN_ALERT_BARS=Xh,exports.MIN_BAR_UNIT=ve,exports.MIN_BAR_UNIT_LIMIT=ye,exports.MTFMovingAverageIndicator=Mn,exports.MajorityRuleIndicator=io,exports.MarketProfileRenderer=at,exports.MassIndexIndicator=wr,exports.McGinleyDynamicIndicator=pi,exports.MeasureOverlay=Kg,exports.MeasureTool=uu,exports.MedianPriceIndicator=Gi,exports.MockAdapter=Jm,exports.ModifiedSchiffPitchforkTool=Zl,exports.MomentumIndicator=wi,exports.NetVolumeIndicator=Li,exports.NoteTool=kd,exports.OBVIndicator=Zn,exports.OrderDraftTool=Up,exports.OrderRenderer=hp,exports.PRICE_SCALE_MARGIN=be,exports.PanHandler=ds,exports.PaneResizeHandler=hs,exports.PaperExecutionAdapter=nm,exports.ParabolicSARIndicator=vn,exports.ParallelChannelTool=Ll,exports.PathTool=Qd,exports.PercentagePriceOscillatorIndicator=Ir,exports.PeriodLevelsRenderer=ut,exports.PinnedTooltip=Hs,exports.PitchfanTool=vf,exports.PitchforkTool=Yl,exports.PivotMarkersRenderer=mt,exports.PivotPointsIndicator=wn,exports.PointAndFigureRenderer=Ve,exports.PollingAdapter=Zm,exports.PolylineTool=$d,exports.PositionRenderer=Dp,exports.PrettyGoodOscillatorIndicator=Ur,exports.PriceAxis=C,exports.PriceAxisAddButton=is,exports.PriceLabelTool=od,exports.PriceLines=Gh,exports.PriceOscillatorIndicator=uo,exports.PriceRangeTool=cu,exports.PriceVolumeTrendIndicator=kr,exports.ProjectionTool=jf,exports.QstickIndicator=Hr,exports.RANGE_PRESETS=we,exports.ROCIndicator=nr,exports.RSIIndicator=Kn,exports.RayTool=Fl,exports.ReconnectManager=sm,exports.RectangleTool=Kl,exports.RegressionChannelTool=Rl,exports.RelativeMomentumIndexIndicator=Br,exports.RelativeVigorIndicator=Mr,exports.RelativeVolatilityIndexIndicator=Mi,exports.RenderEngine=me,exports.RenderLoop=i,exports.RenkoRenderer=ze,exports.ReplayController=Mm,exports.ReplayManager=ug,exports.ResamplingAdapter=bm,exports.RiskRewardTool=Du,exports.SELECTION_BOX_MIN_SIZE=e_,exports.SMAIndicator=pn,exports.SMIErgodicIndicator=lo,exports.SMMAIndicator=li,exports.SNAPSHOT_VERSION=fg,exports.SYMBOL_INDICATOR_IDS=So,exports.SchaffTrendCycleIndicator=vr,exports.SchiffPitchforkTool=Xl,exports.Screenshot=Eh,exports.SelectionBoxOverlay=t_,exports.SessionBreaks=Mh,exports.SessionShading=Hh,exports.SessionVWAPIndicator=Nn,exports.SignalMarkerManager=Hg,exports.SineLineTool=Tf,exports.SpreadIndicator=To,exports.StandardErrorBandsIndicator=Ri,exports.StandardErrorIndicator=Fi,exports.StdDevIndicator=Wr,exports.StepLineRenderer=Ke,exports.StochasticIndicator=Jn,exports.StochasticMomentumIndexIndicator=ji,exports.StochasticRSIIndicator=Nr,exports.StreamManager=jm,exports.SupertrendIndicator=yn,exports.SymbolSeriesStore=yt,exports.TEMAIndicator=Un,exports.TOUCH_REACH=Uo,exports.TRIXIndicator=Er,exports.TSIIndicator=rr,exports.TapTracker=Ko,exports.TextAnnotationTool=fu,exports.ThreeDrivesTool=Uu,exports.TickAggregator=om,exports.TickBarAdapter=Tm,exports.TickBarBuilder=wm,exports.TimeAxis=Ho,exports.TimeCyclesTool=wf,exports.TradeZoneManager=Gg,exports.TradingContextMenu=jp,exports.TradingDragHandler=Ap,exports.TradingManager=em,exports.TradingRenderer=tm,exports.TrendAngleTool=bl,exports.TrendLineTool=jl,exports.TrendStrengthIndexIndicator=Ni,exports.TriangleTool=Jl,exports.TypicalPriceIndicator=Ki,exports.UlcerIndexIndicator=Oi,exports.UltimateOscillatorIndicator=cr,exports.UndoRedoManager=Mg,exports.VOLUME_HEIGHT_RATIO=Ze,exports.VROCIndicator=qr,exports.VWAPIndicator=gn,exports.VWMAIndicator=Ln,exports.VerticalLineTool=Pl,exports.Viewport=Se,exports.VolatilityIndexIndicator=eo,exports.VolatilityOHLCIndicator=mo,exports.VolatilityZeroTrendIndicator=ho,exports.VolumeCandleRenderer=He,exports.VolumeDeltaIndicator=ar,exports.VolumeOscillatorIndicator=Ei,exports.VolumeProfileIndicator=Gr,exports.VolumeProfileRangeTool=yu,exports.VolumeProfileRenderer=$e,exports.VolumeRenderer=Qe,exports.VortexIndicator=or,exports.WMAIndicator=Rn,exports.Watermark=Dh,exports.WebSocketAdapter=Xm,exports.WilliamsADIndicator=Ar,exports.WilliamsFractalsIndicator=vi,exports.WilliamsRIndicator=Qn,exports.XABCDPatternTool=Bu,exports.ZigZagIndicator=Dn,exports.ZoomHandler=fs,exports.alignOutput=Yt,exports.arcPoints=tf,exports.assignSessionLetters=rt,exports.axisFormat=Q,exports.barIndexToTime=e.y,exports.barIndexToX=e.b,exports.barTimeStep=e.x,exports.barTimeStepMs=e.S,exports.bracketRiskReward=Np,exports.canvasMeasure=uv,exports.cappedPixelRatio=o,exports.claimGpuContext=e.n,exports.classifyPivots=ft,exports.cleanIntervals=nn,exports.computeBarLayout=jy,exports.computeBracketDefaults=Mp,exports.computeCalendarLayout=Gb,exports.computeCounterClockLayout=gx,exports.computeDonutLayout=Wy,exports.computeHistogramLayout=mb,exports.computeMarketProfile=tt,exports.computeMatrixLayout=rx,exports.computePeriodLevels=lt,exports.computeScatterLayout=tb,exports.computeSessionProfiles=it,exports.correlationMatrix=$b,exports.counterClockPhase=hx,exports.counterClockPoints=px,exports.curvePoints=ef,exports.dayToIso=zb,exports.defaultFormat=cv,exports.detectCandlePatterns=Fa,exports.drawAxisValueLabels=ne,exports.drawIcon=Jf,exports.drawnKeys=jt,exports.fillTag=E,exports.findDominantSwing=dl,exports.findPivots=pt,exports.forEachPixelColumn=e.d,exports.forecastOutcome=kf,exports.formatTooltipTime=Fs,exports.getIntParam=L,exports.getNumberParam=I,exports.getVisibleData=Ce,exports.gpuContextsLeft=e.r,exports.hasHistogram=zt,exports.hasTrades=Om,exports.histogramBins=lb,exports.hitBar=My,exports.hitCategory=Ny,exports.hitDay=Kb,exports.hitHistogramBar=hb,exports.hitMatrixCell=ix,exports.hitSlice=Gy,exports.indicatorCategory=yo,exports.indicatorValuePrecision=D,exports.inferOrderType=Bp,exports.inputSource=Kt,exports.isDense=e.f,exports.isInWindow=zh,exports.isPriceLevelAlert=Qh,exports.isRegularSession=Bh,exports.isSeriesPalette=an,exports.isUpTone=Mt,exports.isWorkerResponse=bo,exports.labelTextColor=A,exports.layoutAxisValueLabels=te,exports.layoutGroupedTreemap=J_,exports.layoutLegend=dv,exports.layoutSquarifiedTreemap=G_,exports.layoutUniformGrid=V_,exports.lineSourceBars=Jt,exports.lineSpace=kc,exports.loadWebGL=ge,exports.loadWebGLRenderer=_e,exports.lttbDownsample=Ae,exports.lttbVisibleIndices=Me,exports.mergeSessionHours=Lh,exports.minuteOfDay=Rh,exports.nearestCounterClockPoint=vx,exports.nearestPoint=nb,exports.niceScale=av,exports.paneLogRange=Lt,exports.paneValueRange=It,exports.parseDay=Rb,exports.pastTimeStep=e.C,exports.plotColor=Ft,exports.plotLook=N,exports.plotShown=Nt,exports.priceBucketRow=e.w,exports.priceScaleText=c,exports.priceSourceBars=qt,exports.priceToY=e.T,exports.priceToYMapper=e.E,exports.rangePresetStart=ke,exports.readAlertOptions=og,exports.readableText=kb,exports.registerBuiltInDrawingTools=Nf,exports.registerBuiltInIndicators=go,exports.renderAxisValueLabels=re,exports.renderBarChart=Py,exports.renderCalendar=qb,exports.renderCounterClock=bx,exports.renderDenseBars=e.p,exports.renderDepthChart=S_,exports.renderDonut=Ky,exports.renderEquityCurve=B_,exports.renderGauge=wy,exports.renderHeatmap=Sv,exports.renderHistogram=_b,exports.renderMatrix=ax,exports.renderPlots=Bt,exports.renderScatter=rb,exports.renderSparkline=s_,exports.renderWaterfall=Wv,exports.resolveBarIndex=e.D,exports.resolveColorScale=Tb,exports.scaleColor=Eb,exports.servesTimeframe=_m,exports.setMaxWebGLCharts=e.i,exports.shownCount=_x,exports.shownOnInterval=tn,exports.sourceParam=Gt,exports.spreadLabels=k,exports.timeToX=e.O,exports.timestampToBarIndex=e.k,exports.toHeikinAshi=xt,exports.toKagi=Tt,exports.toLineBreak=wt,exports.toPointAndFigure=Et,exports.toRangeBars=Dt,exports.toRenko=St,exports.tpoLetter=nt,exports.waveLabel=$l,exports.whenGpuContextFree=e.a,exports.withResampling=hm,exports.withTickBars=Dm,exports.xToBarIndex=e.A,exports.xToTime=e.j,exports.yToPrice=e.M;
|
|
23
23
|
//# sourceMappingURL=index.cjs.map
|