PageSourceSearch

https://app.radex.global/build/assets/Futures-C1Tcm0Vl.js

js radex.global collected 2026-10-02 01:54:58 UTC 619,482 bytes, 8 lines download raw bytes

1import{r as m,k as ld,j as r,c as Rt,R as ad,q as pm,e as cd,N as Ec,h as hd,u as ud,L as sr}from"./react-B5tenFz7.js";import{t as dd,f as h,s as be,a as ge,g as ve,b as fd,r as gm,h as Li,c as Pl,u as Fc,R as vm}from"./index-BgMSoPU_.js";function ys(s,t){dd.success(s,s,t)}function Dn(s,t){dd.warning(s,s,t)}function Ps(s){m.useEffect(()=>{if(typeof s!="function")return;const t=e=>{e.key==="Escape"&&(e.preventDefault(),e.stopPropagation(),s())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[s])}const xm="https://t.me/Radexglobal_support",Ac="[email protected]",ym=()=>r.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M21.94 4.6 18.9 19.2c-.23 1.02-.84 1.27-1.7.79l-4.7-3.47-2.27 2.19c-.25.25-.46.46-.95.46l.34-4.8 8.73-7.9c.38-.34-.08-.53-.59-.19l-10.8 6.8-4.65-1.46c-1.01-.32-1.03-1.01.21-1.5l18.2-7.02c.84-.31 1.58.2 1.22 1.5Z"})}),bm=()=>r.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2.5",stroke:"currentColor",strokeWidth:"1.7"}),r.jsx("path",{d:"m4 7 7.4 5.3a1 1 0 0 0 1.2 0L20 7",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]});function wm({onClose:s}){return Ps(s),ld.createPortal(r.jsx("div",{className:"fut-modal",onClick:s,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--beta",onClick:t=>t.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Futures are in beta")}),r.jsx("button",{type:"button",onClick:s,children:"✕"})]}),r.jsx("p",{className:"fut-beta__lead",children:h("The terminal works with real money and real markets, but it is young: we keep adding features and polishing what is already there.")}),r.jsxs("ul",{className:"fut-beta__list",children:[r.jsx("li",{children:h("Your funds and positions are real, and so are the fees — beta is not a demo mode.")}),r.jsx("li",{children:h("Some things may look different tomorrow: we change the interface based on what you tell us.")}),r.jsx("li",{children:h("If something looks wrong — a number, an order, a balance — write to us right away, do not wait.")})]}),r.jsx("div",{className:"fut-beta__hint",children:h("When reporting a problem, the trade ID helps most: open the fee breakdown in history and copy the ID from there. Screenshots help too — send them along with the ID.")}),r.jsxs("div",{className:"fut-beta__links",children:[r.jsxs("a",{className:"fut-beta__link",href:xm,target:"_blank",rel:"noreferrer noopener",children:[r.jsx(ym,{}),r.jsxs("span",{children:[r.jsx("em",{children:h("Support in Telegram")}),r.jsx("i",{children:"@Radexglobal_support"})]})]}),r.jsxs("a",{className:"fut-beta__link",href:"mailto:"+Ac,children:[r.jsx(bm,{}),r.jsxs("span",{children:[r.jsx("em",{children:h("Email")}),r.jsx("i",{children:Ac})]})]})]})]})}),document.body)}const ba="futures_settings",zl="futures-settings",Tr={tpslConfirm:!0,priceLines:!0,volume:!0,marketHeight:0,tradeMarks:!0,marketConfirm:!0,orderMoveConfirm:!0,actsX:0,actsY:0,actsPinned:!1,fillNotify:!0,hideAmounts:!1,defaultLeverage:0,defaultMargin:"",closeOffsetPct:0,pnlBg:"",pnlChar:"",pnlPercent:!0,pnlAmount:!1,pnlLeverage:!0,pnlEntry:!0,pnlExit:!0,pnlSize:!1,pnlDate:!0,pnlQr:!0};function mn(){try{const s=JSON.parse(localStorage.getItem(ba)||"{}");return{...Tr,...Object.fromEntries(Object.keys(Tr).filter(t=>typeof s[t]==typeof Tr[t]).map(t=>[t,s[t]]))}}catch{return{...Tr}}}let fn=null;function nr(){return fn||(fn=mn()),fn}function pn(s){fn=s;try{localStorage.setItem(ba,JSON.stringify(s))}catch{}window.dispatchEvent(new CustomEvent(zl,{detail:s}))}function ur(){const[s,t]=m.useState(()=>(fn=mn(),fn));return m.useEffect(()=>{const e=i=>{fn=i.detail??mn(),t(fn)},n=i=>{i.key===ba&&(fn=mn(),t(fn))};return window.addEventListener(zl,e),window.addEventListener("storage",n),()=>{window.removeEventListener(zl,e),window.removeEventListener("storage",n)}},[]),s}function yo(s){const t=typeof s=="string"?s:String(s??""),[e,n]=t.split("."),i=e.startsWith("-")?"-":"",o=i?e.slice(1):e;if(!/^\d+$/.test(o))return t;const l=o.replace(/\B(?=(\d{3})+(?!\d))/g," ");return i+l+(n!==void 0?"."+n:"")}function lt(s,t=6){return yo(be(s,t))}function _i(s,t=6){const e=parseFloat(s)||0;if(e<=0)return 0;const n=Math.pow(10,t);return Math.floor(e*n+1e-9)/n}function bo(s,t=0){const e=Math.abs(parseFloat(s)||0);if(!e)return 0;const n=Math.floor(Math.log10(e))+1;return Math.max(0,Math.min(5-n,6-t))}function _m(s,t=0,e=2){const n=parseFloat(s)||0;if(!n)return"—";const i=Math.max(e,bo(n,t));return yo(n.toFixed(i))}const md="••••";function pe(s){if(nr().hideAmounts)return md;const t=parseFloat(s)||0;return(t<0?"−":"")+"$"+lt(Math.abs(t))}function $e(s,t=null){if(nr().hideAmounts)return md;const e=parseFloat(s)||0;if(e===0)return t===null?"$0":"$"+0 .toFixed(t);const n=t===null?lt(Math.abs(e)):yo(Math.abs(e).toFixed(t));return(e>0?"+":"−")+"$"+n}function Se(s){var t=s.width,e=s.height;if(t<0)throw new Error("Negative width is not allowed for Size");if(e<0)throw new Error("Negative height is not allowed for Size");return{width:t,height:e}}function Xn(s,t){return s.width===t.width&&s.height===t.height}var km=(function(){function s(t){var e=this;this._resolutionListener=function(){return e._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return s.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(s.prototype,"value",{get:function(){return this._window.devicePixelRatio}
1,enumerable:!1,configurable:!0}),s.prototype.subscribe=function(t){var e=this,n={next:t};return this._observers.push(n),{unsubscribe:function(){e._observers=e._observers.filter(function(i){return i!==n})}}},s.prototype._installResolutionListener=function(){if(this._resolutionMediaQueryList!==null)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},s.prototype._uninstallResolutionListener=function(){this._resolutionMediaQueryList!==null&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},s.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},s.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(e){return e.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},s})();function Mm(s){return new km(s)}var jm=(function(){function s(t,e,n){var i;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=Se({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=e??(function(o){return o}),this._allowResizeObserver=(i=n==null?void 0:n.allowResizeObserver)!==null&&i!==void 0?i:!0,this._chooseAndInitObserver()}return s.prototype.dispose=function(){var t,e;if(this._canvasElement===null)throw new Error("Object is disposed");(t=this._canvasElementResizeObserver)===null||t===void 0||t.disconnect(),this._canvasElementResizeObserver=null,(e=this._devicePixelRatioObservable)===null||e===void 0||e.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(s.prototype,"canvasElement",{get:function(){if(this._canvasElement===null)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"bitmapSize",{get:function(){return Se({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),s.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=Se(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},s.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},s.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(e){return e!==t})},Object.defineProperty(s.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),s.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},s.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(e){return e!==t})},s.prototype.applySuggestedBitmapSize=function(){if(this._suggestedBitmapSize!==null){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},s.prototype._resizeBitmap=function(t){var e=this.bitmapSize;Xn(e,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(e,t))},s.prototype._emitBitmapSizeChanged=function(t,e){var n=this;this._bitmapSizeChangedListeners.forEach(function(i){return i.call(n,t,e)})},s.prototype._suggestNewBitmapSize=function(t){var e=this._suggestedBitmapSize,n=Se(this._transformBitmapSize(t,this._canvasElementClientSize)),i=Xn(this.bitmapSize,n)?null:n;e===null&&i===null||e!==null&&i!==null&&Xn(e,i)||(this._suggestedBitmapSize=i,this._emitSuggestedBitmapSizeChanged(e,i))},s.prototype._emitSuggestedBitmapSizeChanged=function(t,e){var n=this;
1this._suggestedBitmapSizeChangedListeners.forEach(function(i){return i.call(n,t,e)})},s.prototype._chooseAndInitObserver=function(){var t=this;if(!this._allowResizeObserver){this._initDevicePixelRatioObservable();return}Nm().then(function(e){return e?t._initResizeObserver():t._initDevicePixelRatioObservable()})},s.prototype._initDevicePixelRatioObservable=function(){var t=this;if(this._canvasElement!==null){var e=Rc(this._canvasElement);if(e===null)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=Mm(e),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},s.prototype._invalidateBitmapSize=function(){var t,e;if(this._canvasElement!==null){var n=Rc(this._canvasElement);if(n!==null){var i=(e=(t=this._devicePixelRatioObservable)===null||t===void 0?void 0:t.value)!==null&&e!==void 0?e:n.devicePixelRatio,o=this._canvasElement.getClientRects(),l=o[0]!==void 0?Cm(o[0],i):Se({width:this._canvasElementClientSize.width*i,height:this._canvasElementClientSize.height*i});this._suggestNewBitmapSize(l)}}},s.prototype._initResizeObserver=function(){var t=this;this._canvasElement!==null&&(this._canvasElementResizeObserver=new ResizeObserver(function(e){var n=e.find(function(l){return l.target===t._canvasElement});if(!(!n||!n.devicePixelContentBoxSize||!n.devicePixelContentBoxSize[0])){var i=n.devicePixelContentBoxSize[0],o=Se({width:i.inlineSize,height:i.blockSize});t._suggestNewBitmapSize(o)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},s})();function Sm(s,t){return new jm(s,t.transform,t.options)}function Rc(s){return s.ownerDocument.defaultView}function Nm(){return new Promise(function(s){var t=new ResizeObserver(function(e){s(e.every(function(n){return"devicePixelContentBoxSize"in n})),t.disconnect()});t.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1})}function Cm(s,t){return Se({width:Math.round(s.left*t+s.width*t)-Math.round(s.left*t),height:Math.round(s.top*t+s.height*t)-Math.round(s.top*t)})}var Tm=(function(){function s(t,e,n){if(e.width===0||e.height===0)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=e,n.width===0||n.height===0)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=n,this._context=t}return s.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},s.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(s.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),s})();function Jn(s,t){var e=s.canvasElementClientSize;if(e.width===0||e.height===0)return null;var n=s.bitmapSize;if(n.width===0||n.height===0)return null;var i=s.canvasElement.getContext("2d",t);return i===null?null:new Tm(i,e,n)}/*!
2 * @license
3 * TradingView Lightweight Charts™ v5.2.0
4 * Copyright (c) 2026 TradingView, Inc.
5 * Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
6 */const pd={title:"",visible:!0,hitTestTolerance:3,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var Dl,yi;function In(s,t){const e=(function(n,i){switch(n){case 0:default:return[];case 1:return[i,i];case 2:return[2*i,2*i];case 3:return[6*i,6*i];case 4:return[i,4*i]}})(t,s.lineWidth);return s.setLineDash(e),e}
6function gd(s,t,e,n){s.beginPath();const i=s.lineWidth%2?.5:0;s.moveTo(e,t+i),s.lineTo(n,t+i),s.stroke()}function fs(s,t){if(!s)throw new Error("Assertion failed"+(t?": "+t:""))}function Cs(s){if(s===void 0)throw new Error("Value is undefined");return s}function ct(s){if(s===null)throw new Error("Value is null");return s}function On(s){return ct(Cs(s))}(function(s){s[s.Simple=0]="Simple",s[s.WithSteps=1]="WithSteps",s[s.Curved=2]="Curved"})(Dl||(Dl={})),(function(s){s[s.Solid=0]="Solid",s[s.Dotted=1]="Dotted",s[s.Dashed=2]="Dashed",s[s.LargeDashed=3]="LargeDashed",s[s.SparseDotted=4]="SparseDotted"})(yi||(yi={}));class Ye{constructor(){this.t=[]}i(t,e,n){const i={h:t,l:e,o:n===!0};this.t.push(i)}_(t){const e=this.t.findIndex((n=>t===n.h));e>-1&&this.t.splice(e,1)}u(t){this.t=this.t.filter((e=>e.l!==t))}p(t,e,n){const i=[...this.t];this.t=this.t.filter((o=>!o.o)),i.forEach((o=>o.h(t,e,n)))}v(){return this.t.length>0}m(){this.t=[]}}function Rs(s,...t){for(const e of t)for(const n in e)e[n]!==void 0&&Object.prototype.hasOwnProperty.call(e,n)&&!["__proto__","constructor","prototype"].includes(n)&&(typeof e[n]!="object"||s[n]===void 0||Array.isArray(e[n])?s[n]=e[n]:Rs(s[n],e[n]));return s}function ti(s){return typeof s=="number"&&isFinite(s)}function ir(s){return typeof s=="number"&&s%1==0}function dr(s){return typeof s=="string"}function Lr(s){return typeof s=="boolean"}function Nn(s){const t=s;if(!t||typeof t!="object")return t;let e,n,i;for(n in e=Array.isArray(t)?[]:{},t)t.hasOwnProperty(n)&&(i=t[n],e[n]=i&&typeof i=="object"?Nn(i):i);return e}function Pc(s){return s!==null}function rr(s){return s===null?void 0:s}const vd="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function or(s,t,e){return t===void 0&&(t=vd),`${e=e!==void 0?`${e} `:""}${s}px ${t}`}class Lm{constructor(t){this.M={S:1,C:5,k:NaN,P:"",T:"",R:"",D:"",I:0,V:0,B:0,A:0,L:0},this.O=t}N(){const t=this.M,e=this.F(),n=this.W();return t.k===e&&t.T===n||(t.k=e,t.T=n,t.P=or(e,n),t.A=2.5/12*e,t.I=t.A,t.V=e/12*t.C,t.B=e/12*t.C,t.L=0),t.R=this.H(),t.D=this.U(),this.M}H(){return this.O.N().layout.textColor}U(){return this.O.$()}F(){return this.O.N().layout.fontSize}W(){return this.O.N().layout.fontFamily}}function qo(s){return s<0?0:s>255?255:Math.round(s)||0}function zc(s){return .199*s[0]+.687*s[1]+.114*s[2]}class Em{constructor(t,e){this.j=new Map,this.q=t,e&&(this.j=e)}Y(t,e){if(t==="transparent")return t;const n=this.K(t),i=n[3];return`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${e*i})`}Z(t){const e=this.K(t);return{G:`rgb(${e[0]}, ${e[1]}, ${e[2]})`,X:zc(e)>160?"black":"white"}}J(t){return zc(this.K(t))}tt(t,e,n){const[i,o,l,a]=this.K(t),[c,u,d,f]=this.K(e),g=[qo(i+n*(c-i)),qo(o+n*(u-o)),qo(l+n*(d-l)),(v=a+n*(f-a),v<=0||v>1?Math.min(Math.max(v,0),1):Math.round(1e4*v)/1e4)];var v;return`rgba(${g[0]}, ${g[1]}, ${g[2]}, ${g[3]})`}K(t){const e=this.j.get(t);if(e)return e;const n=(function(l){const a=document.createElement("div");a.style.display="none",document.body.appendChild(a),a.style.color=l;const c=window.getComputedStyle(a).color;return document.body.removeChild(a),c})(t),i=n.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/);if(!i){if(this.q.length)for(const l of this.q){const a=l(t);if(a)return this.j.set(t,a),a}throw new Error(`Failed to parse color: ${t}`)}const o=[parseInt(i[1],10),parseInt(i[2],10),parseInt(i[3],10),i[4]?parseFloat(i[4]):1];return this.j.set(t,o),o}}class wa{constructor(){this.it=[]}nt(t){this.it=t}st(t,e,n){this.it.forEach((i=>{i.st(t,e,n)}))}}class gn{st(t,e,n){t.useBitmapCoordinateSpace((i=>this.et(i,e,n)))}}class Fm extends gn{constructor(){super(...arguments),this.rt=null}ht(t){this.rt=t}et({context:t,horizontalPixelRatio:e,verticalPixelRatio:n}){if(this.rt===null||this.rt.lt===null)return;const i=this.rt.lt,o=this.rt,l=Math.max(1,Math.floor(e))%2/2,a=c=>{t.beginPath();for(let u=i.to-1;u>=i.from;--u){const d=o.ot[u],f=Math.round(d._t*e)+l,g=d.ut*n,v=c*n+l;t.moveTo(f,g),t.arc(f,g,v,0,2*Math.PI)}t.fill()};o.ct>0&&(t.fillStyle=o.dt,a(o.ft+o.ct)),t.fillStyle=o.vt,a(o.ft)}}function Am(){return{ot:[{_t:0,ut:0,wt:0,Mt:0}],vt:"",dt:"",ft:0,ct:0,lt:null}}const Rm={from:0,to:1};class Pm{constructor(t,e,n){this.gt=new wa,this.bt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=e,this.yt=n,this.gt.nt(this.bt)}kt(t){this.Pt(),this.xt=!0}Tt(){return this.xt&&(this.Rt(),this.xt=!1),this.gt}
vendor: 5,542 bytes, line 6
6Pt(){const t=this.yt.Dt();t.length!==this.bt.length&&(this.St=t.map(Am),this.bt=this.St.map((e=>{const n=new Fm;return n.ht(e),n})),this.gt.nt(this.bt))}Rt(){const t=this.Ct.N().mode===2||!this.Ct.It(),e=this.yt.Vt(),n=this.Ct.Bt(),i=this.O.Et();this.Pt(),e.forEach(((o,l)=>{const a=this.St[l],c=o.At(n),u=o.Lt();!t&&c!==null&&o.It()&&u!==null?(a.vt=c.zt,a.ft=c.ft,a.ct=c.Ot,a.ot[0].Mt=c.Mt,a.ot[0].ut=o.Ft().Nt(c.Mt,u.Wt),a.dt=c.Ht??this.O.Ut(a.ot[0].ut/o.Ft().$t()),a.ot[0].wt=n,a.ot[0]._t=i.jt(n),a.lt=Rm):a.lt=null}))}}class zm extends gn{constructor(t){super(),this.qt=t}et({context:t,bitmapSize:e,horizontalPixelRatio:n,verticalPixelRatio:i}){if(this.qt===null)return;const o=this.qt.Yt.It,l=this.qt.Kt.It;if(!o&&!l)return;const a=Math.round(this.qt._t*n),c=Math.round(this.qt.ut*i);t.lineCap="butt",o&&a>=0&&(t.lineWidth=Math.floor(this.qt.Yt.ct*n),t.strokeStyle=this.qt.Yt.R,t.fillStyle=this.qt.Yt.R,In(t,this.qt.Yt.Zt),(function(u,d,f,g){u.beginPath();const v=u.lineWidth%2?.5:0;u.moveTo(d+v,f),u.lineTo(d+v,g),u.stroke()})(t,a,0,e.height)),l&&c>=0&&(t.lineWidth=Math.floor(this.qt.Kt.ct*i),t.strokeStyle=this.qt.Kt.R,t.fillStyle=this.qt.Kt.R,In(t,this.qt.Kt.Zt),gd(t,c,0,e.width))}}class Dm{constructor(t,e){this.xt=!0,this.Gt={Yt:{ct:1,Zt:0,R:"",It:!1},Kt:{ct:1,Zt:0,R:"",It:!1},_t:0,ut:0},this.Xt=new zm(this.Gt),this.Jt=t,this.yt=e}kt(){this.xt=!0}Tt(t){return this.xt&&(this.Rt(),this.xt=!1),this.Xt}Rt(){const t=this.Jt.It(),e=this.yt.Qt().N().crosshair,n=this.Gt;if(e.mode===2)return n.Kt.It=!1,void(n.Yt.It=!1);n.Kt.It=t&&this.Jt.ti(this.yt),n.Yt.It=t&&this.Jt.ii(),n.Kt.ct=e.horzLine.width,n.Kt.Zt=e.horzLine.style,n.Kt.R=e.horzLine.color,n.Yt.ct=e.vertLine.width,n.Yt.Zt=e.vertLine.style,n.Yt.R=e.vertLine.color,n._t=this.Jt.ni(),n.ut=this.Jt.si()}}function Om(s,t,e,n,i,o){s.fillRect(t+o,e,n-2*o,o),s.fillRect(t+o,e+i-o,n-2*o,o),s.fillRect(t,e,o,i),s.fillRect(t+n-o,e,o,i)}function wo(s,t,e,n,i,o){s.save(),s.globalCompositeOperation="copy",s.fillStyle=o,s.fillRect(t,e,n,i),s.restore()}function Dc(s,t,e,n,i,o){s.beginPath(),s.roundRect?s.roundRect(t,e,n,i,o):(s.lineTo(t+n-o[1],e),o[1]!==0&&s.arcTo(t+n,e,t+n,e+o[1],o[1]),s.lineTo(t+n,e+i-o[2]),o[2]!==0&&s.arcTo(t+n,e+i,t+n-o[2],e+i,o[2]),s.lineTo(t+o[3],e+i),o[3]!==0&&s.arcTo(t,e+i,t,e+i-o[3],o[3]),s.lineTo(t,e+o[0]),o[0]!==0&&s.arcTo(t,e,t+o[0],e,o[0]))}function Oc(s,t,e,n,i,o,l=0,a=[0,0,0,0],c=""){if(s.save(),!l||!c||c===o)return Dc(s,t,e,n,i,a),s.fillStyle=o,s.fill(),void s.restore();const u=l/2;var d;Dc(s,t+u,e+u,n-l,i-l,(d=-u,a.map((f=>f===0?f:f+d)))),o!=="transparent"&&(s.fillStyle=o,s.fill()),c!=="transparent"&&(s.lineWidth=l,s.strokeStyle=c,s.closePath(),s.stroke()),s.restore()}function xd(s,t,e,n,i,o,l){s.save(),s.globalCompositeOperation="copy";const a=s.createLinearGradient(0,0,0,i);a.addColorStop(0,o),a.addColorStop(1,l),s.fillStyle=a,s.fillRect(t,e,n,i),s.restore()}class Ic{constructor(t,e){this.ht(t,e)}ht(t,e){this.qt=t,this.ei=e}$t(t,e){return this.qt.It?t.k+t.A+t.I:0}st(t,e,n,i){if(!this.qt.It||this.qt.ri.length===0)return;const o=this.qt.R,l=this.ei.G,a=t.useBitmapCoordinateSpace((c=>{const u=c.context;u.font=e.P;const d=this.hi(c,e,n,i),f=d.ai;return d.li?Oc(u,f.oi,f._i,f.ui,f.ci,l,f.di,[f.ft,0,0,f.ft],l):Oc(u,f.fi,f._i,f.ui,f.ci,l,f.di,[0,f.ft,f.ft,0],l),this.qt.pi&&(u.fillStyle=o,u.fillRect(f.fi,f.mi,f.wi-f.fi,f.Mi)),this.qt.gi&&(u.fillStyle=e.D,u.fillRect(d.li?f.bi-f.di:0,f._i,f.di,f.Si-f._i)),d}));t.useMediaCoordinateSpace((({context:c})=>{const u=a.xi;c.font=e.P,c.textAlign=a.li?"right":"left",c.textBaseline="middle",c.fillStyle=o,c.fillText(this.qt.ri,u.Ci,(u._i+u.Si)/2+u.yi)}))}hi(t,e,n,i){const{context:o,bitmapSize:l,mediaSize:a,horizontalPixelRatio:c,verticalPixelRatio:u}=t,d=this.qt.pi||!this.qt.ki?e.C:0,f=this.qt.Pi?e.S:0,g=e.A+this.ei.Ti,v=e.I+this.ei.Ri,b=e.V,w=e.B,k=this.qt.ri,y=e.k,S=n.Di(o,k),j=Math.ceil(n.Ii(o,k)),E=y+g+v,z=e.S+b+w+j+d,F=Math.max(1,Math.floor(u));let A=Math.round(E*u);A%2!=F%2&&(A+=1);const J=f>0?Math.max(1,Math.floor(f*c)):0,O=Math.round(z*c),yt=Math.round(d*c),P=this.ei.Vi??this.ei.Bi??this.ei.Ei,G=Math.round(P*u)-Math.floor(.5*u),nt=Math.floor(G+F/2-A/2),bt=nt+A,$=i==="right",ht=$?a.width-f:f,tt=$?l.width-J:J;let H,et,rt;return $?(H=tt-O,et=tt-yt,rt=ht-d-b-f):(H=tt+O,et=tt+yt,rt=ht+d+b),{li:$,ai:{_i:nt,mi:G,Si:bt,ui:O,ci:A,ft:2*c,di:J,oi:H,fi:tt,wi:et,Mi:F,bi:l.width},xi:{_i:nt/u,Si:bt/u,Ci:rt,yi:S}}}}class _o{constructor(t){this.Ai={Ei:0,G:"#000",Ri:0,Ti:0},this.Li={ri:"",It:!1,pi:!0,ki:!1,Ht:"",R:"#FFF",gi:!1,Pi:!1},this.zi={ri:"",It:!1,pi:!1,ki:!0,Ht:"",R:"#FFF",gi:!0,Pi:!0},this.xt=!0,this.Oi=new(t||Ic)(this.Li,this.Ai),this.Ni=new(t||Ic)(this.zi,this.Ai)}ri(){return this.Fi(),this.Li.ri}Ei(){return this.Fi(),this.Ai.Ei}kt(){this.xt=!0}$t(t,e=!1){return Math.max(this.Oi.$t(t,e),this.Ni.$t(t,e))}Wi(){return this.Ai.Vi??null}Hi(){return this.Ai.Vi??this.Ai.Bi??this.Ei()}Ui(t){this.Ai.Bi=t??void 0}$i(){return this.Fi(),this.Li.It||this.zi.It}ji(){return this.Fi(),this.Li.It}Tt(t){return this.Fi(),this.Li.pi=this.Li.pi&&t.N().ticksVisible,this.zi.pi=this.zi.pi&&t.N().ticksVisible,this.Oi.ht(this.Li,this.Ai),this.Ni.ht(this.zi,this.Ai),this.Oi}qi(){return this.Fi(),this.Oi.ht(this.Li,this.Ai),this.Ni.ht(this.zi,this.Ai),this.Ni}Fi(){this.xt&&(this.Li.pi=!0,this.zi.pi=!1,this.Yi(this.Li,this.zi,this.Ai))}}class Im extends _o{constructor(t,e,n){super(),this.Jt=t,this.Ki=e,this.Zi=n}Yi(t,e,n){if(t.It=!1,this.Jt.N().mode===2)return;const i=this.Jt.N().horzLine;if(!i.labelVisible)return;const o=this.Ki.Lt();if(!this.Jt.It()||this.Ki.Gi()||o===null)return;
6const l=this.Ki.Xi().Z(i.labelBackgroundColor);n.G=l.G,t.R=l.X;const a=2/12*this.Ki.k();n.Ti=a,n.Ri=a;const c=this.Zi(this.Ki);n.Ei=c.Ei,t.ri=this.Ki.Ji(c.Mt,o),t.It=!0}}const Bm=/[1-9]/g;class yd{constructor(){this.qt=null}ht(t){this.qt=t}st(t,e){if(this.qt===null||this.qt.It===!1||this.qt.ri.length===0)return;const n=t.useMediaCoordinateSpace((({context:g})=>(g.font=e.P,Math.round(e.Qi.Ii(g,ct(this.qt).ri,Bm)))));if(n<=0)return;const i=e.tn,o=n+2*i,l=o/2,a=this.qt.nn;let c=this.qt.Ei,u=Math.floor(c-l)+.5;u<0?(c+=Math.abs(0-u),u=Math.floor(c-l)+.5):u+o>a&&(c-=Math.abs(a-(u+o)),u=Math.floor(c-l)+.5);const d=u+o,f=Math.ceil(0+e.S+e.C+e.A+e.k+e.I);t.useBitmapCoordinateSpace((({context:g,horizontalPixelRatio:v,verticalPixelRatio:b})=>{const w=ct(this.qt);g.fillStyle=w.G;const k=Math.round(u*v),y=Math.round(0*b),S=Math.round(d*v),j=Math.round(f*b),E=Math.round(2*v);if(g.beginPath(),g.moveTo(k,y),g.lineTo(k,j-E),g.arcTo(k,j,k+E,j,E),g.lineTo(S-E,j),g.arcTo(S,j,S,j-E,E),g.lineTo(S,y),g.fill(),w.pi){const z=Math.round(w.Ei*v),F=y,A=Math.round((F+e.C)*b);g.fillStyle=w.R;const J=Math.max(1,Math.floor(v)),O=Math.floor(.5*v);g.fillRect(z-O,F,J,A-F)}})),t.useMediaCoordinateSpace((({context:g})=>{const v=ct(this.qt),b=0+e.S+e.C+e.A+e.k/2;g.font=e.P,g.textAlign="left",g.textBaseline="middle",g.fillStyle=v.R;const w=e.Qi.Di(g,"Apr0");g.translate(u+i,b+w),g.fillText(v.ri,0,0)}))}}class Wm{constructor(t,e,n){this.xt=!0,this.Xt=new yd,this.Gt={It:!1,G:"#4c525e",R:"white",ri:"",nn:0,Ei:NaN,pi:!0},this.Ct=t,this.sn=e,this.Zi=n}kt(){this.xt=!0}Tt(){return this.xt&&(this.Rt(),this.xt=!1),this.Xt.ht(this.Gt),this.Xt}Rt(){const t=this.Gt;if(t.It=!1,this.Ct.N().mode===2)return;const e=this.Ct.N().vertLine;if(!e.labelVisible)return;const n=this.sn.Et();if(n.Gi())return;t.nn=n.nn();const i=this.Zi();if(i===null)return;t.Ei=i.Ei;const o=n.en(this.Ct.Bt());t.ri=n.rn(ct(o)),t.It=!0;const l=this.sn.Xi().Z(e.labelBackgroundColor);t.G=l.G,t.R=l.X,t.pi=n.N().ticksVisible}}class bd{constructor(){this.hn=null,this.an=0}ln(){return this.an}_n(t){this.an=t}Ft(){return this.hn}un(t){this.hn=t}cn(t){return[]}dn(){return[]}It(){return!0}}var Ol;(function(s){s[s.Normal=0]="Normal",s[s.Magnet=1]="Magnet",s[s.Hidden=2]="Hidden",s[s.MagnetOHLC=3]="MagnetOHLC"})(Ol||(Ol={}));class qm extends bd{constructor(t,e){super(),this.yt=null,this.fn=NaN,this.pn=0,this.vn=!1,this.mn=new Map,this.wn=!1,this.Mn=new WeakMap,this.gn=new WeakMap,this.bn=NaN,this.Sn=NaN,this.xn=NaN,this.Cn=NaN,this.sn=t,this.yn=e,this.kn=((i,o)=>l=>{const a=o(),c=i();if(l===ct(this.yt).Pn())return{Mt:c,Ei:a};{const u=ct(l.Lt());return{Mt:l.Tn(a,u),Ei:a}}})((()=>this.fn),(()=>this.Sn));const n=((i,o)=>()=>{const l=this.sn.Et().Rn(i()),a=o();return l&&Number.isFinite(a)?{wt:l,Ei:a}:null})((()=>this.pn),(()=>this.ni()));this.Dn=new Wm(this,t,n)}N(){return this.yn}In(t,e){this.xn=t,this.Cn=e}Vn(){this.xn=NaN,this.Cn=NaN}Bn(){return this.xn}En(){return this.Cn}An(t,e,n){this.wn||(this.wn=!0),this.vn=!0,this.Ln(t,e,n)}Bt(){return this.pn}ni(){return this.bn}si(){return this.Sn}It(){return this.vn}zn(){this.vn=!1,this.On(),this.fn=NaN,this.bn=NaN,this.Sn=NaN,this.yt=null,this.Vn(),this.Nn()}Fn(t){if(!this.yn.doNotSnapToHiddenSeriesIndices)return t;const e=this.sn,n=e.Et();let i=null,o=null;for(const u of e.Wn()){const d=u.Un().Hn(t,-1);if(d){if(d.$n===t)return t;(i===null||d.$n>i)&&(i=d.$n)}const f=u.Un().Hn(t,1);if(f){if(f.$n===t)return t;(o===null||f.$n<o)&&(o=f.$n)}}const l=[i,o].filter(Pc);if(l.length===0)return t;const a=n.jt(t),c=l.map((u=>Math.abs(a-n.jt(u))));return l[c.indexOf(Math.min(...c))]}jn(t){let e=this.Mn.get(t);e||(e=new Dm(this,t),this.Mn.set(t,e));let n=this.gn.get(t);return n||(n=new Pm(this.sn,this,t),this.gn.set(t,n)),[e,n]}ti(t){return t===this.yt&&this.yn.horzLine.visible}ii(){return this.yn.vertLine.visible}qn(t,e){this.vn&&this.yt===t||this.mn.clear();const n=[];return this.yt===t&&n.push(this.Yn(this.mn,e,this.kn)),n}dn(){return this.vn?[this.Dn]:[]}Kn(){return this.yt}Nn(){this.sn.Zn().forEach((t=>{var e,n;(e=this.Mn.get(t))==null||e.kt(),(n=this.gn.get(t))==null||n.kt()}
6)),this.mn.forEach((t=>t.kt())),this.Dn.kt()}Gn(t){return t&&!t.Pn().Gi()?t.Pn():null}Ln(t,e,n){this.Xn(t,e,n)&&this.Nn()}Xn(t,e,n){const i=this.bn,o=this.Sn,l=this.fn,a=this.pn,c=this.yt,u=this.Gn(n);this.pn=t,this.bn=isNaN(t)?NaN:this.sn.Et().jt(t),this.yt=n;const d=u!==null?u.Lt():null;return u!==null&&d!==null?(this.fn=e,this.Sn=u.Nt(e,d)):(this.fn=NaN,this.Sn=NaN),i!==this.bn||o!==this.Sn||a!==this.pn||l!==this.fn||c!==this.yt}On(){const t=this.sn.Jn().map((n=>n.Un().Qn())).filter(Pc),e=t.length===0?null:Math.max(...t);this.pn=e!==null?e:NaN}Yn(t,e,n){let i=t.get(e);return i===void 0&&(i=new Im(this,e,n),t.set(e,i)),i}}function ko(s){return s==="left"||s==="right"}class ds{constructor(t){this.ts=new Map,this.ns=[],this.ss=t}es(t,e){const n=(function(i,o){return i===void 0?o:{rs:Math.max(i.rs,o.rs),hs:i.hs||o.hs}})(this.ts.get(t),e);this.ts.set(t,n)}ls(){return this.ss}_s(t){const e=this.ts.get(t);return e===void 0?{rs:this.ss}:{rs:Math.max(this.ss,e.rs),hs:e.hs}}us(){this.cs(),this.ns=[{ds:0}]}fs(t){this.cs(),this.ns=[{ds:1,Wt:t}]}ps(t){this.vs(),this.ns.push({ds:5,Wt:t})}cs(){this.vs(),this.ns.push({ds:6})}ws(){this.cs(),this.ns=[{ds:4}]}Ms(t){this.cs(),this.ns.push({ds:2,Wt:t})}gs(t){this.cs(),this.ns.push({ds:3,Wt:t})}bs(){return this.ns}Ss(t){for(const e of t.ns)this.xs(e);this.ss=Math.max(this.ss,t.ss),t.ts.forEach(((e,n)=>{this.es(n,e)}))}static Cs(){return new ds(2)}static ys(){return new ds(3)}xs(t){switch(t.ds){case 0:this.us();break;case 1:this.fs(t.Wt);break;case 2:this.Ms(t.Wt);break;case 3:this.gs(t.Wt);break;case 4:this.ws();break;case 5:this.ps(t.Wt);break;case 6:this.vs()}}vs(){const t=this.ns.findIndex((e=>e.ds===5));t!==-1&&this.ns.splice(t,1)}}class wd{formatTickmarks(t){return t.map((e=>this.format(e)))}}const Bc=".";function Cn(s,t){if(!ti(s))return"n/a";if(!ir(t))throw new TypeError("invalid length");if(t<0||t>16)throw new TypeError("invalid length");return t===0?s.toString():("0000000000000000"+s.toString()).slice(-t)}class Mo extends wd{constructor(t,e){if(super(),e||(e=1),ti(t)&&ir(t)||(t=100),t<0)throw new TypeError("invalid base");this.Ki=t,this.ks=e,this.Ps()}format(t){const e=t<0?"−":"";return t=Math.abs(t),e+this.Ts(t)}Ps(){if(this.Rs=0,this.Ki>0&&this.ks>0){let t=this.Ki;for(;t>1;)t/=10,this.Rs++}}Ts(t){const e=this.Ki/this.ks;let n=Math.floor(t),i="";const o=this.Rs!==void 0?this.Rs:NaN;if(e>1){let l=+(Math.round(t*e)-n*e).toFixed(this.Rs);l>=e&&(l-=e,n+=1),i=Bc+Cn(+l.toFixed(this.Rs)*this.ks,o)}else n=Math.round(n*e)/e,o>0&&(i=Bc+Cn(0,o));return n.toFixed(0)+i}}class _d extends Mo{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Vm extends wd{constructor(t){super(),this.Ds=t}format(t){let e="";return t<0&&(e="-",t=-t),t<995?e+this.Is(t):t<999995?e+this.Is(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),e+this.Is(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),e+this.Is(t/1e9)+"B")}Is(t){let e;const n=Math.pow(10,this.Ds);return e=(t=Math.round(t*n)/n)>=1e-15&&t<1?t.toFixed(this.Ds).replace(/\.?0+$/,""):String(t),e.replace(/(\.[1-9]*)0+$/,((i,o)=>o))}}const Um=/[2-9]/g;class lr{constructor(t=50){this.Vs=0,this.Bs=1,this.Es=1,this.As={},this.Ls=new Map,this.zs=t}Os(){this.Vs=0,this.Ls.clear(),this.Bs=1,this.Es=1,this.As={}}Ii(t,e,n){return this.Ns(t,e,n).width}Di(t,e,n){const i=this.Ns(t,e,n);return((i.actualBoundingBoxAscent||0)-(i.actualBoundingBoxDescent||0))/2}Ns(t,e,n){const i=n||Um,o=String(e).replace(i,"0");if(this.Ls.has(o))return Cs(this.Ls.get(o)).Fs;if(this.Vs===this.zs){const a=this.As[this.Es];delete this.As[this.Es],this.Ls.delete(a),this.Es++,this.Vs--}t.save(),t.textBaseline="middle";const l=t.measureText(o);return t.restore(),l.width===0&&e.length||(this.Ls.set(o,{Fs:l,Ws:this.Bs}),this.As[this.Bs]=o,this.Vs++,this.Bs++),l}}class Hm{constructor(t){this.Hs=null,this.M=null,this.Us="right",this.$s=t}js(t,e,n){this.Hs=t,this.M=e,this.Us=n}st(t){this.M!==null&&this.Hs!==null&&this.Hs.st(t,this.M,this.$s,this.Us)}}class kd{constructor(t,e,n){this.qs=t,this.$s=new lr(50),this.Ys=e,this.O=n,this.F=-1,this.Xt=new Hm(this.$s)}Tt(){const t=this.O.Ks(this.Ys);if(t===null)return null;const e=t.Zs(this.Ys)?t.Gs():this.Ys.Ft();if(e===null)return null;const n=t.Xs(e);if(n==="overlay")return null;const i=this.O.Js();return i.k!==this.F&&(this.F=i.k,this.$s.Os()),this.Xt.js(this.qs.qi(),i,n),this.Xt}}class Km extends gn{constructor(){super(...arguments),this.qt=null}ht(t){this.qt=t}Qs(t,e){var l;if(!((l=this.qt)!=null&&l.It))return null;const{ut:n,ct:i,te:o}=this.qt;return e>=n-i-7&&e<=n+i+7?{ie:this.qt,ne:Math.abs(e-n),se:2,ee:"price-line",te:o}:null}et({context:t,bitmapSize:e,horizontalPixelRatio:n,verticalPixelRatio:i}){if(this.qt===null||this.qt.It===!1)return;const o=Math.round(this.qt.ut*i);o<0||o>e.height||(t.lineCap="butt",t.strokeStyle=this.qt.R,t.lineWidth=Math.floor(this.qt.ct*n),In(t,this.qt.Zt),gd(t,o,0,e.width))}}class _a{constructor(t){this.re={ut:0,R:"rgba(0, 0, 0, 0)",ct:1,Zt:0,It:!1},this.he=new Km,this.xt=!0,this.ae=t,this.le=t.Qt(),this.he.ht(this.re)}kt(){this.xt=!0}Tt(){return this.ae.It()?(this.xt&&(this.oe(),this.xt=!1),this.he):null}}class $m extends _a{constructor(t){super(t)}oe(){this.re.It=!1;const t=this.ae.Ft(),e=t._e()._e;if(e!==2&&e!==3)return;const n=this.ae.N();if(!n.baseLineVisible||!this.ae.It())return;const i=this.ae.Lt();i!==null&&(this.re.It=!0,this.re.ut=t.Nt(i.Wt,i.Wt),this.re.R=n.baseLineColor,this.re.ct=n.baseLineWidth,this.re.Zt=n.baseLineStyle)}
6}class Ym extends gn{constructor(){super(...arguments),this.qt=null}ht(t){this.qt=t}ue(){return this.qt}et({context:t,horizontalPixelRatio:e,verticalPixelRatio:n}){const i=this.qt;if(i===null)return;const o=Math.max(1,Math.floor(e)),l=o%2/2,a=Math.round(i.ce.x*e)+l,c=i.ce.y*n;t.fillStyle=i.de,t.beginPath();const u=Math.max(2,1.5*i.fe)*e;t.arc(a,c,u,0,2*Math.PI,!1),t.fill(),t.fillStyle=i.pe,t.beginPath(),t.arc(a,c,i.ft*e,0,2*Math.PI,!1),t.fill(),t.lineWidth=o,t.strokeStyle=i.ve,t.beginPath(),t.arc(a,c,i.ft*e+o/2,0,2*Math.PI,!1),t.stroke()}}const Qm=[{me:0,we:.25,Me:4,ge:10,be:.25,Se:0,xe:.4,Ce:.8},{me:.25,we:.525,Me:10,ge:14,be:0,Se:0,xe:.8,Ce:0},{me:.525,we:1,Me:14,ge:14,be:0,Se:0,xe:0,Ce:0}];class Gm{constructor(t){this.Xt=new Ym,this.xt=!0,this.ye=!0,this.ke=performance.now(),this.Pe=this.ke-1,this.Te=t}Re(){this.Pe=this.ke-1,this.kt()}De(){if(this.kt(),this.Te.N().lastPriceAnimation===2){const t=performance.now(),e=this.Pe-t;if(e>0)return void(e<650&&(this.Pe+=2600));this.ke=t,this.Pe=t+2600}}kt(){this.xt=!0}Ie(){this.ye=!0}It(){return this.Te.N().lastPriceAnimation!==0}Ve(){switch(this.Te.N().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.Pe}}Tt(){return this.xt?(this.Rt(),this.xt=!1,this.ye=!1):this.ye&&(this.Be(),this.ye=!1),this.Xt}Rt(){this.Xt.ht(null);const t=this.Te.Qt().Et(),e=t.Ee(),n=this.Te.Lt();if(e===null||n===null)return;const i=this.Te.Ae(!0);if(i.Le||!e.ze(i.$n))return;const o={x:t.jt(i.$n),y:this.Te.Ft().Nt(i.Mt,n.Wt)},l=i.R,a=this.Te.N().lineWidth,c=this.Oe(this.Ne(),l);this.Xt.ht({de:l,fe:a,pe:c.pe,ve:c.ve,ft:c.ft,ce:o})}Be(){const t=this.Xt.ue();if(t!==null){const e=this.Oe(this.Ne(),t.de);t.pe=e.pe,t.ve=e.ve,t.ft=e.ft}}Ne(){return this.Ve()?performance.now()-this.ke:2599}Fe(t,e,n,i){const o=n+(i-n)*e;return this.Te.Qt().Xi().Y(t,o)}Oe(t,e){const n=t%2600/2600;let i;for(const u of Qm)if(n>=u.me&&n<=u.we){i=u;break}fs(i!==void 0,"Last price animation internal logic error");const o=(n-i.me)/(i.we-i.me);return{pe:this.Fe(e,o,i.be,i.Se),ve:this.Fe(e,o,i.xe,i.Ce),ft:(l=o,a=i.Me,c=i.ge,a+(c-a)*l)};var l,a,c}}class Xm extends _a{constructor(t){super(t)}oe(){const t=this.re;t.It=!1;const e=this.ae.N();if(!e.priceLineVisible||!this.ae.It())return;const n=this.ae.Ae(e.priceLineSource===0);n.Le||(t.It=!0,t.ut=n.Ei,t.R=this.ae.We(n.R),t.ct=e.priceLineWidth,t.Zt=e.priceLineStyle)}}class Zm extends _o{constructor(t){super(),this.Jt=t}Yi(t,e,n){t.It=!1,e.It=!1;const i=this.Jt;if(!i.It())return;const o=i.N(),l=o.lastValueVisible,a=i.He()!=="",c=o.seriesLastValueMode===0,u=i.Ae(!1);if(u.Le)return;l&&(t.ri=this.Ue(u,l,c),t.It=t.ri.length!==0),(a||c)&&(e.ri=this.$e(u,l,a,c),e.It=e.ri.length>0);const d=i.We(u.R),f=this.Jt.Qt().Xi().Z(d);n.G=f.G,n.Ei=u.Ei,e.Ht=i.Qt().Ut(u.Ei/i.Ft().$t()),t.Ht=d,t.R=f.X,e.R=f.X}$e(t,e,n,i){let o="";const l=this.Jt.He();return n&&l.length!==0&&(o+=`${l} `),e&&i&&(o+=this.Jt.Ft().je()?t.qe:t.Ye),o.trim()}Ue(t,e,n){return e?n?this.Jt.Ft().je()?t.Ye:t.qe:t.ri:""}}function Wc(s,t,e,n){const i=Number.isFinite(t),o=Number.isFinite(e);return i&&o?s(t,e):i||o?i?t:e:n}class bs{constructor(t,e){this.Ke=t,this.Ze=e}Ge(t){return t!==null&&this.Ke===t.Ke&&this.Ze===t.Ze}Xe(){return new bs(this.Ke,this.Ze)}Je(){return this.Ke}Qe(){return this.Ze}tr(){return this.Ze-this.Ke}Gi(){return this.Ze===this.Ke||Number.isNaN(this.Ze)||Number.isNaN(this.Ke)}Ss(t){return t===null?this:new bs(Wc(Math.min,this.Je(),t.Je(),-1/0),Wc(Math.max,this.Qe(),t.Qe(),1/0))}ir(t){if(!ti(t)||this.Ze-this.Ke===0)return;const e=.5*(this.Ze+this.Ke);let n=this.Ze-e,i=this.Ke-e;n*=t,i*=t,this.Ze=e+n,this.Ke=e+i}nr(t){ti(t)&&(this.Ze+=t,this.Ke+=t)}sr(){return{minValue:this.Ke,maxValue:this.Ze}}static er(t){return t===null?null:new bs(t.minValue,t.maxValue)}}class uo{constructor(t,e){this.rr=t,this.hr=e||null}ar(){return this.rr}lr(){return this.hr}sr(){return{priceRange:this.rr===null?null:this.rr.sr(),margins:this.hr||void 0}}static er(t){return t===null?null:new uo(bs.er(t.priceRange),t.margins)}}const Jm=[2,4,8,16,32,64,128,256,512],tp="Custom series with conflation reducer must have a priceValueBuilder method";class ep extends _a{constructor(t,e){super(t),this._r=e}oe(){const t=this.re;t.It=!1;const e=this._r.N();if(!this.ae.It()||!e.lineVisible)return;const n=this._r.ur();n!==null&&(t.It=!0,t.ut=n,t.R=e.color,t.ct=e.lineWidth,t.Zt=e.lineStyle,t.te=this._r.N().id)}}class sp extends _o{constructor(t,e){super(),this.Te=t,this._r=e}Yi(t,e,n){t.It=!1,e.It=!1;const i=this._r.N(),o=i.axisLabelVisible,l=i.title!=="",a=this.Te;if(!o||!a.It())return;const c=this._r.ur();if(c===null)return;
6l&&(e.ri=i.title,e.It=!0),e.Ht=a.Qt().Ut(c/a.Ft().$t()),t.ri=this.cr(i.price),t.It=!0;const u=this.Te.Qt().Xi().Z(i.axisLabelColor||i.color);n.G=u.G;const d=i.axisLabelTextColor||u.X;t.R=d,e.R=d,n.Ei=c}cr(t){const e=this.Te.Lt();return e===null?"":this.Te.Ft().Ji(t,e.Wt)}}class np{constructor(t,e){this.Te=t,this.yn=e,this.dr=new ep(t,this),this.qs=new sp(t,this),this.pr=new kd(this.qs,t,t.Qt())}vr(t){Rs(this.yn,t),this.kt(),this.Te.Qt().mr()}N(){return this.yn}wr(){return this.dr}Mr(){return this.pr}gr(){return this.qs}kt(){this.dr.kt(),this.qs.kt()}ur(){const t=this.Te,e=t.Ft();if(t.Qt().Et().Gi()||e.Gi())return null;const n=t.Lt();return n===null?null:e.Nt(this.yn.price,n.Wt)}}class ip{constructor(){this.br=new WeakMap}Sr(t,e,n){const i=1/e*n;if(t>=i)return 1;const o=i/t,l=Math.pow(2,Math.floor(Math.log2(o)));return Math.min(l,512)}Cr(t,e,n,i=!1,o){if(t.length===0||e<=1)return t;const l=this.yr(e);if(l<=1)return t;const a=this.kr(t);let c=a.Pr.get(l);return c!==void 0||(c=this.Tr(t,l,n,i,o,a.Pr),a.Pr.set(l,c)),c}Rr(t,e,n,i,o=!1,l){if(n<1||t.length===0)return t;const a=this.kr(t),c=a.Pr.get(n);if(!c)return this.Cr(t,n,i,o,l);const u=this.Dr(t,e,n,c,o,i,l);return a.Pr.set(n,u),u}yr(t){if(t<=2)return 2;for(const e of Jm)if(t<=e)return e;return 512}Ir(t){if(t.length===0)return 0;const e=t[0],n=t[t.length-1];return 31*t.length+17*e.$n+13*n.$n}Tr(t,e,n,i=!1,o,l=new Map){if(e===2)return this.Vr(t,2,n,i,o);const a=e/2;let c=l.get(a);return c||(c=this.Tr(t,a,n,i,o,l),l.set(a,c)),this.Br(c,n,i,o)}Vr(t,e,n,i=!1,o){const l=this.Er(t,e,n,i,o);return this.Ar(l,i)}Br(t,e,n=!1,i){const o=this.Er(t,2,e,n,i);return this.Ar(o,n)}Er(t,e,n,i=!1,o){const l=[];for(let a=0;a<t.length;a+=e)if(t.length-a>=e){const c=this.Lr(t[a],t[a+1],n,i,o);c.zr=!1,l.push(c)}else if(l.length===0)l.push(this.Or(t[a],!0));else{const c=l[l.length-1];l[l.length-1]=this.Nr(c,t[a],n,i,o)}return l}Fr(t,e){return(t??1)+(e??1)}Lr(t,e,n,i=!1,o){if(!i||!n||!o){const u=t.Wt[1]>e.Wt[1]?t.Wt[1]:e.Wt[1],d=t.Wt[2]<e.Wt[2]?t.Wt[2]:e.Wt[2];return{Wr:t.$n,Hr:e.$n,Ur:t.wt,$r:e.wt,jr:t.Wt[0],qr:u,Yr:d,Kr:e.Wt[3],Zr:this.Fr(t.Zr,e.Zr),Gr:void 0,zr:!1}}const l=n(this.Xr(t,o),this.Xr(e,o)),a=o(l),c=a.length?a[a.length-1]:0;return{Wr:t.$n,Hr:e.$n,Ur:t.wt,$r:e.wt,jr:t.Wt[0],qr:Math.max(t.Wt[1],c),Yr:Math.min(t.Wt[2],c),Kr:c,Zr:this.Fr(t.Zr,e.Zr),Gr:l,zr:!1}}Nr(t,e,n,i=!1,o){if(!i||!n||!o)return{Wr:t.Wr,Hr:e.$n,Ur:t.Ur,$r:e.wt,jr:t.jr,qr:t.qr>e.Wt[1]?t.qr:e.Wt[1],Yr:t.Yr<e.Wt[2]?t.Yr:e.Wt[2],Kr:e.Wt[3],Zr:t.Zr+(e.Zr??1),Gr:t.Gr,zr:!1};const l=t.Gr,a=this.Xr(e,o),c=l?{data:l,index:t.Wr,originalTime:t.Ur,time:t.Ur,priceValues:o(l)}:null,u=c?n(c,a):a.data,d=c?o(u):a.priceValues,f=d.length?d[d.length-1]:0;return{Wr:t.Wr,Hr:e.$n,Ur:t.Ur,$r:e.wt,jr:t.jr,qr:Math.max(t.qr,f),Yr:Math.min(t.Yr,f),Kr:f,Zr:t.Zr+(e.Zr??1),Gr:u,zr:!1}}Jr(t,e,n,i,o,l,a=!1,c){const u=e===i?o:t[e];if(n-e==1)return this.Or(u,!0);const d=e+1===i?o:t[e+1];let f=this.Lr(u,d,l,a,c);for(let g=e+2;g<n;g++){const v=g===i?o:t[g];f=this.Nr(f,v,l,a,c)}return f}Xr(t,e){const n=t.ue??{};return{data:t.ue,index:t.$n,originalTime:t.Qr,time:t.wt,priceValues:e(n)}}th(t,e=!1){const n=e===!0,i=!!t.Gr;return{$n:t.Wr,wt:t.Ur,Qr:t.Ur,Wt:[n?t.Kr:t.jr,t.qr,t.Yr,t.Kr],Zr:t.Zr,ue:n?i?t.Gr:{wt:t.Ur}:void 0}}Ar(t,e=!1){return t.map((n=>this.th(n,e)))}Dr(t,e,n,i,o=!1,l,a){if(i.length===0)return i;const c=t.length-1,u=Math.floor(c/n)*n;if(Math.min(u+n,t.length)-u<n&&t.length>n){const d=t.slice();return d[d.length-1]=e,this.Cr(d,n,l,o,a)}if(Math.floor((c-1)/n)===Math.floor(c/n)||i.length===1){const d=Math.min(u+n,t.length),f=d-u;if(f<=0)return i;const g=f===1?this.Or(u===c?e:t[u],!0):this.Jr(t,u,d,c,e,l,o,a);return i[i.length-1]=this.th(g,o),i}{const d=t.slice();return d[d.length-1]=e,this.Cr(d,n,l,o,a)}}Or(t,e=!1){return{Wr:t.$n,Hr:t.$n,Ur:t.wt,$r:t.wt,jr:t.Wt[0],qr:t.Wt[1],Yr:t.Wt[2],Kr:t.Wt[3],Zr:t.Zr??1,Gr:t.ue,zr:e}}kr(t){const e=this.ih(t),n=this.Ir(t);return e.nh!==n&&(e.Pr.clear(),e.nh=n),e}ih(t){let e=this.br.get(t);return e===void 0&&(e={nh:this.Ir(t),Pr:new Map},this.br.set(t,e)),e}}class rp extends bd{constructor(t){super(),this.sn=t}Qt(){return this.sn}}const op={Bar:(s,t,e,n)=>{const i=t.upColor,o=t.downColor,l=ct(s(e,n)),a=On(l.Wt[0])<=On(l.Wt[3]);return{sh:l.R??(a?i:o)}},Candlestick:(s,t,e,n)=>{const i=t.upColor,o=t.downColor,l=t.borderUpColor,a=t.borderDownColor,c=t.wickUpColor,u=t.wickDownColor,d=ct(s(e,n)),f=On(d.Wt[0])<=On(d.Wt[3]);return{sh:d.R??(f?i:o),eh:d.Ht??(f?l:a),rh:d.hh??(f?c:u)}},Custom:(s,t,e,n)=>({sh:ct(s(e,n)).R??t.color}),Area:(s,t,e,n)=>{const i=ct(s(e,n));return{sh:i.vt??t.lineColor,vt:i.vt??t.lineColor,ah:i.ah??t.topColor,oh:i.oh??t.bottomColor}},Baseline:(s,t,e,n)=>{const i=ct(s(e,n));return{sh:i.Wt[3]>=t.baseValue.price?t.topLineColor:t.bottomLineColor,_h:i._h??t.topLineColor,uh:i.uh??t.bottomLineColor,dh:i.dh??t.topFillColor1,fh:i.fh??t.topFillColor2,ph:i.ph??t.bottomFillColor1,mh:i.mh??t.bottomFillColor2}},Line:(s,t,e,n)=>{const i=ct(s(e,n));return{sh:i.R??t.color,vt:i.R??t.color}},Histogram:(s,t,e,n)=>({sh:ct(s(e,n)).R??t.color})};class lp{constructor(t){this.wh=(e,n)=>n!==void 0?n.Wt:this.Te.Un().Mh(e),this.Te=t,this.gh=op[t.bh()]}Sh(t,e){return this.gh(this.wh,this.Te.N(),t,e)}}function Md(s,t,e,n,i=0,o=t.length){let l=o-i;for(;0<l;){const a=l>>1,c=i+a;n(t[c],e)===s?(i=c+1,l-=a+1):l=a}return i}const ei=Md.bind(null,!0),ka=Md.bind(null,!1);var qc;(function(s){s[s.NearestLeft=-1]="NearestLeft",s[s.None=0]="None",s[s.NearestRight=1]="NearestRight"})(qc||(qc={}));const Pn=30;class ap{constructor(){this.xh=[],this.Ch=new Map,this.yh=new Map,this.kh=[]}Ph(){return this.Th()>0?this.xh[this.xh.length-1]:null}Rh(){return this.Th()>0?this.Dh(0):null}Qn(){return this.Th()>0?this.Dh(this.xh.length-1):null}Th(){return this.xh.length}Gi(){return this.Th()===0}ze(t){return this.Ih(t,0)!==null}Mh(t){return this.Hn(t)}Hn(t,e=0){const n=this.Ih(t,e);return n===null?null:{...this.Vh(n),$n:this.Dh(n)}}Bh(){return this.xh}Eh(t,e,n){if(this.Gi())return null;let i=null;for(const o of n)i=Er(i,this.Ah(t,e,o));return i}ht(t){this.yh.clear(),this.Ch.clear(),this.xh=t,this.kh=t.map((e=>e.$n))}Lh(){return this.kh}Dh(t){return this.xh[t].$n}Vh(t){return this.xh[t]}Ih(t,e){const n=this.zh(t);if(n===null&&e!==0)switch(e){case-1:return this.Oh(t);case 1:return this.Nh(t);default:throw new TypeError("Unknown search mode")}return n}Oh(t){let e=this.Fh(t);return e>0&&(e-=1),e!==this.xh.length&&this.Dh(e)<t?e:null}Nh(t){const e=this.Wh(t);return e!==this.xh.length&&t<this.Dh(e)?e:null}zh(t){const e=this.Fh(t);return e===this.xh.length||t<this.xh[e].$n?null:e}Fh(t){return ei(this.xh,t,((e,n)=>e.$n<n))}Wh(t){return ka(this.xh,t,((e,n)=>e.$n>n))}Hh(t,e,n){let i=null;for(let o=t;o<e;o++){const l=this.xh[o].Wt[n];Number.isNaN(l)||(i===null?i={Uh:l,$h:l}:(l<i.Uh&&(i.Uh=l),l>i.$h&&(i.$h=l)))}return i}Ah(t,e,n){if(this.Gi())return null;let i=null;const o=ct(this.Rh()),l=ct(this.Qn()),a=Math.max(t,o),c=Math.min(e,l),u=Math.ceil(a/Pn)*Pn,d=Math.max(u,Math.floor(c/Pn)*Pn);{const g=this.Fh(a),v=this.Wh(Math.min(c,u,e));i=Er(i,this.Hh(g,v,n))}let f=this.Ch.get(n);f===void 0&&(f=new Map,this.Ch.set(n,f));for(let g=Math.max(u+1,a);g<d;g+=Pn){const v=Math.floor(g/Pn);let b=f.get(v);if(b===void 0){const w=this.Fh(v*Pn),k=this.Wh((v+1)*Pn-1);b=this.Hh(w,k,n),f.set(v,b)}i=Er(i,b)}{const g=this.Fh(d),v=this.Wh(c);i=Er(i,this.Hh(g,v,n))}return i}}function Er(s,t){return s===null?t:t===null?s:{Uh:Math.min(s.Uh,t.Uh),$h:Math.max(s.$h,t.$h)}}function Vo(){return new ap}const fo={setLineStyle:In};class cp{constructor(t){this.jh=t}st(t,e,n){this.jh.draw(t,fo)}qh(t,e,n){var i,o;
6(o=(i=this.jh).drawBackground)==null||o.call(i,t,fo)}}class hp{constructor(t){this.Ls=null,this.Yh=t}Tt(){var n;const t=this.Yh.renderer();if(t===null)return null;if(((n=this.Ls)==null?void 0:n.Kh)===t)return this.Ls.Zh;const e=new cp(t);return this.Ls={Kh:t,Zh:e},e}Gh(){var t,e;return((e=(t=this.Yh).zOrder)==null?void 0:e.call(t))??"normal"}}class jd{constructor(t){this.Xh=null,this.Jh=t}Qh(){return this.Jh}Nn(){var t,e;(e=(t=this.Jh).updateAllViews)==null||e.call(t)}jn(){var n,i,o;const t=((i=(n=this.Jh).paneViews)==null?void 0:i.call(n))??[];if(((o=this.Xh)==null?void 0:o.Kh)===t)return this.Xh.Zh;const e=t.map((l=>new hp(l)));return this.Xh={Kh:t,Zh:e},e}Qs(t,e){var n,i;return((i=(n=this.Jh).hitTest)==null?void 0:i.call(n,t,e))??null}}let up=class extends jd{cn(){return[]}};class dp{constructor(t){this.jh=t}st(t,e,n){this.jh.draw(t,fo)}qh(t,e,n){var i,o;(o=(i=this.jh).drawBackground)==null||o.call(i,t,fo)}}class Vc{constructor(t){this.Ls=null,this.Yh=t}Tt(){var n;const t=this.Yh.renderer();if(t===null)return null;if(((n=this.Ls)==null?void 0:n.Kh)===t)return this.Ls.Zh;const e=new dp(t);return this.Ls={Kh:t,Zh:e},e}Gh(){var t,e;return((e=(t=this.Yh).zOrder)==null?void 0:e.call(t))??"normal"}}function Sd(s){var t,e,n;return{ri:s.text(),Ei:s.coordinate(),Vi:(t=s.fixedCoordinate)==null?void 0:t.call(s),R:s.textColor(),G:s.backColor(),It:((e=s.visible)==null?void 0:e.call(s))??!0,pi:((n=s.tickVisible)==null?void 0:n.call(s))??!0}}class fp{constructor(t,e){this.Xt=new yd,this.ta=t,this.ia=e}Tt(){return this.Xt.ht({nn:this.ia.nn(),...Sd(this.ta)}),this.Xt}}class mp extends _o{constructor(t,e){super(),this.ta=t,this.Ki=e}Yi(t,e,n){const i=Sd(this.ta);n.G=i.G,t.R=i.R;const o=2/12*this.Ki.k();n.Ti=o,n.Ri=o,n.Ei=i.Ei,n.Vi=i.Vi,t.ri=i.ri,t.It=i.It,t.pi=i.pi}}class pp extends jd{constructor(t,e){super(t),this.na=null,this.sa=null,this.ea=null,this.ra=null,this.Te=e}dn(){var i,o,l;const t=((o=(i=this.Jh).timeAxisViews)==null?void 0:o.call(i))??[];if(((l=this.na)==null?void 0:l.Kh)===t)return this.na.Zh;const e=this.Te.Qt().Et(),n=t.map((a=>new fp(a,e)));return this.na={Kh:t,Zh:n},n}qn(){var i,o,l;const t=((o=(i=this.Jh).priceAxisViews)==null?void 0:o.call(i))??[];if(((l=this.sa)==null?void 0:l.Kh)===t)return this.sa.Zh;const e=this.Te.Ft(),n=t.map((a=>new mp(a,e)));return this.sa={Kh:t,Zh:n},n}ha(){var n,i,o;const t=((i=(n=this.Jh).priceAxisPaneViews)==null?void 0:i.call(n))??[];if(((o=this.ea)==null?void 0:o.Kh)===t)return this.ea.Zh;const e=t.map((l=>new Vc(l)));return this.ea={Kh:t,Zh:e},e}aa(){var n,i,o;const t=((i=(n=this.Jh).timeAxisPaneViews)==null?void 0:i.call(n))??[];if(((o=this.ra)==null?void 0:o.Kh)===t)return this.ra.Zh;const e=t.map((l=>new Vc(l)));return this.ra={Kh:t,Zh:e},e}la(t,e){var n,i;return((i=(n=this.Jh).autoscaleInfo)==null?void 0:i.call(n,t,e))??null}}function Uo(s,t,e,n){s.forEach((i=>{t(i).forEach((o=>{o.Gh()===e&&n.push(o)}))}))}function Ho(s){return s.jn()}function gp(s){return s.ha()}function vp(s){return s.aa()}const xp=["Area","Line","Baseline"];class jo extends rp{constructor(t,e,n,i,o){super(t),this.qt=Vo(),this.dr=new Xm(this),this.oa=[],this._a=new $m(this),this.ua=null,this.ca=null,this.da=null,this.fa=[],this.pa=new ip,this.va=new Map,this.ma=null,this.yn=n,this.wa=e;const l=new Zm(this);if(this.mn=[l],this.pr=new kd(l,this,t),xp.includes(this.wa)&&(this.ua=new Gm(this)),this.Ma(),this.Yh=i(this,this.Qt(),o),this.wa==="Custom"){const a=this.Yh;a.ga&&this.ba(a.ga)}}m(){this.da!==null&&clearTimeout(this.da)}We(t){return this.yn.priceLineColor||t}Ae(t){const e={Le:!0},n=this.Ft();if(this.Qt().Et().Gi()||n.Gi()||this.qt.Gi())return e;const i=this.Qt().Et().Ee(),o=this.Lt();if(i===null||o===null)return e;let l,a;if(t){const f=this.qt.Ph();if(f===null)return e;l=f,a=f.$n}else{const f=this.qt.Hn(i.bi(),-1);if(f===null||(l=this.qt.Mh(f.$n),l===null))return e;a=f.$n}const c=l.Wt[3],u=this.Sa().Sh(a,{Wt:l}),d=n.Nt(c,o.Wt);return{Le:!1,Mt:c,ri:n.Ji(c,o.Wt),qe:n.xa(c),Ye:n.Ca(c,o.Wt),R:u.sh,Ei:d,$n:a}}Sa(){return this.ca!==null||(this.ca=new lp(this)),this.ca}N(){return this.yn}vr(t){const e=this.Qt(),{priceScaleId:n,visible:i,priceFormat:o}=t;n!==void 0&&n!==this.yn.priceScaleId&&e.ya(this,n),i!==void 0&&i!==this.yn.visible&&e.ka();const l=t.conflationThresholdFactor!==void 0;Rs(this.yn,t),l&&(this.va.clear(),this.Qt().mr()),o!==void 0&&(this.Ma(),e.Pa()),e.Ta(this),e.Ra(),this.Yh.kt("options")}ht(t,e){this.qt.ht(t),this.va.clear();const n=this.Qt().Et().N();n.enableConflation&&n.precomputeConflationOnInit&&this.Da(n.prec
6omputeConflationPriority),this.Yh.kt("data"),this.ua!==null&&(e&&e.Ia?this.ua.De():t.length===0&&this.ua.Re());const i=this.Qt().Ks(this);this.Qt().Va(i),this.Qt().Ta(this),this.Qt().Ra(),this.Qt().mr()}Ba(t){const e=new np(this,t);return this.oa.push(e),this.Qt().Ta(this),e}Ea(t){const e=this.oa.indexOf(t);e!==-1&&this.oa.splice(e,1),this.Qt().Ta(this)}Aa(){return this.oa}bh(){return this.wa}Lt(){const t=this.La();return t===null?null:{Wt:t.Wt[3],za:t.wt}}La(){const t=this.Qt().Et().Ee();if(t===null)return null;const e=t.Oa();return this.qt.Hn(e,1)}Un(){return this.qt}ba(t){this.ma=t,this.va.clear()}Na(){return!!this.Qt().Et().N().enableConflation&&this.Fa()>1}Rr(t){if(!this.Na())return;const e=this.Fa();if(!this.va.has(e))return;const n=this.wa==="Custom",i=n&&this.ma||void 0,o=n&&this.Yh.Wa?c=>{const u=c,d=this.Yh.Wa(u);return Array.isArray(d)?d:[typeof d=="number"?d:0]}:void 0,l=this.pa.Rr(this.qt.Bh(),t,e,i,n,o),a=Vo();a.ht(l),this.va.set(e,a)}Ha(){const t=this.Qt().Et().N().enableConflation;if(this.wa==="Custom"&&this.ma===null)return this.qt;if(!t)return this.qt;const e=this.Fa(),n=this.va.get(e);return n||(this.Ua(e),this.va.get(e)??this.qt)}$a(t){const e=this.qt.Mh(t);return e===null?null:this.wa==="Bar"||this.wa==="Candlestick"||this.wa==="Custom"?{jr:e.Wt[0],qr:e.Wt[1],Yr:e.Wt[2],Kr:e.Wt[3]}:e.Wt[3]}ja(t){const e=[];Uo(this.fa,Ho,"top",e);const n=this.ua;return n!==null&&n.It()&&(this.da===null&&n.Ve()&&(this.da=setTimeout((()=>{this.da=null,this.Qt().qa()}),0)),n.Ie(),e.unshift(n)),e}jn(){const t=[];this.Ya()||t.push(this._a),t.push(this.Yh,this.dr);const e=this.oa.map((n=>n.wr()));return t.push(...e),Uo(this.fa,Ho,"normal",t),t}Ka(){return this.Za(Ho,"bottom")}Ga(t){return this.Za(gp,t)}Xa(t){return this.Za(vp,t)}Ja(t,e){return this.fa.map((n=>n.Qs(t,e))).filter((n=>n!==null))}cn(){return[this.pr,...this.oa.map((t=>t.Mr()))]}qn(t,e){if(e!==this.hn&&!this.Ya())return[];const n=[...this.mn];for(const i of this.oa)n.push(i.gr());return this.fa.forEach((i=>{n.push(...i.qn())})),n}dn(){const t=[];return this.fa.forEach((e=>{t.push(...e.dn())})),t}la(t,e){if(this.yn.autoscaleInfoProvider!==void 0){const n=this.yn.autoscaleInfoProvider((()=>{const i=this.Qa(t,e);return i===null?null:i.sr()}));return uo.er(n)}return this.Qa(t,e)}Kh(){const t=this.yn.priceFormat;return t.base??1/t.minMove}tl(){return this.il}Nn(){var t;this.Yh.kt();for(const e of this.mn)e.kt();for(const e of this.oa)e.kt();this.dr.kt(),this._a.kt(),(t=this.ua)==null||t.kt(),this.fa.forEach((e=>e.Nn()))}Ft(){return ct(super.Ft())}At(t){if(!((this.wa==="Line"||this.wa==="Area"||this.wa==="Baseline")&&this.yn.crosshairMarkerVisible))return null;const e=this.qt.Mh(t);return e===null?null:{Mt:e.Wt[3],ft:this.nl(),Ht:this.sl(),Ot:this.el(),zt:this.rl(t)}}He(){return this.yn.title}It(){return this.yn.visible}hl(t){this.fa.push(new pp(t,this))}al(t){this.fa=this.fa.filter((e=>e.Qh()!==t))}ll(){if(this.wa==="Custom")return t=>this.Yh.Wa(t)}ol(){if(this.wa==="Custom")return t=>this.Yh._l(t)}ul(){return this.qt.Lh()}Ya(){return!ko(this.Ft().cl())}Qa(t,e){if(!ir(t)||!ir(e)||this.qt.Gi())return null;const n=this.wa==="Line"||this.wa==="Area"||this.wa==="Baseline"||this.wa==="Histogram"?[3]:[2,1],i=this.qt.Eh(t,e,n);let o=i!==null?new bs(i.Uh,i.$h):null,l=null;if(this.bh()==="Histogram"){const a=this.yn.base,c=new bs(a,a);o=o!==null?o.Ss(c):c}return this.fa.forEach((a=>{const c=a.la(t,e);if(c!=null&&c.priceRange){const u=new bs(c.priceRange.minValue,c.priceRange.maxValue);o=o!==null?o.Ss(u):u}c!=null&&c.margins&&(l=c.margins)})),new uo(o,l)}nl(){switch(this.wa){case"Line":case"Area":case"Baseline":return this.yn.crosshairMarkerRadius}return 0}sl(){switch(this.wa){case"Line":case"Area":case"Baseline":{const t=this.yn.crosshairMarkerBorderColor;if(t.length!==0)return t}}return null}el(){switch(this.wa){case"Line":case"Area":case"Baseline":return this.yn.crosshairMarkerBorderWidth}return 0}rl(t){switch(this.wa){case"Line":case"Area":case"Baseline":{const e=this.yn.crosshairMarkerBackgroundColor;if(e.length!==0)return e}}return this.Sa().Sh(t).sh}
6Ma(){switch(this.yn.priceFormat.type){case"custom":{const t=this.yn.priceFormat.formatter;this.il={format:t,formatTickmarks:this.yn.priceFormat.tickmarksFormatter??(e=>e.map(t))};break}case"volume":this.il=new Vm(this.yn.priceFormat.precision);break;case"percent":this.il=new _d(this.yn.priceFormat.precision);break;default:{const t=Math.pow(10,this.yn.priceFormat.precision);this.il=new Mo(t,this.yn.priceFormat.minMove*t)}}this.hn!==null&&this.hn.dl()}Za(t,e){const n=[];return Uo(this.fa,t,e,n),n}Fa(){const{fl:t,pl:e,vl:n}=this.ml();return this.pa.Sr(t,e,n)}ml(){const t=this.Qt().Et(),e=t.fl(),n=window.devicePixelRatio||1,i=t.N().conflationThresholdFactor;return{fl:e,pl:n,vl:this.yn.conflationThresholdFactor??i??1}}wl(t){const e=this.qt.Bh();let n;if(this.wa==="Custom"&&this.ma!==null){const o=this.ll();if(!o)throw new Error(tp);n=this.pa.Cr(e,t,this.ma,!0,(l=>o(l)))}else n=this.pa.Cr(e,t);const i=Vo();return i.ht(n),i}Ua(t){const e=this.wl(t);this.va.set(t,e)}Da(t){var n;if(this.wa==="Custom"&&(this.ma===null||!this.ll()))return;this.va.clear();const e=this.Qt().Et().Ml();for(const i of e){const o=()=>{this.gl(i)},l=typeof window=="object"&&window||typeof self=="object"&&self;(n=l==null?void 0:l.Sl)!=null&&n.bl?l.Sl.bl((()=>{o()}),{se:t}):Promise.resolve().then((()=>o()))}}gl(t){if(this.va.has(t)||this.qt.Bh().length===0)return;const e=this.wl(t);this.va.set(t,e)}}const yp=[3],bp=[0,1,2,3];class wp{constructor(t){this.yn=t}xl(t,e,n){let i=t;if(this.yn.mode===0)return i;const o=n.Pn(),l=o.Lt();if(l===null)return i;const a=o.Nt(t,l),c=n.Cl().filter((d=>d instanceof jo)).reduce(((d,f)=>{if(n.Zs(f)||!f.It())return d;const g=f.Ft(),v=f.Un();if(g.Gi()||!v.ze(e))return d;const b=v.Mh(e);if(b===null)return d;const w=On(f.Lt()),k=this.yn.mode===3?bp:yp;return d.concat(k.map((y=>g.Nt(b.Wt[y],w.Wt))))}),[]);if(c.length===0)return i;c.sort(((d,f)=>Math.abs(d-a)-Math.abs(f-a)));const u=c[0];return i=o.Tn(u,l),i}}function ki(s,t,e){return Math.min(Math.max(s,t),e)}function Fr(s,t,e){return t-s<=e}function Ma(s){const t=Math.ceil(s);return t%2==0?t-1:t}class _p extends gn{constructor(){super(...arguments),this.qt=null}ht(t){this.qt=t}et({context:t,bitmapSize:e,horizontalPixelRatio:n,verticalPixelRatio:i}){if(this.qt===null)return;const o=Math.max(1,Math.floor(n));t.lineWidth=o,(function(l,a){l.save(),l.lineWidth%2&&l.translate(.5,.5),a(),l.restore()})(t,(()=>{const l=ct(this.qt);if(l.yl){t.strokeStyle=l.kl,In(t,l.Pl),t.beginPath();for(const a of l.Tl){const c=Math.round(a.Rl*n);t.moveTo(c,-o),t.lineTo(c,e.height+o)}t.stroke()}if(l.Dl){t.strokeStyle=l.Il,In(t,l.Vl),t.beginPath();for(const a of l.Bl){const c=Math.round(a.Rl*i);t.moveTo(-o,c),t.lineTo(e.width+o,c)}t.stroke()}}))}}class kp{constructor(t){this.Xt=new _p,this.xt=!0,this.yt=t}kt(){this.xt=!0}Tt(){if(this.xt){const t=this.yt.Qt().N().grid,e={Dl:t.horzLines.visible,yl:t.vertLines.visible,Il:t.horzLines.color,kl:t.vertLines.color,Vl:t.horzLines.style,Pl:t.vertLines.style,Bl:this.yt.Pn().El(),Tl:(this.yt.Qt().Et().El()||[]).map((n=>({Rl:n.coord})))};this.Xt.ht(e),this.xt=!1}return this.Xt}}class Mp{constructor(t){this.Yh=new kp(t)}wr(){return this.Yh}}const Ko={Al:4,Ll:1e-4};function bi(s,t){const e=100*(s-t)/t;return t<0?-e:e}function jp(s,t){const e=bi(s.Je(),t),n=bi(s.Qe(),t);return new bs(e,n)}function Qi(s,t){const e=100*(s-t)/t+100;return t<0?-e:e}function Sp(s,t){const e=Qi(s.Je(),t),n=Qi(s.Qe(),t);return new bs(e,n)}function mo(s,t){const e=Math.abs(s);if(e<1e-15)return 0;const n=Math.log10(e+t.Ll)+t.Al;return s<0?-n:n}function Gi(s,t){const e=Math.abs(s);if(e<1e-15)return 0;const n=Math.pow(10,e-t.Al)-t.Ll;return s<0?-n:n}function Bi(s,t){if(s===null)return null;const e=mo(s.Je(),t),n=mo(s.Qe(),t);return new bs(e,n)}function wi(s,t){if(s===null)return null;const e=Gi(s.Je(),t),n=Gi(s.Qe(),t);return new bs(e,n)}function $o(s){if(s===null)return Ko;const t=Math.abs(s.Qe()-s.Je());if(t>=1||t<1e-15)return Ko;const e=Math.ceil(Math.abs(Math.log10(t))),n=Ko.Al+e;return{Al:n,Ll:1/Math.pow(10,n)}}class Yo{constructor(t,e){if(this.zl=t,this.Ol=e,(function(n){if(n<0)return!1;if(n>1e18)return!0;for(let i=n;i>1;i/=10)if(i%10!=0)return!1;return!0})(this.zl))this.Nl=[2,2.5,2];else{this.Nl=[];for(let n=this.zl;n!==1;){if(n%2==0)this.Nl.push(2),n/=2;else{if(n%5!=0)throw new Error("unexpected base");this.Nl.push(2,2.5),n/=5}if(this.Nl.length>100)throw new Error("something wrong with base")}}}Fl(t,e,n){const i=this.zl===0?0:1/this.zl;let o=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-e)))),l=0,a=this.Ol[0];for(;;){const f=Fr(o,i,1e-14)&&o>
6i+1e-14,g=Fr(o,n*a,1e-14),v=Fr(o,1,1e-14);if(!(f&&g&&v))break;o/=a,a=this.Ol[++l%this.Ol.length]}if(o<=i+1e-14&&(o=i),o=Math.max(1,o),this.Nl.length>0&&(c=o,u=1,d=1e-14,Math.abs(c-u)<d))for(l=0,a=this.Nl[0];Fr(o,n*a,1e-14)&&o>i+1e-14;)o/=a,a=this.Nl[++l%this.Nl.length];var c,u,d;return o}}class Uc{constructor(t,e,n,i){this.Wl=[],this.Ki=t,this.zl=e,this.Hl=n,this.Ul=i}Fl(t,e){if(t<e)throw new Error("high < low");const n=this.Ki.$t(),i=(t-e)*this.$l()/n,o=new Yo(this.zl,[2,2.5,2]),l=new Yo(this.zl,[2,2,2.5]),a=new Yo(this.zl,[2.5,2,2]),c=[];return c.push(o.Fl(t,e,i),l.Fl(t,e,i),a.Fl(t,e,i)),(function(u){if(u.length<1)throw Error("array is empty");let d=u[0];for(let f=1;f<u.length;++f)u[f]<d&&(d=u[f]);return d})(c)}jl(){const t=this.Ki,e=t.Lt();if(e===null)return void(this.Wl=[]);const n=t.$t(),i=this.Hl(n-1,e),o=this.Hl(0,e),l=this.Ki.N().entireTextOnly?this.ql()/2:0,a=l,c=n-1-l,u=Math.max(i,o),d=Math.min(i,o);if(u===d)return void(this.Wl=[]);const f=this.Fl(u,d);if(this.Yl(e,f,u,d,a,c),t.Kl()&&this.Zl(f,d,u)){const b=this.Ki.Gl();this.Xl(e,f,a,c,b,2*b)}const g=this.Wl.map((b=>b.Jl)),v=this.Ki.Ql(g);for(let b=0;b<this.Wl.length;b++)this.Wl[b].io=v[b]}El(){return this.Wl}ql(){return this.Ki.k()}$l(){return Math.ceil(this.ql()*this.Ki.N().tickMarkDensity)}Yl(t,e,n,i,o,l){const a=this.Wl,c=this.Ki;let u=n%e;u+=u<0?e:0;const d=n>=i?1:-1;let f=null,g=0;for(let v=n-u;v>i;v-=e){const b=this.Ul(v,t,!0);f!==null&&Math.abs(b-f)<this.$l()||b<o||b>l||(g<a.length?(a[g].Rl=b,a[g].io=c.no(v),a[g].Jl=v):a.push({Rl:b,io:c.no(v),Jl:v}),g++,f=b,c.so()&&(e=this.Fl(v*d,i)))}a.length=g}Xl(t,e,n,i,o,l){const a=this.Wl,c=this.eo(t,n,o,l),u=this.eo(t,i,-l,-o),d=this.Ul(0,t,!0)-this.Ul(e,t,!0);a.length>0&&a[0].Rl-c.Rl<d/2&&a.shift(),a.length>0&&u.Rl-a[a.length-1].Rl<d/2&&a.pop(),a.unshift(c),a.push(u)}eo(t,e,n,i){const o=(n+i)/2,l=this.Hl(e+n,t),a=this.Hl(e+i,t),c=Math.min(l,a),u=Math.max(l,a),d=Math.max(.1,this.Fl(u,c)),f=this.Hl(e+o,t),g=f-f%d,v=this.Ul(g,t,!0);return{io:this.Ki.no(g),Rl:v,Jl:g}}Zl(t,e,n){let i=On(this.Ki.ar());return this.Ki.so()&&(i=wi(i,this.Ki.ro())),i.Je()-e<t&&n-i.Qe()<t}}function Nd(s){return s.slice().sort(((t,e)=>ct(t.ln())-ct(e.ln())))}var Xi;(function(s){s[s.Normal=0]="Normal",s[s.Logarithmic=1]="Logarithmic",s[s.Percentage=2]="Percentage",s[s.IndexedTo100=3]="IndexedTo100"})(Xi||(Xi={}));const Hc=new _d,Kc=new Mo(100,1);class Np{constructor(t,e,n,i,o){this.ho=0,this.ao=null,this.rr=null,this.lo=null,this.oo={_o:!1,uo:null},this.co=!1,this.do=0,this.fo=0,this.po=new Ye,this.vo=new Ye,this.mo=[],this.wo=null,this.Mo=null,this.bo=null,this.So=null,this.xo=null,this.il=Kc,this.Co=$o(null),this.yo=t,this.yn=e,this.ko=n,this.Po=i,this.To=o,this.Ro=new Uc(this,100,this.Do.bind(this),this.Io.bind(this))}cl(){return this.yo}N(){return this.yn}vr(t){if(Rs(this.yn,t),this.dl(),t.mode!==void 0&&this.Vo({_e:t.mode}),t.scaleMargins!==void 0){const e=Cs(t.scaleMargins.top),n=Cs(t.scaleMargins.bottom);if(e<0||e>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${e}`);if(n<0||n>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${n}`);if(e+n>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${e+n}`);this.Bo(),this.bo=null}}Eo(){return this.yn.autoScale}Ao(){return this.co}so(){return this.yn.mode===1}je(){return this.yn.mode===2}Lo(){return this.yn.mode===3}ro(){return this.Co}_e(){return{hs:this.yn.autoScale,zo:this.yn.invertScale,_e:this.yn.mode}}Vo(t){const e=this._e();let n=null;t.hs!==void 0&&(this.yn.autoScale=t.hs),t._e!==void 0&&(this.yn.mode=t._e,t._e!==2&&t._e!==3||(this.yn.autoScale=!0),this.oo._o=!1),e._e===1&&t._e!==e._e&&((function(o,l){if(o===null)return!1;const a=Gi(o.Je(),l),c=Gi(o.Qe(),l);return isFinite(a)&&isFinite(c)})(this.rr,this.Co)?(n=wi(this.rr,this.Co),n!==null&&this.Oo(n)):this.yn.autoScale=!0),t._e===1&&t._e!==e._e&&(n=Bi(this.rr,this.Co),n!==null&&this.Oo(n));const i=e._e!==this.yn.mode;i&&(e._e===2||this.je())&&this.dl(),i&&(e._e===3||this.Lo())&&this.dl(),t.zo!==void 0&&e.zo!==t.zo&&(this.yn.invertScale=t.zo,this.No()),this.vo.p(e,this._e())}Fo(){return this.vo}k(){return this.ko.fontSize}$t(){return this.ho}Wo(t){this.ho!==t&&(this.ho=t,this.Bo(),this.bo=null)}Ho(){if(this.ao)return this.ao;const t=this.$t()-this.Uo()-this.$o();return this.ao=t,t}ar(){return this.jo(),this.rr}Oo(t,e){const n=this.rr;(e||n===null&&t!==null||n!==null&&!n.Ge(t))&&(this.bo=null,this.rr=t)}qo(t){this.Oo(t),this.Yo(t!==null)}Gi(){return this.jo(),this.ho===0||!this.rr||this.rr.Gi()}Ko(t){return this.zo()?t:this.$t()-1-t}Nt(t,e){return this.je()?t=bi(t,e):this.Lo()&&(t=Qi(t,e)),this.Io(t,e)}Zo(t,e,n){this.jo();const i=this.$o(),o=ct(this.ar()),l=o.Je(),a=o.Qe(),c=this.Ho()-1,u=this.zo(),d=c/(a-l),f=n===void 0?0:n.from,g=n===void 0?t.length:n.to,v=this.Go();for(let b=f;b<g;b++){const w=t[b],k=w.Mt;if(isNaN(k))continue;let y=k;
6v!==null&&(y=v(w.Mt,e));const S=i+d*(y-l),j=u?S:this.ho-1-S;w.ut=j}}Xo(t,e,n){this.jo();const i=this.$o(),o=ct(this.ar()),l=o.Je(),a=o.Qe(),c=this.Ho()-1,u=this.zo(),d=c/(a-l),f=n===void 0?0:n.from,g=n===void 0?t.length:n.to,v=this.Go();for(let b=f;b<g;b++){const w=t[b];let k=w.jr,y=w.qr,S=w.Yr,j=w.Kr;v!==null&&(k=v(w.jr,e),y=v(w.qr,e),S=v(w.Yr,e),j=v(w.Kr,e));let E=i+d*(k-l),z=u?E:this.ho-1-E;w.Jo=z,E=i+d*(y-l),z=u?E:this.ho-1-E,w.Qo=z,E=i+d*(S-l),z=u?E:this.ho-1-E,w.t_=z,E=i+d*(j-l),z=u?E:this.ho-1-E,w.i_=z}}Tn(t,e){const n=this.Do(t,e);return this.n_(n,e)}n_(t,e){let n=t;return this.je()?n=(function(i,o){return o<0&&(i=-i),i/100*o+o})(n,e):this.Lo()&&(n=(function(i,o){return i-=100,o<0&&(i=-i),i/100*o+o})(n,e)),n}Cl(){return this.mo}Dt(){return this.Mo||(this.Mo=Nd(this.mo)),this.Mo}s_(t){this.mo.indexOf(t)===-1&&(this.mo.push(t),this.dl(),this.e_())}r_(t){const e=this.mo.indexOf(t);if(e===-1)throw new Error("source is not attached to scale");this.mo.splice(e,1),this.mo.length===0&&(this.Vo({hs:!0}),this.Oo(null)),this.dl(),this.e_()}Lt(){let t=null;for(const e of this.mo){const n=e.Lt();n!==null&&(t===null||n.za<t.za)&&(t=n)}return t===null?null:t.Wt}zo(){return this.yn.invertScale}El(){const t=this.Lt()===null;if(this.bo!==null&&(t||this.bo.h_===t))return this.bo.El;this.Ro.jl();const e=this.Ro.El();return this.bo={El:e,h_:t},this.po.p(),e}a_(){return this.po}l_(t){this.je()||this.Lo()||this.So===null&&this.lo===null&&(this.Gi()||(this.So=this.ho-t,this.lo=ct(this.ar()).Xe()))}o_(t){if(this.je()||this.Lo()||this.So===null)return;this.Vo({hs:!1}),(t=this.ho-t)<0&&(t=0);let e=(this.So+.2*(this.ho-1))/(t+.2*(this.ho-1));const n=ct(this.lo).Xe();e=Math.max(e,.1),n.ir(e),this.Oo(n)}__(){this.je()||this.Lo()||(this.So=null,this.lo=null)}u_(t){this.Eo()||this.xo===null&&this.lo===null&&(this.Gi()||(this.xo=t,this.lo=ct(this.ar()).Xe()))}c_(t){if(this.Eo()||this.xo===null)return;const e=ct(this.ar()).tr()/(this.Ho()-1);let n=t-this.xo;this.zo()&&(n*=-1);const i=n*e,o=ct(this.lo).Xe();o.nr(i),this.Oo(o,!0),this.bo=null}d_(){this.Eo()||this.xo!==null&&(this.xo=null,this.lo=null)}tl(){return this.il||this.dl(),this.il}Ji(t,e){switch(this.yn.mode){case 2:return this.f_(bi(t,e));case 3:return this.tl().format(Qi(t,e));default:return this.cr(t)}}no(t){switch(this.yn.mode){case 2:return this.f_(t);case 3:return this.tl().format(t);default:return this.cr(t)}}Ql(t){switch(this.yn.mode){case 2:return this.p_(t);case 3:return this.tl().formatTickmarks(t);default:return this.v_(t)}}xa(t){return this.cr(t,ct(this.wo).tl())}Ca(t,e){return t=bi(t,e),this.f_(t,Hc)}m_(){return this.mo}w_(t){this.oo={uo:t,_o:!1}}Nn(){this.mo.forEach((t=>t.Nn()))}Kl(){return this.yn.ensureEdgeTickMarksVisible&&this.Eo()}Gl(){return this.k()/2}dl(){this.bo=null;let t=1/0;this.wo=null;for(const n of this.mo)n.ln()<t&&(t=n.ln(),this.wo=n);let e=100;this.wo!==null&&(e=Math.round(this.wo.Kh())),this.il=Kc,this.je()?(this.il=Hc,e=100):this.Lo()?(this.il=new Mo(100,1),e=100):this.wo!==null&&(this.il=this.wo.tl()),this.Ro=new Uc(this,e,this.Do.bind(this),this.Io.bind(this)),this.Ro.jl()}e_(){this.Mo=null}M_(){return this.wo===null||this.je()||this.Lo()?1:1/this.wo.Kh()}Xi(){return this.To}Yo(t){this.co=t}Uo(){return this.zo()?this.yn.scaleMargins.bottom*this.$t()+this.fo:this.yn.scaleMargins.top*this.$t()+this.do}$o(){return this.zo()?this.yn.scaleMargins.top*this.$t()+this.do:this.yn.scaleMargins.bottom*this.$t()+this.fo}jo(){this.oo._o||(this.oo._o=!0,this.g_())}Bo(){this.ao=null}Io(t,e){if(this.jo(),this.Gi())return 0;t=this.so()&&t?mo(t,this.Co):t;const n=ct(this.ar()),i=this.$o()+(this.Ho()-1)*(t-n.Je())/n.tr();return this.Ko(i)}Do(t,e){if(this.jo(),this.Gi())return 0;const n=this.Ko(t),i=ct(this.ar()),o=i.Je()+i.tr()*((n-this.$o())/(this.Ho()-1));return this.so()?Gi(o,this.Co):o}No(){this.bo=null,this.Ro.jl()}g_(){if(this.Ao()&&!this.Eo())return;const t=this.oo.uo;if(t===null)return;let e=null;const n=this.m_();let i=0,o=0;for(const c of n){if(!c.It())continue;const u=c.Lt();if(u===null)continue;const d=c.la(t.Oa(),t.bi());let f=d&&d.ar();if(f!==null){switch(this.yn.mode){case 1:f=Bi(f,this.Co);break;case 2:f=jp(f,u.Wt);break;case 3:f=Sp(f,u.Wt)}if(e=e===null?f:e.Ss(ct(f)),d!==null){const g=d.lr();g!==null&&(i=Math.max(i,g.above),o=Math.max(o,g.below))}}}if(this.Kl()&&(i=Math.max(i,this.Gl()),o=Math.max(o,this.Gl())),i===this.do&&o===this.fo||(this.do=i,this.fo=o,this.bo=null,this.Bo()),e!==null){if(e.Je()===e.Qe()){const c=5*this.M_();this.so()&&(e=wi(e,this.Co)),e=new bs(e.Je()-c,e.Qe()+c),this.so()&&(e=Bi(e,this.Co))}if(this.so()){const c=wi(e,this.Co),u=$o(c);if(l=u,a=this.Co,l.Al!==a.Al||l.Ll!==a.Ll){const d=this.lo!==null?wi(this.lo,this.Co):null;this.Co=u,e=Bi(c,u),d!==null&&(this.lo=Bi(d,u))}}this.Oo(e)}else this.rr===null&&(this.Oo(new bs(-.5,.5)),this.Co=$o(null));var l,a}Go(){return this.je()?bi:this.Lo()?Qi:this.so()?t=>mo(t,this.Co):null}b_(t,e,n){return e===void 0?(n===void 0&&(n=this.tl()),n.format(t)):e(t)}S_(t,e,n){return e===void 0?(n===void 0&&(n=this.tl()),n.formatTickmarks(t)):e(t)}cr(t,e){return this.b_(t,this.Po.priceFormatter,e)}v_(t,e){const n=this.Po.priceFormatter;return this.S_(t,this.Po.tickmarksPriceFormatter??(n?i=>i.map(n):void 0),e)}f_(t,e){return this.b_(t,this.Po.percentageFormatter,e)}p_(t,e){const n=this.Po.percentageFormatter;return this.S_(t,this.Po.tickmarksPercentageFormatter??(n?i=>i.map(n):void 0),e)}}function $c(s){return s instanceof jo}class Il{constructor(t,e){this.mo=[],this.x_=new Map,this.ho=0,this.C_=0,this.y_=1,this.Mo=null,this.k_=null,this.P_=!1,this.T_=new Ye,this.fa=[],this.ia=t,this.sn=e,this.R_=new Mp(this);const n=e.N();this.D_=this.I_("left",n.leftPriceScale),this.V_=this.I_("right",n.rightPriceScale),this.D_.Fo().i(this.B_.bind(this,this.D_),this),this.V_.Fo().i(this.B_.bind(this,this.V_),this),this.E_(n)}E_(t){if(t.leftPriceScale&&this.D_.vr(t.leftPriceScale),t.rightPriceScale&&this.V_.vr(t.rightPriceScale),t.localization&&(this.D_.dl(),this.V_.dl()),t.overlayPriceScales){const e=Array.from(this.x_.values());for(const n of e){const i=ct(n[0].Ft());i.vr(t.overlayPriceScales),t.localization&&i.dl()}}}A_(t){switch(t){case"left":return this.D_;case"right":return this.V_}return this.x_.has(t)?Cs(this.x_.get(t))[0].Ft():null}m(){this.Qt().L_().u(this),this.D_.Fo().u(this),this.V_.Fo().u(this),this.mo.forEach((t=>{t.m&&t.m()})),this.fa=this.fa.filter((t=>{const e=t.Qh();return e.detached&&e.detached(),!1})),this.T_.p()}z_(){return this.y_}O_(t){this.y_=t}Qt(){return this.sn}nn(){return this.C_}$t(){return this.ho}N_(t){this.C_=t,this.F_()}Wo(t){this.ho=t,this.D_.Wo(t),this.V_.Wo(t),this.mo.forEach((e=>{if(this.Zs(e)){const n=e.Ft();n!==null&&n.Wo(t)}}
6)),this.F_()}W_(t){this.P_=t}H_(){return this.P_}U_(){return this.mo.filter($c)}Cl(){return this.mo}Zs(t){const e=t.Ft();return e===null||this.D_!==e&&this.V_!==e}s_(t,e,n){this.j_(t,e,n?t.ln():this.mo.length)}r_(t,e){const n=this.mo.indexOf(t);fs(n!==-1,"removeDataSource: invalid data source"),this.mo.splice(n,1),e||this.mo.forEach(((l,a)=>l._n(a)));const i=ct(t.Ft()).cl();if(this.x_.has(i)){const l=Cs(this.x_.get(i)),a=l.indexOf(t);a!==-1&&(l.splice(a,1),l.length===0&&this.x_.delete(i))}const o=t.Ft();o&&o.Cl().indexOf(t)>=0&&(o.r_(t),this.q_(o)),this.Y_()}Xs(t){return t===this.D_?"left":t===this.V_?"right":"overlay"}K_(){return this.D_}Z_(){return this.V_}G_(t,e){t.l_(e)}X_(t,e){t.o_(e),this.F_()}J_(t){t.__()}Q_(t,e){t.u_(e)}tu(t,e){t.c_(e),this.F_()}iu(t){t.d_()}F_(){this.mo.forEach((t=>{t.Nn()}))}Pn(){const[t,e]=this.nu();let n=null;return t.N().visible&&t.Cl().length!==0?n=t:e.N().visible&&e.Cl().length!==0?n=e:this.mo.length!==0&&(n=this.mo[0].Ft()),n===null&&(n=this.Gs()??t),n}Gs(){const[t,e]=this.nu();return t.N().visible?t:e.N().visible?e:null}q_(t){t!==null&&t.Eo()&&this.su(t)}eu(t){const e=this.ia.Ee();t.Vo({hs:!0}),e!==null&&t.w_(e),this.F_()}ru(){this.su(this.D_),this.su(this.V_)}hu(){this.q_(this.D_),this.q_(this.V_),this.mo.forEach((t=>{this.Zs(t)&&this.q_(t.Ft())})),this.F_(),this.sn.mr()}Dt(){return this.Mo===null&&(this.Mo=Nd(this.mo)),this.Mo}au(){var l;const t=this.Dt(),e=(l=this.sn.ou())==null?void 0:l.lu,n=this.sn.N().hoveredSeriesOnTop,i=this.k_;if(i!==null&&i.Kh===t&&i._u===e&&i.uu===n)return i.cu;const o=(function(a,c,u){if(!u)return a;const d=a.indexOf(c);if(d===-1||d===a.length-1)return a;const f=[];for(let g=0;g<a.length;g++)g!==d&&f.push(a[g]);return f.push(a[d]),f})(t,e,n);return this.k_={Kh:t,_u:e,uu:n,cu:o},o}du(t,e){e=ki(e,0,this.mo.length-1);const n=this.mo.indexOf(t);fs(n!==-1,"setSeriesOrder: invalid data source"),this.mo.splice(n,1),this.mo.splice(e,0,t),this.mo.forEach(((i,o)=>i._n(o))),this.Y_();for(const i of[this.D_,this.V_])i.e_(),i.dl();this.sn.mr()}Vt(){return this.Dt().filter($c)}fu(){return this.T_}pu(){return this.R_}hl(t){this.fa.push(new up(t))}al(t){this.fa=this.fa.filter((e=>e.Qh()!==t)),t.detached&&t.detached(),this.sn.mr()}vu(){return this.fa}Ja(t,e){return this.fa.map((n=>n.Qs(t,e))).filter((n=>n!==null))}su(t){const e=t.m_();if(e&&e.length>0&&!this.ia.Gi()){const n=this.ia.Ee();n!==null&&t.w_(n)}t.Nn()}j_(t,e,n){let i=this.A_(e);if(i===null&&(i=this.I_(e,this.sn.N().overlayPriceScales)),this.mo.splice(n,0,t),!ko(e)){const o=this.x_.get(e)||[];o.push(t),this.x_.set(e,o)}t._n(n),i.s_(t),t.un(i),this.q_(i),this.Y_()}Y_(){this.Mo=null,this.k_=null}nu(){return this.sn.N().defaultVisiblePriceScaleId==="left"?[this.D_,this.V_]:[this.V_,this.D_]}B_(t,e,n){e._e!==n._e&&this.su(t)}I_(t,e){const n={visible:!0,autoScale:!0,...Nn(e)},i=new Np(t,n,this.sn.N().layout,this.sn.N().localization,this.sn.Xi());return i.Wo(this.$t()),i}}function Bl(s,t){return t===null||s.se===2&&t.se!==2||(t.se!==2||s.se===2)&&s.ne!==t.ne&&s.ne<t.ne}function Cd(s){return{te:s.te,ie:s.ie}}function Cp(s){return{ne:s.distance??0,se:s.hitTestPriority??(s.itemType==="marker"?2:0),ee:s.itemType??"primitive",mu:s.cursorStyle,te:s.externalId}}function Ar(s){return{lu:s.lu,wu:Cd(s.Mu),mu:s.Mu.mu,ee:s.Mu.ee??"primitive"}}function Tp(s,t,e,n){var o;let i=null;for(const l of s){let a=((o=l.Qs)==null?void 0:o.call(l,t,e,n))??null;if(a===null){const c=l.Tt(n);a=c!==null&&c.Qs?c.Qs(t,e):null}if(a!==null){const c={gu:l,Mu:a};(i===null||Bl(c.Mu,i.Mu))&&(i=c)}}return i}function Lp(s){return s.jn!==void 0}function Td(s,t,e){const n=[s,...s.Dt()].reverse(),i=(function(a,c,u){var w;let d,f,g;for(const k of a){const y=((w=k.Ja)==null?void 0:w.call(k,c,u))??[];for(const S of y){const j=Cp(S);v=S.zOrder,b=d==null?void 0:d.zOrder,(!b||v==="top"&&b!=="top"||v==="normal"&&b==="bottom"||S.zOrder===(d==null?void 0:d.zOrder)&&f!==void 0&&Bl(j,f)||S.zOrder===(d==null?void 0:d.zOrder)&&f===void 0)&&(d=S,f=j,g=k)}}var v,b;return d&&g&&f?{Mu:f,bu:d,lu:g}:null})(n,t,e);if((i==null?void 0:i.bu.zOrder)==="top")return Ar(i);let o=null,l=null;for(const a of n){if(i&&i.lu===a&&i.bu.zOrder!=="bottom"&&!i.bu.isBackgroun
6d)return o??Ar(i);if(Lp(a)){const c=Tp(a.jn(s),t,e,s);if(c!==null){const u={lu:a,gu:c.gu,wu:Cd(c.Mu),mu:c.Mu.mu,ee:c.Mu.ee??"primitive"};(o===null||Bl(c.Mu,l))&&(o=u,l=c.Mu)}}if(i&&i.lu===a&&i.bu.zOrder!=="bottom"&&i.bu.isBackground)return o??Ar(i)}return o!==null?o:i!=null&&i.bu?Ar(i):null}class Ep{constructor(t,e,n=50){this.Vs=0,this.Bs=1,this.Es=1,this.Ls=new Map,this.As=new Map,this.Su=t,this.xu=e,this.zs=n}Cu(t){const e=t.time,n=this.xu.cacheKey(e),i=this.Ls.get(n);if(i!==void 0)return i.yu;if(this.Vs===this.zs){const l=this.As.get(this.Es);this.As.delete(this.Es),this.Ls.delete(Cs(l)),this.Es++,this.Vs--}const o=this.Su(t);return this.Ls.set(n,{yu:o,Ws:this.Bs}),this.As.set(this.Bs,n),this.Vs++,this.Bs++,o}}class Mi{constructor(t,e){fs(t<=e,"right should be >= left"),this.ku=t,this.Pu=e}Oa(){return this.ku}bi(){return this.Pu}Tu(){return this.Pu-this.ku+1}ze(t){return this.ku<=t&&t<=this.Pu}Ge(t){return this.ku===t.Oa()&&this.Pu===t.bi()}}function Yc(s,t){return s===null||t===null?s===t:s.Ge(t)}class Fp{constructor(){this.Ru=new Map,this.Ls=null,this.Du=!1}Iu(t){this.Du=t,this.Ls=null}Vu(t,e){this.Bu(e),this.Ls=null;for(let n=e;n<t.length;++n){const i=t[n];let o=this.Ru.get(i.timeWeight);o===void 0&&(o=[],this.Ru.set(i.timeWeight,o)),o.push({index:n,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}Eu(t,e,n,i,o){const l=Math.ceil(e/t);return this.Ls!==null&&this.Ls.Au===l&&o===this.Ls.Lu&&n===this.Ls.zu||(this.Ls={Lu:o,zu:n,El:this.Ou(l,n,i),Au:l}),this.Ls.El}Bu(t){if(t===0)return void this.Ru.clear();const e=[];this.Ru.forEach(((n,i)=>{t<=n[0].index?e.push(i):n.splice(ei(n,t,(o=>o.index<t)),1/0)}));for(const n of e)this.Ru.delete(n)}Ou(t,e,n){let i=[];const o=l=>!e||n.has(l.index);for(const l of Array.from(this.Ru.keys()).sort(((a,c)=>c-a))){if(!this.Ru.get(l))continue;const a=i;i=[];const c=a.length;let u=0;const d=Cs(this.Ru.get(l)),f=d.length;let g=1/0,v=-1/0;for(let b=0;b<f;b++){const w=d[b],k=w.index;for(;u<c;){const y=a[u],S=y.index;if(!(S<k&&o(y))){g=S;break}u++,i.push(y),v=S,g=1/0}if(g-k>=t&&k-v>=t&&o(w))i.push(w),v=k;else if(this.Du)return a}for(;u<c;u++)o(a[u])&&i.push(a[u])}return i}}class ji{constructor(t){this.Nu=t}Fu(){return this.Nu===null?null:new Mi(Math.floor(this.Nu.Oa()),Math.ceil(this.Nu.bi()))}Wu(){return this.Nu}static Hu(){return new ji(null)}}function Ap(s,t){return s.weight>t.weight?s:t}class Rp{constructor(t,e,n,i){this.C_=0,this.Uu=null,this.$u=[],this.xo=null,this.So=null,this.ju=new Fp,this.qu=new Map,this.Yu=ji.Hu(),this.Ku=!0,this.Zu=new Ye,this.Gu=new Ye,this.Xu=new Ye,this.Ju=null,this.Qu=null,this.tc=new Map,this.nc=-1,this.sc=[],this.ec=1,this.yn=e,this.Po=n,this.rc=e.rightOffset,this.hc=e.barSpacing,this.sn=t,this.ac(e),this.xu=i,this.lc(),this.ju.Iu(e.uniformDistribution),this.oc(),this._c()}N(){return this.yn}uc(t){Rs(this.Po,t),this.cc(),this.lc()}vr(t,e){Rs(this.yn,t),this.yn.fixLeftEdge&&this.dc(),this.yn.fixRightEdge&&this.fc(),t.barSpacing!==void 0&&this.sn.Ms(t.barSpacing),t.rightOffset!==void 0&&this.sn.gs(t.rightOffset),this.ac(t),t.minBarSpacing===void 0&&t.maxBarSpacing===void 0||this.sn.Ms(t.barSpacing??this.hc),t.ignoreWhitespaceIndices!==void 0&&t.ignoreWhitespaceIndices!==this.yn.ignoreWhitespaceIndices&&this._c(),this.cc(),this.lc(),t.enableConflation===void 0&&t.conflationThresholdFactor===void 0||this.oc(),this.Xu.p()}Rn(t){var e;return((e=this.$u[t])==null?void 0:e.time)??null}en(t){return this.$u[t]??null}vc(t,e){if(this.$u.length<1)return null;if(this.xu.key(t)>this.xu.key(this.$u[this.$u.length-1].time))return e?this.$u.length-1:null;const n=ei(this.$u,this.xu.key(t),((i,o)=>this.xu.key(i.time)<o));return this.xu.key(t)<this.xu.key(this.$u[n].time)?e?n:null:n}Gi(){return this.C_===0||this.$u.length===0||this.Uu===null}mc(){return this.$u.length>0}Ee(){return this.wc(),this.Yu.Fu()}Mc(){return this.wc(),this.Yu.Wu()}gc(){const t=this.Ee();if(t===null)return null;const e={from:t.Oa(),to:t.bi()};return this.bc(e)}bc(t){const e=Math.round(t.from),n=Math.round(t.to),i=ct(this.Sc()),o=ct(this.xc());return{from:ct(this.en(Math.max(i,e))),to:ct(this.en(Math.min(o,n)))}}Cc(t){return{from:ct(this.vc(t.from,!0)),to:ct(this.vc(t.to,!0))}}nn(){return this.C_}N_(t){if(!isFinite(t)||t<=0||this.C_===t)return;const e=this.Mc(),n=this.C_;if(this.C_=t,this.Ku=!0,this.yn.lockVisibleTimeRangeOnResize&&n!==0){const i=this.hc*t/n;this.hc=i}if(this.yn.fixLeftEdge&&e!==null&&e.Oa()<=0){const i=n-t;this.rc-=Math.round(i/this.hc)+1,this.Ku=!0}this.yc(),this.kc()}jt(t){if(this.Gi()||!ir(t))return 0;const e=this.Pc()+this.rc-t;return this.C_-(e+.5)*this.hc-1}Tc(t,e){const n=this.Pc(),i=e===void 0?0:e.from,o=e===void 0?t.length:e.to;for(let l=i;l<o;l++){const a=t[l].wt,c=n+this.rc-a,u=this.C_-(c+.5)*this.hc-1;t[l]._t=u}}Rc(t,e){const n=Math.ceil(this.Dc(t));return e&&this.yn.ignoreWhitespaceIndices&&!this.Ic(n)?this.Vc(n):n}gs(t){this.Ku=!0,this.rc=t,this.kc(),this.sn.Bc(),this.sn.mr()}fl(){return this.hc}Ms(t){const e=this.hc;if(this.Ec(t),this.yn.rightOffsetPixels!==void 0&&e!==0){const n=this.rc*e/this.hc;this.rc=n}this.kc(),this.sn.Bc(),this.sn.mr()}Ac(){return this.rc}El(){if(this.Gi())return null;if(this.Qu!==null)return this.Qu;const t=this.hc,e=5*(this.sn.N().layout.fontSize+4)/8*(this.yn.tickMarkMaxCharacterLength||8),n=Math.round(e/t),i=ct(this.Ee()),o=Math.max(i.Oa(),i.Oa()-n),l=Math.max(i.bi(),i.bi()-n),a=this.ju.Eu(t,e,this.yn.ignoreWhitespaceIndices,this.tc,this.nc),c=this.Sc()+n,u=this.xc()-n,d=this.Lc(),f=this.yn.fixLeftEdge||d,g=this.yn.fixRightEdge||d;let v=0;for(const b of a){if(!(o<=b.index&&b.index<=l))continue;let w;v<this.sc.length?(w=this.sc[v],w.coord=this.jt(b.index),w.label=this.zc(b),w.weight=b.weight):(w={needAlignCoordinate:!1,coord:this.jt(b.index),label:this.zc(b),weight:b.weight},this.sc.push(w)),this.hc>e/2&&!d?w.needAlignCoordinate=!1:w.needAlignCoordinate=f&&b.index<=c||g&&b.index>=u,v++}return this.sc.length=v,this.Qu=this.sc,this.sc}Oc(){let t;this.Ku=!0,this.Ms(this.yn.barSpacing),t=this.yn.rightOffsetPixels!==void 0?this.yn.rightOffsetPixels/this.fl():this.yn.rightOffset,this.gs(t)}Nc(t){this.Ku=!0,this.Uu=t,this.kc(),this.dc()}Fc(t,e){const n=this.Dc(t),i=this.fl(),o=i+e*(i/10);this.Ms(o),this.yn.rightBarStaysOnScroll||this.gs(this.Ac()+(n-this.Dc(t)))}l_(t){this.xo&&this.d_(),this.So===null&&this.Ju===null&&(this.Gi()||(this.So=t,this.Wc()))}o_(t){if(this.Ju===null)return;const e=ki(this.C_-t,0,this.C_),n=ki(this.C_-ct(this.So),0,this.C_);e!==0&&n!==0&&this.Ms(this.Ju.fl*e/n)}__(){this.So!==null&&(this.So=null,this.Hc())}u_(t){this.xo===null&&this.Ju===null&&(this.Gi()||(this.xo=t,this.Wc()))}c_(t){if(this.xo===null)return;const e=(this.xo-t)/this.fl();this.rc=ct(this.Ju).Ac+e,this.Ku=!0,this.kc()}d_(){this.xo!==null&&(this.xo=null,this.Hc())}Uc(){this.$c(this.yn.rightOffset)}$c(t,e=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(e)||e<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const n=this.rc,i=performance.now();this.sn.ps({jc:o=>(o-i)/e>=1,qc:o=>{const l=(o-i)/e;return l>=1?t:n+(t-n)*l}})}kt(t,e){this.Ku=!0,this.$u=t,this.ju.Vu(t,e),this.kc()}Yc(){return this.Zu}Kc(){return this.Gu}Zc(){return this.Xu}Pc(){return this.Uu||0}Gc(t,e){const n=t.Tu(),i=e&&this.yn.rightOffsetPixels||0;this.Ec((this.C_-i)/n),this.rc=t.bi()-this.Pc(),e&&(this.rc=i?i/this.fl():this.yn.rightOffset),this.kc(),this.Ku=!0,this.sn.Bc(),this.sn.mr()}Xc(){const t=this.Sc(),e=this.xc();if(t===null||e===null)return;const n=!this.yn.rightOffsetPixels&&this.yn.rightOffset||0;this.Gc(new Mi(t,e+n),!0)}Jc(t){const e=new Mi(t.from,t.to);this.Gc(e)}rn(t){return this.Po.timeFormatter!==void 0?this.Po.timeFormatter(t.originalTime):this.xu.formatHorzItem(t.time)}_c(){if(!this.yn.ignoreWhitespaceIndices)return;this.tc.clear();const t=this.sn.Jn();for(const e of t)for(const n of e.ul())this.tc.set(n,!0);this.nc++}Qc(){return this.ec}Ml(){const t=1/(window.devicePixelRatio||1),e=this.yn.minBarSpacing;if(e>=t)return[1];const n=[1];let i=2;
6for(;i<=512;)e<t/i&&n.push(i),i*=2;return n}Lc(){const t=this.sn.N().handleScroll,e=this.sn.N().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||e.axisDoubleClickReset.time||e.axisPressedMouseMove.time||e.mouseWheel||e.pinch)}Sc(){return this.$u.length===0?null:0}xc(){return this.$u.length===0?null:this.$u.length-1}td(t){return(this.C_-1-t)/this.hc}Dc(t){const e=this.td(t),n=this.Pc()+this.rc-e;return Math.round(1e6*n)/1e6}Ec(t){const e=this.hc;this.hc=t,this.yc(),e!==this.hc&&(this.Ku=!0,this.nd(),this.oc())}wc(){if(!this.Ku)return;if(this.Ku=!1,this.Gi())return void this.sd(ji.Hu());const t=this.Pc(),e=this.C_/this.hc,n=this.rc+t,i=new Mi(n-e+1,n);this.sd(new ji(i))}yc(){const t=ki(this.hc,this.ed(),this.rd());this.hc!==t&&(this.hc=t,this.Ku=!0)}rd(){return this.yn.maxBarSpacing>0?this.yn.maxBarSpacing:.5*this.C_}ed(){return this.yn.fixLeftEdge&&this.yn.fixRightEdge&&this.$u.length!==0?this.C_/this.$u.length:this.yn.minBarSpacing}oc(){if(!this.yn.enableConflation)return void(this.ec=1);const t=1/(window.devicePixelRatio||1)*(this.yn.conflationThresholdFactor??1);if(this.hc>=t)return void(this.ec=1);const e=t/this.hc,n=Math.pow(2,Math.floor(Math.log2(e)));this.ec=Math.min(n,512)}kc(){const t=this.hd();t!==null&&this.rc<t&&(this.rc=t,this.Ku=!0);const e=this.ad();this.rc>e&&(this.rc=e,this.Ku=!0)}hd(){const t=this.Sc(),e=this.Uu;return t===null||e===null?null:t-e-1+(this.yn.fixLeftEdge?this.C_/this.hc:Math.min(2,this.$u.length))}ad(){return this.yn.fixRightEdge?0:this.C_/this.hc-Math.min(2,this.$u.length)}Wc(){this.Ju={fl:this.fl(),Ac:this.Ac()}}Hc(){this.Ju=null}zc(t){let e=this.qu.get(t.weight);return e===void 0&&(e=new Ep((n=>this.ld(n)),this.xu),this.qu.set(t.weight,e)),e.Cu(t)}ld(t){return this.xu.formatTickmark(t,this.Po)}sd(t){const e=this.Yu;this.Yu=t,Yc(e.Fu(),this.Yu.Fu())||this.Zu.p(),Yc(e.Wu(),this.Yu.Wu())||this.Gu.p(),this.nd()}nd(){this.Qu=null}cc(){this.nd(),this.qu.clear()}lc(){this.xu.updateFormatter(this.Po)}dc(){if(!this.yn.fixLeftEdge)return;const t=this.Sc();if(t===null)return;const e=this.Ee();if(e===null)return;const n=e.Oa()-t;if(n<0){const i=this.rc-n-1;this.gs(i)}this.yc()}fc(){this.kc(),this.yc()}Ic(t){return!this.yn.ignoreWhitespaceIndices||this.tc.get(t)||!1}Vc(t){const e=(function*(i){const o=Math.round(i),l=o<i;let a=1;for(;;)l?(yield o+a,yield o-a):(yield o-a,yield o+a),a++})(t),n=this.xc();for(;n;){const i=e.next().value;if(this.tc.get(i))return i;if(i<0||i>n)break}return t}ac(t){if(t.rightOffsetPixels!==void 0){const e=t.rightOffsetPixels/(t.barSpacing||this.hc);this.sn.gs(e)}}}var Qc,Gc,Xc,Zc,Jc;(function(s){s[s.OnTouchEnd=0]="OnTouchEnd",s[s.OnNextTap=1]="OnNextTap"})(Qc||(Qc={}));class Pp{constructor(t,e,n){this.od=[],this._d=[],this.ud=null,this.C_=0,this.dd=null,this.fd=new Ye,this.pd=new Ye,this.vd=null,this.md=t,this.yn=e,this.xu=n,this.To=new Em(this.yn.layout.colorParsers),this.wd=new Lm(this),this.ia=new Rp(this,e.timeScale,this.yn.localization,n),this.Ct=new qm(this,e.crosshair),this.Md=new wp(e.crosshair),e.addDefaultPane&&(this.gd(0),this.od[0].O_(2)),this.bd=this.Sd(0),this.xd=this.Sd(1)}Pa(){this.Cd(ds.ys())}mr(){this.Cd(ds.Cs())}qa(){this.Cd(new ds(1))}Ta(t){const e=this.yd(t);this.Cd(e)}ou(){return this.dd}kd(t){var n,i,o,l,a,c,u,d,f;if(((n=this.dd)==null?void 0:n.lu)===(t==null?void 0:t.lu)&&((o=(i=this.dd)==null?void 0:i.wu)==null?void 0:o.te)===((l=t==null?void 0:t.wu)==null?void 0:l.te)&&((c=(a=this.dd)==null?void 0:a.wu)==null?void 0:c.ie)===((u=t==null?void 0:t.wu)==null?void 0:u.ie)&&((d=this.dd)==null?void 0:d.mu)===(t==null?void 0:t.mu)&&((f=this.dd)==null?void 0:f.ee)===(t==null?void 0:t.ee))return;const e=this.dd;this.dd=t,e!==null&&this.Ta(e.lu),t!==null&&t.lu!==(e==null?void 0:e.lu)&&this.Ta(t.lu)}N(){return this.yn}vr(t){Rs(this.yn,t),this.od.forEach((e=>e.E_(t))),t.timeScale!==void 0&&this.ia.vr(t.timeScale),t.localization!==void 0&&this.ia.uc(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.fd.p(),this.bd=this.Sd(0),this.xd=this.Sd(1),this.Pa()}Pd(t,e,n=0){const i=this.od[n];if(i===void 0)return;if(t==="left")return Rs(this.yn,{leftPriceScale:e}),i.E_({leftPriceScale:e}),this.fd.p(),void this.Pa();if(t==="right")return Rs(this.yn,{rightPriceScale:e}),i.E_({rightPriceScale:e}),this.fd.p(),void this.Pa();const o=this.Td(t,n);o!==null&&(o.Ft.vr(e),this.fd.p())}Td(t,e){const n=this.od[e];if(n===void 0)return null;const i=n.A_(t);return i!==null?{Kn:n,Ft:i}:null}Et(){return this.ia}Zn(){return this.od}Rd(){return this.Ct}Dd(){return this.pd}
6Id(t,e){t.Wo(e),this.Bc()}N_(t){this.C_=t,this.ia.N_(this.C_),this.od.forEach((e=>e.N_(t))),this.Bc()}Vd(t){this.od.length!==1&&(fs(t>=0&&t<this.od.length,"Invalid pane index"),this.od.splice(t,1),this.Pa())}Bd(t,e){if(this.od.length<2)return;fs(t>=0&&t<this.od.length,"Invalid pane index");const n=this.od[t],i=this.od.reduce(((f,g)=>f+g.z_()),0),o=this.od.reduce(((f,g)=>f+g.$t()),0),l=o-30*(this.od.length-1);e=Math.min(l,Math.max(30,e));const a=i/o,c=n.$t();n.O_(e*a);let u=e-c,d=this.od.length-1;for(const f of this.od)if(f!==n){const g=Math.min(l,Math.max(30,f.$t()-u/d));u-=f.$t()-g,d-=1;const v=g*a;f.O_(v)}this.Pa()}Ed(t,e){fs(t>=0&&t<this.od.length&&e>=0&&e<this.od.length,"Invalid pane index");const n=this.od[t],i=this.od[e];this.od[t]=i,this.od[e]=n,this.Pa()}Ad(t,e){if(fs(t>=0&&t<this.od.length&&e>=0&&e<this.od.length,"Invalid pane index"),t===e)return;const[n]=this.od.splice(t,1);this.od.splice(e,0,n),this.Pa()}G_(t,e,n){t.G_(e,n)}X_(t,e,n){t.X_(e,n),this.Ra(),this.Cd(this.Ld(t,2))}J_(t,e){t.J_(e),this.Cd(this.Ld(t,2))}Q_(t,e,n){e.Eo()||t.Q_(e,n)}tu(t,e,n){e.Eo()||(t.tu(e,n),this.Ra(),this.Cd(this.Ld(t,2)))}iu(t,e){e.Eo()||(t.iu(e),this.Cd(this.Ld(t,2)))}eu(t,e){t.eu(e),this.Cd(this.Ld(t,2))}zd(t){this.ia.l_(t)}Od(t,e){const n=this.Et();if(n.Gi()||e===0)return;const i=n.nn();t=Math.max(1,Math.min(t,i)),n.Fc(t,e),this.Bc()}Nd(t){this.Fd(0),this.Wd(t),this.Hd()}Ud(t){this.ia.o_(t),this.Bc()}$d(){this.ia.__(),this.mr()}Fd(t){this.ia.u_(t)}Wd(t){this.ia.c_(t),this.Bc()}Hd(){this.ia.d_(),this.mr()}Jn(){return this._d}Wn(){return this.ud===null&&(this.ud=this._d.filter((t=>t.It()))),this.ud}ka(){this.ud=null}jd(t,e,n,i,o){this.Ct.In(t,e);let l=NaN,a=this.ia.Rc(t,!0);const c=this.ia.Ee();c!==null&&(a=Math.min(Math.max(c.Oa(),a),c.bi())),a=this.Ct.Fn(a);const u=i.Pn(),d=u.Lt();if(d!==null&&(l=u.Tn(e,d)),l=this.Md.xl(l,a,i),this.Ct.An(a,l,i),this.qa(),!o){const f=Td(i,t,e);this.kd(f&&{lu:f.lu,wu:f.wu,mu:f.mu||null,ee:f.ee}),this.pd.p(this.Ct.Bt(),{x:t,y:e},n)}}qd(t,e,n){const i=n.Pn(),o=i.Lt(),l=i.Nt(t,ct(o)),a=this.ia.vc(e,!0),c=this.ia.jt(ct(a));this.jd(c,l,null,n,!0)}Yd(t){this.Rd().zn(),this.qa(),t||this.pd.p(null,null,null)}Ra(){const t=this.Ct.Kn();if(t!==null){const e=this.Ct.Bn(),n=this.Ct.En();this.jd(e,n,null,t)}this.Ct.Nn()}Kd(t,e,n){const i=this.ia.Rn(0);e!==void 0&&n!==void 0&&this.ia.kt(e,n);const o=this.ia.Rn(0),l=this.ia.Pc(),a=this.ia.Ee();if(a!==null&&i!==null&&o!==null){const c=a.ze(l),u=this.xu.key(i)>this.xu.key(o),d=t!==null&&t>l&&!u,f=this.ia.N().allowShiftVisibleRangeOnWhitespaceReplacement,g=c&&(n!==void 0||f)&&this.ia.N().shiftVisibleRangeOnNewBar;if(d&&!g){const v=t-l;this.ia.gs(this.ia.Ac()-v)}}this.ia.Nc(t)}Va(t){t!==null&&t.hu()}Ks(t){if((function(n){return n instanceof Il})(t))return t;const e=this.od.find((n=>n.Dt().includes(t)));return e===void 0?null:e}Bc(){this.od.forEach((t=>t.hu())),this.Ra()}m(){this.od.forEach((t=>t.m())),this.od.length=0,this.yn.localization.priceFormatter=void 0,this.yn.localization.percentageFormatter=void 0,this.yn.localization.timeFormatter=void 0}Zd(){return this.wd}Js(){return this.wd.N()}L_(){return this.fd}Gd(t,e){const n=this.gd(e);this.Xd(t,n),this._d.push(t),this.ka(),this._d.length===1?this.Pa():this.mr()}Jd(t){const e=this.Ks(t),n=this._d.indexOf(t);fs(n!==-1,"Series not found");const i=ct(e);this._d.splice(n,1),i.r_(t),t.m&&t.m(),this.ka(),this.ia._c(),this.Qd(i)}ya(t,e){const n=ct(this.Ks(t));n.r_(t,!0),n.s_(t,e,!0)}Xc(){const t=ds.Cs();t.us(),this.Cd(t)}tf(t){const e=ds.Cs();e.fs(t),this.Cd(e)}ws(){const t=ds.Cs();t.ws(),this.Cd(t)}Ms(t){const e=ds.Cs();e.Ms(t),this.Cd(e)}gs(t){const e=ds.Cs();e.gs(t),this.Cd(e)}ps(t){const e=ds.Cs();e.ps(t),this.Cd(e)}cs(){const t=ds.Cs();t.cs(),this.Cd(t)}if(){const t=this.yn.defaultVisiblePriceScaleId,e=this.yn.leftPriceScale.visible;return e!==this.yn.rightPriceScale.visible?e?"left":"right":t}nf(t,e){if(fs(e>=0,"Index should be greater or equal to 0"),e===this.sf(t))return;const n=ct(this.Ks(t));n.r_(t);const i=this.gd(e);this.Xd(t,i);let o=!1;n.Cl().length===0&&(o=this.Qd(n)),o||this.Pa()}ef(){return this.xd}$(){return this.bd}Ut(t){const e=this.xd,n=this.bd;if(e===n)return e;if(t=Math.max(0,Math.min(100,Math.round(100*t))),this.vd===null||this.vd.ah!==n||this.vd.oh!==e)this.vd={ah:n,oh:e,rf:new Map};else{const o=this.vd.rf.get(t);if(o!==void 0)return o}const i=this.To.tt(n,e,t/100);return this.vd.rf.set(t,i),i}hf(t){return this.od.indexOf(t)}Xi(){return this.To}af(){return this.lf()}lf(t){const e=new Il(this.ia,this);this.od.push(e);const n=t??this.od.length-1,i=ds.ys();return i.es(n,{rs:0,hs:!0}),this.Cd(i),e}gd(t){return fs(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.od.length,t))<this.od.length?this.od[t]:this.lf(t)}sf(t){return this.od.findIndex((e=>e.U_().includes(t)))}Ld(t,e){const n=new ds(e);if(t!==null){const i=this.od.indexOf(t);n.es(i,{rs:e})}return n}yd(t,e){return e===void 0&&(e=2),this.Ld(this.Ks(t),e)}
6Cd(t){this.md&&this.md(t),this.od.forEach((e=>e.pu().wr().kt()))}Xd(t,e){const n=t.N().priceScaleId,i=n!==void 0?n:this.if();e.s_(t,i),ko(i)||t.vr(t.N())}Sd(t){const e=this.yn.layout;return e.background.type==="gradient"?t===0?e.background.topColor:e.background.bottomColor:e.background.color}Qd(t){return!t.H_()&&t.Cl().length===0&&this.od.length>1&&(this.od.splice(this.hf(t),1),this.Pa(),!0)}}function Ld(s){if(s>=1)return 0;let t=0;for(;t<8;t++){const e=Math.round(s);if(Math.abs(e-s)<1e-8)return t;s*=10}return t}function Wl(s){return!ti(s)&&!dr(s)}function Ed(s){return ti(s)}(function(s){s[s.Disabled=0]="Disabled",s[s.Continuous=1]="Continuous",s[s.OnDataUpdate=2]="OnDataUpdate"})(Gc||(Gc={})),(function(s){s[s.LastBar=0]="LastBar",s[s.LastVisible=1]="LastVisible"})(Xc||(Xc={})),(function(s){s.Solid="solid",s.VerticalGradient="gradient"})(Zc||(Zc={})),(function(s){s[s.Year=0]="Year",s[s.Month=1]="Month",s[s.DayOfMonth=2]="DayOfMonth",s[s.Time=3]="Time",s[s.TimeWithSeconds=4]="TimeWithSeconds"})(Jc||(Jc={}));const th=s=>s.getUTCFullYear();function zp(s,t,e){return t.replace(/yyyy/g,(n=>Cn(th(n),4))(s)).replace(/yy/g,(n=>Cn(th(n)%100,2))(s)).replace(/MMMM/g,((n,i)=>new Date(n.getUTCFullYear(),n.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(s,e)).replace(/MMM/g,((n,i)=>new Date(n.getUTCFullYear(),n.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(s,e)).replace(/MM/g,(n=>Cn((i=>i.getUTCMonth()+1)(n),2))(s)).replace(/dd/g,(n=>Cn((i=>i.getUTCDate())(n),2))(s))}class Fd{constructor(t="yyyy-MM-dd",e="default"){this._f=t,this.uf=e}Cu(t){return zp(t,this._f,this.uf)}}class Dp{constructor(t){this.cf=t||"%h:%m:%s"}Cu(t){return this.cf.replace("%h",Cn(t.getUTCHours(),2)).replace("%m",Cn(t.getUTCMinutes(),2)).replace("%s",Cn(t.getUTCSeconds(),2))}}const Op={df:"yyyy-MM-dd",ff:"%h:%m:%s",pf:" ",vf:"default"};class Ip{constructor(t={}){const e={...Op,...t};this.mf=new Fd(e.df,e.vf),this.wf=new Dp(e.ff),this.Mf=e.pf}Cu(t){return`${this.mf.Cu(t)}${this.Mf}${this.wf.Cu(t)}`}}function Rr(s){return 60*s*60*1e3}function Qo(s){return 60*s*1e3}const Pr=[{gf:(eh=1,1e3*eh),bf:10},{gf:Qo(1),bf:20},{gf:Qo(5),bf:21},{gf:Qo(30),bf:22},{gf:Rr(1),bf:30},{gf:Rr(3),bf:31},{gf:Rr(6),bf:32},{gf:Rr(12),bf:33}];var eh;function sh(s,t){if(s.getUTCFullYear()!==t.getUTCFullYear())return 70;if(s.getUTCMonth()!==t.getUTCMonth())return 60;if(s.getUTCDate()!==t.getUTCDate())return 50;for(let e=Pr.length-1;e>=0;--e)if(Math.floor(t.getTime()/Pr[e].gf)!==Math.floor(s.getTime()/Pr[e].gf))return Pr[e].bf;return 0}function Go(s){let t=s;if(dr(s)&&(t=ja(s)),!Wl(t))throw new Error("time must be of type BusinessDay");const e=new Date(Date.UTC(t.year,t.month-1,t.day,0,0,0,0));return{Sf:Math.round(e.getTime()/1e3),xf:t}}function nh(s){if(!Ed(s))throw new Error("time must be of type isUTCTimestamp");return{Sf:s}}function ja(s){const t=new Date(s);if(isNaN(t.getTime()))throw new Error(`Invalid date string=${s}, expected format=yyyy-mm-dd`);return{day:t.getUTCDate(),month:t.getUTCMonth()+1,year:t.getUTCFullYear()}}function ih(s){dr(s.time)&&(s.time=ja(s.time))}class rh{options(){return this.yn}setOptions(t){this.yn=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?(function(e){e.forEach(ih)})(t):ih(t)}createConverterToInternalObj(t){return ct((function(e){return e.length===0?null:Wl(e[0].time)||dr(e[0].time)?Go:nh})(t))}key(t){return typeof t=="object"&&"Sf"in t?t.Sf:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const e=t;return e.xf===void 0?new Date(1e3*e.Sf).getTime():new Date(Date.UTC(e.xf.year,e.xf.month-1,e.xf.day)).getTime()}convertHorzItemToInternal(t){return Ed(e=t)?nh(e):Wl(e)?Go(e):Go(ja(e));var e}updateFormatter(t){if(!this.yn)return;const e=t.dateFormat;this.yn.timeScale.timeVisible?this.Cf=new Ip({df:e,ff:this.yn.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",pf:"   ",vf:t.locale}):this.Cf=new Fd(e,t.locale)}formatHorzItem(t){const e=t;return this.Cf.Cu(new Date(1e3*e.Sf))}formatTickmark(t,e){const n=(function(o,l,a){switch(o){case 0:case 10:return l?a?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return l?3:2;case 50:return 2;case 60:return 1;case 70:return 0}})(t.weight,this.yn.timeScale.timeVisible,this.yn.timeScale.secondsVisible),i=this.yn.timeScale;if(i.tickMarkFormatter!==void 0){const o=i.tickMarkFormatter(t.originalTime,n,e.locale);if(o!==null)return o}return(function(o,l,a){const c={};switch(l){case 0:c.year="numeric";break;case 1:c.month="short";break;case 2:c.day="numeric";break;case 3:c.hour12=!1,c.hour="2-digit",c.minute="2-digit";break;case 4:c.hour12=!1,c.hour="2-digit",c.minute="2-digit",c.second="2-digit"}const u=o.xf===void 0?new Date(1e3*o.Sf):new Date(Date.UTC(o.xf.year,o.xf.month-1,o.xf.day));return new Date(u.getUTCFullYear(),u.getUTCMonth(),u.getUTCDate(),u.getUTCHours(),u.getUTCMinutes(),u.getUTCSeconds(),u.getUTCMilliseconds()).toLocaleStr
6ing(a,c)})(t.time,n,e.locale)}maxTickMarkWeight(t){let e=t.reduce(Ap,t[0]).weight;return e>30&&e<50&&(e=30),e}fillWeightsForPoints(t,e){(function(n,i=0){if(n.length===0)return;let o=i===0?null:n[i-1].time.Sf,l=o!==null?new Date(1e3*o):null,a=0;for(let c=i;c<n.length;++c){const u=n[c],d=new Date(1e3*u.time.Sf);l!==null&&(u.timeWeight=sh(d,l)),a+=u.time.Sf-(o||u.time.Sf),o=u.time.Sf,l=d}if(i===0&&n.length>1){const c=Math.ceil(a/(n.length-1)),u=new Date(1e3*(n[0].time.Sf-c));n[0].timeWeight=sh(new Date(1e3*n[0].time.Sf),u)}})(t,e)}static yf(t){return Rs({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}const Ei=typeof window<"u";function oh(){return!!Ei&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function Xo(){return!!Ei&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function Bp(s,t){switch(s){case"custom":return t!==void 0?"custom-object":"series";case"price-line":return"custom-price-line";case"marker":return"series-marker";case"primitive":return"primitive";default:return"series"}}function ql(s){return s+s%2}function Wp(s){Ei&&window.chrome!==void 0&&s.addEventListener("mousedown",(t=>{if(t.button===1)return t.preventDefault(),!1}))}class So{constructor(t,e,n){this.kf=0,this.Pf=null,this.Tf={_t:Number.NEGATIVE_INFINITY,ut:Number.POSITIVE_INFINITY},this.Rf=0,this.Df=null,this.If={_t:Number.NEGATIVE_INFINITY,ut:Number.POSITIVE_INFINITY},this.Vf=null,this.Bf=!1,this.Ef=null,this.Af=null,this.Lf=!1,this.zf=!1,this.Of=!1,this.Nf=null,this.Ff=null,this.Wf=null,this.Hf=null,this.Uf=null,this.$f=null,this.jf=null,this.qf=0,this.Yf=!1,this.Kf=!1,this.Zf=!1,this.Gf=0,this.Xf=null,this.Jf=!Xo(),this.Qf=i=>{this.tp(i)},this.ip=i=>{if(this.np(i)){const o=this.sp(i);if(++this.Rf,this.Df&&this.Rf>1){const{ep:l}=this.rp(un(i),this.If);l<30&&!this.Of&&this.hp(o,this.lp.ap),this.op()}}else{const o=this.sp(i);if(++this.kf,this.Pf&&this.kf>1){const{ep:l}=this.rp(un(i),this.Tf);l<5&&!this.zf&&this._p(o,this.lp.up),this.cp()}}},this.dp=t,this.lp=e,this.yn=n,this.fp()}m(){this.Nf!==null&&(this.Nf(),this.Nf=null),this.Ff!==null&&(this.Ff(),this.Ff=null),this.Hf!==null&&(this.Hf(),this.Hf=null),this.Uf!==null&&(this.Uf(),this.Uf=null),this.$f!==null&&(this.$f(),this.$f=null),this.Wf!==null&&(this.Wf(),this.Wf=null),this.pp(),this.cp()}vp(t){this.Hf&&this.Hf();const e=this.mp.bind(this);if(this.Hf=()=>{this.dp.removeEventListener("mousemove",e)},this.dp.addEventListener("mousemove",e),this.np(t))return;const n=this.sp(t);this._p(n,this.lp.wp),this.Jf=!0}cp(){this.Pf!==null&&clearTimeout(this.Pf),this.kf=0,this.Pf=null,this.Tf={_t:Number.NEGATIVE_INFINITY,ut:Number.POSITIVE_INFINITY}}op(){this.Df!==null&&clearTimeout(this.Df),this.Rf=0,this.Df=null,this.If={_t:Number.NEGATIVE_INFINITY,ut:Number.POSITIVE_INFINITY}}mp(t){if(this.Zf||this.Af!==null||this.np(t))return;const e=this.sp(t);this._p(e,this.lp.Mp),this.Jf=!0}gp(t){const e=Zo(t.changedTouches,ct(this.Xf));if(e===null||(this.Gf=zr(t),this.jf!==null)||this.Kf)return;this.Yf=!0;const n=this.rp(un(e),ct(this.Af)),{bp:i,Sp:o,ep:l}=n;if(this.Lf||!(l<5)){if(!this.Lf){const a=.5*i,c=o>=a&&!this.yn.xp(),u=a>o&&!this.yn.Cp();c||u||(this.Kf=!0),this.Lf=!0,this.Of=!0,this.pp(),this.op()}if(!this.Kf){const a=this.sp(t,e);this.hp(a,this.lp.yp),di(t)}}}kp(t){if(t.button!==0)return;const e=this.rp(un(t),ct(this.Ef)),{ep:n}=e;if(n>=5&&(this.zf=!0,this.cp()),this.zf){const i=this.sp(t);this._p(i,this.lp.Pp)}}rp(t,e){const n=Math.abs(e._t-t._t),i=Math.abs(e.ut-t.ut);return{bp:n,Sp:i,ep:n+i}}Tp(t){let e=Zo(t.changedTouches,ct(this.Xf));if(e===null&&t.touches.length===0&&(e=t.changedTouches[0]),e===null)return;this.Xf=null,this.Gf=zr(t),this.pp(),this.Af=null,this.$f&&(this.$f(),this.$f=null);const n=this.sp(t,e);if(this.hp(n,this.lp.Rp),++this.Rf,this.Df&&this.Rf>1){const{ep:i}=this.rp(un(e),this.If);i<30&&!this.Of&&this.hp(n,this.lp.ap),this.op()}else this.Of||(this.hp(n,this.lp.Dp),this.lp.Dp&&di(t));this.Rf===0&&di(t),t.touches.length===0&&this.Bf&&(this.Bf=!1,di(t))}tp(t){if(t.button!==0)return;const e=this.sp(t);if(this.Ef=null,this.Zf=!1,this.Uf&&(this.Uf(),this.Uf=null),oh()&&this.dp.ownerDocument.documentElement.removeEventListener("mouseleave",this.Qf),!this.np(t))if(this._p(e,this.lp.Ip),++this.kf,this.Pf&&this.kf>1){const{ep:n}=this.rp(un(t),this.Tf);n<5&&!this.zf&&this._p(e,this.lp.up),this.cp()}else this.zf||this._p(e,this.lp.Vp)}pp(){this.Vf!==null&&(clearTimeout(this.Vf),this.Vf=null)}Bp(t){if(this.Xf!==null)return;const e=t.changedTouches[0];this.Xf=e.identifier,this.Gf=zr(t);const n=this.dp.ownerDocument.documentElement;this.Of=!1,this.Lf=!1,this.Kf=!1,this.Af=un(e),this.$f&&(this.$f(),this.$f=null);{const o=this.gp.bind(this),l=this.Tp.bind(this);this.$f=()=>{n.removeEventListener("touchmove",o),n.removeEventListener("touchend",l)},n.addEventListener("touchmove",o,{passive:!1}),n.addEventListener("touchend",l,{passive:!1}),this.pp(),this.Vf=setTimeout(this.Ep.bind(this,t),240)}const i=this.sp(t,e);this.hp(i,this.lp.Ap),this.Df||(this.Rf=0,this.Df=setTimeout(this.op.bind(this),500),this.If=un(e))}Lp(t){if(t.button!==0)return;const e=this.dp.ownerDocument.documentElement;oh()&&e.addEventListener("mouseleave",this.Qf),this.zf=!1,this.Ef=un(t),this.Uf&&(this.Uf(),this.Uf=null);{const i=this.kp.bind(this),o=this.tp.bind(this);this.Uf=()=>{e.removeEventListener("mousemove",i),e.removeEventListener("mouseup",o)},e.addEventListener("mousemove",i),e.addEventListener("mouseup",o)}if(this.Zf=!0,this.np(t))return;const n=this.sp(t);this._p(n,this.lp.zp),this.Pf||(this.kf=0,this.Pf=setTimeout(this.cp.bind(this),500),this.Tf=un(t))}fp(){this.dp.addEventListener("mouseenter",this.vp.bind(this)),this.dp.addEventListener("touchcancel",this.pp.bind(this));{const t=this.dp.ownerDocument,e=n=>{this.lp.Op&&(n.composed&&this.dp.contains(n.composedPath()[0])||n.target&&this.dp.contains(n.target)||this.lp.Op())};this.Ff=()=>{t.removeEventListener("touchstart",e)},this.Nf=()=>{t.removeEventListener("mousedown",e)},t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0})}Xo()&&(this.Wf=()=>{this.dp.removeEventListener("dblclick",this.ip)},this.dp.addEventListener("dblclick",this.ip)),this.dp.addEventListener("mouseleave",this.Np.bind(this)),this.dp.addEventListener("touchstart",this.Bp.bind(this),{passive:!0}),Wp(this.dp),this.dp.addEventListener("mousedown",this.Lp.bind(this)),this.Fp(),this.dp.addEventListener("touchmove",(()=>{}),{passive:!1})}Fp(){this.lp.Wp===void 0&&this.lp.Hp===void 0&&this.lp.Up===void 0||(this.dp.addEventListener("touchstart",(t=>this.$p(t.touches)),{passive:!0}),this.dp.addEventListener("touchmove",(t=>{if(t.touches.length===2&&this.jf!==null&&this.lp.Hp!==void 0){const e=lh(t.touches[0],t.touches[1])/this.qf;this.lp.Hp(this.jf,e),di(t)}}),{passive:!1}),this.dp.addEventListener("touchend",(t=>{this.$p(t.touches)})))}$p(t){t.length===1&&(this.Yf=!1),t.length!==2||this.Yf||this.Bf?this.jp():this.qp(t)}qp(t){const e=this.dp.getBoundingClientRect()||{left:0,top:0};this.jf={_t:(t[0].clientX-e.left+(t[1].clientX-e.left))/2,ut:(t[0].clientY-e.top+(t[1].clientY-e.top))/2},this.qf=lh(t[0],t[1]),this.lp.Wp!==void 0&&this.lp.Wp(),this.pp()}jp(){this.jf!==null&&(this.jf=null,this.lp.Up!==void 0&&this.lp.Up())}Np(t){if(this.Hf&&this.Hf(),this.np(t)||!this.Jf)return;const e=this.sp(t);this._p(e,this.lp.Yp),this.Jf=!Xo()}Ep(t){const e=Zo(t.touches,ct(this.Xf));if(e===null)return;const n=this.sp(t,e);this.hp(n,this.lp.Kp),this.Of=!0,this.Bf=!0}np(t){return t.sourceCapabilities&&t.sourceCapabilities.firesTouchEvents!==void 0?t.sourceCapabilities.firesTouchEvents:zr(t)<this.Gf+500}hp(t,e){e&&e.call(this.lp,t)}_p(t,e){e&&e.call(this.lp,t)}sp(t,e){const n=e||t,i=this.dp.getBoundingClientRect()||{left:0,top:0};return{clientX:n.clientX,clientY:n.clientY,pageX:n.pageX,pageY:n.pageY,screenX:n.screenX,screenY:n.screenY,localX:n.clientX-i.left,localY:n.clientY-i.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Zp:!t.type.startsWith("mouse")&&t.type!=="contextmenu"&&t.type!=="click",Gp:t.type,Xp:n.target,gu:t.view,Jp:()=>{t.type!=="touchstart"&&di(t)}}}}function lh(s,t){const e=s.clientX-t.clientX,n=s.clientY-t.clientY;return Math.sqrt(e*e+n*n)}function di(s){s.cancelable&&s.preventDefault()}function un(s){return{_t:s.pageX,ut:s.pageY}}function zr(s){return s.timeStamp||performance.now()}function Zo(s,t){for(let e=0;e<s.length;++e)if(s[e].identifier===t)return s[e];return null}class qp{constructor(t,e,n){this.Qp=null,this.tv=null,this.iv=!0,this.nv=null,this.sv=t,this.ev=t.rv()[e],this.hv=t.rv()[n],this.av=document.createElement("tr"),this.av.style.height="1px",this.lv=document.createElement("td"),this.lv.style.position="relative",this.lv.style.padding="0",this.lv.style.margin="0",this.lv.setAttribute("colspan","3"),this.ov(),this.av.appendChild(this.lv),this.iv=this.sv.N().layout.panes.enableResize,this.iv?this._v():(this.Qp=null,this.tv=null)}m(){this.tv!==null&&this.tv.m()}uv(){return this.av}cv(){return Se({width:this.ev.cv().width,height:1})}dv(){return Se({width:this.ev.dv().width,height:1*window.devicePixelRatio})}fv(t,e,n){const i=this.dv();t.fillStyle=this.sv.N().layout.panes.separatorColor,t.fillRect(e,n,i.width,i.height)}kt(){this.ov(),this.sv.N().layout.panes.enableResize!==this.iv&&(this.iv=this.sv.N().layout.panes.enableResize,this.iv?this._v():(this.Qp!==null&&(this.lv.removeChild(this.Qp.pv),this.lv.removeChild(this.Qp.vv),this.Qp=null),this.tv!==null&&(this.tv.m(),this.tv=null)))}_v(){const t=document.createElement("div"),e=t.style;e.position="fixed",e.display="none",e.zIndex="49",e.top="0",e.left="0",e.width="100%",e.height="100%",e.cursor="row-resize",this.lv.appendChild(t);const n=document.createElement("div"),i=n.style;i.position="absolute",i.zIndex="50",i.top="-4px",i.height="9px",i.width="100%",i.backgroundColor="",i.cursor="row-resize",this.lv.appendChild(n);const o={wp:this.mv.bind(this),Yp:this.wv.bind(this),zp:this.Mv.bind(this),Ap:this.Mv.bind(this),Pp:this.gv.bind(this),yp:this.gv.bind(this),Ip:this.bv.bind(this),Rp:this.bv.bind(this)};this.tv=new So(n,o,{xp:()=>!1,Cp:()=>!0}),this.Qp={vv:n,pv:t}}ov(){this.lv.style.background=this.sv.N().layout.panes.separatorColor}mv(t){this.Qp!==null&&(this.Qp.vv.style.backgroundColor=this.sv.N().layout.panes.separatorHoverColor)}wv(t){this.Qp!==null&&this.nv===null&&(this.Qp.vv.style.backgroundColor="")}Mv(t){if(this.Qp===null)return;const e=this.ev.Sv().z_()+this.hv.Sv().z_(),n=e/(this.ev.cv().height+this.hv.cv().height),i=30*n;e<=2*i||(this.nv={xv:t.pageY,Cv:this.ev.Sv().z_(),yv:e-i,kv:e,Pv:n,Tv:i},this.Qp.pv.style.display="block")}gv(t){const e=this.nv;if(e===null)return;const n=(t.pageY-e.xv)*e.Pv,i=ki(e.Cv+n,e.Tv,e.yv);this.ev.Sv().O_(i),this.hv.Sv().O_(e.kv-i),this.sv.Qt().Pa()}bv(t){this.nv!==null&&this.Qp!==null&&(this.nv=null,this.Qp.pv.style.display="none")}}function Jo(s,t){return s.Rv-t.Rv}function tl(s,t,e){const n=(s.Rv-t.Rv)/(s.wt-t.wt);return Math.sign(n)*Math.min(Math.abs(n),e)}class Vp{constructor(t,e,n,i){this.Dv=null,this.Iv=null,this.Vv=null,this.Bv=null,this.Ev=null,this.Av=0,this.Lv=0,this.zv=t,this.Ov=e,this.Nv=n,this.ks=i}Fv(t,e){if(this.Dv!==null){if(this.Dv.wt===e)return void(this.Dv.Rv=t);if(Math.abs(this.Dv.Rv-t)<this.ks)return}this.Bv=this.Vv,this.Vv=this.Iv,this.Iv=this.Dv,this.Dv={wt:e,Rv:t}}me(t,e){if(this.Dv===null||this.Iv===null||e-this.Dv.wt>50)return;let n=0;const i=tl(this.Dv,this.Iv,this.Ov),o=Jo(this.Dv,this.Iv),l=[i],a=[o];if(n+=o,this.Vv!==null){const u=tl(this.Iv,this.Vv,this.Ov);if(Math.sign(u)===Math.sign(i)){const d=Jo(this.Iv,this.Vv);
6if(l.push(u),a.push(d),n+=d,this.Bv!==null){const f=tl(this.Vv,this.Bv,this.Ov);if(Math.sign(f)===Math.sign(i)){const g=Jo(this.Vv,this.Bv);l.push(f),a.push(g),n+=g}}}}let c=0;for(let u=0;u<l.length;++u)c+=a[u]/n*l[u];Math.abs(c)<this.zv||(this.Ev={Rv:t,wt:e},this.Lv=c,this.Av=(function(u,d){const f=Math.log(d);return Math.log(1*f/-u)/f})(Math.abs(c),this.Nv))}qc(t){const e=ct(this.Ev),n=t-e.wt;return e.Rv+this.Lv*(Math.pow(this.Nv,n)-1)/Math.log(this.Nv)}jc(t){return this.Ev===null||this.Wv(t)===this.Av}Wv(t){const e=t-ct(this.Ev).wt;return Math.min(e,this.Av)}}class Up{constructor(t,e){this.Hv=void 0,this.Uv=void 0,this.$v=void 0,this.vn=!1,this.jv=t,this.qv=e,this.Yv()}kt(){this.Yv()}Kv(){this.Hv&&this.jv.removeChild(this.Hv),this.Uv&&this.jv.removeChild(this.Uv),this.Hv=void 0,this.Uv=void 0}Zv(){return this.vn!==this.Gv()||this.$v!==this.Xv()}Xv(){return this.qv.Qt().Xi().J(this.qv.N().layout.textColor)>160?"dark":"light"}Gv(){return this.qv.N().layout.attributionLogo}Jv(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Yv(){this.Zv()&&(this.Kv(),this.vn=this.Gv(),this.vn&&(this.$v=this.Xv(),this.Uv=document.createElement("style"),this.Uv.innerText="a#tv-attr-logo{--fill:#131722;--stroke:#fff;position:absolute;left:10px;bottom:10px;height:19px;width:35px;margin:0;padding:0;border:0;z-index:3;}a#tv-attr-logo[data-dark]{--fill:#D1D4DC;--stroke:#131722;}",this.Hv=document.createElement("a"),this.Hv.href=`https://www.tradingview.com/?utm_medium=lwc-link&utm_campaign=lwc-chart${this.Jv()}`,this.Hv.title="Charting by TradingView",this.Hv.id="tv-attr-logo",this.Hv.target="_blank",this.Hv.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="35" height="19" fill="none"><g fill-rule="evenodd" clip-path="url(#a)" clip-rule="evenodd"><path fill="var(--stroke)" d="M2 0H0v10h6v9h21.4l.5-1.3 6-15 1-2.7H23.7l-.5 1.3-.2.6a5 5 0 0 0-7-.9V0H2Zm20 17h4l5.2-13 .8-2h-7l-1 2.5-.2.5-1.5 3.8-.3.7V17Zm-.8-10a3 3 0 0 0 .7-2.7A3 3 0 1 0 16.8 7h4.4ZM14 7V2H2v6h6v9h4V7h2Z"/><path fill="var(--fill)" d="M14 2H2v6h6v9h6V2Zm12 15h-7l6-15h7l-6 15Zm-7-9a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></g><defs><clipPath id="a"><path fill="var(--stroke)" d="M0 0h35v19H0z"/></clipPath></defs></svg>',this.Hv.toggleAttribute("data-dark",this.$v==="dark"),this.jv.appendChild(this.Uv),this.jv.appendChild(this.Hv)))}}function si(s,t){const e=ct(s.ownerDocument).createElement("canvas");s.appendChild(e);const n=Sm(e,{options:{allowResizeObserver:!0},transform:(i,o)=>({width:Math.max(i.width,o.width),height:Math.max(i.height,o.height)})});return n.resizeCanvasElement(t),n}function ni(s){var t;s.width=1,s.height=1,(t=s.getContext("2d"))==null||t.clearRect(0,0,1,1)}function Vl(s,t,e,n){s.qh&&s.qh(t,e,n)}function no(s,t,e,n){s.st(t,e,n)}function Ul(s,t,e,n){const i=s(e,n);for(const o of i){const l=o.Tt(n);l!==null&&t(l)}}function el(s,t){return e=>{var n,i;return(function(o){return o.Ft!==void 0})(e)?(((n=e.Ft())==null?void 0:n.cl())??"")!==t?[]:((i=e.Ga)==null?void 0:i.call(e,s))??[]:[]}}function ah(s,t,e,n){if(!s.length)return;let i=0;const o=s[0].$t(n,!0);let l=t===1?e/2-(s[0].Hi()-o/2):s[0].Hi()-o/2-e/2;l=Math.max(0,l);for(let a=1;a<s.length;a++){const c=s[a],u=s[a-1],d=u.$t(n,!1),f=c.Hi(),g=u.Hi();if(t===1?f>g-d:f<g+d){const v=g-d*t;c.Ui(v);const b=v-t*d/2;if((t===1?b<0:b>e)&&l>0){const w=t===1?-1-b:b-e,k=Math.min(w,l);for(let y=i;y<s.length;y++)s[y].Ui(s[y].Hi()+t*k);l-=k}}else i=a,l=t===1?g-d-f:f-(g+d)}}class ch{constructor(t,e,n,i){this.Ki=null,this.Qv=null,this.tm=!1,this.im=new lr(200),this.nm=null,this.sm=0,this.rm=!1,this.hm=()=>{this.rm||this.yt.am().Qt().mr()},this.lm=()=>{this.rm||this.yt.am().Qt().mr()},this.yt=t,this.yn=e,this.ko=e.layout,this.wd=n,this.om=i==="left",this._m=el("normal",i),this.um=el("top",i),this.dm=el("bottom",i),this.lv=document.createElement("div"),this.lv.style.height="100%",this.lv.style.overflow="hidden",this.lv.style.width="25px",this.lv.style.left="0",this.lv.style.position="relative",this.fm=si(this.lv,Se({width:16,height:16})),this.fm.subscribeSuggestedBitmapSizeChanged(this.hm);const o=this.fm.canvasElement;o.style.position="absolute",o.style.zIndex="1",o.style.left="0",o.style.top="0",this.pm=si(this.lv,Se({width:16,height:16})),this.pm.subscribeSuggestedBitmapSizeChanged(this.lm);const l=this.pm.canvasElement;l.style.position="absolute",l.style.zIndex="2",l.style.left="0",l.style.top="0";const a={zp:this.Mv.bind(this),Ap:this.Mv.bind(this),Pp:this.gv.bind(this),yp:this.gv.bind(this),Op:this.vm.bind(this),Ip:this.bv.bind(this),Rp:this.bv.bind(this),up:this.wm.bind(this),ap:this.wm.bind(this),wp:this.Mm.bind(this),Yp:this.wv.bind(this)};this.tv=new So(this.pm.canvasElement,a,{xp:()=>!this.yn.handleScroll.vertTouchDrag,Cp:()=>!0})}m(){this.tv.m(),this.pm.unsubscribeSuggestedBitmapSizeChanged(this.lm),ni(this.pm.canvasElement),this.pm.dispose(),this.fm.unsubscribeSuggestedBitmapSizeChanged(this.hm),ni(this.fm.canvasElement),this.fm.dispose(),this.Ki!==null&&this.Ki.a_().u(this),this.Ki=null}uv(){return this.lv}k(){return this.ko.fontSize}gm(){const t=this.wd.N();return this.nm!==t.P&&(this.im.Os(),this.nm=t.P),t}bm(){if(this.Ki===null)return 0;let t=0;const e=this.gm(),n=ct(this.fm.canvasElement.getContext("2d",{colorSpace:this.yt.am().N().layout.colorSpace}));n.save();const i=this.Ki.El();n.font=this.Sm(),i.length>0&&(t=Math.max(this.im.Ii(n,i[0].io),this.im.Ii(n,i[i.length-1].io)));const o=this.xm();for(let u=o.length;u--;){const d=this.im.Ii(n,o[u].ri());d>t&&(t=d)}const l=this.Ki.Lt();if(l!==null&&this.Qv!==null&&(a=this.yn.crosshair).mode!==2&&a.horzLine.visible&&a.horzLine.labelVisible){const u=this.Ki.Tn(1,l),d=this.Ki.Tn(this.Qv.height-2,l);t=Math.max(t,this.im.Ii(n,this.Ki.Ji(Math.floor(Math.min(u,d))+.11111111111111,l)),this.im.Ii(n,this.Ki.Ji(Math.ceil(Math.max(u,d))-.11111111111111,l)))}var a;
6n.restore();const c=t||34;return ql(Math.ceil(e.S+e.C+e.V+e.B+5+c))}Cm(t){this.Qv!==null&&Xn(this.Qv,t)||(this.Qv=t,this.rm=!0,this.fm.resizeCanvasElement(t),this.pm.resizeCanvasElement(t),this.rm=!1,this.lv.style.width=`${t.width}px`,this.lv.style.height=`${t.height}px`)}ym(){return ct(this.Qv).width}un(t){this.Ki!==t&&(this.Ki!==null&&this.Ki.a_().u(this),this.Ki=t,t.a_().i(this.po.bind(this),this))}Ft(){return this.Ki}Os(){const t=this.yt.Sv();this.yt.am().Qt().eu(t,ct(this.Ft()))}km(t){if(this.Qv===null)return;const e={colorSpace:this.yt.am().N().layout.colorSpace};if(t!==1){this.Pm(),this.fm.applySuggestedBitmapSize();const i=Jn(this.fm,e);i!==null&&(i.useBitmapCoordinateSpace((o=>{this.Tm(o),this.Rm(o)})),this.yt.Dm(i,this.dm),this.Im(i),this.yt.Dm(i,this._m),this.Vm(i))}this.pm.applySuggestedBitmapSize();const n=Jn(this.pm,e);n!==null&&(n.useBitmapCoordinateSpace((({context:i,bitmapSize:o})=>{i.clearRect(0,0,o.width,o.height)})),this.Bm(n),this.yt.Dm(n,this.um))}dv(){return this.fm.bitmapSize}fv(t,e,n,i){const o=this.dv();if(o.width>0&&o.height>0&&(t.drawImage(this.fm.canvasElement,e,n),i)){const l=this.pm.canvasElement;t.drawImage(l,e,n)}}kt(){var t;(t=this.Ki)==null||t.El()}Mv(t){if(this.Ki===null||this.Ki.Gi()||!this.yn.handleScale.axisPressedMouseMove.price)return;const e=this.yt.am().Qt(),n=this.yt.Sv();this.tm=!0,e.G_(n,this.Ki,t.localY)}gv(t){if(this.Ki===null||!this.yn.handleScale.axisPressedMouseMove.price)return;const e=this.yt.am().Qt(),n=this.yt.Sv(),i=this.Ki;e.X_(n,i,t.localY)}vm(){if(this.Ki===null||!this.yn.handleScale.axisPressedMouseMove.price)return;const t=this.yt.am().Qt(),e=this.yt.Sv(),n=this.Ki;this.tm&&(this.tm=!1,t.J_(e,n))}bv(t){if(this.Ki===null||!this.yn.handleScale.axisPressedMouseMove.price)return;const e=this.yt.am().Qt(),n=this.yt.Sv();this.tm=!1,e.J_(n,this.Ki)}wm(t){this.yn.handleScale.axisDoubleClickReset.price&&this.Os()}Mm(t){this.Ki!==null&&(!this.yt.am().Qt().N().handleScale.axisPressedMouseMove.price||this.Ki.je()||this.Ki.Lo()||this.Em(1))}wv(t){this.Em(0)}xm(){const t=[],e=this.Ki===null?void 0:this.Ki;return(n=>{for(let i=0;i<n.length;++i){const o=n[i].qn(this.yt.Sv(),e);for(let l=0;l<o.length;l++)t.push(o[l])}})(this.yt.Sv().Dt()),t}Tm({context:t,bitmapSize:e}){const{width:n,height:i}=e,o=this.yt.Sv().Qt(),l=o.$(),a=o.ef();l===a?wo(t,0,0,n,i,l):xd(t,0,0,n,i,l,a)}Rm({context:t,bitmapSize:e,horizontalPixelRatio:n}){if(this.Qv===null||this.Ki===null||!this.Ki.N().borderVisible)return;t.fillStyle=this.Ki.N().borderColor;const i=Math.max(1,Math.floor(this.gm().S*n));let o;o=this.om?e.width-i:0,t.fillRect(o,0,i,e.height)}Im(t){if(this.Qv===null||this.Ki===null)return;const e=this.Ki.El(),n=this.Ki.N(),i=this.gm(),o=this.om?this.Qv.width-i.C:0;n.borderVisible&&n.ticksVisible&&t.useBitmapCoordinateSpace((({context:l,horizontalPixelRatio:a,verticalPixelRatio:c})=>{l.fillStyle=n.borderColor;const u=Math.max(1,Math.floor(c)),d=Math.floor(.5*c),f=Math.round(i.C*a);l.beginPath();for(const g of e)l.rect(Math.floor(o*a),Math.round(g.Rl*c)-d,f,u);l.fill()})),t.useMediaCoordinateSpace((({context:l})=>{l.font=this.Sm(),l.fillStyle=n.textColor??this.ko.textColor,l.textAlign=this.om?"right":"left",l.textBaseline="middle";const a=this.om?Math.round(o-i.V):Math.round(o+i.C+i.V),c=e.map((u=>this.im.Di(l,u.io)));for(let u=e.length;u--;){const d=e[u];l.fillText(d.io,a,d.Rl+c[u])}}))}Pm(){if(this.Qv===null||this.Ki===null)return;let t=this.Qv.height/2;const e=[],n=this.Ki.Dt().slice(),i=this.yt.Sv(),o=this.gm();this.Ki===i.Gs()&&this.yt.Sv().Dt().forEach((c=>{i.Zs(c)&&n.push(c)}));const l=this.Ki.Cl()[0],a=this.Ki;n.forEach((c=>{const u=c.qn(i,a);u.forEach((d=>{d.$i()&&d.Wi()===null&&(d.Ui(null),e.push(d))})),l===c&&u.length>0&&(t=u[0].Ei())})),this.Ki.N().alignLabels&&this.Am(e,o,t)}Am(t,e,n){if(this.Qv===null)return;const i=t.filter((l=>l.Ei()<=n)),o=t.filter((l=>l.Ei()>n));i.sort(((l,a)=>a.Ei()-l.Ei())),i.length&&o.length&&o.push(i[0]),o.sort(((l,a)=>l.Ei()-a.Ei()));for(const l of t){const a=Math.floor(l.$t(e)/2),c=l.Ei();c>-a&&c<a&&l.Ui(a),c>this.Qv.height-a&&c<this.Qv.height+a&&l.Ui(this.Qv.height-a)}ah(i,1,this.Qv.height,e),ah(o,-1,this.Qv.height,e)}Vm(t){if(this.Qv===null)return;const e=this.xm(),n=this.gm(),i=this.om?"right":"left";e.forEach((o=>{o.ji()&&o.Tt(ct(this.Ki)).st(t,n,this.im,i)}))}Bm(t){if(this.Qv===null||this.Ki===null)return;const e=this.yt.am().Qt(),n=[],i=this.yt.Sv(),o=e.Rd().qn(i,this.Ki);o.length&&n.push(o);const l=this.gm(),a=this.om?"right":"left";
6n.forEach((c=>{c.forEach((u=>{u.Tt(ct(this.Ki)).st(t,l,this.im,a)}))}))}Em(t){this.lv.style.cursor=t===1?"ns-resize":"default"}po(){const t=this.bm();this.sm<t&&this.yt.am().Qt().Pa(),this.sm=t}Sm(){return or(this.ko.fontSize,this.ko.fontFamily)}}function Hp(s,t){var e;return((e=s.Ka)==null?void 0:e.call(s,t))??[]}function hh(s,t){var e;return((e=s.jn)==null?void 0:e.call(s,t))??[]}function uh(s,t){var e;return((e=s.cn)==null?void 0:e.call(s,t))??[]}function Kp(s,t){var e;return((e=s.ja)==null?void 0:e.call(s,t))??[]}class Sa{constructor(t,e){this.Qv=Se({width:0,height:0}),this.Lm=null,this.zm=null,this.Om=null,this.Nm=null,this.Fm=!1,this.Wm=new Ye,this.Hm=new Ye,this.Um=0,this.$m=!1,this.jm=null,this.qm=!1,this.Ym=null,this.Km=null,this.rm=!1,this.hm=()=>{this.rm||this.Zm===null||this.sn().mr()},this.lm=()=>{this.rm||this.Zm===null||this.sn().mr()},this.qv=t,this.Zm=e,this.Zm.fu().i(this.Gm.bind(this),this,!0),this.Xm=document.createElement("td"),this.Xm.style.padding="0",this.Xm.style.position="relative";const n=document.createElement("div");n.style.width="100%",n.style.height="100%",n.style.position="relative",n.style.overflow="hidden",this.Jm=document.createElement("td"),this.Jm.style.padding="0",this.Qm=document.createElement("td"),this.Qm.style.padding="0",this.Xm.appendChild(n),this.fm=si(n,Se({width:16,height:16})),this.fm.subscribeSuggestedBitmapSizeChanged(this.hm);const i=this.fm.canvasElement;i.style.position="absolute",i.style.zIndex="1",i.style.left="0",i.style.top="0",this.pm=si(n,Se({width:16,height:16})),this.pm.subscribeSuggestedBitmapSizeChanged(this.lm);const o=this.pm.canvasElement;o.style.position="absolute",o.style.zIndex="2",o.style.left="0",o.style.top="0",this.av=document.createElement("tr"),this.av.appendChild(this.Jm),this.av.appendChild(this.Xm),this.av.appendChild(this.Qm),this.tw(),this.tv=new So(this.pm.canvasElement,this,{xp:()=>this.jm===null&&!this.qv.N().handleScroll.vertTouchDrag,Cp:()=>this.jm===null&&!this.qv.N().handleScroll.horzTouchDrag})}m(){this.Lm!==null&&this.Lm.m(),this.zm!==null&&this.zm.m(),this.Om=null,this.pm.unsubscribeSuggestedBitmapSizeChanged(this.lm),ni(this.pm.canvasElement),this.pm.dispose(),this.fm.unsubscribeSuggestedBitmapSizeChanged(this.hm),ni(this.fm.canvasElement),this.fm.dispose(),this.Zm!==null&&(this.Zm.fu().u(this),this.Zm.m()),this.tv.m()}Sv(){return ct(this.Zm)}iw(t){var e;this.Zm!==null&&this.Zm.fu().u(this),this.Zm=t,this.Zm!==null&&this.Zm.fu().i(Sa.prototype.Gm.bind(this),this,!0),this.tw(),this.qv.rv().indexOf(this)===this.qv.rv().length-1?(this.Om=this.Om??new Up(this.Xm,this.qv),this.Om.kt()):((e=this.Om)==null||e.Kv(),this.Om=null)}am(){return this.qv}uv(){return this.av}tw(){if(this.Zm!==null&&(this.nw(),this.sn().Jn().length!==0)){if(this.Lm!==null){const t=this.Zm.K_();this.Lm.un(ct(t))}if(this.zm!==null){const t=this.Zm.Z_();this.zm.un(ct(t))}}}sw(){this.Lm!==null&&this.Lm.kt(),this.zm!==null&&this.zm.kt()}z_(){return this.Zm!==null?this.Zm.z_():0}O_(t){this.Zm&&this.Zm.O_(t)}wp(t){if(!this.Zm)return;this.ew();const e=t.localX,n=t.localY;this.rw(e,n,t)}zp(t){this.ew(),this.hw(),this.rw(t.localX,t.localY,t)}Mp(t){if(!this.Zm)return;this.ew();const e=t.localX,n=t.localY;this.rw(e,n,t)}Vp(t){this.Zm!==null&&(this.ew(),this.rw(t.localX,t.localY,t),this.aw(t))}up(t){this.Zm!==null&&this.lw(this.Hm,t)}ap(t){this.up(t)}Pp(t){this.ew(),this.ow(t),this.rw(t.localX,t.localY,t)}Ip(t){this.Zm!==null&&(this.ew(),this.$m=!1,this._w(t))}Dp(t){this.Zm!==null&&this.aw(t)}Kp(t){if(this.$m=!0,this.jm===null){const e={x:t.localX,y:t.localY};this.uw(e,e,t)}}Yp(t){this.Zm!==null&&(this.ew(),this.Zm.Qt().kd(null),this.cw())}dw(){return this.Wm}fw(){return this.Hm}Wp(){this.Um=1,this.sn().cs()}Hp(t,e){if(!this.qv.N().handleScale.pinch)return;const n=5*(e-this.Um);this.Um=e,this.sn().Od(t._t,n)}Ap(t){this.$m=!1,this.qm=this.jm!==null,this.hw();const e=this.sn().Rd();this.jm!==null&&e.It()&&(this.Ym={x:e.ni(),y:e.si()},this.jm={x:t.localX,y:t.localY})}yp(t){if(this.Zm===null)return;const e=t.localX,n=t.localY;if(this.jm===null)this.ow(t);else{this.qm=!1;const i=ct(this.Ym),o=i.x+(e-this.jm.x),l=i.y+(n-this.jm.y);this.rw(o,l,t)}}Rp(t){this.am().N().trackingMode.exitMode===0&&(this.qm=!0),this.pw(),this._w(t)}Qs(t,e){const n=this.Zm;return n===null?null:Td(n,t,e)}mw(t,e){ct(e==="left"?this.Lm:this.zm).Cm(Se({width:t,height:this.Qv.height}))}cv(){return this.Qv}Cm(t){Xn(this.Qv,t)||(this.Qv=t,this.rm=!0,this.fm.resizeCanvasElement(t),this.pm.resizeCanvasElement(t),this.rm=!1,this.Xm.style.width=t.width+"px",this.Xm.style.height=t.height+"px")}ww(){const t=ct(this.Zm);t.q_(t.K_()),t.q_(t.Z_());for(const e of t.Cl())if(t.Zs(e)){const n=e.Ft();n!==null&&t.q_(n),e.Nn()}for(const e of t.vu())e.Nn()}dv(){return this.fm.bitmapSize}fv(t,e,n,i){const o=this.dv();if(o.width>0&&o.height>0&&(t.drawImage(this.fm.canvasElement,e,n),i)){const l=this.pm.canvasElement;t!==null&&t.drawImage(l,e,n)}}km(t){if(t===0||this.Zm===null)return;t>1&&this.ww(),this.Lm!==null&&this.Lm.km(t),this.zm!==null&&this.zm.km(t);const e={colorSpace:this.qv.N().layout.colorSpace};if(t!==1){this.fm.applySuggestedBitmapSize();const i=Jn(this.fm,e);i!==null&&(i.useBitmapCoordinateSpace((o=>{this.Tm(o)})),this.Zm&&(this.Mw(i,Hp),this.gw(i),this.Mw(i,hh),this.Mw(i,uh)))}this.pm.applySuggestedBitmapSize();const n=Jn(this.pm,e);n!==null&&(n.useBitmapCoordinateSpace((({context:i,bitmapSize:o})=>{i.clearRect(0,0,o.width,o.height)})),this.bw(n),this.Mw(n,Kp),this.Mw(n,uh))}Sw(){return this.Lm}xw(){return this.zm}Dm(t,e){this.Mw(t,e)}Gm(){this.Zm!==null&&this.Zm.fu().u(this),this.Zm=null}aw(t){this.lw(this.Wm,t)}lw(t,e){const n=e.localX,i=e.localY;t.v()&&t.p(this.sn().Et().Rc(n),{x:n,y:i},e)}Tm({context:t,bitmapSize:e}){const{width:n,height:i}=e,o=this.sn(),l=o.$(),a=o.ef();l===a?wo(t,0,0,n,i,a):xd(t,0,0,n,i,l,a)}gw(t){const e=ct(this.Zm),n=e.pu().wr().Tt(e);n!==null&&n.st(t,!1)}bw(t){this.Cw(t,hh,no,this.sn().Rd())}Mw(t,e){const n=ct(this.Zm),i=n.au(),o=n.vu();for(const l of o)this.Cw(t,e,Vl,l);for(const l of i)this.Cw(t,e,Vl,l);for(const l of o)this.Cw(t,e,no,l);for(const l of i)this.Cw(t,e,no,l)}Cw(t,e,n,i){const o=ct(this.Zm),l=o.Qt().ou(),a=l!==null&&l.lu===i,c=l!==null&&a&&l.wu!==void 0?l.wu.ie:void 0;Ul(e,(u=>n(u,t,a,c)),i,o)}nw(){if(this.Zm===null)return;const t=this.qv,e=this.Zm.K_().N().visible,n=this.Zm.Z_().N().visible;e||this.Lm===null||(this.Jm.removeChild(this.Lm.uv()),this.Lm.m(),this.Lm=null),n||this.zm===null||(this.Qm.removeChild(this.zm.uv()),this.zm.m(),this.zm=null);const i=t.Qt().Zd();e&&this.Lm===null&&(this.Lm=new ch(this,t.N(),i,"left"),this.Jm.appendChild(this.Lm.uv())),n&&this.zm===null&&(this.zm=new ch(this,t.N(),i,"right"),this.Qm.appendChild(this.zm.uv()))}yw(t){return t.Zp&&this.$m||this.jm!==null}rw(t,e,n){t=Math.max(0,Math.min(t,this.Qv.width-1)),e=Math.max(0,Math.min(e,this.Qv.height-1)),this.sn().jd(t,e,n,ct(this.Zm))}cw(){this.sn().Yd()}pw(){this.qm&&(this.jm=null,this.cw())}uw(t,e,n){this.jm=t,this.qm=!1,this.rw(e.x,e.y,n);const i=this.sn().Rd();this.Ym={x:i.ni(),y:i.si()}}sn(){return this.qv.Qt()}_w(t){if(!this.Fm)return;const e=this.sn(),n=this.Sv();if(e.iu(n,n.Pn()),this.Nm=null,this.Fm=!1,e.Hd(),this.Km!==null){const i=performance.now(),o=e.Et();this.Km.me(o.Ac(),i),this.Km.jc(i)||e.ps(this.Km)}}ew(){this.jm=null}hw(){if(this.Zm){if(this.sn().cs(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)ct(document.activeElement).blur();else{const t=document.getSelection();t!==null&&t.removeAllRanges()}!this.Zm.Pn().Gi()&&this.sn().Et().Gi()}}ow(t){if(this.Zm===null)return;const e=this.sn(),n=e.Et();if(n.Gi())return;const i=this.qv.N(),o=i.handleScroll,l=i.kineticScroll;if((!o.pressedMouseMove||t.Zp)&&(!o.horzTouchDrag&&!o.vertTouchDrag||!t.Zp))return;const a=this.Zm.Pn(),c=performance.now();if(this.Nm!==null||this.yw(t)||(this.Nm={x:t.clientX,y:t.clientY,Sf:c,kw:t.localX,Pw:t.localY}),this.Nm!==null&&!this.Fm&&(this.Nm.x!==t.clientX||this.Nm.y!==t.clientY)){if(t.Zp&&l.touch||!t.Zp&&l.mouse){const u=n.fl();this.Km=new Vp(.2/u,7/u,.997,15/u),this.Km.Fv(n.Ac(),this.Nm.Sf)}else this.Km=null;a.Gi()||e.Q_(this.Zm,a,t.localY),e.Fd(t.localX),this.Fm=!0}this.Fm&&(a.Gi()||e.tu(this.Zm,a,t.localY),e.Wd(t.localX),this.Km!==null&&this.Km.Fv(n.Ac(),c))}}class dh{constructor(t,e,n,i,o){this.xt=!0,this.Qv=Se({width:0,height:0}),this.hm=()=>this.km(3),this.om=t==="left",this.wd=n.Zd,this.yn=e,this.Tw=i,this.Rw=o,this.lv=document.createElement("div"),this.lv.style.width="25px",this.lv.style.height="100%",this.lv.style.overflow="hidden",this.fm=si(this.lv,Se({width:16,height:16})),this.fm.subscribeSuggestedBitmapSizeChanged(this.hm)}m(){this.fm.unsubscribeSuggestedBitmapSizeChanged(this.hm),ni(this.fm.canvasElement),this.fm.dispose()}uv(){return this.lv}cv(){return this.Qv}Cm(t){Xn(this.Qv,t)||(this.Qv=t,this.fm.resizeCanvasElement(t),this.lv.style.width=`${t.width}px`,this.lv.style.height=`${t.height}px`,this.xt=!0)}km(t){if(t<3&&!this.xt||this.Qv.width===0||this.Qv.height===0)return;this.xt=!1,this.fm.applySuggestedBitmapSize();const e=Jn(this.fm,{colorSpace:this.yn.layout.colorSpace});e!==null&&e.useBitmapCoordinateSpace((n=>{this.Tm(n),this.Rm(n)}))}dv(){return this.fm.bitmapSize}fv(t,e,n){const i=this.dv();i.width>0&&i.height>0&&t.drawImage(this.fm.canvasElement,e,n)}Rm({context:t,bitmapSize:e,horizontalPixelRatio:n,verticalPixelRatio:i}){if(!this.Tw())return;t.fillStyle=this.yn.timeScale.borderColor;const o=Math.floor(this.wd.N().S*n),l=Math.floor(this.wd.N().S*i),a=this.om?e.width-o:0;t.fillRect(a,0,o,l)}Tm({context:t,bitmapSize:e}){wo(t,0,0,e.width,e.height,this.Rw())}}function Na(s){return t=>{var e;return((e=t.Xa)==null?void 0:e.call(t,s))??[]}}const $p=Na("normal"),Yp=Na("top"),Qp=Na("bottom");class Gp{constructor(t,e){this.Dw=null,this.Iw=null,this.M=null,this.Vw=!1,this.Qv=Se({width:0,height:0}),this.Bw=new Ye,this.im=new lr(5),this.rm=!1,this.hm=()=>{this.rm||this.qv.Qt().mr()},this.lm=()=>{this.rm||this.qv.Qt().mr()},this.qv=t,this.xu=e,this.yn=t.N().layout,this.Hv=document.createElement("tr"),this.Ew=document.createElement("td"),this.Ew.style.padding="0",this.Aw=document.createElement("td"),this.Aw.style.padding="0",this.lv=document.createElement("td"),this.lv.style.height="25px",this.lv.style.padding="0",this.Lw=document.createElement("div"),this.Lw.style.width="100%",this.Lw.style.height="100%",this.Lw.style.position="relative",this.Lw.style.overflow="hidden",this.lv.appendChild(this.Lw),this.fm=si(this.Lw,Se({width:16,height:16})),this.fm.subscribeSuggestedBitmapSizeChanged(this.hm);const n=this.fm.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.pm=si(this.Lw,Se({width:16,height:16})),this.pm.subscribeSuggestedBitmapSizeChanged(this.lm);const i=this.pm.canvasElement;i.style.position="absolute",i.style.zIndex="2",i.style.left="0",i.style.top="0",this.Hv.appendChild(this.Ew),this.Hv.appendChild(this.lv),this.Hv.appendChild(this.Aw),this.zw(),this.qv.Qt().L_().i(this.zw.bind(this),this),this.tv=new So(this.pm.canvasElement,this,{xp:()=>!0,Cp:()=>!this.qv.N().handleScroll.horzTouchDrag})}m(){this.tv.m(),this.Dw!==null&&this.Dw.m(),this.Iw!==null&&this.Iw.m(),this.pm.unsubscribeSuggestedBitmapSizeChanged(this.lm),ni(this.pm.canvasElement),this.pm.dispose(),this.fm.unsubscribeSuggestedBitmapSizeChanged(this.hm),ni(this.fm.canvasElement),this.fm.dispose()}uv(){return this.Hv}Ow(){return this.Dw}Nw(){return this.Iw}zp(t){if(this.Vw)return;this.Vw=!0;const e=this.qv.Qt();!e.Et().Gi()&&this.qv.N().handleScale.axisPressedMouseMove.time&&e.zd(t.localX)}Ap(t){this.zp(t)}Op(){const t=this.qv.Qt();!t.Et().Gi()&&this.Vw&&(this.Vw=!1,this.qv.N().handleScale.axisPressedMouseMove.time&&t.$d())}Pp(t){const e=this.qv.Qt();!e.Et().Gi()&&this.qv.N().handleScale.axisPressedMouseMove.time&&e.Ud(t.localX)}yp(t){this.Pp(t)}Ip(){this.Vw=!1;const t=this.qv.Qt();t.Et().Gi()&&!this.qv.N().handleScale.axisPressedMouseMove.time||t.$d()}Rp(){this.Ip()}up(){this.qv.N().handleScale.axisDoubleClickReset.time&&this.qv.Qt().ws()}ap(){this.up()}wp(){this.qv.Qt().N().handleScale.axisPressedMouseMove.time&&this.Em(1)}Yp(){this.Em(0)}cv(){return this.Qv}Fw(){return this.Bw}Ww(t,e,n){Xn(this.Qv,t)||(this.Qv=t,this.rm=!0,this.fm.resizeCanvasElement(t),this.pm.resizeCanvasElement(t),this.rm=!1,this.lv.style.width=`${t.width}px`,this.lv.style.height=`${t.height}px`,this.Bw.p(t)),this.Dw!==null&&this.Dw.Cm(Se({width:e,height:t.height})),this.Iw!==null&&this.Iw.Cm(Se({width:n,height:t.height}))}Hw(){const t=this.Uw();return Math.ceil(t.S+t.C+t.k+t.A+t.I+t.$w)}kt(){this.qv.Qt().Et().El()}dv(){return this.fm.bitmapSize}fv(t,e,n,i){const o=this.dv();if(o.width>0&&o.height>0&&(t.drawImage(this.fm.canvasElement,e,n),i)){const l=this.pm.canvasElement;t.drawImage(l,e,n)}}km(t){if(t===0)return;const e={colorSpace:this.yn.colorSpace};if(t!==1){this.fm.applySuggestedBitmapSize();const i=Jn(this.fm,e);i!==null&&(i.useBitmapCoordinateSpace((o=>{this.Tm(o),this.Rm(o),this.jw(i,Qp)})),this.Im(i),this.jw(i,$p)),this.Dw!==null&&this.Dw.km(t),this.Iw!==null&&this.Iw.km(t)}this.pm.applySuggestedBitmapSize();const n=Jn(this.pm,e);n!==null&&(n.useBitmapCoordinateSpace((({context:i,bitmapSize:o})=>{i.clearRect(0,0,o.width,o.height)})),this.qw([...this.qv.Qt().Jn(),this.qv.Qt().Rd()],n),this.jw(n,Yp))}jw(t,e){const n=this.qv.Qt().Jn();for(const i of n)Ul(e,(o=>Vl(o,t,!1,void 0)),i,void 0);for(const i of n)Ul(e,(o=>no(o,t,!1,void 0)),i,void 0)}Tm({context:t,bitmapSize:e}){wo(t,0,0,e.width,e.height,this.qv.Qt().ef())}Rm({context:t,bitmapSize:e,verticalPixelRatio:n}){if(this.qv.N().timeScale.borderVisible){t.fillStyle=this.Yw();const i=Math.max(1,Math.floor(this.Uw().S*n));t.fillRect(0,0,e.width,i)}}Im(t){const e=this.qv.Qt().Et(),n=e.El();if(!n||n.length===0)return;const i=this.xu.maxTickMarkWeight(n),o=this.Uw(),l=e.N();l.borderVisible&&l.ticksVisible&&t.useBitmapCoordinateSpace((({context:a,horizontalPixelRatio:c,verticalPixelRatio:u})=>{a.strokeStyle=this.Yw(),a.fillStyle=this.Yw();const d=Math.max(1,Math.floor(c)),f=Math.floor(.5*c);a.beginPath();const g=Math.round(o.C*u);for(let v=n.length;v--;){const b=Math.round(n[v].coord*c);a.rect(b-f,0,d,g)}a.fill()})),t.useMediaCoordinateSpace((({context:a})=>{const c=o.S+o.C+o.A+o.k/2;a.textAlign="center",a.textBaseline="middle",a.fillStyle=this.H(),a.font=this.Sm();for(const u of n)if(u.weight<i){const d=u.needAlignCoordinate?this.Kw(a,u.coord,u.label):u.coord;a.fillText(u.label,d,c)}this.qv.N().timeScale.allowBoldLabels&&(a.font=this.Zw());for(const u of n)if(u.weight>=i){const d=u.needAlignCoordinate?this.Kw(a,u.coord,u.label):u.coord;a.fillText(u.label,d,c)}}))}Kw(t,e,n){const i=this.im.Ii(t,n),o=i/2,l=Math.floor(e-o)+.5;return l<0?e+=Math.abs(0-l):l+i>this.Qv.width&&(e-=Math.abs(this.Qv.width-(l+i))),e}qw(t,e){const n=this.Uw();
6for(const i of t)for(const o of i.dn())o.Tt().st(e,n)}Yw(){return this.qv.N().timeScale.borderColor}H(){return this.yn.textColor}F(){return this.yn.fontSize}Sm(){return or(this.F(),this.yn.fontFamily)}Zw(){return or(this.F(),this.yn.fontFamily,"bold")}Uw(){this.M===null&&(this.M={S:1,L:NaN,A:NaN,I:NaN,tn:NaN,C:5,k:NaN,P:"",Qi:new lr,$w:0});const t=this.M,e=this.Sm();if(t.P!==e){const n=this.F();t.k=n,t.P=e,t.A=3*n/12,t.I=3*n/12,t.tn=9*n/12,t.L=0,t.$w=4*n/12,t.Qi.Os()}return this.M}Em(t){this.lv.style.cursor=t===1?"ew-resize":"default"}zw(){const t=this.qv.Qt(),e=t.N();e.leftPriceScale.visible||this.Dw===null||(this.Ew.removeChild(this.Dw.uv()),this.Dw.m(),this.Dw=null),e.rightPriceScale.visible||this.Iw===null||(this.Aw.removeChild(this.Iw.uv()),this.Iw.m(),this.Iw=null);const n={Zd:this.qv.Qt().Zd()},i=()=>e.leftPriceScale.borderVisible&&t.Et().N().borderVisible,o=()=>t.ef();e.leftPriceScale.visible&&this.Dw===null&&(this.Dw=new dh("left",e,n,i,o),this.Ew.appendChild(this.Dw.uv())),e.rightPriceScale.visible&&this.Iw===null&&(this.Iw=new dh("right",e,n,i,o),this.Aw.appendChild(this.Iw.uv()))}}var od;const Xp=!!Ei&&!!navigator.userAgentData&&navigator.userAgentData.brands.some((s=>s.brand.includes("Chromium")))&&!!Ei&&((od=navigator==null?void 0:navigator.userAgentData)!=null&&od.platform?navigator.userAgentData.platform==="Windows":navigator.userAgent.toLowerCase().indexOf("win")>=0);class Zp{constructor(t,e,n){var i;this.Gw=[],this.Xw=[],this.Jw=0,this.ho=0,this.C_=0,this.Qw=0,this.tM=0,this.iM=null,this.nM=!1,this.Wm=new Ye,this.Hm=new Ye,this.pd=new Ye,this.sM=null,this.eM=null,this.jv=t,this.yn=e,this.xu=n,this.Hv=document.createElement("div"),this.Hv.classList.add("tv-lightweight-charts"),this.Hv.style.overflow="hidden",this.Hv.style.direction="ltr",this.Hv.style.width="100%",this.Hv.style.height="100%",(i=this.Hv).style.userSelect="none",i.style.webkitUserSelect="none",i.style.msUserSelect="none",i.style.MozUserSelect="none",i.style.webkitTapHighlightColor="transparent",this.rM=document.createElement("table"),this.rM.setAttribute("cellspacing","0"),this.Hv.appendChild(this.rM),this.hM=this.aM.bind(this),sl(this.yn)&&this.lM(!0),this.sn=new Pp(this.md.bind(this),this.yn,n),this.Qt().Dd().i(this.oM.bind(this),this),this._M=new Gp(this,this.xu),this.rM.appendChild(this._M.uv());const o=e.autoSize&&this.uM();let l=this.yn.width,a=this.yn.height;if(o||l===0||a===0){const c=t.getBoundingClientRect();l=l||c.width,a=a||c.height}this.cM(l,a),this.dM(),t.appendChild(this.Hv),this.fM(),this.sn.Et().Zc().i(this.sn.Pa.bind(this.sn),this),this.sn.L_().i(this.sn.Pa.bind(this.sn),this)}Qt(){return this.sn}N(){return this.yn}rv(){return this.Gw}pM(){return this._M}m(){this.lM(!1),this.Jw!==0&&window.cancelAnimationFrame(this.Jw),this.sn.Dd().u(this),this.sn.Et().Zc().u(this),this.sn.L_().u(this),this.sn.m();for(const t of this.Gw)this.rM.removeChild(t.uv()),t.dw().u(this),t.fw().u(this),t.m();this.Gw=[];for(const t of this.Xw)this.vM(t);this.Xw=[],ct(this._M).m(),this.Hv.parentElement!==null&&this.Hv.parentElement.removeChild(this.Hv),this.pd.m(),this.Wm.m(),this.Hm.m(),this.mM()}cM(t,e,n=!1){if(this.ho===e&&this.C_===t)return;const i=(function(a){const c=Math.floor(a.width),u=Math.floor(a.height);return Se({width:c-c%2,height:u-u%2})})(Se({width:t,height:e}));this.ho=i.height,this.C_=i.width;const o=this.ho+"px",l=this.C_+"px";if(this.wM()||(ct(this.Hv).style.height=o,ct(this.Hv).style.width=l),this.rM.style.height=o,this.rM.style.width=l,n){this.Jw!==0&&(window.cancelAnimationFrame(this.Jw),this.Jw=0),this.nM=!1;const a=ds.ys();this.iM!==null&&(a.Ss(this.iM),this.iM=null),this.MM(a,performance.now())}else this.sn.Pa()}km(t){t===void 0&&(t=ds.ys());for(let e=0;e<this.Gw.length;e++)this.Gw[e].km(t._s(e).rs);this.yn.timeScale.visible&&this._M.km(t.ls())}vr(t){var i;const e=sl(this.yn);this.sn.vr(t);const n=sl(this.yn);n!==e&&this.lM(n),(i=t.layout)!=null&&i.panes&&this.gM(),this.fM(),this.bM(t)}dw(){return this.Wm}fw(){return this.Hm}Dd(){return this.pd}SM(t=!1){this.iM!==null&&(this.MM(this.iM,performance.now()),this.iM=null);const e=this.xM(null),n=document.createElement("canvas");n.width=e.width,n.height=e.height;const i=ct(n.getContext("2d"));return this.xM(i,t),n}CM(t){return t==="left"&&!this.yM()||t==="right"&&!this.kM()||this.Gw.length===0?0:ct(t==="left"?this.Gw[0].Sw():this.Gw[0].xw()).ym()}wM(){return this.yn.autoSize&&this.sM!==null}vv(){return this.Hv}PM(t){this.eM=t,this.eM?this.vv().style.setProperty("cursor",t):this.vv().style.removeProperty("cursor")}TM(){return this.eM}RM(t){return Cs(this.Gw[t]).cv()}gM(){this.Xw.forEach((t=>{t.kt()}))}bM(t){(t.autoSize!==void 0||!this.sM||t.width===void 0&&t.height===void 0)&&(t.autoSize&&!this.sM&&this.uM(),t.autoSize===!1&&this.sM!==null&&this.mM(),t.autoSize||t.width===void 0&&t.height===void 0||this.cM(t.width||this.C_,t.height||this.ho))}xM(t,e){let n=0,i=0;const o=this.Gw[0],l=(c,u)=>{let d=0;for(let f=0;f<this.Gw.length;f++){const g=this.Gw[f],v=ct(c==="left"?g.Sw():g.xw()),b=v.dv();
6if(t!==null&&v.fv(t,u,d,e),d+=b.height,f<this.Gw.length-1){const w=this.Xw[f],k=w.dv();t!==null&&w.fv(t,u,d),d+=k.height}}};this.yM()&&(l("left",0),n+=ct(o.Sw()).dv().width);for(let c=0;c<this.Gw.length;c++){const u=this.Gw[c],d=u.dv();if(t!==null&&u.fv(t,n,i,e),i+=d.height,c<this.Gw.length-1){const f=this.Xw[c],g=f.dv();t!==null&&f.fv(t,n,i),i+=g.height}}n+=o.dv().width,this.kM()&&(l("right",n),n+=ct(o.xw()).dv().width);const a=(c,u,d)=>{ct(c==="left"?this._M.Ow():this._M.Nw()).fv(ct(t),u,d)};if(this.yn.timeScale.visible){const c=this._M.dv();if(t!==null){let u=0;this.yM()&&(a("left",u,i),u=ct(o.Sw()).dv().width),this._M.fv(t,u,i,e),u+=c.width,this.kM()&&a("right",u,i)}i+=c.height}return Se({width:n,height:i})}DM(){let t=0,e=0,n=0;for(const k of this.Gw)this.yM()&&(e=Math.max(e,ct(k.Sw()).bm(),this.yn.leftPriceScale.minimumWidth)),this.kM()&&(n=Math.max(n,ct(k.xw()).bm(),this.yn.rightPriceScale.minimumWidth)),t+=k.z_();e=ql(e),n=ql(n);const i=this.C_,o=this.ho,l=Math.max(i-e-n,0),a=1*this.Xw.length,c=this.yn.timeScale.visible;let u=c?Math.max(this._M.Hw(),this.yn.timeScale.minimumHeight):0;var d;u=(d=u)+d%2;const f=a+u,g=o<f?0:o-f,v=g/t;let b=0;const w=window.devicePixelRatio||1;for(let k=0;k<this.Gw.length;++k){const y=this.Gw[k];y.iw(this.sn.Zn()[k]);let S=0,j=0;j=k===this.Gw.length-1?Math.ceil((g-b)*w)/w:Math.round(y.z_()*v*w)/w,S=Math.max(j,2),b+=S,y.Cm(Se({width:l,height:S})),this.yM()&&y.mw(e,"left"),this.kM()&&y.mw(n,"right"),y.Sv()&&this.sn.Id(y.Sv(),S)}this._M.Ww(Se({width:c?l:0,height:u}),c?e:0,c?n:0),this.sn.N_(l),this.Qw!==e&&(this.Qw=e),this.tM!==n&&(this.tM=n)}lM(t){t?this.Hv.addEventListener("wheel",this.hM,{passive:!1}):this.Hv.removeEventListener("wheel",this.hM)}IM(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return Xp?1/window.devicePixelRatio:1}aM(t){if(!(t.deltaX!==0&&this.yn.handleScroll.mouseWheel||t.deltaY!==0&&this.yn.handleScale.mouseWheel))return;const e=this.IM(t),n=e*t.deltaX/100,i=-e*t.deltaY/100;if(t.cancelable&&t.preventDefault(),i!==0&&this.yn.handleScale.mouseWheel){const o=Math.sign(i)*Math.min(1,Math.abs(i)),l=t.clientX-this.Hv.getBoundingClientRect().left;this.Qt().Od(l,o)}n!==0&&this.yn.handleScroll.mouseWheel&&this.Qt().Nd(-80*n)}MM(t,e){var i;const n=t.ls();n===3&&this.VM(),n!==3&&n!==2||(this.BM(t),this.EM(t,e),this._M.kt(),this.Gw.forEach((o=>{o.sw()})),((i=this.iM)==null?void 0:i.ls())===3&&(this.iM.Ss(t),this.VM(),this.BM(this.iM),this.EM(this.iM,e),t=this.iM,this.iM=null)),this.km(t)}EM(t,e){for(const n of t.bs())this.xs(n,e)}BM(t){const e=this.sn.Zn();for(let n=0;n<e.length;n++)t._s(n).hs&&e[n].ru()}xs(t,e){const n=this.sn.Et();switch(t.ds){case 0:n.Xc();break;case 1:n.Jc(t.Wt);break;case 2:n.Ms(t.Wt);break;case 3:n.gs(t.Wt);break;case 4:n.Oc();break;case 5:t.Wt.jc(e)||n.gs(t.Wt.qc(e))}}md(t){this.iM!==null?this.iM.Ss(t):this.iM=t,this.nM||(this.nM=!0,this.Jw=window.requestAnimationFrame((e=>{if(this.nM=!1,this.Jw=0,this.iM!==null){const n=this.iM;this.iM=null,this.MM(n,e);for(const i of n.bs())if(i.ds===5&&!i.Wt.jc(e)){this.Qt().ps(i.Wt);break}}})))}VM(){this.dM()}vM(t){this.rM.removeChild(t.uv()),t.m()}dM(){const t=this.sn.Zn(),e=t.length,n=this.Gw.length;for(let i=e;i<n;i++){const o=Cs(this.Gw.pop());this.rM.removeChild(o.uv()),o.dw().u(this),o.fw().u(this),o.m();const l=this.Xw.pop();l!==void 0&&this.vM(l)}for(let i=n;i<e;i++){const o=new Sa(this,t[i]);if(o.dw().i(this.AM.bind(this,o),this),o.fw().i(this.LM.bind(this,o),this),this.Gw.push(o),i>0){const l=new qp(this,i-1,i);this.Xw.push(l),this.rM.insertBefore(l.uv(),this._M.uv())}this.rM.insertBefore(o.uv(),this._M.uv())}for(let i=0;i<e;i++){const o=t[i],l=this.Gw[i];l.Sv()!==o?l.iw(o):l.tw()}this.fM(),this.DM()}zM(t,e,n,i){var d;const o=new Map;
6t!==null&&this.sn.Jn().forEach((f=>{const g=f.Un().Hn(t);g!==null&&o.set(f,g)}));let l;if(t!==null){const f=(d=this.sn.Et().en(t))==null?void 0:d.originalTime;f!==void 0&&(l=f)}const a=this.Qt().ou(),c=this.OM(i),u=(function(f,g){var S;const v=f!==null&&f.lu instanceof jo?f.lu:void 0,b=(S=f==null?void 0:f.wu)==null?void 0:S.te,w=g!==void 0&&g!==-1?g:void 0;return f===null||f.ee===void 0?{NM:v,FM:b}:{NM:v,FM:b,WM:{ds:f.ee,HM:(k=f.lu,y=f.ee,k instanceof Il?"pane-primitive":y==="marker"||y==="primitive"?"series-primitive":"series"),UM:Bp(f.ee,b),U_:v,$M:b,jM:w}};var k,y})(a,c);return{Qr:l,$n:t??void 0,qM:e??void 0,jM:c!==-1?c:void 0,NM:u.NM,YM:o,FM:u.FM,WM:u.WM,KM:n??void 0}}OM(t){let e=-1;if(t)e=this.Gw.indexOf(t);else{const n=this.Qt().Rd().Kn();n!==null&&(e=this.Qt().Zn().indexOf(n))}return e}AM(t,e,n,i){this.Wm.p((()=>this.zM(e,n,i,t)))}LM(t,e,n,i){this.Hm.p((()=>this.zM(e,n,i,t)))}oM(t,e,n){var i;this.PM(((i=this.Qt().ou())==null?void 0:i.mu)??null),this.pd.p((()=>this.zM(t,e,n)))}fM(){const t=this.yn.timeScale.visible?"":"none";this._M.uv().style.display=t}yM(){return this.Gw[0].Sv().K_().N().visible}kM(){return this.Gw[0].Sv().Z_().N().visible}uM(){return"ResizeObserver"in window&&(this.sM=new ResizeObserver((t=>{const e=t[t.length-1];if(!e)return;const n=e.contentRect.width,i=e.contentRect.height;this.cM(n,i,!0)})),this.sM.observe(this.jv,{box:"border-box"}),!0)}mM(){this.sM!==null&&this.sM.disconnect(),this.sM=null}}function sl(s){return!!(s.handleScroll.mouseWheel||s.handleScale.mouseWheel)}function Jp(s){return s.open===void 0&&s.value===void 0}function tg(s){return(function(t){return t.open!==void 0})(s)||(function(t){return t.value!==void 0})(s)}function fh(s,t,e,n){const i=e.value,o={$n:t,wt:s,Wt:[i,i,i,i],Qr:n};return e.color!==void 0&&(o.R=e.color),o}function eg(s,t,e,n){const i=e.value,o={$n:t,wt:s,Wt:[i,i,i,i],Qr:n};return e.lineColor!==void 0&&(o.vt=e.lineColor),e.topColor!==void 0&&(o.ah=e.topColor),e.bottomColor!==void 0&&(o.oh=e.bottomColor),o}function sg(s,t,e,n){const i=e.value,o={$n:t,wt:s,Wt:[i,i,i,i],Qr:n};return e.topLineColor!==void 0&&(o._h=e.topLineColor),e.bottomLineColor!==void 0&&(o.uh=e.bottomLineColor),e.topFillColor1!==void 0&&(o.dh=e.topFillColor1),e.topFillColor2!==void 0&&(o.fh=e.topFillColor2),e.bottomFillColor1!==void 0&&(o.ph=e.bottomFillColor1),e.bottomFillColor2!==void 0&&(o.mh=e.bottomFillColor2),o}function ng(s,t,e,n){const i={$n:t,wt:s,Wt:[e.open,e.high,e.low,e.close],Qr:n};return e.color!==void 0&&(i.R=e.color),i}function ig(s,t,e,n){const i={$n:t,wt:s,Wt:[e.open,e.high,e.low,e.close],Qr:n};return e.color!==void 0&&(i.R=e.color),e.borderColor!==void 0&&(i.Ht=e.borderColor),e.wickColor!==void 0&&(i.hh=e.wickColor),i}function rg(s,t,e,n,i){const o=Cs(i)(e),l=Math.max(...o),a=Math.min(...o),c=o[o.length-1],u=[c,l,a,c],{time:d,color:f,...g}=e;return{$n:t,wt:s,Wt:u,Qr:n,ue:g,R:f}}function fi(s){return s.Wt!==void 0}function mh(s,t){return t.customValues!==void 0&&(s.ZM=t.customValues),s}function Yn(s){return(t,e,n,i,o,l)=>(function(a,c){return c?c(a):Jp(a)})(n,l)?mh({wt:t,$n:e,Qr:i},n):mh(s(t,e,n,i,o),n)}function ph(s){return{Candlestick:Yn(ig),Bar:Yn(ng),Area:Yn(eg),Baseline:Yn(sg),Histogram:Yn(fh),Line:Yn(fh),Custom:Yn(rg)}[s]}function gh(s){return{$n:0,GM:new Map,za:s}}function vh(s,t){if(s!==void 0&&s.length!==0)return{XM:t.key(s[0].wt),JM:t.key(s[s.length-1].wt)}}function xh(s){let t;return s.forEach((e=>{t===void 0&&(t=e.Qr)}
6)),Cs(t)}class og{constructor(t){this.QM=new Map,this.tg=new Map,this.ig=new Map,this.ng=[],this.xu=t}m(){this.QM.clear(),this.tg.clear(),this.ig.clear(),this.ng=[]}sg(t,e){let n=this.QM.size!==0,i=!1;const o=this.tg.get(t);if(o!==void 0)if(this.tg.size===1)n=!1,i=!0,this.QM.clear();else for(const c of this.ng)c.pointData.GM.delete(t)&&(i=!0);let l=[];if(e.length!==0){const c=e.map((v=>v.time)),u=this.xu.createConverterToInternalObj(e),d=ph(t.bh()),f=t.ll(),g=t.ol();l=e.map(((v,b)=>{const w=u(v.time),k=this.xu.key(w);let y=this.QM.get(k);y===void 0&&(y=gh(w),this.QM.set(k,y),i=!0);const S=d(w,y.$n,v,c[b],f,g);return y.GM.set(t,S),S}))}n&&this.eg(),this.rg(t,l);let a=-1;if(i){const c=[];this.QM.forEach((u=>{c.push({timeWeight:0,time:u.za,pointData:u,originalTime:xh(u.GM)})})),c.sort(((u,d)=>this.xu.key(u.time)-this.xu.key(d.time))),a=this.hg(c)}return this.ag(t,a,(function(c,u,d){const f=vh(c,d),g=vh(u,d);if(f!==void 0&&g!==void 0)return{lg:!1,Ia:f.JM>=g.JM&&f.XM>=g.XM}})(this.tg.get(t),o,this.xu))}Jd(t){return this.sg(t,[])}og(t,e,n){if(n&&t.Na())throw new Error("Historical updates are not supported when conflation is enabled. Conflation requires data to be processed in order.");const i=e;(function(y){y.Qr===void 0&&(y.Qr=y.time)})(i),this.xu.preprocessData(e);const o=this.xu.createConverterToInternalObj([e])(e.time),l=this.ig.get(t);if(!n&&l!==void 0&&this.xu.key(o)<this.xu.key(l))throw new Error(`Cannot update oldest data, last time=${l}, new time=${o}`);let a=this.QM.get(this.xu.key(o));if(n&&a===void 0)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const c=a===void 0;a===void 0&&(a=gh(o),this.QM.set(this.xu.key(o),a));const u=ph(t.bh()),d=t.ll(),f=t.ol(),g=u(o,a.$n,e,i.Qr,d,f),v=!n&&!c&&l!==void 0&&this.xu.key(o)===this.xu.key(l);a.GM.set(t,g),n?this._g(t,g,a.$n):v&&t.Na()&&fi(g)?(t.Rr(g),this.ug(t,g)):this.ug(t,g);const b={Ia:fi(g),lg:n};if(!c)return this.ag(t,-1,b);const w={timeWeight:0,time:a.za,pointData:a,originalTime:xh(a.GM)},k=ei(this.ng,this.xu.key(w.time),((y,S)=>this.xu.key(y.time)<S));this.ng.splice(k,0,w);for(let y=k;y<this.ng.length;++y)Dr(this.ng[y].pointData,y);return this.xu.fillWeightsForPoints(this.ng,k),this.ag(t,k,b)}cg(t,e){const n=this.tg.get(t);if(n===void 0||e<=0)return[[],this.dg()];e=Math.min(e,n.length);const i=n.splice(-e).reverse();n.length===0?this.ig.delete(t):this.ig.set(t,n[n.length-1].wt);for(const o of i){const l=this.QM.get(this.xu.key(o.wt));if(l&&(l.GM.delete(t),l.GM.size===0)){this.QM.delete(this.xu.key(l.za)),this.ng.splice(l.$n,1);for(let a=l.$n;a<this.ng.length;++a)Dr(this.ng[a].pointData,a)}}return[i,this.ag(t,this.ng.length-1,{lg:!1,Ia:!1})]}ug(t,e){let n=this.tg.get(t);n===void 0&&(n=[],this.tg.set(t,n));const i=n.length!==0?n[n.length-1]:null;i===null||this.xu.key(e.wt)>this.xu.key(i.wt)?fi(e)&&n.push(e):fi(e)?n[n.length-1]=e:n.splice(-1,1),this.ig.set(t,e.wt)}_g(t,e,n){const i=this.tg.get(t);if(i===void 0)return;const o=ei(i,n,((l,a)=>l.$n<a));fi(e)?i[o]=e:i.splice(o,1)}rg(t,e){e.length!==0?(this.tg.set(t,e.filter(fi)),this.ig.set(t,e[e.length-1].wt)):(this.tg.delete(t),this.ig.delete(t))}eg(){for(const t of this.ng)t.pointData.GM.size===0&&this.QM.delete(this.xu.key(t.time))}hg(t){let e=-1;for(let n=0;n<this.ng.length&&n<t.length;++n){const i=this.ng[n],o=t[n];if(this.xu.key(i.time)!==this.xu.key(o.time)){e=n;break}o.timeWeight=i.timeWeight,Dr(o.pointData,n)}if(e===-1&&this.ng.length!==t.length&&(e=Math.min(this.ng.length,t.length)),e===-1)return-1;for(let n=e;n<t.length;++n)Dr(t[n].pointData,n);return this.xu.fillWeightsForPoints(t,e),this.ng=t,e}fg(){if(this.tg.size===0)return null;let t=0;return this.tg.forEach((e=>{e.length!==0&&(t=Math.max(t,e[e.length-1].$n))})),t}ag(t,e,n){const i=this.dg();if(e!==-1)this.tg.forEach(((o,l)=>{i.U_.set(l,{ue:o,pg:l===t?n:void 0})})),this.tg.has(t)||i.U_.set(t,{ue:[],pg:n}),i.Et.vg=this.ng,i.Et.mg=e;else{const o=this.tg.get(t);i.U_.set(t,{ue:o||[],pg:n})}return i}dg(){return{U_:new Map,Et:{Pc:this.fg()}}}}function Dr(s,t){s.$n=t,s.GM.forEach((e=>{e.$n=t}))}function lg(s,t){return s._t<t}function ag(s,t){return t<s._t}function Hl(s,t,e,n){return ei(s,t,lg,e,n)}function Kl(s,t,e,n){return ka(s,t,ag,e,n)}function io(s,t,e){return{ne:s,se:t,ee:e}}function yh(s,t,e,n){return s>=t-n&&s<=e+n}function Yi(s,t,e,n,i,o){const l=i-e,a=o-n;if(l===0&&a===0)return Math.hypot(s-e,t-n);const c=((s-e)*l+(t-n)*a)/(l*l+a*a),u=Math.max(0,Math.min(1,c)),d=e+l*u,f=n+a*u;return Math.hypot(s-d,t-f)}const nl=[0,0];function cg(s,t,e){return t===void 0||t.wt!==s.wt-1?s._t-e/2:(t._t+s._t)/2}function hg(s,t,e){return t===void 0||t.wt!==s.wt+1?s._t+e/2:(s._t+t._t)/2}function Ca(s,t,e,n,i,o,l){if(t===null||t.from>=t.to||s.length===0)return null;const a=i/2+o,c=Hl(s,e-a,t.from,t.to),u=Kl(s,e+a,c,t.to);if(c>=u)return null;let d=Number.POSITIVE_INFINITY;for(let f=c;f<u;f++){const g=s[f],v=f>t.from?s[f-1]:void 0,b=f<t.to-1?s[f+1]:void 0,w=cg(g,v,i)-o,k=hg(g,b,i)+o;if(e<w||e>k)continue;l(g,nl);const y=nl[0],S=nl[1],j=Math.min(y,S),E=Math.max(y,S),z=j-o,F=E+o;if(n>=j&&n<=E)d=Math.min(d,0);else if(n>=z&&n<=F){const A=Math.min(Math.abs(n-j),Math.abs(E-n));d=Math.min(d,A)}}return Number.isFinite(d)?io(d,0,"series-range"):null}function ug(s,t){return s.wt<t}function dg(s,t){return t<s.wt}function Ad(s,t,e){const n=t.Oa(),i=t.bi(),o=ei(s,n,ug),l=ka(s,i,dg);if(!e)return{from:o,to:l};let a=o,c=l;return o>0&&o<s.length&&s[o].wt>=n&&(a=o-1),l>0&&l<s.length&&s[l-1].wt<=i&&(c=l+1),{from:a,to:c}}class Ta{constructor(t,e,n){this.wg=!0,this.Mg=!0,this.gg=!0,this.bg=[],this.Sg=null,this.xg=-1,this.ae=t,this.le=e,this.Cg=n}kt(t){this.wg=!0,t==="data"&&(this.Mg=!0),t==="options"&&(this.gg=!0)}Tt(){return this.ae.It()?(this.yg(),this.Sg===null?null:this.kg):null}Qs(t,e){return this.ae.It()?(this.yg(),this.Sg===null?null:this.Pg(t,e)):null}Pg(t,e){return null}Tg(){this.bg=this.bg.map((t=>({...t,...this.ae.Sa().Sh(t.wt)})))}Rg(){this.Sg=null}yg(){const t=this.le.Et(),e=t.N().enableConflation?t.Qc():0;e!==this.xg&&(this.Mg=!0,this.xg=e),this.Mg&&(this.Dg(),this.Mg=!1),this.gg&&(this.Tg(),this.gg=!1),this.wg&&(this.Ig(),this.wg=!1)}Ig(){const t=this.ae.Ft(),e=this.le.Et();if(this.Rg(),e.Gi()||t.Gi())return;const n=e.Ee();if(n===null||this.ae.Un().Th()===0)return;const i=this.ae.Lt();i!==null&&(this.Sg=Ad(this.bg,n,this.Cg),this.Vg(t,e,i.Wt),this.Bg())}}class fg{constructor(t,e){this.Eg=t,this.Ki=e}st(t,e,n){this.Eg.draw(t,this.Ki,e,n)}}function mg(s){switch(s){case"point":return 2;case"range":return 0;default:return 1}}class pg extends Ta{constructor(t,e,n){super(t,e,!1),this.Yh=n,this.Eg=this.Yh.renderer(),this.kg=ne
6w fg(this.Eg,(i=>this.Ag(i)))}get ga(){return this.Yh.conflationReducer}Wa(t){return this.Yh.priceValueBuilder(t)}_l(t){return this.Yh.isWhitespace(t)}Pg(t,e){var l,a;const n=(a=(l=this.Eg).hitTest)==null?void 0:a.call(l,t,e,(c=>this.Ag(c)));if(n!=null)return{ne:(i=n).distance,se:mg(i.type),ee:"custom",mu:i.cursorStyle,te:i.objectId,ie:i.hitTestData};var i;const o=Ca(this.bg,this.Sg,t,e,this.le.Et().fl(),this.ae.N().hitTestTolerance,((c,u)=>{const d=c.Lg;let f=NaN,g=NaN;if(d!==void 0&&!this.Yh.isWhitespace(d))for(const v of this.Yh.priceValueBuilder(d)){const b=this.Ag(v);b!==null&&(f=Number.isNaN(f)?b:Math.min(f,b),g=Number.isNaN(g)?b:Math.max(g,b))}u[0]=f,u[1]=g}));return o===null?null:{...o,ee:"custom"}}Dg(){const t=this.ae.Sa();this.bg=this.ae.Ha().Bh().map((e=>({wt:e.$n,_t:NaN,...t.Sh(e.$n),Lg:e.ue})))}Vg(t,e){e.Tc(this.bg,rr(this.Sg))}Bg(){this.Yh.update({bars:this.bg.map(gg),barSpacing:this.le.Et().fl(),visibleRange:this.Sg,conflationFactor:this.le.Et().Qc()},this.ae.N())}Ag(t){const e=this.ae.Lt();return e===null?null:this.ae.Ft().Nt(t,e.Wt)}}function gg(s){return{x:s._t,time:s.wt,originalData:s.Lg,barColor:s.sh}}const vg={color:"#2196f3"},xg=(s,t,e)=>{const n=On(e);return new pg(s,t,n)};function La(s){const t={value:s.Wt[3],time:s.Qr};return s.ZM!==void 0&&(t.customValues=s.ZM),t}function bh(s){const t=La(s);return s.R!==void 0&&(t.color=s.R),t}function yg(s){const t=La(s);return s.vt!==void 0&&(t.lineColor=s.vt),s.ah!==void 0&&(t.topColor=s.ah),s.oh!==void 0&&(t.bottomColor=s.oh),t}function bg(s){const t=La(s);return s._h!==void 0&&(t.topLineColor=s._h),s.uh!==void 0&&(t.bottomLineColor=s.uh),s.dh!==void 0&&(t.topFillColor1=s.dh),s.fh!==void 0&&(t.topFillColor2=s.fh),s.ph!==void 0&&(t.bottomFillColor1=s.ph),s.mh!==void 0&&(t.bottomFillColor2=s.mh),t}function Rd(s){const t={open:s.Wt[0],high:s.Wt[1],low:s.Wt[2],close:s.Wt[3],time:s.Qr};return s.ZM!==void 0&&(t.customValues=s.ZM),t}function wg(s){const t=Rd(s);return s.R!==void 0&&(t.color=s.R),t}function _g(s){const t=Rd(s),{R:e,Ht:n,hh:i}=s;return e!==void 0&&(t.color=e),n!==void 0&&(t.borderColor=n),i!==void 0&&(t.wickColor=i),t}function ro(s){return{Area:yg,Line:bh,Baseline:bg,Histogram:bh,Bar:wg,Candlestick:_g,Custom:kg}[s]}function kg(s){const t=s.Qr;return{...s.ue,time:t}}const Mg={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1,doNotSnapToHiddenSeriesIndices:!1},jg={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},Sg={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:vd,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},il={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0,ensureEdgeTickMarksVisible:!1,tickMarkDensity:2.5},Ng={rightOffset:0,barSpacing:6,minBarSpacing:.5,maxBarSpacing:0,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0,ignoreWhitespaceIndices:!1,enableConflation:!1,conflationThresholdFactor:1,precomputeConflationOnInit:!1,precomputeConflationPriority:"background"};function wh(){return{addDefaultPane:!0,hoveredSeriesOnTop:!0,width:0,height:0,autoSize:!1,layout:Sg,crosshair:Mg,grid:jg,overlayPriceScales:{...il},leftPriceScale:{...il,visible:!1},rightPriceScale:{...il,visible:!0},defaultVisiblePriceScaleId:"right",timeScale:Ng,localization:{locale:Ei?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class Pd{constructor(t,e,n){this.sv=t,this.zg=e,this.Og=n??0}applyOptions(t){this.sv.Qt().Pd(this.zg,t,this.Og)}options(){return this.Ki().N()}width(){return ko(this.zg)?this.sv.CM(this.zg):0}setVisibleRange(t){this.setAutoScale(!1),this.Ki().qo(new bs(t.from,t.to))}getVisibleRange(){let t,e,n=this.Ki().ar();if(n===null)return null;if(this.Ki().so()){const i=this.Ki().M_(),o=Ld(i);n=wi(n,this.Ki().ro()),t=Number((Math.round(n.Je()/i)*i).toFixed(o)),e=Number((Math.round(n.Qe()/i)*i).toFixed(o))}else t=n.Je(),e=n.Qe();return{from:t,to:e}}setAutoScale(t){this.applyOptions({autoScale:t})}Ki(){return ct(this.sv.Qt().Td(this.zg,this.Og)).Ft}}class Cg{constructor(t,e,n,i){this.sv=t,this.yt=n,this.Ng=e,this.Fg=i}getHeight(){return this.yt.$t()}setHeight(t){const e=this.sv.Qt(),n=e.hf(this.yt);e.Bd(n,t)}getStretchFactor(){return this.yt.z_()}setStretchFactor(t){this.yt.O_(t),this.sv.Qt().Pa()}paneIndex(){return this.sv.Qt().hf(this.yt)}moveTo(t){const e=this.paneIndex();e!==t&&(fs(t>=0&&t<this.sv.rv().length,"Invalid pane index"),this.sv.Qt().Ad(e,t))}getSeries(){return this.yt.U_().map((t=>this.Ng(t)))??[]}getHTMLElement(){const t=this.sv.rv();return t&&t.length!==0&&t[this.paneIndex()]?t[this.paneIndex()].uv():null}attachPrimitive(t){this.yt.hl(t),t.attached&&t.attached({chart:this.Fg,requestUpdate:()=>this.yt.Qt().Pa()})}detachPrimitive(t){this.yt.al(t)}priceScale(t){if(this.yt.A_(t)===null)throw new Error(`Cannot find price scale with id: ${t}`);return new Pd(this.sv,t,this.paneIndex())}setPreserveEmptyPane(t){this.yt.W_(t)}preserveEmptyPane(){return this.yt.H_()}addCustomSeries(t,e={},n=0){return this.Fg.addCustomSeries(t,e,n)}addSeries(t,e={}){return this.Fg.addSeries(t,e,this.paneIndex())}}const Tg={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class _h{constructor(t){this._r=t}applyOptions(t){this._r.vr(t)}options(){return this._r.N()}Wg(){return this._r}}class Lg{constructor(t,e,n,i,o,l){this.Hg=new Ye,this.ae=t,this.Ug=e,this.$g=n,this.xu=o,this.Fg=i,this.jg=l}m(){this.Hg.m()}priceFormatter(){return this.ae.tl()}priceToCoordinate(t){const e=this.ae.Lt();return e===null?null:this.ae.Ft().Nt(t,e.Wt)}coordinateToPrice(t){const e=this.ae.Lt();return e===null?null:this.ae.Ft().Tn(t,e.Wt)}barsInLogicalRange(t){if(t===null)return null;const e=new ji(new Mi(t.from,t.to)).Fu(),n=this.ae.Un();if(n.Gi())return null;const i=n.Hn(e.Oa(),1),o=n.Hn(e.bi(),-1),l=ct(n.Rh()),a=ct(n.Qn());if(i!==null&&o!==null&&i.$n>o.$n)return{barsBefore:t.from-l,barsAfter:a-t.to};const c={barsBefore:i===null||i.$n===l?t.from-l:i.$n-l,barsAfter:o===null||o.$n===a?a-t.to:a-o.$n};return i!==null&&o!==null&&(c.from=i.Qr,c.to=o.Qr),c}setData(t){this.xu,this.ae.bh(),this.Ug.qg(this.ae,t),this.Yg("full")}update(t,e=!1){this.ae.bh(),this.Ug.Kg(this.ae,t,e),this.Yg("update")}pop(t=1){const e=this.Ug.Zg(this.ae,t);e.length!==0&&this.Yg("update");const n=ro(this.seriesType());return e.map((i=>n(i)))}dataByIndex(t,e){const n=this.ae.Un().Hn(t,e);return n===null?null:ro(this.seriesType())(n)}data(){const t=ro(this.seriesType());return this.ae.Un().Bh().map((e=>t(e)))}subscribeDataChanged(t){this.Hg.i(t)}unsubscribeDataChanged(t){this.Hg._(t)}applyOptions(t){this.ae.vr(t)}options(){return Nn(this.ae.N())}priceScale(){return this.$g.priceScale(this.ae.Ft().cl(),this.getPane().paneIndex())}
6createPriceLine(t){const e=Rs(Nn(Tg),t),n=this.ae.Ba(e);return new _h(n)}removePriceLine(t){this.ae.Ea(t.Wg())}priceLines(){return this.ae.Aa().map((t=>new _h(t)))}seriesType(){return this.ae.bh()}lastValueData(t){const e=this.ae.Ae(t);return e.Le?{noData:!0}:{noData:!1,price:e.Mt,color:e.R}}attachPrimitive(t){this.ae.hl(t),t.attached&&t.attached({chart:this.Fg,series:this,requestUpdate:()=>this.ae.Qt().Pa(),horzScaleBehavior:this.xu})}detachPrimitive(t){this.ae.al(t),t.detached&&t.detached(),this.ae.Qt().Pa()}getPane(){const t=this.ae,e=ct(this.ae.Qt().Ks(t));return this.jg(e)}moveToPane(t){this.ae.Qt().nf(this.ae,t)}seriesOrder(){const t=this.ae.Qt().Ks(this.ae);return t===null?-1:t.U_().indexOf(this.ae)}setSeriesOrder(t){const e=this.ae.Qt().Ks(this.ae);e!==null&&e.du(this.ae,t)}Yg(t){this.Hg.v()&&this.Hg.p(t)}}class Eg{constructor(t,e,n){this.Gg=new Ye,this.Gu=new Ye,this.Bw=new Ye,this.sn=t,this.ia=t.Et(),this._M=e,this.ia.Yc().i(this.Xg.bind(this)),this.ia.Kc().i(this.Jg.bind(this)),this._M.Fw().i(this.Qg.bind(this)),this.xu=n}m(){this.ia.Yc().u(this),this.ia.Kc().u(this),this._M.Fw().u(this),this.Gg.m(),this.Gu.m(),this.Bw.m()}scrollPosition(){return this.ia.Ac()}scrollToPosition(t,e){e?this.ia.$c(t,1e3):this.sn.gs(t)}scrollToRealTime(){this.ia.Uc()}getVisibleRange(){const t=this.ia.gc();return t===null?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const e={from:this.xu.convertHorzItemToInternal(t.from),to:this.xu.convertHorzItemToInternal(t.to)},n=this.ia.Cc(e);this.sn.tf(n)}getVisibleLogicalRange(){const t=this.ia.Mc();return t===null?null:{from:t.Oa(),to:t.bi()}}setVisibleLogicalRange(t){fs(t.from<=t.to,"The from index cannot be after the to index."),this.sn.tf(t)}resetTimeScale(){this.sn.ws()}fitContent(){this.sn.Xc()}logicalToCoordinate(t){const e=this.sn.Et();return e.Gi()?null:e.jt(t)}coordinateToLogical(t){return this.ia.Gi()?null:this.ia.Rc(t)}timeToIndex(t,e){const n=this.xu.convertHorzItemToInternal(t);return this.ia.vc(n,e)}timeToCoordinate(t){const e=this.timeToIndex(t,!1);return e===null?null:this.ia.jt(e)}coordinateToTime(t){const e=this.sn.Et(),n=e.Rc(t),i=e.en(n);return i===null?null:i.originalTime}width(){return this._M.cv().width}height(){return this._M.cv().height}subscribeVisibleTimeRangeChange(t){this.Gg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Gg._(t)}subscribeVisibleLogicalRangeChange(t){this.Gu.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.Gu._(t)}subscribeSizeChange(t){this.Bw.i(t)}unsubscribeSizeChange(t){this.Bw._(t)}applyOptions(t){this.ia.vr(t)}options(){return{...Nn(this.ia.N()),barSpacing:this.ia.fl()}}Xg(){this.Gg.v()&&this.Gg.p(this.getVisibleRange())}Jg(){this.Gu.v()&&this.Gu.p(this.getVisibleLogicalRange())}Qg(t){this.Bw.p(t.width,t.height)}}function kh(s){return(function(t){if(Lr(t.handleScale)){const n=t.handleScale;t.handleScale={axisDoubleClickReset:{time:n,price:n},axisPressedMouseMove:{time:n,price:n},mouseWheel:n,pinch:n}}else if(t.handleScale!==void 0){const{axisPressedMouseMove:n,axisDoubleClickReset:i}=t.handleScale;Lr(n)&&(t.handleScale.axisPressedMouseMove={time:n,price:n}),Lr(i)&&(t.handleScale.axisDoubleClickReset={time:i,price:i})}const e=t.handleScroll;Lr(e)&&(t.handleScroll={horzTouchDrag:e,vertTouchDrag:e,mouseWheel:e,pressedMouseMove:e})})(s),s}class Fg{constructor(t,e,n){this.tb=new Map,this.ib=new Map,this.nb=new Ye,this.sb=new Ye,this.eb=new Ye,this.od=new WeakMap,this.rb=new og(e);const i=n===void 0?Nn(wh()):Rs(Nn(wh()),kh(n));this.hb=e,this.sv=new Zp(t,i,e),this.sv.dw().i((l=>{this.nb.v()&&this.nb.p(this.ab(l()))}),this),this.sv.fw().i((l=>{this.sb.v()&&this.sb.p(this.ab(l()))}),this),this.sv.Dd().i((l=>{this.eb.v()&&this.eb.p(this.ab(l()))}),this);const o=this.sv.Qt();this.lb=new Eg(o,this.sv.pM(),this.hb)}remove(){this.sv.dw().u(this),this.sv.fw().u(this),this.sv.Dd().u(this),this.lb.m(),this.sv.m(),this.tb.clear(),this.ib.clear(),this.nb.m(),this.sb.m(),this.eb.m(),this.rb.m()}resize(t,e,n){this.autoSizeActive()||this.sv.cM(t,e,n)}addCustomSeries(t,e={},n=0){const i=(o=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...vg,...o.defaultOptions()},ob:xg,_b:o}))(On(t));return this.ub(i,e,n)}addSeries(t,e={},n=0){return this.ub(t,e,n)}removeSeries(t){const e=Cs(this.tb.get(t)),n=this.rb.Jd(e);this.sv.Qt().Jd(e),this.cb(n),this.tb.delete(t),this.ib.delete(e)}qg(t,e){this.cb(this.rb.sg(t,e))}Kg(t,e,n){this.cb(this.rb.og(t,e,n))}Zg(t,e){const[n,i]=this.rb.cg(t,e);return n.length!==0&&this.cb(i),n}subscribeClick(t){this.nb.i(t)}unsubscribeClick(t){this.nb._(t)}subscribeCrosshairMove(t){this.eb.i(t)}unsubscribeCrosshairMove(t){this.eb._(t)}subscribeDblClick(t){this.sb.i(t)}unsubscribeDblClick(t){this.sb._(t)}priceScale(t,e=0){return new Pd(this.sv,t,e)}timeScale(){return this.lb}applyOptions(t){this.sv.vr(kh(t))}options(){return this.sv.N()}takeScreenshot(t=!1,e=!1){let n,i;try{e||(n=this.sv.Qt().N().crosshair.mode,this.sv.vr({crosshair:{mode:2}})),i=this.sv.SM(t)}finally{e||n===void 0||this.sv.Qt().vr({crosshair:{mode:n}})}return i}addPane(t=!1){const e=this.sv.Qt().af();return e.W_(t),this.fb(e)}removePane(t){this.sv.Qt().Vd(t)}swapPanes(t,e){this.sv.Qt().Ed(t,e)}autoSizeActive(){return this.sv.wM()}chartElement(){return this.sv.vv()}panes(){return this.sv.Qt().Zn().map((t=>this.fb(t)))}paneSize(t=0){const e=this.sv.RM(t);return{height:e.height,width:e.width}}setCrosshairPosition(t,e,n){const i=this.tb.get(n);if(i===void 0)return;const o=this.sv.Qt().Ks(i);o!==null&&this.sv.Qt().qd(t,e,o)}clearCrosshairPosition(){this.sv.Qt().Yd(!0)}horzBehaviour(){return this.hb}ub(t,e={},n=0){fs(t.ob!==void 0),(function(c){if(c===void 0||c.type==="custom")return;const u=c;u.minMove!==void 0&&u.precision===void 0&&(u.precision=Ld(u.minMove))})(e.priceFormat),t.type==="Candlestick"&&(function(c){c.borderColor!==void 0&&(c.borderUpColor=c.borderColor,c.borderDownColor=c.borderColor),c.wickColor!==void 0&&(c.wickUpColor=c.wickColor,c.wickDownColor=c.wickColor)})(e);const i=Rs(Nn(pd),Nn(t.defaultOptions),e),o=t.ob,l=new jo(this.sv.Qt(),t.type,i,o,t._b);this.sv.Qt().Gd(l,n);const a=new Lg(l,this,this,this,this.hb,(c=>this.fb(c)));return this.tb.set(a,l),this.ib.set(l,a),a}cb(t){const e=this.sv.Qt();e.Kd(t.Et.Pc,t.Et.vg,t.Et.mg),t.U_.forEach(((n,i)=>i.ht(n.ue,n.pg))),e.Et()._c(),e.Bc()}pb(t){return Cs(this.ib.get(t))}mb(t){return t!==void 0&&this.ib.has(t)?this.pb(t):void 0}ab(t){const e=new Map;t.YM.forEach(((o,l)=>{const a=l.bh(),c=ro(a)(o);if(a!=="Custom")fs(tg(c));else{const u=l.ol();fs(!u||u(c)===!1)}e.set(this.pb(l),c)}
6));const n=this.mb(t.NM),i=t.WM===void 0?void 0:{type:t.WM.ds,sourceKind:t.WM.HM,objectKind:t.WM.UM,series:this.mb(t.WM.U_),objectId:t.WM.$M,paneIndex:t.WM.jM};return{time:t.Qr,logical:t.$n,point:t.qM,paneIndex:t.jM,hoveredInfo:i,hoveredSeries:n,hoveredObjectId:t.FM,seriesData:e,sourceEvent:t.KM}}fb(t){let e=this.od.get(t);return e||(e=new Cg(this.sv,(n=>this.pb(n)),t,this),this.od.set(t,e)),e}}function Ag(s){if(dr(s)){const t=document.getElementById(s);return fs(t!==null,`Cannot find element in DOM with id=${s}`),t}return s}function Rg(s,t,e){const n=Ag(s),i=new Fg(n,t,e);return t.setOptions(i.options()),i}function Pg(s,t){return Rg(s,new rh,rh.yf(t))}function Wi(s,t,e,n){return Math.hypot(e-s,n-t)}function zd(s,t,e,n,i,o,l,a=0){if(t.length===0||n.from>=t.length||n.to<=0)return;const{context:c,horizontalPixelRatio:u,verticalPixelRatio:d}=s,f=t[n.from];let g=o(s,f),v=f;if(n.to-n.from<2){const b=i/2;c.beginPath();const w={_t:f._t-b,ut:f.ut},k={_t:f._t+b,ut:f.ut};c.moveTo(w._t*u,w.ut*d),c.lineTo(k._t*u,k.ut*d),l(s,g,w,k)}else{const b=a>0;let w=0;const k=(S,j)=>{if(l(s,g,v,j),c.beginPath(),g=S,v=j,b){const E=w%a;c.lineDashOffset=E,w=E}};let y=v;c.beginPath(),c.moveTo(f._t*u,f.ut*d);for(let S=n.from+1;S<n.to;++S){y=t[S];const j=y._t*u,E=y.ut*d,z=o(s,y);switch(e){case 0:if(c.lineTo(j,E),b){const F=t[S-1],A=F._t*u,J=F.ut*d;w+=Wi(A,J,j,E)}break;case 1:{const F=t[S-1],A=F.ut*d;c.lineTo(j,A),b&&(w+=Math.abs(y._t-F._t)*u),z!==g&&(k(z,y),c.lineTo(j,A)),c.lineTo(j,E),b&&(w+=Math.abs(y.ut-F.ut)*d);break}case 2:{const[F,A]=Ea(t,S-1,S),J=F._t*u,O=F.ut*d,yt=A._t*u,P=A.ut*d;if(c.bezierCurveTo(J,O,yt,P,j,E),b){const G=t[S-1],nt=G._t*u,bt=G.ut*d,$=Wi(nt,bt,j,E),ht=Wi(nt,bt,J,O)+Wi(J,O,yt,P)+Wi(yt,P,j,E);w+=($+ht)/2}break}}e!==1&&z!==g&&(k(z,y),c.moveTo(j,E))}(v!==y||v===y&&e===1)&&l(s,g,v,y),b&&(c.lineDashOffset=0)}}const Mh=6;function rl(s,t){return{_t:s._t-t._t,ut:s.ut-t.ut}}function jh(s,t){return{_t:s._t/t,ut:s.ut/t}}function Ea(s,t,e){const n=Math.max(0,t-1),i=Math.min(s.length-1,e+1);var o,l;return[(o=s[t],l=jh(rl(s[e],s[n]),Mh),{_t:o._t+l._t,ut:o.ut+l.ut}),rl(s[e],jh(rl(s[i],s[t]),Mh))]}function zg(s,t){const e=s.context;
6e.strokeStyle=t,e.stroke()}class Dd extends gn{constructor(){super(...arguments),this.rt=null}ht(t){this.rt=t}et(t){if(this.rt===null)return;const{ot:e,lt:n,wb:i,Mb:o,ct:l,Zt:a,gb:c}=this.rt;if(n===null)return;const u=t.context;u.lineCap="butt",u.lineWidth=l*t.verticalPixelRatio;const d=In(u,a);u.lineJoin="round";const f=this.bb.bind(this),g=(function(v){return v.reduce(((b,w)=>b+w),0)})(d);o!==void 0&&zd(t,e,o,n,i,f,zg,g),c&&(function(v,b,w,k,y){if(k.to-k.from<=0)return;const{horizontalPixelRatio:S,verticalPixelRatio:j,context:E}=v;let z=null;const F=Math.max(1,Math.floor(S))%2/2,A=w*j+F;for(let J=k.to-1;J>=k.from;--J){const O=b[J];if(O){const yt=y(v,O);yt!==z&&(z!==null&&E.fill(),E.beginPath(),E.fillStyle=yt,z=yt);const P=Math.round(O._t*S)+F,G=O.ut*j;E.moveTo(P,G),E.arc(P,G,A,0,2*Math.PI)}}E.fill()})(t,e,c,n,f)}}let Od=class extends Dd{bb(t,e){return e.vt}};function Sh(s,t,e,n,i){const o=1-i;return o*o*o*s+3*o*o*i*t+3*o*i*i*e+i*i*i*n}function Dg(s,t,e,n,i){if(e===2){const[o,l]=Ea(n,i-1,i);return[Math.min(s._t,t._t,o._t,l._t),Math.max(s._t,t._t,o._t,l._t)]}return[Math.min(s._t,t._t),Math.max(s._t,t._t)]}function Og(s,t,e,n,i,o,l,a){switch(i){case 1:{const c=Yi(s,t,e._t,e.ut,n._t,e.ut),u=Yi(s,t,n._t,e.ut,n._t,n.ut),d=Math.min(c,u);return d<=a?d:null}case 2:{const[c,u]=Ea(o,l-1,l),d=(function(f,g,v){let b=Number.POSITIVE_INFINITY,w=v[0];for(let k=1;k<=12;k++){const y=k/12,S={_t:Sh(v[0]._t,v[1]._t,v[2]._t,v[3]._t,y),ut:Sh(v[0].ut,v[1].ut,v[2].ut,v[3].ut,y)};b=Math.min(b,Yi(f,g,w._t,w.ut,S._t,S.ut)),w=S}return b})(s,t,[e,c,u,n]);return d<=a?d:null}default:{const c=Yi(s,t,e._t,e.ut,n._t,n.ut);return c<=a?c:null}}}class Id extends Ta{constructor(t,e){super(t,e,!0)}Vg(t,e,n){e.Tc(this.bg,rr(this.Sg)),t.Zo(this.bg,n,rr(this.Sg))}Sb(t,e){return{wt:t,Mt:e,_t:NaN,ut:NaN}}Dg(){const t=this.ae.Sa();this.bg=this.ae.Ha().Bh().map((e=>{let n;if((e.Zr??1)>1){const i=e.Wt[1],o=e.Wt[2],l=e.Wt[3];n=Math.abs(i-l)>Math.abs(o-l)?i:o}else n=e.Wt[3];return this.xb(e.$n,n,t)}))}}class Fa extends Id{Pg(t,e){const n=this.ae.N();return(function(i,o,l,a,c,u,d,f=0,g=0){if(o===null||o.from>=o.to||i.length===0)return null;const v=Math.max(u/2,d??0)+g;let b=Number.POSITIVE_INFINITY;if(d!==void 0){const E=d+g,z=Hl(i,l-E,o.from,o.to),F=Kl(i,l+E,z,o.to);for(let A=z;A<F;A++){const J=i[A];if(!yh(l,J._t,J._t,d+g))continue;const O=Math.hypot(l-J._t,a-J.ut);O<=d+g&&(b=Math.min(b,O))}}if(o.to-o.from<2){const E=i[o.from],z=Math.max(f/2,v),F=Yi(l,a,E._t-z,E.ut,E._t+z,E.ut);return F<=v&&(b=Math.min(b,F)),Number.isFinite(b)?io(b,2,"series-point"):null}let w=Number.POSITIVE_INFINITY;const k=Hl(i,l-v,o.from,o.to),y=Kl(i,l+v,k,o.to),S=Math.max(o.from+1,k),j=Math.min(o.to,y+1);for(let E=S;E<j;E++){const z=i[E-1],F=i[E],[A,J]=Dg(z,F,c,i,E);if(!yh(l,A,J,v))continue;const O=Og(l,a,z,F,c,i,E,v);O!==null&&(w=Math.min(w,O))}return Number.isFinite(b)?io(b,2,"series-point"):Number.isFinite(w)?io(w,1,"series-line"):null})(this.bg,this.Sg,t,e,n.lineType,n.lineVisible?n.lineWidth:1,n.pointMarkersVisible?n.pointMarkersRadius||n.lineWidth/2+2:void 0,this.le.Et().fl(),n.hitTestTolerance)}}class Ig extends Fa{constructor(){super(...arguments),this.kg=new Od}xb(t,e,n){return{...this.Sb(t,e),...n.Sh(t)}}Bg(){const t=this.ae.N(),e={ot:this.bg,Zt:t.lineStyle,Mb:t.lineVisible?t.lineType:void 0,ct:t.lineWidth,gb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,lt:this.Sg,wb:this.le.Et().fl()};this.kg.ht(e)}}const Si={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},ob:(s,t)=>new Ig(s,t)};function Bg(s,t,e,n,i){const{context:o,horizontalPixelRatio:l,verticalPixelRatio:a}=t;o.lineTo(i._t*l,s*a),o.lineTo(n._t*l,s*a),o.closePath(),o.fillStyle=e,o.fill()}class Bd extends gn{constructor(){super(...arguments),this.rt=null}ht(t){this.rt=t}et(t){if(this.rt===null)return;const{ot:e,lt:n,wb:i,ct:o,Zt:l,Mb:a}=this.rt,c=this.rt.Db??(this.rt.Ib?0:t.mediaSize.height);if(n===null)return;const u=t.context;u.lineCap="butt",u.lineJoin="round",u.lineWidth=o,In(u,l),u.lineWidth=1,zd(t,e,a,n,i,this.Vb.bind(this),Bg.bind(null,c))}}class Aa{Bb(t,e){const n=this.Eb,{Ab:i,Lb:o,zb:l,Ob:a,Db:c,Nb:u,Fb:d}=e;if(this.Wb===void 0||n===void 0||n.Ab!==i||n.Lb!==o||n.zb!==l||n.Ob!==a||n.Db!==c||n.Nb!==u||n.Fb!==d){const{verticalPixelRatio:f}=t,g=c||u>
60?f:1,v=u*g,b=d===t.bitmapSize.height?d:d*g,w=(c??0)*g,k=t.context.createLinearGradient(0,v,0,b);if(k.addColorStop(0,i),c!=null){const y=ki((w-v)/(b-v),0,1);k.addColorStop(y,o),k.addColorStop(y,l)}k.addColorStop(1,a),this.Wb=k,this.Eb=e}return this.Wb}}class Wg extends Bd{constructor(){super(...arguments),this.Hb=new Aa}Vb(t,e){const n=this.rt;return this.Hb.Bb(t,{Ab:e.dh,Lb:e.fh,zb:e.ph,Ob:e.mh,Db:n.Db,Nb:n.Nb??0,Fb:n.Fb??t.bitmapSize.height})}}class qg extends Dd{constructor(){super(...arguments),this.Ub=new Aa}bb(t,e){const n=this.rt;return this.Ub.Bb(t,{Ab:e._h,Lb:e._h,zb:e.uh,Ob:e.uh,Db:n.Db,Nb:n.Nb??0,Fb:n.Fb??t.bitmapSize.height})}}class Vg extends Fa{constructor(t,e){super(t,e),this.kg=new wa,this.$b=new Wg,this.jb=new qg,this.kg.nt([this.$b,this.jb])}xb(t,e,n){return{...this.Sb(t,e),...n.Sh(t)}}Bg(){const t=this.ae.Lt();if(t===null)return;const e=this.ae.N(),n=this.ae.Ft().Nt(e.baseValue.price,t.Wt),i=this.le.Et().fl();if(this.Sg===null||this.bg.length===0)return;let o,l;if(e.relativeGradient){o=this.bg[this.Sg.from].ut,l=this.bg[this.Sg.from].ut;for(let a=this.Sg.from;a<this.Sg.to;a++){const c=this.bg[a];c.ut<o&&(o=c.ut),c.ut>l&&(l=c.ut)}}this.$b.ht({ot:this.bg,ct:e.lineWidth,Zt:e.lineStyle,Mb:e.lineType,Db:n,Nb:o,Fb:l,Ib:!1,lt:this.Sg,wb:i}),this.jb.ht({ot:this.bg,ct:e.lineWidth,Zt:e.lineStyle,Mb:e.lineVisible?e.lineType:void 0,gb:e.pointMarkersVisible?e.pointMarkersRadius||e.lineWidth/2+2:void 0,Db:n,Nb:o,Fb:l,lt:this.Sg,wb:i})}}const Ug={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},ob:(s,t)=>new Vg(s,t)};class Hg extends Bd{constructor(){super(...arguments),this.Hb=new Aa}Vb(t,e){var n;return this.Hb.Bb(t,{Ab:e.ah,Lb:"",zb:"",Ob:e.oh,Nb:((n=this.rt)==null?void 0:n.Nb)??0,Fb:t.bitmapSize.height})}}
6class Kg extends Fa{constructor(t,e){super(t,e),this.kg=new wa,this.qb=new Hg,this.Yb=new Od,this.kg.nt([this.qb,this.Yb])}xb(t,e,n){return{...this.Sb(t,e),...n.Sh(t)}}Bg(){const t=this.ae.N();if(this.Sg===null||this.bg.length===0)return;let e;if(t.relativeGradient){e=this.bg[this.Sg.from].ut;for(let n=this.Sg.from;n<this.Sg.to;n++){const i=this.bg[n];i.ut<e&&(e=i.ut)}}this.qb.ht({Mb:t.lineType,ot:this.bg,Zt:t.lineStyle,ct:t.lineWidth,Db:null,Nb:e,Ib:t.invertFilledArea,lt:this.Sg,wb:this.le.Et().fl()}),this.Yb.ht({Mb:t.lineVisible?t.lineType:void 0,ot:this.bg,Zt:t.lineStyle,ct:t.lineWidth,lt:this.Sg,wb:this.le.Et().fl(),gb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const $g={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},ob:(s,t)=>new Kg(s,t)};class Yg extends gn{constructor(){super(...arguments),this.qt=null,this.Kb=0,this.Zb=0}ht(t){this.qt=t}et({context:t,horizontalPixelRatio:e,verticalPixelRatio:n}){if(this.qt===null||this.qt.Un.length===0||this.qt.lt===null)return;this.Kb=this.Gb(e),this.Kb>=2&&Math.max(1,Math.floor(e))%2!=this.Kb%2&&this.Kb--,this.Zb=this.qt.Xb?Math.min(this.Kb,Math.floor(e)):this.Kb;let i=null;const o=this.Zb<=this.Kb&&this.qt.fl>=Math.floor(1.5*e);for(let l=this.qt.lt.from;l<this.qt.lt.to;++l){const a=this.qt.Un[l];i!==a.sh&&(t.fillStyle=a.sh,i=a.sh);const c=Math.floor(.5*this.Zb),u=Math.round(a._t*e),d=u-c,f=this.Zb,g=d+f-1,v=Math.min(a.Qo,a.t_),b=Math.max(a.Qo,a.t_),w=Math.round(v*n)-c,k=Math.round(b*n)+c,y=Math.max(k-w,this.Zb);t.fillRect(d,w,f,y);const S=Math.ceil(1.5*this.Kb);if(o){if(this.qt.Jb){const F=u-S;let A=Math.max(w,Math.round(a.Jo*n)-c),J=A+f-1;J>w+y-1&&(J=w+y-1,A=J-f+1),t.fillRect(F,A,d-F,J-A+1)}const j=u+S;let E=Math.max(w,Math.round(a.i_*n)-c),z=E+f-1;z>w+y-1&&(z=w+y-1,E=z-f+1),t.fillRect(g+1,E,j-g,z-E+1)}}}Gb(t){const e=Math.floor(t);return Math.max(e,Math.floor((function(n,i){return Math.floor(.3*n*i)})(ct(this.qt).fl,t)))}}class Wd extends Ta{constructor(t,e){super(t,e,!1)}Pg(t,e){return Ca(this.bg,this.Sg,t,e,this.le.Et().fl(),this.ae.N().hitTestTolerance,((n,i)=>{i[0]=n.Qo,i[1]=n.t_}))}Vg(t,e,n){e.Tc(this.bg,rr(this.Sg)),t.Xo(this.bg,n,rr(this.Sg))}Qb(t,e,n){return{wt:t,jr:e.Wt[0],qr:e.Wt[1],Yr:e.Wt[2],Kr:e.Wt[3],_t:NaN,Jo:NaN,Qo:NaN,t_:NaN,i_:NaN}}Dg(){const t=this.ae.Sa();this.bg=this.ae.Ha().Bh().map((e=>this.xb(e.$n,e,t)))}}class Qg extends Wd{constructor(){super(...arguments),this.kg=new Yg}xb(t,e,n){return{...this.Qb(t,e,n),...n.Sh(t)}}Bg(){const t=this.ae.N();this.kg.ht({Un:this.bg,fl:this.le.Et().fl(),Jb:t.openVisible,Xb:t.thinBars,lt:this.Sg})}}const Gg={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},ob:(s,t)=>new Qg(s,t)};class Xg extends gn{constructor(){super(...arguments),this.qt=null,this.Kb=0}ht(t){this.qt=t}et(t){if(this.qt===null||this.qt.Un.length===0||this.qt.lt===null)return;const{horizontalPixelRatio:e}=t;this.Kb=(function(o,l){if(o>=2.5&&o<=4)return Math.floor(3*l);const a=1-.2*Math.atan(Math.max(4,o)-4)/(.5*Math.PI),c=Math.floor(o*a*l),u=Math.floor(o*l),d=Math.min(c,u);return Math.max(Math.floor(l),d)})(this.qt.fl,e),this.Kb>=2&&Math.floor(e)%2!=this.Kb%2&&this.Kb--;const n=this.qt.Un;this.qt.tS&&this.iS(t,n,this.qt.lt),this.qt.gi&&this.Rm(t,n,this.qt.lt);const i=this.nS(e);(!this.qt.gi||this.Kb>2*i)&&this.sS(t,n,this.qt.lt)}iS(t,e,n){if(this.qt===null)return;const{context:i,horizontalPixelRatio:o,verticalPixelRatio:l}=t;let a="",c=Math.min(Math.floor(o),Math.floor(this.qt.fl*o));c=Math.max(Math.floor(o),Math.min(c,this.Kb));const u=Math.floor(.5*c);let d=null;for(let f=n.from;f<n.to;f++){const g=e[f];g.rh!==a&&(i.fillStyle=g.rh,a=g.rh);const v=Math.round(Math.min(g.Jo,g.i_)*l),b=Math.round(Math.max(g.Jo,g.i_)*l),w=Math.round(g.Qo*l),k=Math.round(g.t_*l);let y=Math.round(o*g._t)-u;const S=y+c-1;d!==null&&(y=Math.max(d+1,y),y=Math.min(y,S));const j=S-y+1;i.fillRect(y,w,j,v-w),i.fillRect(y,b+1,j,k-b),d=S}}nS(t){let e=Math.floor(1*t);this.Kb<=2*e&&(e=Math.floor(.5*(this.Kb-1)));const n=Math.max(Math.floor(t),e);return this.Kb<=2*n?Math.max(Math.floor(t),Math.floor(1*t)):n}Rm(t,e,n){if(this.qt===null)return;const{context:i,horizontalPixelRatio:o,verticalPixelRatio:l}=t;let a="";const c=this.nS(o);let u=null;for(let d=n.from;d<n.to;d++){const f=e[d];f.eh!==a&&(i.fillStyle=f.eh,a=f.eh);let g=Math.round(f._t*o)-Math.floor(.5*this.Kb);const v=g+this.Kb-1,b=Math.round(Math.min(f.Jo,f.i_)*l),w=Math.round(Math.max(f.Jo,f.i_)*l);if(u!==null&&(g=Math.max(u+1,g),g=Math.min(g,v)),this.qt.fl*o>2*c)Om(i,g,b,v-g+1,w-b+1,c);
6else{const k=v-g+1;i.fillRect(g,b,k,w-b+1)}u=v}}sS(t,e,n){if(this.qt===null)return;const{context:i,horizontalPixelRatio:o,verticalPixelRatio:l}=t;let a="";const c=this.nS(o);for(let u=n.from;u<n.to;u++){const d=e[u];let f=Math.round(Math.min(d.Jo,d.i_)*l),g=Math.round(Math.max(d.Jo,d.i_)*l),v=Math.round(d._t*o)-Math.floor(.5*this.Kb),b=v+this.Kb-1;if(d.sh!==a){const w=d.sh;i.fillStyle=w,a=w}this.qt.gi&&(v+=c,f+=c,b-=c,g-=c),f>g||i.fillRect(v,f,b-v+1,g-f+1)}}}class Zg extends Wd{constructor(){super(...arguments),this.kg=new Xg}xb(t,e,n){return{...this.Qb(t,e,n),...n.Sh(t)}}Bg(){const t=this.ae.N();this.kg.ht({Un:this.bg,fl:this.le.Et().fl(),tS:t.wickVisible,gi:t.borderVisible,lt:this.Sg})}}const ol={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},ob:(s,t)=>new Zg(s,t)};class Jg extends gn{constructor(){super(...arguments),this.qt=null,this.eS=[]}ht(t){this.qt=t,this.eS=[]}et({context:t,horizontalPixelRatio:e,verticalPixelRatio:n}){if(this.qt===null||this.qt.ot.length===0||this.qt.lt===null)return;this.eS.length||this.rS(e);const i=Math.max(1,Math.floor(n)),o=Math.round(this.qt.hS*n)-Math.floor(i/2),l=o+i;for(let a=this.qt.lt.from;a<this.qt.lt.to;a++){const c=this.qt.ot[a],u=this.eS[a-this.qt.lt.from],d=Math.round(c.ut*n);let f,g;t.fillStyle=c.sh,d<=o?(f=d,g=l):(f=o,g=d-Math.floor(i/2)+i),t.fillRect(u.Oa,f,u.bi-u.Oa+1,g-f)}}rS(t){if(this.qt===null||this.qt.ot.length===0||this.qt.lt===null)return void(this.eS=[]);const e=Math.ceil(this.qt.fl*t)<=1?0:Math.max(1,Math.floor(t)),n=Math.round(this.qt.fl*t)-e;this.eS=new Array(this.qt.lt.to-this.qt.lt.from);for(let o=this.qt.lt.from;o<this.qt.lt.to;o++){const l=this.qt.ot[o],a=Math.round(l._t*t);let c,u;if(n%2){const d=(n-1)/2;c=a-d,u=a+d}else{const d=n/2;c=a-d,u=a+d-1}this.eS[o-this.qt.lt.from]={Oa:c,bi:u,aS:a,ce:l._t*t,wt:l.wt}}for(let o=this.qt.lt.from+1;o<this.qt.lt.to;o++){const l=this.eS[o-this.qt.lt.from],a=this.eS[o-this.qt.lt.from-1];l.wt===a.wt+1&&l.Oa-a.bi!==e+1&&(a.aS>a.ce?a.bi=l.Oa-e-1:l.Oa=a.bi+e+1)}let i=Math.ceil(this.qt.fl*t);for(let o=this.qt.lt.from;o<this.qt.lt.to;o++){const l=this.eS[o-this.qt.lt.from];l.bi<l.Oa&&(l.bi=l.Oa);const a=l.bi-l.Oa+1;i=Math.min(a,i)}if(e>0&&i<4)for(let o=this.qt.lt.from;o<this.qt.lt.to;o++){const l=this.eS[o-this.qt.lt.from];l.bi-l.Oa+1>i&&(l.aS>l.ce?l.bi-=1:l.Oa+=1)}}}class t0 extends Id{constructor(){super(...arguments),this.kg=new Jg}Pg(t,e){const n=this.ae.Ft().Nt(this.ae.N().base,ct(this.ae.Lt()).Wt);return n===null?null:Ca(this.bg,this.Sg,t,e,this.le.Et().fl(),this.ae.N().hitTestTolerance,((i,o)=>{o[0]=i.ut,o[1]=n}))}xb(t,e,n){return{...this.Sb(t,e),...n.Sh(t)}}Bg(){const t={ot:this.bg,fl:this.le.Et().fl(),lt:this.Sg,hS:this.ae.Ft().Nt(this.ae.N().base,ct(this.ae.Lt()).Wt)};this.kg.ht(t)}}const $l={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},ob:(s,t)=>new t0(s,t)};class e0{constructor(t,e){this.ae=t,this.Jh=e,this.oS()}detach(){this.ae.detachPrimitive(this.Jh)}getSeries(){return this.ae}applyOptions(t){this.Jh&&this.Jh.vr&&this.Jh.vr(t)}oS(){this.ae.attachPrimitive(this.Jh)}}const s0={autoScale:!0,zOrder:"normal"};function Zi(s,t){return Ma(Math.min(Math.max(s,12),30)*t)}function Fi(s,t){switch(s){case"arrowDown":case"arrowUp":return Zi(t,1);case"circle":return Zi(t,.8);case"square":return Zi(t,.7)}}function qd(s){return(function(t){const e=Math.ceil(t);return e%2!=0?e-1:e})(Zi(s,1))}function Vd(s){return Math.max(Zi(s,.1),3)}function Nh(s,t,e){return t?s:e?Math.ceil(s/2):0}function Ch(s,t,e,n){const i=(Fi("arrowUp",n)-1)/2*e.VS,o=(Ma(n/2)-1)/2*e.VS;t.beginPath(),s?(t.moveTo(e._t-i,e.ut),t.lineTo(e._t,e.ut-i),t.lineTo(e._t+i,e.ut),t.lineTo(e._t+o,e.ut),t.lineTo(e._t+o,e.ut+i),t.lineTo(e._t-o,e.ut+i),t.lineTo(e._t-o,e.ut)):(t.moveTo(e._t-i,e.ut),t.lineTo(e._t,e.ut+i),t.lineTo(e._t+i,e.ut),t.lineTo(e._t+o,e.ut),t.lineTo(e._t+o,e.ut-i),t.lineTo(e._t-o,e.ut-i),t.lineTo(e._t-o,e.ut)),t.fill()}function Th(s,t,e,n,i,o){const l=(Fi("arrowUp",n)-1)/2,a=(Ma(n/2)-1)/2;return i>=t-a-2&&i<=t+a+2&&o>=(s?e:e-l)-2&&o<=(s?e+l:e)+2?!0:(()=>
6{if(i<t-l-3||i>t+l+3||o<(s?e-l-3:e)||o>(s?e:e+l+3))return!1;const c=Math.abs(i-t);return Math.abs(o-e)+3>=c/2})()}class n0{constructor(){this.qt=null,this.$s=new lr,this.F=-1,this.W="",this.nm="",this.BS="normal"}ht(t){this.qt=t}js(t,e,n){this.F===t&&this.W===e||(this.F=t,this.W=e,this.nm=or(t,e),this.$s.Os()),this.BS=n}Qs(t,e){if(this.qt===null||this.qt.lt===null)return null;for(let n=this.qt.lt.from;n<this.qt.lt.to;n++){const i=this.qt.ot[n];if(i&&r0(i,t,e))return{zOrder:"normal",externalId:i.te??"",itemType:"marker"}}return null}draw(t){this.BS!=="aboveSeries"&&t.useBitmapCoordinateSpace((e=>{this.et(e)}))}drawBackground(t){this.BS==="aboveSeries"&&t.useBitmapCoordinateSpace((e=>{this.et(e)}))}et({context:t,horizontalPixelRatio:e,verticalPixelRatio:n}){if(this.qt!==null&&this.qt.lt!==null){t.textBaseline="middle",t.font=this.nm;for(let i=this.qt.lt.from;i<this.qt.lt.to;i++){const o=this.qt.ot[i];o.ri!==void 0&&(o.ri.nn=this.$s.Ii(t,o.ri.ES),o.ri.$t=this.F,o.ri._t=o._t-o.ri.nn/2),i0(o,t,e,n)}}}}function i0(s,t,e,n){t.fillStyle=s.R,s.ri!==void 0&&(function(i,o,l,a,c,u){i.save(),i.scale(c,u),i.fillText(o,l,a),i.restore()})(t,s.ri.ES,s.ri._t,s.ri.ut,e,n),(function(i,o,l){if(i.Th!==0){switch(i.AS){case"arrowDown":return void Ch(!1,o,l,i.Th);case"arrowUp":return void Ch(!0,o,l,i.Th);case"circle":return void(function(a,c,u){const d=(Fi("circle",u)-1)/2;a.beginPath(),a.arc(c._t,c.ut,d*c.VS,0,2*Math.PI,!1),a.fill()})(o,l,i.Th);case"square":return void(function(a,c,u){const d=Fi("square",u),f=(d-1)*c.VS/2,g=c._t-f,v=c.ut-f;a.fillRect(g,v,d*c.VS,d*c.VS)})(o,l,i.Th)}i.AS}})(s,t,(function(i,o,l){const a=Math.max(1,Math.floor(o))%2/2;return{_t:Math.round(i._t*o)+a,ut:i.ut*l,VS:o}})(s,e,n))}function r0(s,t,e){return!(s.ri===void 0||!(function(n,i,o,l,a,c){const u=l/2;return a>=n&&a<=n+o&&c>=i-u&&c<=i+u})(s.ri._t,s.ri.ut,s.ri.nn,s.ri.$t,t,e))||(function(n,i,o){if(n.Th===0)return!1;switch(n.AS){case"arrowDown":return Th(!0,n._t,n.ut,n.Th,i,o);case"arrowUp":return Th(!1,n._t,n.ut,n.Th,i,o);case"circle":return(function(l,a,c,u,d){const f=2+Fi("circle",c)/2,g=l-u,v=a-d;return Math.sqrt(g*g+v*v)<=f})(n._t,n.ut,n.Th,i,o);case"square":return(function(l,a,c,u,d){const f=Fi("square",c),g=(f-1)/2,v=l-g,b=a-g;return u>=v&&u<=v+f&&d>=b&&d<=b+f})(n._t,n.ut,n.Th,i,o)}})(s,t,e)}function Lh(s){return s==="atPriceTop"||s==="atPriceBottom"||s==="atPriceMiddle"}function o0(s,t,e,n,i,o,l,a){const c=(function(b,w,k){if(Lh(w.position)&&w.price!==void 0)return w.price;if("value"in(y=b)&&typeof y.value=="number")return b.value;var y;if((function(S){return"open"in S&&"high"in S&&"low"in S&&"close"in S})(b)){if(w.position==="inBar")return b.close;if(w.position==="aboveBar")return k?b.low:b.high;if(w.position==="belowBar")return k?b.high:b.low}})(e,t,l.priceScale().options().invertScale);if(c===void 0)return;const u=Lh(t.position),d=a.timeScale(),f=ti(t.size)?Math.max(t.size,0):1,g=qd(d.options().barSpacing)*f,v=g/2;switch(s.Th=g,t.position){case"inBar":case"atPriceMiddle":return s.ut=ct(l.priceToCoordinate(c)),void(s.ri!==void 0&&(s.ri.ut=s.ut+v+o+.6*i));case"aboveBar":case"atPriceTop":{const b=u?0:n.LS;return s.ut=ct(l.priceToCoordinate(c))-v-b,s.ri!==void 0&&(s.ri.ut=s.ut-v-.6*i,n.LS+=1.2*i),void(u||(n.LS+=g+o))}case"belowBar":case"atPriceBottom":{const b=u?0:n.zS;return s.ut=ct(l.priceToCoordinate(c))+v+b,s.ri!==void 0&&(s.ri.ut=s.ut+v+o+.6*i,n.zS+=1.2*i),void(u||(n.zS+=g+o))}}}class l0{constructor(t,e,n){this.OS=[],this.xt=!0,this.NS=!0,this.Xt=new n0,this.Te=t,this.qv=e,this.qt={ot:[],lt:null},this.yn=n}renderer(){if(!this.Te.options().visible)return null;this.xt&&this.yg();const t=this.qv.options().layout;return this.Xt.js(t.fontSize,t.fontFamily,this.yn.zOrder),this.Xt.ht(this.qt),this.Xt}FS(t){this.OS=t,this.kt("data")}kt(t){this.xt=!0,t==="data"&&(this.NS=!0)}WS(t){this.xt=!0,this.yn=t}zOrder(){return this.yn.zOrder==="aboveSeries"?"top":this.yn.zOrder}yg(){const t=this.qv.timeScale(),e=this.OS;this.NS&&(this.qt.ot=e.map((u=>({wt:u.time,_t:0,ut:0,Th:0,AS:u.shape,R:u.color,te:u.id,HS:u.HS,ri:void 0}))),this.NS=!1);const n=this.qv.options().layout;this.qt.lt=null;const i=t.getVisibleLogicalRange();if(i===null)return;const o=new Mi(Math.floor(i.from),Math.ceil(i.to));if(this.Te.data()[0]===null||this.qt.ot.length===0)return;let l=NaN;const a=Vd(t.options().barSpacing),c={LS:a,zS:a};this.qt.lt=Ad(this.qt.ot,o,!0);for(let u=this.qt.lt.from;u<this.qt.lt.to;u++){const d=e[u];d.time!==l&&(c.LS=a,c.zS=a,l=d.time);const f=this.qt.ot[u];f._t=ct(t.logicalToCoordinate(d.time)),d.text!==void 0&&d.text.length>0&&(f.ri={ES:d.text,_t:0,ut:0,nn:0,$t:0});const g=this.Te.dataByIndex(d.time,0);g!==null&&o0(f,d,g,c,n.fontSize,a,this.Te,this.qv)}this.xt=!1}}function Eh(s){return{...s0,...s}}class a0{constructor(t){this.Yh=null,this.OS=[],this.US=[],this.$S=null,this.Te=null,this.qv=null,this.jS=!0,this.qS=null,this.YS=null,this.KS=null,this.ZS=!0,this.yn=Eh(t)}attached(t){this.GS(),this.qv=t.chart,this.Te=t.series,this.Yh=new l0(this.Te,ct(this.qv),this.yn),this.DS=t.requestUpdate,this.Te.subscribeDataChanged((e=>this.Yg(e))),this.ZS=!0,this.pS()}pS(){this.DS&&this.DS()}detached(){this.Te&&this.$S&&this.Te.unsubscribeDataChanged(this.$S),this.qv=null,this.Te=null,this.Yh=null,this.$S=null}FS(t){this.ZS=!0,this.OS=t,this.GS(),this.jS=!0,this.YS=null,this.pS()}XS(){return this.OS}paneViews(){return this.Yh?[this.Yh]:[]}updateAllViews(){this.JS()}
6hitTest(t,e){var n;return this.Yh?((n=this.Yh.renderer())==null?void 0:n.Qs(t,e))??null:null}autoscaleInfo(t,e){if(this.yn.autoScale&&this.Yh){const n=this.QS();if(n)return{priceRange:null,margins:n}}return null}vr(t){this.yn=Eh({...this.yn,...t}),this.pS&&this.pS()}QS(){const t=ct(this.qv).timeScale().options().barSpacing;if(this.jS||t!==this.KS){if(this.KS=t,this.OS.length>0){const e=Vd(t),n=1.5*qd(t)+2*e,i=this.tx();this.qS={above:Nh(n,i.aboveBar,i.inBar),below:Nh(n,i.belowBar,i.inBar)}}else this.qS=null;this.jS=!1}return this.qS}tx(){return this.YS===null&&(this.YS=this.OS.reduce(((t,e)=>(t[e.position]||(t[e.position]=!0),t)),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.YS}GS(){var i;if(!this.ZS||!this.qv||!this.Te)return;const t=this.qv.timeScale(),e=(i=this.Te)==null?void 0:i.data();if(t.getVisibleLogicalRange()==null||!this.Te||e.length===0)return void(this.US=[]);const n=t.timeToIndex(ct(e[0].time),!0);this.US=this.OS.map(((o,l)=>{const a=t.timeToIndex(o.time,!0),c=a<n?1:-1,u=ct(this.Te).dataByIndex(a,c),d={time:t.timeToIndex(ct(u).time,!1),position:o.position,shape:o.shape,color:o.color,id:o.id,HS:l,text:o.text,size:o.size,price:o.price,Qr:o.time};if(o.position==="atPriceTop"||o.position==="atPriceBottom"||o.position==="atPriceMiddle"){if(o.price===void 0)throw new Error(`Price is required for position ${o.position}`);return{...d,position:o.position,price:o.price}}return{...d,position:o.position,price:o.price}})),this.ZS=!1}JS(t){this.Yh&&(this.GS(),this.Yh.FS(this.US),this.Yh.WS(this.yn),this.Yh.kt(t))}Yg(t){this.ZS=!0,this.pS()}}class c0 extends e0{constructor(t,e,n){super(t,e),n&&this.setMarkers(n)}setMarkers(t){this.Jh.FS(t)}markers(){return this.Jh.XS()}}function h0(s,t,e){const n=new c0(s,new a0({}));return t&&n.setMarkers(t),n}({...pd});const u0=1e3,d0=15e3,f0=25e3;class m0{constructor(){this.ws=null,this.url=null,this.token=null,this.authed=!1,this.attempt=0,this.pingTimer=null,this.subs=new Map,this.pendingSubs=new Map,this.statusHandlers=new Set}connect(t,e){const n=this.token!==e;if(this.token=e,this.ws&&this.url===t){n&&e&&this.ws.readyState===WebSocket.OPEN&&(this.authed=!1,this.send({op:"auth",token:e}));return}this.url=t,this.open()}open(){if(this.url){try{this.ws=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.ws.onopen=()=>{this.attempt=0,this.authed=!1,this.token&&this.send({op:"auth",token:this.token});for(const t of this.pendingSubs.values())this.send(t);this.startPing(),this.emitStatus("open")},this.ws.onmessage=t=>{let e;try{e=JSON.parse(t.data)}catch{return}if(e.channel==="auth"){this.authed=!0;return}if(e.channel!=="pong"){if(e.channel==="error"){console.warn("[hl-ws]",e.message);return}this.dispatch(e)}},this.ws.onclose=t=>{this.stopPing(),this.ws=null,this.authed=!1,this.emitStatus("closed"),(t==null?void 0:t.code)===1013&&(this.attempt=99),this.scheduleReconnect()},this.ws.onerror=()=>{}}}dispatch(t){const e=this.keyOf(t),n=this.subs.get(e);if(n)for(const i of n)try{i(t.data,t)}catch(o){console.error("[hl-ws] обработчик упал",o)}}keyOf(t){switch(t.channel){case"mids":return"mids";case"book":return`book:${t.coin}:${t.sig??0}`;case"bbo":return`bbo:${t.coin}`;case"trades":return`trades:${t.coin}`;case"ctx":return`ctx:${t.coin}`;case"candle":return`candle:${t.coin}:${t.interval}`;default:return`user:${t.channel}`}}subscribe(t,e,n){return this.subs.has(t)||(this.subs.set(t,new Set),this.pendingSubs.set(t,e),this.send(e)),this.subs.get(t).add(n),()=>this.unsubscribe(t,n)}unsubscribe(t,e){const n=this.subs.get(t);if(n&&(n.delete(e),n.size===0)){this.subs.delete(t);const i=this.pendingSubs.get(t);this.pendingSubs.delete(t),i&&this.send({...i,op:"unsub"})}}send(t){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(t))}startPing(){this.stopPing(),this.pingTimer=setInterval(()=>this.send({op:"ping"}),f0)}stopPing(){this.pingTimer&&(clearInterval(this.pingTimer),this.pingTimer=null)}scheduleReconnect(){const t=Math.min(u0*Math.pow(2,this.attempt),d0);this.attempt++,setTimeout(()=>this.open(),t)}onStatus(t){return this.statusHandlers.add(t),()=>this.statusHandlers.delete(t)}emitStatus(t){for(const e of this.statusHandlers)try{e(t)}catch{}}}const Ai=new m0;function p0(s,t=null){s&&Ai.connect(s,t||null)}function sn(s,t,e,n=!0){const i=m.useRef(e);i.current=e;const o=JSON.stringify(t??{});m.useEffect(()=>{if(!n)return;const l=JSON.parse(o);let a;
6s==="mids"?a="mids":s==="candle"?a=`candle:${l.coin}:${l.interval}`:s==="user"?a=`user:${l.sub}`:s==="book"?a=`book:${l.coin}:${l.sig??0}`:a=`${s}:${l.coin}`;const c={op:"sub",channel:s,...l};s==="user"&&delete c.sub;const u=(d,f)=>i.current(d,f);return Ai.subscribe(a,c,u)},[s,o,n])}function g0(){const[s,t]=m.useState("closed");return m.useEffect(()=>Ai.onStatus(t),[]),s}const Fh=/^\s*Ордер отклонён:\s*/i,v0=/^\s*Hyperliquid отклонил действие:\s*/i,x0=[/[.,]?\s*asset\s*=\s*\d+\s*$/i,/\s*User:\s*0x[0-9a-f]+\.?\s*$/i],y0=[{test:/minimum value of \$?\s*([\d.,]+)/i,key:"Minimum order value is {amount}. Increase the order size.",vars:s=>({amount:"$"+s[1]})},{test:/sufficient margin for reduction/i,key:"Cannot withdraw this much collateral — the position would be left without enough margin. Reduce the amount or close part of the position."},{test:/(add|transfer).{0,20}margin.{0,40}(insufficient|not enough)|margin.{0,20}exceeds/i,key:"Not enough free funds on this account to add collateral."},{test:/(switch|change).{0,20}leverage type|leverage type.{0,40}open position/i,key:"Cross and isolated margin cannot be switched while a position is open on this market — that is an exchange rule. Close the position to change the mode."},{test:/(cross|isolated).{0,30}margin.{0,30}(not allowed|cannot|invalid)|not.{0,10}isolated/i,key:"Collateral can only be changed on an isolated position."},{test:/insufficient margin/i,key:"Not enough margin for this order"},{test:/(reference|oracle|mark) price/i,key:"The order price is too far from the market price."},{test:/post[\s-]?only/i,key:"A post-only (ALO) order cannot cross the spread. Lower the price or use GTC."},{test:/reduce[\s-]?only/i,key:"A reduce-only order cannot increase the position."},{test:/immediately match/i,key:"The IOC order found no matching orders and was cancelled."},{test:/must deposit/i,key:"Deposit first — the exchange does not allow trading before the first deposit."},{test:/never placed|already cance?lled|already filled/i,key:"The order is already filled or cancelled."},{test:/main order cannot be trigger order/i,key:"The exchange did not accept take profit and stop loss together. Set them one at a time."},{test:/invalid price|tick size|price must be/i,key:"Invalid order price."},{test:/invalid size|zero size|lot size|size must be/i,key:"Invalid order size."},{test:/open interest|position limit|too many positions/i,key:"The exchange has reached the position limit for this market. Try again later."},{test:/does not exist|not registered|api wallet/i,key:"The trading key is not registered on the exchange. Re-enable futures."},{test:/insufficient (balance|funds)|not enough (balance|funds)/i,key:"Not enough balance on the exchange."}];function b0(s){var e,n;const t=s.indexOf("{");if(t===-1)return s;try{const i=JSON.parse(s.slice(t));if(typeof(i==null?void 0:i.response)=="string")return i.response;const o=(n=(e=i==null?void 0:i.response)==null?void 0:e.data)==null?void 0:n.statuses;if(Array.isArray(o)){const l=o.map(a=>a==null?void 0:a.error).filter(Boolean);if(l.length)return l.join("; ")}}catch{}return s}function w0(s){if(s==null)return"";let t=typeof s=="string"?s:JSON.stringify(s);const e=Fh.test(t);t=t.replace(Fh,"").replace(v0,""),t=b0(t).trim();for(const n of x0)t=t.replace(n,"");if(t=t.trim(),!t)return h("Unknown error");for(const n of y0){const i=t.match(n.test);if(i)return h(n.key,n.vars?n.vars(i):void 0)}return e?h("The exchange rejected the order: {text}",{text:t}):t}const Ud=m.createContext({showError:()=>{}});function Ln(){return m.useContext(Ud)}function _0({children:s}){const[t,e]=m.useState(null),n=m.useCallback((o,l)=>{const a=typeof o=="string"?o:JSON.stringify(o,null,2),c=w0(a)||h("Unknown error"),u=a===h("Network error")||typeof navigator<"u"&&navigator.onLine===!1;e({message:c,raw:a,title:l,offline:u})},[]);m.useEffect(()=>{if(!(t!=null&&t.offline))return;const o=()=>e(null);return window.addEventListener("online",o),()=>window.removeEventListener("online",o)},[t]);const i=m.useMemo(()=>({showError:n}),[n]);return r.jsxs(Ud.Provider,{value:i,children:[s,t&&r.jsx(k0,{title:t.title,message:t.message,onClose:()=>e(null)})]})}function k0({title:s,message:t,onClose:e}){return r.jsx("div",{className:"fut-modal fut-error",onClick:e,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:n=>n.stopPropagation(),children:[r.jsxs("div",{className:"fut-error__head",children:[r.jsx("span",{className:"fut-error__icon","aria-hidden":"true",children:r.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("path",{d:"M12 8v5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}
6),r.jsx("circle",{cx:"12",cy:"16.5",r:"1.2",fill:"currentColor"}),r.jsx("path",{d:"M10.3 3.9 2.6 17.4A2 2 0 0 0 4.3 20.4h15.4a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})]})}),r.jsx("b",{children:s||h("Error")}),r.jsx("button",{type:"button",className:"fut-error__close",onClick:e,"aria-label":h("Close"),children:"✕"})]}),r.jsx("div",{className:"fut-error__body",children:r.jsx("div",{className:"fut-error__text",children:t})}),r.jsx("button",{type:"button",className:"fut-error__ok",onClick:e,children:h("Close")})]})})}function zt(s){if(!s)return"";const t=s.indexOf(":");return t===-1?s:s.slice(t+1)}function ar(s){if(!s)return"";const t=s.indexOf(":");return t===-1?"":s.slice(0,t)}function M0(s){return zt(s)}function j0(s,t){if(!s||!Array.isArray(t))return null;const e=String(s).toUpperCase();for(const n of t){const i=n==null?void 0:n.name;if(i&&(i.toUpperCase()===e||zt(i).toUpperCase()===e))return i}return null}const Hd=.1,ri=.045+Hd,Ra=.015+Hd,S0=5,Ji=10;function N0(s){return s>0?1/(2*s):0}function Kd({entryPx:s,size:t,leverage:e,maxLeverage:n,isLong:i,isCross:o=!0,equity:l=0,usedMaintenance:a=0}){if(!s||!t||!e||!n)return 0;const c=t*s,u=N0(n),d=c*u,f=o?l-a-d:c/e-d;if(f<=0)return 0;const g=i?1:-1,v=s-g*(f/t)/(1-u*g);return v>0?v:0}function Ah({entryPx:s,exitPx:t,size:e,leverage:n,isLong:i,feePct:o=ri}){const l=s&&e&&n?e*s/n:0;if(!s||!t||!e)return{margin:l,gross:0,fees:0,net:0,roi:0,changePct:0};const c=(i?1:-1)*e*(t-s),u=(e*s+e*t)*(o/100),d=c-u;return{margin:l,gross:c,fees:u,net:d,roi:l?d/l*100:0,changePct:s?(t-s)/s*100:0}}function po(s,t=0,e=ri){const n=parseFloat((s==null?void 0:s.szi)??0)||0,i=parseFloat((s==null?void 0:s.entryPx)??0)||0,o=parseFloat(t??0)||0,l=o&&i?n*(o-i):parseFloat((s==null?void 0:s.unrealizedPnl)??0)||0,c=Math.abs(n)*(o||i)*e/100;return{gross:l,fee:c,net:l-c}}function C0({entryPx:s,size:t,isLong:e,target:n,feePct:i=ri}){if(!s||!t||!Number.isFinite(n))return 0;const o=e?1:-1,l=i/100,a=t*(o-l);if(!a)return 0;const c=(n+t*s*(o+l))/a;return c>0?c:0}function Pa(s){return!(s!=null&&s.isTrigger)||!s.reduceOnly&&!s.isPositionTpsl?!1:/Market/i.test(String(s.orderType??""))}function $d(s){const t=String((s==null?void 0:s.orderType)??"");return t.includes("Take Profit")?"tp":t.includes("Stop")?"sl":null}function Yd(s,t){const e=[];for(const n of s??[]){if(!(n!=null&&n.coin)||n.coin!==t||!Pa(n))continue;const i=$d(n),o=parseFloat(n.triggerPx??0)||0;!i||!o||e.push({key:String(n.oid??""),kind:i,price:o,size:parseFloat(n.sz??0)||0})}return e.sort((n,i)=>i.price-n.price)}function Yl(s,t){return(s??[]).filter(e=>e.kind===t)}function Rh(s,t,e){const n=Yl(s,t);if(n.length!==1)return!1;const i=n[0].size;return!i||e>0&&i>=e*.9975}function T0(s,t){const e=Yl(s,"tp"),n=Yl(s,"sl");return!e.length&&!n.length?!0:!(e.length&&!Rh(s,"tp",t)||n.length&&!Rh(s,"sl",t))}function Qd(s,t){return(s??[]).filter(e=>e.price>0).map(e=>({kind:e.kind,price:e.price,size:e.size>0?e.size:t}))}const cr=["#4a9eff","#2ebd85","#f0616d","#f5c451","#a06bff","#e8eaf0"],Ph={"#4a9eff":"Blue","#2ebd85":"Green","#f0616d":"Red","#f5c451":"Yellow","#a06bff":"Purple","#e8eaf0":"White"},ll={color:cr[0],width:1,dash:!1},L0=cr[0],E0=cr[2],Gd=[{id:"trend",title:"Trend Line",points:2},{id:"ray",title:"Ray",points:2},{id:"arrow",title:"Arrow",points:2},{id:"hline",title:"Horizontal Line",points:1,hotkey:"Alt+H"},{id:"hray",title:"Horizontal Ray",points:1,hotkey:"Alt+J"},{id:"vline",title:"Vertical Line",points:1,hotkey:"Alt+V"},{id:"channel",title:"Parallel Channel",points:3},{id:"rect",title:"Rectangle",points:2},{id:"circle",title:"Circle",points:2},{id:"brush",title:"Brush",points:0},{id:"text",title:"Text",points:1},{id:"arrowUp",title:"Arrow Mark Up",points:1},{id:"arrowDown",title:"Arrow Mark Down",points:1},{id:"longPos",title:"Long Position",points:2},{id:"shortPos",title:"Short Position",points:2},{id:"priceRange",title:"Price Range",points:2},{id:"dateRange",title:"Date Range",points:2},{id:"measure",title:"Measure",points:2},{id:"fibRet",title:"Fib Retracement",points:2,hotkey:"Alt+F"},{id:"fibExt",title:"Trend-Based Fib Extension",points:3},{id:"fibChan",title:"Fib Channel",points:3},{id:"fibTime",title:"Fib Time Zone",points:2},{id:"fibFan",title:"Fib Speed Resistance Fan",points:2}];function za(s){const[t,e,n]=s??[];if(!t||!e||!n)return s;const i=e.time-t.time;if(!i)return s;const o=t.time+i/2;if(n.time===o)return s;const l=a=>t.price+(a-t.time)*((e.price-t.price)/i);return[t,e,{time:o,price:l(o)+(n.price-l(n.time))}]}function Xd(s){const[t,e,n]=s??[];return!t||!e||!n||n.time===e.time?s:[t,e,{time:e.time,price:n.price}]}const Da=s=>s==="longPos"||s==="shortPos";function F0(s){if(s.tool==="channel")return{...s,points:za(s.points)};if(!Da(s.tool))return s;const[t,e]=s.points,n=e.price-t.price;return{...s,points:[t,e,{time:e.time,price:t.price-n}]}}const oo=s=>Gd.find(t=>
6t.id===s)??null,Ql=[{id:"lines",title:"Lines",tools:["trend","ray","arrow","hline","hray","vline","channel"]},{id:"shapes",title:"Shapes",tools:["rect","circle","brush"]},{id:"marks",title:"Marks",tools:["text","arrowUp","arrowDown"]},{id:"trades",title:"Positions",tools:["longPos","shortPos"]},{id:"ranges",title:"Measurements",tools:["priceRange","dateRange"]},{id:"fib",title:"Fibonacci",tools:["fibRet","fibExt","fibChan","fibTime","fibFan"]}],zh=s=>Ql.find(t=>t.tools.includes(s))??null,A0=new Set(["rect","circle","channel","measure","priceRange","dateRange","fibRet","fibExt","fibChan"]),Dh=s=>A0.has(s),Oa={text:12,arrowUp:18,arrowDown:18},Zd=s=>Object.hasOwn(Oa,s),Ni=s=>{const t=parseFloat((s==null?void 0:s.size)??0)||0;return t>0?t:Oa[s==null?void 0:s.tool]??0},R0={text:[10,12,16,22,30],arrowUp:[12,18,26,36,48],arrowDown:[12,18,26,36,48]},P0=new Set(["trend","ray","arrow","channel","rect","circle","priceRange","dateRange","measure","longPos","shortPos","fibRet","fibExt","fibChan","fibFan"]),z0=s=>P0.has(s),Zn="none",No=.1,D0=.8;function Gl(s){const t=Number(s==null?void 0:s.lineAlpha);return Number.isFinite(t)?Math.min(1,Math.max(0,t)):D0}function Zs(s){const t=Number(s==null?void 0:s.fillAlpha);return Number.isFinite(t)?Math.min(1,Math.max(0,t)):No}function qi(s){return s.fill===Zn?null:s.fill||s.color}const Ia={fibRet:[0,.236,.382,.5,.618,.786,1],fibExt:[0,.618,1,1.272,1.414,1.618,2.618],fibChan:[0,.236,.382,.5,.618,.786,1],fibTime:[0,1,2,3,5,8,13,21,34,55],fibFan:[.236,.382,.5,.618,.786]},Oh={fibRet:[0,.236,.382,.5,.618,.786,1,1.272,1.618,2.618],fibExt:[0,.382,.5,.618,1,1.272,1.414,1.618,2,2.618,3.618,4.236],fibChan:[0,.236,.382,.5,.618,.786,1,1.272,1.618,2.618],fibTime:[0,1,2,3,5,8,13,21,34,55,89,144],fibFan:[.236,.382,.5,.618,.786]},Jd=s=>Object.prototype.hasOwnProperty.call(Ia,s),O0={0:"#787b86",.236:"#f23645",.382:"#ff9800",.5:"#4caf50",.618:"#089981",.786:"#00bcd4",1:"#787b86",1.272:"#2962ff",1.414:"#5e35b1",1.618:"#9c27b0",2:"#e91e63",2.618:"#f23645",3.618:"#ff9800",4.236:"#089981"},Ih=["#787b86","#f23645","#ff9800","#4caf50","#089981","#00bcd4","#2962ff","#9c27b0"];function al(s,t,e=0){return(s==null?void 0:s.fibColors)===!1?s.color:O0[t]??Ih[e%Ih.length]}function Xl(s){return Array.isArray(s==null?void 0:s.levels)?s.levels:Ia[s==null?void 0:s.tool]??[]}const cl=s=>String(Number(s.toFixed(3))),Bh={KeyF:"fibRet",KeyH:"hline",KeyJ:"hray",KeyV:"vline"},tf="futures_chart_drawings",I0=300,Wh=120;function ef(){try{return JSON.parse(localStorage.getItem(tf))??{}}catch{return{}}}function B0(s){const t=ef();return(Array.isArray(t[s])?t[s]:[]).map(n=>(n==null?void 0:n.tool)==="channel"?{...n,points:za(n.points)}:Da(n==null?void 0:n.tool)?{...n,points:Xd(n.points)}:n)}function W0(s,t){try{const e=ef();t.length?e[s]=t.slice(-I0).map(n=>n.tool==="brush"&&n.points.length>Wh?{...n,points:q0(n.points,Wh)}:n):delete e[s],localStorage.setItem(tf,JSON.stringify(e))}catch{}}function q0(s,t){if(s.length<=t)return s;const e=(s.length-1)/(t-1),n=[];for(let i=0;i<t;i++)n.push(s[Math.round(i*e)]);return n}const sf="futures_chart_draw_styles";function nf(){try{return JSON.parse(localStorage.getItem(sf))??{}}catch{return{}}}function hl(s){const t=nf()[s],e=s==="priceRange"||s==="dateRange",n=Jd(s)||e?{fill:Zn}:{},i=e?{width:1}:{};return{...n,color:(t==null?void 0:t.color)??ll.color,width:(t==null?void 0:t.width)??ll.width,...i,dash:(t==null?void 0:t.dash)??ll.dash,...Zd(s)?{size:(t==null?void 0:t.size)??Oa[s]}:{},...(t==null?void 0:t.fill)!==void 0?{fill:t.fill}:{},...(t==null?void 0:t.fillAlpha)!==void 0?{fillAlpha:t.fillAlpha}:{},...(t==null?void 0:t.lineAlpha)!==void 0?{lineAlpha:t.lineAlpha}:{},...Array.isArray(t==null?void 0:t.levels)?{levels:t.levels.slice()}:{}}}function V0(s,t){try{const e=nf();e[s]={color:t.color,width:t.width,dash:t.dash,...t.size?{size:t.size}:{},...t.fill!==void 0?{fill:t.fill}:{},...t.fillAlpha!==void 0?{fillAlpha:t.fillAlpha}:{},...t.lineAlpha!==void 0?{lineAlpha:t.lineAlpha}:{},...Array.isArray(t.levels)?{levels:t.levels.slice()}:{}},localStorage.setItem(sf,JSON.stringify(e))}catch{}}function ul(){return"d"+Date.now().toString(36)+Math.random().toString(36).slice(2,7)}function zn(s,t,e,n,i,o){const l=i-e,a=o-n,c=l*l+a*a;if(!c)return Math.hypot(s-e,t-n);let u=((s-e)*l+(t-n)*a)/c;return u=Math.max(0,Math.min(1,u)),Math.hypot(s-(e+u*l),t-(n+u*a))}function qh(s,t,e,n,i,o,l){return s>=Math.min(e,i)-l&&s<=Math.max(e,i)+l&&t>=Math.min(n,o)-l&&t<=Math.max(n,o)+l}const rf=2.5,U0=7;function Co(s,t){const e=[];for(const n of s.points){const i=t.toX(n.time),o=t.toY(n.price);if(i===null||o===null||!Number.isFinite(i)||!Number.isFinite(o))return null;e.push({x:i,y:o})}return e}function H0(s,t){const e=Co(s,t);if(!e||!e.length)return null;let n=1/0,i=-1/0,o=1/0,l=-1/0;for(const a of e)!Number.isFinite(a.x)||!Number.isFinite(a.y)||(a.x<n&&(n=a.x),a.x>i&&(i=a.x),a.y<o&&(o=a.y),a.y>l&&(l=a.y));return Number.isFinite(n)&&Number.isFinite(o)?{left:n,right:i,top:o,bottom:l}:null}function mi(s,t,e,n,i=0){const o=Co(s,t);if(!o)return null;const l=s.tool==="brush"&&o.length>2?[0,o.length-1]:o.map((a,c)=>c);for(const a of l)if(Math.hypot(e-o[a].x,n-o[a].y)<=rf+6.5+i)return{handle:a};return K0(s,o,t,e,n,i)?{handle:-1}:null}function K0(s,t,e,n,i,o=0){var u;const l=U0+o,[a,c]=t;switch(s.tool){case"trend":return zn(n,i,a.x,a.y,c.x,c.y)<=l;case"ray":{const d=Wa(a,c,e);return zn(n,i,a.x,a.y,d.x,d.y)<=l}case"hline":return Math.abs(i-a.y)<=l;case"hray":return Math.abs(i-a.y)<=l&&n>=a.x-l;case"vline":return Math.abs(n-a.x)<=l;case"fibRet":case"fibExt":case"fibChan":case"fibTime":case"fibFan":{const d=lf(s,e);if(!d)return!1;for(const f of d.lines)if(zn(n,i,f.x1,f.y1,f.x2,f.y2)<=l)return!0;for(const f of d.guides)if(zn(n,i,f.x1,f.y1,f.x2,f.y2)<=l)return!0;return!1}case"brush":{for(let d=1;d<t.length;d++)if(zn(n,i,t[d-1].x,t[d-1].y,t[d].x,t[d].y)<=l)return!0;return!1}case"arrowUp":{const d=Ni(s);return Math.abs(n-a.x)<=d*.55&&i>=a.y-4&&i<=a.y+d+2}case"arrowDown":{const d=Ni(s);return Math.abs(n-a.x)<=d*.55&&i<=a.y+4&&i>=a.y-d-2}case"text":{const d=Ni(s),f=(((u=s.text)==null?void 0:u.length)??1)*d*.58+8;return n>=a.x-4&&n<=a.x+f&&i>=a.y-d&&i<=a.y+d*.34}case"arrow":return zn(n,i,a.x,a.y,c.x,c.y)<=l;case"channel":{const d=Ba(t);if(zn(n,i,a.x,a.y,c.x,c.y)<=l||zn(n,i,a.x,a.y+d,c.x,c.y+d)<=l)return!0;const f=c.x-a.x;if(!f||n<Math.min(a.x,c.x)||n>Math.max(a.x,c.x))return!1;const g=a.y+(n-a.x)*((c.y-a.y)/f);return i>
6=Math.min(g,g+d)&&i<=Math.max(g,g+d)}case"longPos":case"shortPos":{const d=of(t);return qh(n,i,d.left,d.top,d.right,d.bottom,0)}case"circle":{const d=(a.x+c.x)/2,f=(a.y+c.y)/2,g=Math.abs(c.x-a.x)/2||1,v=Math.abs(c.y-a.y)/2||1,b=(n-d)/g,w=(i-f)/v;return b*b+w*w<=1+l/Math.min(g,v)}case"rect":case"measure":return qh(n,i,a.x,a.y,c.x,c.y,0);case"priceRange":{const d=Math.min(a.x,c.x)-l,f=Math.max(a.x,c.x)+l,g=Math.min(a.y,c.y)-l,v=Math.max(a.y,c.y)+l;return n>=d&&n<=f&&(Math.abs(i-a.y)<=l||Math.abs(i-c.y)<=l)?!0:i>=g&&i<=v&&Math.abs(n-(a.x+c.x)/2)<=l}case"dateRange":{const d=Math.min(a.x,c.x)-l,f=Math.max(a.x,c.x)+l,g=Math.min(a.y,c.y)-l,v=Math.max(a.y,c.y)+l;return i>=g&&i<=v&&(Math.abs(n-a.x)<=l||Math.abs(n-c.x)<=l)?!0:n>=d&&n<=f&&Math.abs(i-(a.y+c.y)/2)<=l}default:return!1}}function Ba(s){const[t,e,n]=s;if(!n)return 0;const i=e.x-t.x;if(!i)return n.y-t.y;const o=t.y+(n.x-t.x)*((e.y-t.y)/i);return n.y-o}function of(s){const[t,e,n]=s,i=Math.min(t.x,e.x),o=Math.max(t.x,e.x),l=[t.y,e.y,n?n.y:t.y];return{left:i,right:o,top:Math.min(...l),bottom:Math.max(...l)}}function lf(s,t){const e=Co(s,t);if(!e)return null;const n=Xl(s),i=s.points,[o,l,a]=e,c=(u,d,f,g)=>{const v=t.toY(d);return v===null||!Number.isFinite(v)?null:{x1:f,y1:v,x2:g,y2:v,level:u,label:cl(u)+" ("+lt(d)+")"}};switch(s.tool){case"fibRet":{const u=Math.min(o.x,l.x),d=Math.max(o.x,l.x),f=i[1].price,g=i[0].price-i[1].price;return{lines:n.map(v=>c(v,f+g*v,u,d)).filter(Boolean),guides:[{x1:o.x,y1:o.y,x2:l.x,y2:l.y}]}}case"fibExt":{if(!a)return{lines:[],guides:[{x1:o.x,y1:o.y,x2:l.x,y2:l.y}]};const u=i[1].price-i[0].price,d=Math.min(o.x,l.x,a.x);return{lines:n.map(f=>c(f,i[2].price+u*f,d,t.width)).filter(Boolean),guides:[{x1:o.x,y1:o.y,x2:l.x,y2:l.y},{x1:l.x,y1:l.y,x2:a.x,y2:a.y}]}}case"fibChan":{if(!a)return{lines:[],guides:[{x1:o.x,y1:o.y,x2:l.x,y2:l.y}]};const u=Ba(e),d=l.x-o.x;if(!d)return null;const f=(l.y-o.y)/d,g=(v,b)=>o.y+(v-o.x)*f+b;return{lines:n.map(v=>({x1:0,y1:g(0,u*v),x2:t.width,y2:g(t.width,u*v),level:v,label:cl(v)})),guides:[{x1:o.x,y1:o.y,x2:l.x,y2:l.y}]}}case"fibTime":{const u=i[1].time-i[0].time;if(!u)return null;const d=0,f=t.height;return{lines:n.map(g=>{const v=t.toX(i[0].time+u*g);return v===null||!Number.isFinite(v)?null:{x1:v,y1:d,x2:v,y2:f,level:g,label:String(g)}}).filter(Boolean),guides:[]}}case"fibFan":return l.x-o.x?{lines:n.map(d=>{const f={x:l.x,y:o.y+(l.y-o.y)*d},g=Wa(o,f,t);return{x1:o.x,y1:o.y,x2:g.x,y2:g.y,level:d,label:cl(d),at:f}}),guides:[{x1:o.x,y1:o.y,x2:l.x,y2:o.y},{x1:l.x,y1:o.y,x2:l.x,y2:l.y}]}:null;default:return null}}function Wa(s,t,e){const n=t.x-s.x,i=t.y-s.y;if(!n&&!i)return t;const o=(Math.abs(e.width)+Math.abs(e.height))*2,l=Math.hypot(n,i);return{x:s.x+n/l*o,y:s.y+i/l*o}}const Ci='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function dl(s,t,e,n,i){const o=s.globalAlpha;s.globalAlpha=1,s.font="10px "+Ci,s.fillStyle=i,s.fillText(t,e,n),s.globalAlpha=o}function Vi(s,t,e,n,i){const o=s.globalAlpha;s.globalAlpha=1,s.font="11px "+Ci,s.fillStyle=i,s.fillText(t,e,n),s.globalAlpha=o}function $0(s,t,e,n,i,o=!1){const l=s.globalAlpha;s.globalAlpha=1,s.font="600 12px "+Ci;const a=11,c=8,u=17,d=Math.max(...t.map(w=>s.measureText(w).width))+a*2,f=t.length*u+c*2-4,g=Math.round(e-d/2),v=Math.round(o?n:n-f),b=6;s.beginPath(),s.moveTo(g+b,v),s.arcTo(g+d,v,g+d,v+f,b),s.arcTo(g+d,v+f,g,v+f,b),s.arcTo(g,v+f,g,v,b),s.arcTo(g,v,g+d,v,b),s.closePath(),s.fillStyle=i,s.fill(),s.fillStyle="#ffffff",s.textAlign="center",t.forEach((w,k)=>s.fillText(w,e,v+c+u*k+12)),s.textAlign="left",s.globalAlpha=l}function Vh(s){const t=Math.abs(Math.round(s)),e=Math.floor(t/86400),n=Math.floor(t%86400/3600),i=Math.floor(t%3600/60),o=c=>h("{n}d",{n:c}),l=c=>h("{n}h",{n:c}),a=c=>h("{n}m",{n:c});return e?o(e)+(n?" "+l(n):""):n?l(n)+(i?" "+a(i):""):a(i)}function Uh(s,t,e,n,i=!1,o=1){const l=Co(t,e);if(!l)return;const[a,c]=l;switch(s.save(),s.strokeStyle=t.color,s.fillStyle=t.color,s.lineWidth=t.width,s.lineJoin="round",s.lineCap="round",s.setLineDash(t.dash?[6,5]:[]),s.globalAlpha=Gl(t),t.tool){case"trend":Je(s,a,c);break;case"ray":Je(s,a,Wa(a,c,e));break;case"hline":Je(s,{x:0,y:a.y},{x:e.width,y:a.y}),s.setLineDash([]);break;case"hray":Je(s,a,{x:e.width,y:a.y}),s.setLineDash([]);break;case"vline":Je(s,{x:a.x,y:0},{x:a.x,y:e.height});break;case"brush":s.beginPath(),s.moveTo(l[0].x,l[0].y);for(let u=1;u<l.length;u++)s.lineTo(l[u].x,l[u].y);s.stroke();break;case"arrowUp":case"arrowDown":{const u=t.tool==="arrowUp"?1:-1,d=Ni(t),f=d/18;s.beginPath(),s.moveTo(a.x,a.y),s.lineTo(a.x-6*f,a.y+u*9*f),s.lineTo(a.x-2.5*f,a.y+u*9*f),s.lineTo(a.x-2.5*f,a.y+u*d),s.lineTo(a.x+2.5*f,a.y+u*d),s.lineTo(a.x+2.5*f,a.y+u*9*f),s.lineTo(a.x+6*f,a.y+u*9*f),s.closePath(),s.setLineDash([]),s.fill();break}case"text":s.setLineDash([]),s.font=Ni(t)+"px "+Ci,s.fillText(t.text||"…",a.x,a.y);break;case"priceRange":{const u=Math.min(a.x,c.x),d=Math.max(a.x,c.x),f=(a.x+c.x)/2;$h(s,a,c,Yh(t),Zs(t)),Je(s,{x:u,y:a.y},{x:d,y:a.y}),Je(s,{x:u,y:c.y},{x:d,y:c.y}),s.save(),s.globalAlpha=.7,s.setLineDash([4,4]),Je(s,{x:f,y:a.y},{x:f,y:c.y}),s.setLineDash([]);const g=6+t.width*1.5;pi(s,{x:f,y:c.y},{x:f,y:a.y},g),pi(s,{x:f,y:a.y},{x:f,y:c.y}
6,g),s.restore();const v=t.points[0].price,w=t.points[1].price-v,k=v?w/v*100:0;s.setLineDash([]);const y=(w>=0?"+":"")+lt(w)+"   "+(k>=0?"+":"")+k.toFixed(2)+"%";s.font="11px "+Ci,Vi(s,y,f-s.measureText(y).width/2,Math.min(a.y,c.y)-7,t.color);break}case"fibRet":case"fibExt":case"fibChan":case"fibTime":case"fibFan":{const u=lf(t,e);if(!u)break;if(u.guides.length){s.save(),s.globalAlpha=.45,s.setLineDash([5,4]);for(const f of u.guides)Je(s,{x:f.x1,y:f.y1},{x:f.x2,y:f.y2});s.restore()}const d=qi(t);if(d&&Zs(t)>0&&t.tool!=="fibTime"&&t.tool!=="fibFan"){s.save(),s.fillStyle=d;for(let f=1;f<u.lines.length;f++){const g=u.lines[f-1],v=u.lines[f];s.globalAlpha=Zs(t)*(f%2?1:.35),s.fillStyle=t.fill&&t.fill!==Zn?d:al(t,g.level,f-1),s.beginPath(),s.moveTo(g.x1,g.y1),s.lineTo(g.x2,g.y2),s.lineTo(v.x2,v.y2),s.lineTo(v.x1,v.y1),s.closePath(),s.fill()}s.restore()}s.setLineDash(t.dash?[6,5]:[]),u.lines.forEach((f,g)=>{s.strokeStyle=al(t,f.level,g),Je(s,{x:f.x1,y:f.y1},{x:f.x2,y:f.y2})}),s.setLineDash([]),u.lines.forEach((f,g)=>{if(!f.label)return;const v=al(t,f.level,g);t.tool==="fibTime"?dl(s,f.label,f.x1+4,14,v):t.tool==="fibFan"?dl(s,f.label,f.at.x+5,f.at.y-3,v):dl(s,f.label,Math.min(f.x1,f.x2)+5,f.y1-4,v)});break}case"rect":Kh(s,a,c,qi(t),Zs(t));break;case"circle":Y0(s,a,c,qi(t),Zs(t));break;case"arrow":{Je(s,a,c);const u=Math.atan2(c.y-a.y,c.x-a.x),d=9+t.width*2;s.setLineDash([]),s.beginPath(),s.moveTo(c.x,c.y),s.lineTo(c.x-d*Math.cos(u-.42),c.y-d*Math.sin(u-.42)),s.lineTo(c.x-d*Math.cos(u+.42),c.y-d*Math.sin(u+.42)),s.closePath(),s.fill();break}case"channel":{const u=Ba(l),d=qi(t);if(d&&Zs(t)>0){const f=s.globalAlpha;s.globalAlpha=Zs(t),s.fillStyle=d,s.beginPath(),s.moveTo(a.x,a.y),s.lineTo(c.x,c.y),s.lineTo(c.x,c.y+u),s.lineTo(a.x,a.y+u),s.closePath(),s.fill(),s.globalAlpha=f}s.fillStyle=t.color,Je(s,a,c),Je(s,{x:a.x,y:a.y+u},{x:c.x,y:c.y+u});break}case"longPos":case"shortPos":{const[u,d]=l;if(!u||!d)break;const f=l[2]??{x:d.x,y:u.y+(u.y-d.y)},g=of([u,d,f]);Hh(s,g.left,u.y,g.right,d.y,"#2ebd85"),Hh(s,g.left,u.y,g.right,f.y,"#f0616d"),s.setLineDash([]),s.strokeStyle=t.color,s.lineWidth=t.width,Je(s,{x:g.left,y:u.y},{x:g.right,y:u.y});const[v,b]=t.points,w=t.points[2]??{time:b.time,price:v.price-(b.price-v.price)};if(!(i||n||l.length<3))break;const y=Math.abs(b.price-v.price),S=Math.abs(v.price-w.price),j=b.price>=v.price?1:-1,E=(F,A)=>F?j*((A-F)/F)*100:0,z=F=>F<u.y?F+12:F-4;Vi(s,h("Target")+" "+lt(b.price)+"  "+fl(E(v.price,b.price))+"%",g.left+6,z(d.y),"#2ebd85"),Vi(s,h("Stop")+" "+lt(w.price)+"  "+fl(E(v.price,w.price))+"%",g.left+6,z(f.y),"#f0616d"),Vi(s,"R:R  "+(S?(y/S).toFixed(2):"—"),g.left+6,u.y-5,t.color);break}case"measure":{const u=t.points[0],d=t.points[1],f=d.price-u.price,g=u.price?f/u.price*100:0,v=d.time-u.time,b=e.barSeconds?Math.round(Math.abs(v)/e.barSeconds):0,w=f>=0,k=w?L0:E0;s.strokeStyle=k,s.fillStyle=k,Kh(s,a,c,qi(t)?k:null,Zs(t));const y=6+t.width*1.5;s.save(),s.setLineDash([]),s.globalAlpha=.8;const S=(a.x+c.x)/2,j=(a.y+c.y)/2;Je(s,{x:S,y:a.y},{x:S,y:c.y}),pi(s,{x:S,y:a.y},{x:S,y:c.y},y),Je(s,{x:a.x,y:j},{x:c.x,y:j}),pi(s,{x:a.x,y:j},{x:c.x,y:j},y),s.restore(),s.setLineDash([]),$0(s,[(w?"+":"")+lt(f)+"  ("+fl(g)+"%)",b+" "+h("bars")+", "+Vh(v)],(a.x+c.x)/2,w?Math.min(a.y,c.y)-8:Math.max(a.y,c.y)+8,k,!w);break}case"dateRange":{const u=Math.min(a.y,c.y),d=Math.max(a.y,c.y),f=(a.y+c.y)/2;$h(s,a,c,Yh(t),Zs(t)),Je(s,{x:a.x,y:u},{x:a.x,y:d}),Je(s,{x:c.x,y:u},{x:c.x,y:d}),s.save(),s.globalAlpha=.7,s.setLineDash([4,4]),Je(s,{x:a.x,y:f},{x:c.x,y:f}),s.setLineDash([]);const g=6+t.width*1.5;pi(s,{x:c.x,y:f},{x:a.x,y:f},g),pi(s,{x:a.x,y:f},{x:c.x,y:f},g),s.restore();const v=t.points[1].time-t.points[0].time,b=e.barSeconds?Math.round(Math.abs(v)/e.barSeconds):0;s.setLineDash([]);const w=b+" "+h("bars")+" × "+Vh(v);s.font="11px "+Ci,Vi(s,w,(a.x+c.x)/2-s.measureText(w).width/2,u-7,t.color);break}}if(n){s.setLineDash([]),s.globalAlpha=1;const u=t.tool==="brush"&&l.length>2?[l[0],l[l.length-1]]:l,d=rf*o;for(const f of u)s.beginPath(),s.arc(f.x,f.y,d,0,Math.PI*2),s.fillStyle="#14151c",s.strokeStyle=t.color,s.lineWidth=o>1?1.6:1,s.fill(),s.stroke()}
6s.restore()}function fl(s){return(s>=0?"+":"")+s.toFixed(2)}function Hh(s,t,e,n,i,o){const l=Math.min(e,i),a=Math.abs(i-e),c=s.globalAlpha;s.globalAlpha=.14,s.fillStyle=o,s.fillRect(t,l,n-t,a),s.globalAlpha=c,s.setLineDash([]),s.strokeStyle=o,s.lineWidth=1,s.strokeRect(t,l,n-t,a)}function Je(s,t,e){s.beginPath(),s.moveTo(t.x,t.y),s.lineTo(e.x,e.y),s.stroke()}function Kh(s,t,e,n,i=No){const o=Math.min(t.x,e.x),l=Math.min(t.y,e.y),a=Math.abs(e.x-t.x),c=Math.abs(e.y-t.y);if(n&&i>0){const u=s.globalAlpha;s.globalAlpha=i,s.fillStyle=n,s.fillRect(o,l,a,c),s.globalAlpha=u}s.strokeRect(o,l,a,c)}function $h(s,t,e,n,i=No){if(!n||!(i>0))return;const o=s.globalAlpha;s.globalAlpha=i,s.fillStyle=n,s.fillRect(Math.min(t.x,e.x),Math.min(t.y,e.y),Math.abs(e.x-t.x),Math.abs(e.y-t.y)),s.globalAlpha=o}function Yh(s){const t=s==null?void 0:s.fill;return t&&t!==Zn?t:null}function pi(s,t,e,n){const i=Math.atan2(e.y-t.y,e.x-t.x);s.beginPath(),s.moveTo(e.x,e.y),s.lineTo(e.x-n*Math.cos(i-.42),e.y-n*Math.sin(i-.42)),s.lineTo(e.x-n*Math.cos(i+.42),e.y-n*Math.sin(i+.42)),s.closePath(),s.fill()}function Y0(s,t,e,n,i=No){const o=(t.x+e.x)/2,l=(t.y+e.y)/2,a=Math.abs(e.x-t.x)/2,c=Math.abs(e.y-t.y)/2;if(!(a<.5||c<.5)){if(s.beginPath(),s.ellipse(o,l,a,c,0,0,Math.PI*2),n&&i>0){const u=s.globalAlpha;s.globalAlpha=i,s.fillStyle=n,s.fill(),s.globalAlpha=u}s.stroke()}}const Q0=[{id:"drawings",title:"Hide drawings"},{id:"indicators",title:"Hide indicators"},{id:"orders",title:"Hide positions and orders"},{id:"all",title:"Hide all"}],G0={drawings:!1,indicators:!1,orders:!1},Ui="@hide",Ut={fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round"},Qh=(s,t)=>r.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[r.jsx("path",{d:"M2 12s3.6-6.5 10-6.5S22 12 22 12s-3.6 6.5-10 6.5S2 12 2 12z",...Ut}),r.jsx("circle",{cx:"12",cy:"12",r:"2.6",...Ut}),s&&r.jsx("path",{d:"M4 20 20 4",...Ut})]}),ml={trend:r.jsx("path",{d:"M4 19 20 5",...Ut}),ray:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"5.5",cy:"18.5",r:"2.2",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M7.2 16.8 21 3",...Ut})]}),hline:r.jsx("path",{d:"M3 12h18",...Ut}),fibRet:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 4h18M3 9h18M3 15h18M3 20h18",...Ut}),r.jsx("path",{d:"M6 4 18 20",...Ut,strokeOpacity:"0.45"})]}),fibExt:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4 20 9 9l5 6",...Ut,strokeOpacity:"0.45"}),r.jsx("path",{d:"M3 4h18M3 8h18M3 14h18",...Ut})]}),fibChan:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 18 21 6",...Ut}),r.jsx("path",{d:"M3 13 21 1",...Ut}),r.jsx("path",{d:"M3 22 21 10",...Ut,strokeOpacity:"0.55"})]}),fibTime:r.jsx(r.Fragment,{children:r.jsx("path",{d:"M4 3v18M8 3v18M14 3v18M21 3v18",...Ut})}),fibFan:r.jsx(r.Fragment,{children:r.jsx("path",{d:"M4 20 21 3M4 20 21 9M4 20 21 15M4 20 21 20",...Ut})}),hray:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"5",cy:"12",r:"2.2",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M7.5 12H21",...Ut})]}),vline:r.jsx("path",{d:"M12 3v18",...Ut}),brush:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M17.8 3.4a2 2 0 0 1 2.8 2.8l-7.8 7.8-2.8-2.8z",...Ut}),r.jsx("path",{d:"M10 11.2l2.8 2.8-2 2a3 3 0 0 1-1.5.8L5 20l1.2-4.3a3 3 0 0 1 .8-1.5z",...Ut})]}),arrowUp:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 4v16",...Ut}),r.jsx("path",{d:"M6 10l6-6 6 6",...Ut})]}),arrowDown:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 20V4",...Ut}),r.jsx("path",{d:"M6 14l6 6 6-6",...Ut})]}),text:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M5 6h14",...Ut}),r.jsx("path",{d:"M12 6v13",...Ut})]}),arrow:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4 20 19 5",...Ut}),r.jsx("path",{d:"M12 5h7v7",...Ut})]}),channel:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 16 17 4",...Ut}),r.jsx("path",{d:"M7 20 21 8",...Ut})]}),rect:r.jsx("rect",{x:"4",y:"6",width:"16",height:"12",rx:"1.5",...Ut}),circle:r.jsx("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6.5",...Ut}),longPos:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"4",y:"5",width:"16",height:"6",rx:"1",...Ut}),r.jsx("rect",{x:"4",y:"13",width:"16",height:"6",rx:"1",...Ut}),r.jsx("path",{d:"M12 11V8m-2 2 2-2 2 2",...Ut})]}),shortPos:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"4",y:"5",width:"16",height:"6",rx:"1",...Ut}),r.jsx("rect",{x:"4",y:"13",width:"16",height:"6",rx:"1",...Ut}),r.jsx("path",{d:"M12 13v3m-2-2 2 2 2-2",...Ut})]}),measure:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"1.5",...Ut}),r.jsx("path",{d:"M8 8v3M12 8v4M16 8v3",...Ut})]}),priceRange:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"1.5",...Ut}),r.jsx("path",{d:"M12 8v8M9.5 10.5 12 8l2.5 2.5M9.5 13.5 12 16l2.5-2.5",...Ut})]}),dateRange:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"1.5",...Ut}),r.jsx("path",{d:"M8 12h8M10.5 9.5 8 12l2.5 2.5M13.5 9.5 16 12l-2.5 2.5",...Ut})]})};function X0({active:s,onPick:t,onRemoveAll:e,onBack:n,onToggleHide:i,hide:o=G0,c
6ount:l=0,compact:a=!1}){var S;const c=()=>{try{return window.matchMedia("(hover: hover) and (pointer: fine)").matches}catch{return!1}},u=m.useRef(null),[d,f]=m.useState(null),[g,v]=m.useState(()=>Object.fromEntries(Ql.map(j=>[j.id,j.tools[0]]))),b=s?((S=zh(s))==null?void 0:S.id)??null:null,w=o.drawings||o.indicators||o.orders,k=o.drawings&&o.indicators&&o.orders,y=j=>{const E=zh(j);E&&v(z=>({...z,[E.id]:j})),f(null),t(s===j?null:j)};return m.useEffect(()=>{if(d===null)return;const j=z=>{var F;(F=u.current)!=null&&F.contains(z.target)||f(null)},E=z=>{z.key==="Escape"&&f(null)};return document.addEventListener("pointerdown",j),document.addEventListener("keydown",E),()=>{document.removeEventListener("pointerdown",j),document.removeEventListener("keydown",E)}},[d]),r.jsxs("div",{className:"fut-draw"+(a?" fut-draw--compact":""),ref:u,children:[r.jsx(Rt.Tooltip,{title:h("Cursor"),position:"right",arrow:!0,tag:"span",distance:8,children:r.jsx("button",{type:"button",className:"fut-draw__tool"+(s?"":" is-active"),"aria-pressed":!s,onClick:()=>{f(null),t(null)},children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24","aria-hidden":"true",children:[r.jsx("path",{d:"M12 3v5M12 16v5M3 12h5M16 12h5",...Ut}),r.jsx("circle",{cx:"12",cy:"12",r:"2.6",...Ut})]})})}),r.jsx(Rt.Tooltip,{title:h("Measure")+"   "+h("Shift + click"),position:"right",arrow:!0,tag:"span",distance:8,children:r.jsx("button",{type:"button",className:"fut-draw__tool"+(s==="measure"?" is-active":""),"aria-pressed":s==="measure",onClick:()=>y("measure"),children:r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24","aria-hidden":"true",children:ml.measure})})}),r.jsx("span",{className:"fut-draw__sep"}),Ql.map(j=>{const E=g[j.id];return r.jsxs("div",{className:"fut-draw__group",onMouseEnter:()=>{c()&&f(j.id)},onMouseLeave:()=>{c()&&f(null)},children:[r.jsx("button",{type:"button",className:"fut-draw__tool fut-draw__tool--group"+(b===j.id?" is-active":""),"aria-haspopup":"menu","aria-expanded":d===j.id,onClick:()=>{if(c()){y(E);return}f(d===j.id?null:j.id)},children:r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24","aria-hidden":"true",children:ml[E]})}),d===j.id&&r.jsxs("div",{className:"fut-draw__flyout",role:"menu",children:[r.jsx("div",{className:"fut-draw__flyout-head",children:h(j.title)}),j.tools.map(z=>{const F=Gd.find(A=>A.id===z);return r.jsxs("button",{type:"button",role:"menuitem",className:s===z?"is-active":"",onClick:()=>y(z),children:[r.jsx("svg",{width:"17",height:"17",viewBox:"0 0 24 24","aria-hidden":"true",children:ml[z]}),r.jsx("span",{children:h(F.title)}),F.hotkey&&r.jsx("i",{children:F.hotkey})]},z)})]})]},j.id)}),r.jsx("span",{className:"fut-draw__sep"}),r.jsx(Rt.Tooltip,{title:h("Back to current price")+"   Alt+R",position:"right",arrow:!0,tag:"span",distance:8,children:r.jsx("button",{type:"button",className:"fut-draw__tool",onClick:n,children:r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24","aria-hidden":"true",children:[r.jsx("path",{d:"M4 12h13",...Ut}),r.jsx("path",{d:"M13 7l5 5-5 5",...Ut}),r.jsx("path",{d:"M21 4v16",...Ut})]})})}),r.jsxs("div",{className:"fut-draw__group",onMouseEnter:()=>{c()&&f(Ui)},onMouseLeave:()=>{c()&&f(null)},children:[r.jsx("button",{type:"button",className:"fut-draw__tool fut-draw__tool--group"+(w?" is-active":""),"aria-haspopup":"menu","aria-expanded":d===Ui,onClick:()=>{if(c()){i("all");return}f(d===Ui?null:Ui)},children:Qh(w,18)}),d===Ui&&r.jsxs("div",{className:"fut-draw__flyout",role:"menu",children:[r.jsx("div",{className:"fut-draw__flyout-head",children:h("Hide")}),Q0.map(j=>{const E=j.id==="all"?k:!!o[j.id];return r.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":E,className:E?"is-active":"",onClick:()=>i(j.id),children:[Qh(E,17),r.jsx("span",{children:h(j.title)})]},j.id)})]})]}),r.jsx(Rt.Tooltip,{title:h("Remove All"),position:"right",arrow:!0,tag:"span",distance:8,children:r.jsx("button",{type:"button",className:"fut-draw__tool fut-draw__tool--danger",disabled:!l,onClick:e,children:r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",...Ut})})})})]})}const af="futures_chart_indicators",Z0="ema4",qa=1,cf=.7;function Zl(s){const t=Number(s==null?void 0:s.alpha);return Number.isFinite(t)?Math.min(1,Math.max(0,t)):cf}function J0(s,t){if(t>=1)return s;const e=String(s??"").trim(),n=/^#([0-9a-f]{6})$/i.exec(e);if(!n)return e;const i=parseInt(n[1],16);return"rgba("+(i>>16&255)+", "+(i>>8&255)+", "+(i&255)+", "+t+")"}const q=["#4a9eff","#f5c451","#a06bff","#2ebd85","#f0616d","#e8eaf0"],Ge="#26a17b",Ss="#e35b5b",tv=[{key:"close",label:"Close"},{key:"open",label:"Open"},{key:"high",label:"High"},{key:"low",label:"Low"},{key:"hl2",label:"HL2"},{key:"hlc3",label:"HLC3"},{key:"ohlc4",label:"OHLC4"},{key:"hlcc4",label:"HLCC4"}];function Ft(s,t){switch(t){case"open":return s.map(e=>e.open);case"high":return s.map(e=>e.high);case"low":return s.map(e=>e.low);case"hl2":return s.map(e=>(e.high+e.low)/2);case"hlc3":return s.map(e=>(e.high+e.low+e.close)/3);case"ohlc4":return s.map(e=>(e.open+e.high+e.low+e.close)/4);case"hlcc4":return s.map(e=>(e.high+e.low+2*e.close)/4);default:return s.map(e=>e.close)}}const ev=[{key:"sma",label:"SMA"},{key:"ema",label:"EMA"},{key:"wma",label:"WMA"},{key:"rma",label:"RMA"},{key:"vwma",label:"VWMA"}];function Ts(s){let t=0;for(;t<s.length&&(s[t]===null||!Number.isFinite(s[t]));)t++;return t}function je(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);let i=0;for(let o=n;o<s.length;o++)i+=s[o],o>=n+t&&(i-=s[o-t]),o>=n+t-1&&(e[o]=i/t);return e}function ee(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);if(s.length-n<t)return e;let i=0;for(let a=n;a<n+t;a++)i+=s[a];let o=i/t;e[n+t-1]=o;const l=2/(t+1);for(let a=n+t;a<s.length;
6a++)o=s[a]*l+o*(1-l),e[a]=o;return e}function en(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);if(s.length-n<t)return e;let i=0;for(let l=n;l<n+t;l++)i+=s[l];let o=i/t;e[n+t-1]=o;for(let l=n+t;l<s.length;l++)o=(o*(t-1)+s[l])/t,e[l]=o;return e}function Ti(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s),i=t*(t+1)/2;for(let o=n+t-1;o<s.length;o++){let l=0;for(let a=0;a<t;a++)l+=s[o-t+1+a]*(a+1);e[o]=l/i}return e}function hf(s,t,e){const n=new Array(s.length).fill(null);if(!(e>0))return n;const i=Ts(s);let o=0,l=0;for(let a=i;a<s.length;a++){const c=t[a]||0;o+=s[a]*c,l+=c,a>=i+e&&(o-=s[a-e]*(t[a-e]||0),l-=t[a-e]||0),a>=i+e-1&&(n[a]=l>0?o/l:null)}return n}function sv(s,t){const e=ee(s,t),n=ee(e,t);return e.map((i,o)=>i===null||n[o]===null?null:2*i-n[o])}function nv(s,t){const e=ee(s,t),n=ee(e,t),i=ee(n,t);return e.map((o,l)=>o===null||n[l]===null||i[l]===null?null:3*o-3*n[l]+i[l])}function iv(s,t){if(!(t>1))return new Array(s.length).fill(null);const e=Math.max(1,Math.round(t/2)),n=Math.max(1,Math.round(Math.sqrt(t))),i=Ti(s,e),o=Ti(s,t),l=i.map((a,c)=>a===null||o[c]===null?null:2*a-o[c]);return Ti(l,n)}function rv(s,t,e,n){const i=new Array(s.length).fill(null);if(!(t>0)||!(n>0))return i;const o=e*(t-1),l=t/n,a=new Array(t);let c=0;for(let d=0;d<t;d++)a[d]=Math.exp(-((d-o)*(d-o))/(2*l*l)),c+=a[d];const u=Ts(s);for(let d=u+t-1;d<s.length;d++){let f=0;for(let g=0;g<t;g++)f+=s[d-t+1+g]*a[g];i[d]=f/c}return i}function Le(s,t,e,n){switch(e){case"ema":return ee(s,t);case"wma":return Ti(s,t);case"rma":return en(s,t);case"vwma":return hf(s,(n??[]).map(i=>i.volume??0),t);default:return je(s,t)}}function gi(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s),i=je(s,t);for(let o=n+t-1;o<s.length;o++){let l=0;for(let a=0;a<t;a++){const c=s[o-a]-i[o];l+=c*c}e[o]=Math.sqrt(l/t)}return e}function $s(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);for(let i=n+t-1;i<s.length;i++){let o=-1/0;for(let l=0;l<t;l++)o=Math.max(o,s[i-l]);e[i]=o}return e}function Ys(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);for(let i=n+t-1;i<s.length;i++){let o=1/0;for(let l=0;l<t;l++)o=Math.min(o,s[i-l]);e[i]=o}return e}function tr(s){return s.map((t,e)=>e===0?t.high-t.low:Math.max(t.high-t.low,Math.abs(t.high-s[e-1].close),Math.abs(t.low-s[e-1].close)))}function pl(s,t,e="rma"){return Le(tr(s),t,e,s)}function Or(s,t){const e=new Array(s.length).fill(null),n=new Array(s.length).fill(null),i=new Array(s.length).fill(null);for(let a=1;a<s.length;a++){const c=s[a]-s[a-1];n[a]=c>0?c:0,i[a]=c<0?-c:0}const o=en(n,t),l=en(i,t);for(let a=0;a<s.length;a++)o[a]===null||l[a]===null||(e[a]=l[a]===0?100:o[a]===0?0:100-100/(1+o[a]/l[a]));return e}function ov(s,t=1){return s.map((e,n)=>n<t||e===null||s[n-t]===null?null:e-s[n-t])}function Gh(s,t,e){const n=new Array(s.length).fill(null),i=new Array(s.length).fill(null);for(let f=1;f<s.length;f++){const g=s[f].high-s[f-1].high,v=s[f-1].low-s[f].low;n[f]=g>v&&g>0?g:0,i[f]=v>g&&v>0?v:0}const o=en(tr(s),t),l=en(n,t),a=en(i,t),c=new Array(s.length).fill(null),u=new Array(s.length).fill(null),d=new Array(s.length).fill(null);for(let f=0;f<s.length;f++){if(o[f]===null||o[f]===0||l[f]===null||a[f]===null)continue;c[f]=100*l[f]/o[f],u[f]=100*a[f]/o[f];const g=c[f]+u[f];d[f]=g===0?0:100*Math.abs(c[f]-u[f])/g}return{plusDi:c,minusDi:u,adx:en(d,e)}}function Qs(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);let i=0;for(let o=n;o<s.length;o++)i+=s[o],o>=n+t&&(i-=s[o-t]),o>=n+t-1&&(e[o]=i);return e}function gl(s){return s.map((t,e)=>{if(e<3)return null;const n=s[e-3],i=s[e-2],o=s[e-1];return n===null||i===null||o===null||t===null?null:(n+2*i+2*o+t)/6})}function vl(s,t,e=0){const n=new Array(s.length).fill(null);if(!(t>1))return n;const i=Ts(s),o=t,l=o*(o-1)/2,a=(o-1)*o*(2*o-1)/6,c=o*a-l*l;if(c===0)return n;for(let u=i+t-1;u<s.length;u++){let d=0,f=0;for(let b=0;b<o;b++){const w=s[u-o+1+b];d+=w,f+=b*w}const g=(o*f-l*d)/c,v=(d-g*l)/o;n[u]=v+g*(o-1-e)}return n}function Ir(s,t){return s.map((e,n)=>n<t||e===null||!s[n-t]?null:100*(e-s[n-t])/s[n-t])}function xl(s){return s.map(t=>{const e=t.high-t.low;return e===0?0:(t.close-t.low-(t.high-t.close))/e*(t.volume??0)})}function lv(s,t){const e=new Array(s.length).fill(null);if(!(t>1))return e;const n=Ts(s),i=t,o=i*(i-1)/2,l=(i-1)*i*(2*i-1)/6,a=i*l-o*o;if(a===0)return e;for(let c=n+t-1;c<s.length;c++){let u=0,d=0;for(let f=0;f<i;f++){const g=s[c-i+1+f];u+=g,d+=f*g}e[c]=(i*d-o*u)/a}return e}function Xh(s,t){const e=new Array(s.length).fill(null);if(!(t>2))return e;const n=Ts(s),i=t,o=i*(i-1)/2,l=(i-1)*i*(2*i-1)/6,a=i*l-o*o;if(a===0)return e;for(let c=n+t-1;c<s.length;c++){let u=0,d=0;for(let b=0;b<i;b++){const w=s[c-i+1+b];u+=w,d+=b*w}const f=(i*d-o*u)/a,g=(u-f*o)/i;let v=0;for(let b=0;b<i;b++){const w=s[c-i+1+b]-(g+f*b);v+=w*w}e[c]=Math.sqrt(v/(i-2))}return e}function av(s,t){const e=new Array(s.length).fill(null);if(!(t>0))return e;const n=Ts(s);for(let i=n+t;i<s.length;i++){if(s[i]===null)continue;let o=0;for(let l=1;l<=t;l++)s[i-l]!==null&&s[i-l]<s[i]&&o++;e[i]=100*o/t}return e}function yl(s){const t=new Array(s.length).fill(null);let e=0;for(let n=0;n<s.length;n++)s[n]!==null&&Number.isFinite(s[n])&&(e+=s[n]),t[n]=e;return t}function Br(s){if(s.length<2)return 365;const t=s[1].time-s[0].time;return t>0?31557600/t:365}function bl(s){return s.map((t,e)=>e===0||!s[e-1].close||!t.close?null:Math.log(t.close/s[e-1].close))}function Wr(s,t){if(!t||!t.length)return null;const e=new Map;for(const o of t)e.set(o.time,o.close);const n=new Array(s.length).fill(null);let i=null;for(let o=0;o<s.length;o++){const l=e.get(s[o].time);l!==void 0&&(i=l),n[o]=i}return n}function Zh(s,t,e){const n=new Array(s.length).fill(null);if(!(e>1))return n;for(let i=e-1;i<s.length;i++){let o=0,l=0,a=0,c=0,u=0,d=0;for(let g=0;g<e;g++){const v=s[i-g],b=t[i-g];if(v===null||b===null||!Number.isFinite(v)||!Number.isFinite(b)){d=0;break}o+=v,l+=b,a+=v*v,c+=b*b,u+=v*b,d++}if(d!==e)continue;const f=Math.sqrt((e*a-o*o)*(e*c-l*l));n[i]=f===0?0:(e*u-o*l)/f}return n}function cv(s,t){if(t<s.length)return s[t].time;const e=s.length-1,n=e>0?s[e].time-s[e-1].time:60;return s[e].time+n*(t-e)}function W(s,t,e,n,i={}
6){const{offset:o=0,kind:l="line",barColors:a=null}=i,c=[];for(let u=0;u<s.length;u++){const d=t[u];if(d==null||!Number.isFinite(d))continue;const f=u+o;if(f<0)continue;const g={time:cv(s,f),value:d};a&&a[u]&&(g.color=a[u]),c.push(g)}return{title:e,color:n,data:c,kind:l}}const lo=[{id:"ma",title:"Moving Average",params:[{key:"length",name:"Length",type:"int",value:9,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"},{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>[W(s,Le(Ft(s,t.source),t.length,t.method,s),"MA "+t.length,q[0],{offset:t.offset})]},{id:"ema",title:"Moving Average Exponential",params:[{key:"length",name:"Length",type:"int",value:21,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>[W(s,ee(Ft(s,t.source),t.length),"EMA "+t.length,q[0],{offset:t.offset})]},{id:"wma",title:"Moving Average Weighted",params:[{key:"length",name:"Length",type:"int",value:9,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}
6,{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>[W(s,Ti(Ft(s,t.source),t.length),"WMA "+t.length,q[0],{offset:t.offset})]},{id:"smma",title:"Smoothed Moving Average",params:[{key:"length",name:"Length",type:"int",value:7,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>[W(s,en(Ft(s,t.source),t.length),"SMMA "+t.length,q[0],{offset:t.offset})]},{id:"hma",title:"Hull Moving Average",params:[{key:"length",name:"Length",type:"int",value:9,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>[W(s,iv(Ft(s,t.source),t.length),"HMA "+t.length,q[0],{offset:t.offset})]},{id:"alma",title:"Arnaud Legoux Moving Average",params:[{key:"length",name:"Length",type:"int",value:9,min:2,max:5e3},{key:"offset",name:"Offset",type:"float",value:.85,min:0,max:1,step:.05},{key:"sigma",name:"Sigma",type:"float",value:6,min:.1,max:100,step:.5},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,rv(Ft(s,t.source),t.length,t.offset,t.sigma),"ALMA "+t.length,q[0])]},{id:"vwma",title:"VWMA",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,hf(Ft(s,t.source),s.map(e=>e.volume??0),t.length),"VWMA "+t.length,q[0])]},{id:"dema",title:"Double EMA",params:[{key:"length",name:"Length",type:"int",value:21,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,sv(Ft(s,t.source),t.length),"Double EMA "+t.length,q[2])]},{id:"tema",title:"Triple EMA",params:[{key:"length",name:"Length",type:"int",value:21,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,nv(Ft(s,t.source),t.length),"Triple EMA "+t.length,q[3])]},{id:"emaCross",title:"EMA Cross",params:[{key:"fast",name:"Fast",type:"int",value:9,min:1,max:5e3},{key:"slow",name:"Slow",type:"int",value:21,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source);return[W(s,ee(e,t.fast),"EMA "+t.fast,q[0]),W(s,ee(e,t.slow),"EMA "+t.slow,q[1])]}},{id:"maCross",title:"MA Cross",params:[{key:"fast",name:"Fast",type:"int",value:10,min:1,max:5e3},{key:"slow",name:"Slow",type:"int",value:30,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=Ft(s,t.source);return[W(s,Le(e,t.fast,t.method,s),"MA "+t.fast,q[0]),W(s,Le(e,t.slow,t.method,s),"MA "+t.slow,q[1])]}},{id:"maEmaCross",title:"MA with EMA Cross",params:[{key:"ma",name:"MA",type:"int",value:50,min:1,max:5e3},{key:"ema",name:"EMA",type:"int",value:21,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source);return[W(s,je(e,t.ma),"MA "+t.ma,q[1]),W(s,ee(e,t.ema),"EMA "+t.ema,q[0])]}},{id:"ema4",title:"EMA 20/50/100/200",params:[{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source);return[20,50,100,200].map((n,i)=>W(s,ee(e,n),"EMA "+n,q[i]))}},{id:"bb",title:"Bollinger Bands",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"mult",name:"Deviation",type:"float",value:2,min:.001,max:50,step:.1},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"}
6,{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>{const e=Ft(s,t.source),n=Le(e,t.length,t.method,s),i=gi(e,t.length),o=n.map((a,c)=>a===null||i[c]===null?null:a+t.mult*i[c]),l=n.map((a,c)=>a===null||i[c]===null?null:a-t.mult*i[c]);return[W(s,o,"Upper",q[0],{offset:t.offset}),W(s,n,"Basis",q[1],{offset:t.offset}),W(s,l,"Lower",q[0],{offset:t.offset})]}},{id:"donchian",title:"Donchian Channels",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>{const e=$s(s.map(o=>o.high),t.length),n=Ys(s.map(o=>o.low),t.length),i=e.map((o,l)=>o===null||n[l]===null?null:(o+n[l])/2);return[W(s,e,"Upper",q[0],{offset:t.offset}),W(s,i,"Basis",q[1],{offset:t.offset}),W(s,n,"Lower",q[0],{offset:t.offset})]}},{id:"keltner",title:"Keltner Channels",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"mult",name:"Multiplier",type:"float",value:2,min:.001,max:50,step:.1},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"ema"},{key:"atrLen",name:"ATR Length",type:"int",value:10,min:1,max:5e3},{key:"useTr",name:"True Range",type:"bool",value:!0}],build:(s,t)=>{const e=Le(Ft(s,t.source),t.length,t.method,s),n=t.useTr?tr(s):s.map(a=>a.high-a.low),i=ee(n,t.atrLen),o=e.map((a,c)=>a===null||i[c]===null?null:a+t.mult*i[c]),l=e.map((a,c)=>a===null||i[c]===null?null:a-t.mult*i[c]);return[W(s,o,"Upper",q[0]),W(s,e,"Basis",q[1]),W(s,l,"Lower",q[0])]}},{id:"envelopes",title:"Envelopes",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"percent",name:"Percent",type:"float",value:10,min:.01,max:100,step:.5},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=Le(Ft(s,t.source),t.length,t.method,s),n=t.percent/100;return[W(s,e.map(i=>i===null?null:i*(1+n)),"Upper",q[0]),W(s,e,"Basis",q[1]),W(s,e.map(i=>i===null?null:i*(1-n)),"Lower",q[0])]}},{id:"supertrend",title:"SuperTrend",params:[{key:"length",name:"ATR Length",type:"int",value:10,min:1,max:5e3},{key:"mult",name:"Multiplier",type:"float",value:3,min:.01,max:100,step:.1}],build:(s,t)=>{const e=pl(s,t.length),n=new Array(s.length).fill(null),i=new Array(s.length).fill(null);let o=null,l=null,a=1;for(let c=0;c<s.length;c++){if(e[c]===null)continue;const u=(s[c].high+s[c].low)/2;let d=u-t.mult*e[c],f=u+t.mult*e[c];o!==null&&s[c-1].close>o&&(d=Math.max(d,o)),l!==null&&s[c-1].close<l&&(f=Math.min(f,l)),l!==null&&s[c].close>l?a=1:o!==null&&s[c].close<o&&(a=-1),a===1?n[c]=d:i[c]=f,o=d,l=f}return[W(s,n,"Up",Ge),W(s,i,"Down",Ss)]}},{id:"vwap",title:"VWAP",params:[{key:"anchor",name:"Anchor",type:"select",value:"day",options:[{key:"day",label:"Day"},{key:"week",label:"Week"},{key:"month",label:"Month"}]},{key:"source",name:"Source",type:"source",value:"hlc3"},{key:"mult",name:"Bands Multiplier",type:"float",value:0,min:0,max:20,step:.5}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=new Array(s.length).fill(null),o=new Array(s.length).fill(null);let l=0,a=0,c=0,u=null;for(let f=0;f<s.length;f++){const g=new Date(s[f].time*1e3);let v;t.anchor==="month"?v=g.getUTCFullYear()+"-"+g.getUTCMonth():t.anchor==="week"?v=Math.floor((s[f].time-4*86400)/604800):v=Math.floor(s[f].time/86400),v!==u&&(u=v,l=0,a=0,c=0);const b=s[f].volume??0;if(l+=e[f]*b,c+=e[f]*e[f]*b,a+=b,a<=0)continue;const w=l/a;if(n[f]=w,t.mult>0){const k=Math.max(0,c/a-w*w),y=Math.sqrt(k);i[f]=w+t.mult*y,o[f]=w-t.mult*y}}const d=[W(s,n,"VWAP",q[1])];return t.mult>0&&(d.push(W(s,i,"Upper",q[0])),d.push(W(s,o,"Lower",q[0]))),d}},{id:"averagePrice",title:"Average Price",params:[],build:s=>[W(s,Ft(s,"ohlc4"),"Average",q[0])]},{id:"medianPrice",title:"Median Price",params:[],build:s=>[W(s,Ft(s,"hl2"),"Median",q[0])]},{id:"typicalPrice",title:"Typical Price",params:[],build:s=>[W(s,Ft(s,"hlc3"),"Typical",q[0])]},{id:"lsma",title:"Least Squares Moving Average",params:[{key:"length",name:"Length",type:"int",value:25,min:2,max:5e3}
6,{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,vl(Ft(s,t.source),t.length,t.offset),"LSMA "+t.length,q[0])]},{id:"linreg",title:"Linear Regression Curve",params:[{key:"length",name:"Length",type:"int",value:100,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,vl(Ft(s,t.source),t.length,0),"LinReg "+t.length,q[0])]},{id:"mcginley",title:"McGinley Dynamic",params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=ee(e,t.length);let o=null;for(let l=0;l<e.length;l++){if(o===null){if(i[l]===null)continue;o=i[l],n[l]=o;continue}const a=e[l]/o;o=o+(e[l]-o)/(t.length*Math.pow(a,4)),n[l]=o}return[W(s,n,"McGinley "+t.length,q[0])]}},{id:"kama",title:"Moving Average Adaptive",params:[{key:"length",name:"Length",type:"int",value:21,min:2,max:5e3},{key:"fast",name:"Fast",type:"int",value:2,min:1,max:5e3},{key:"slow",name:"Slow",type:"int",value:30,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=2/(t.fast+1),o=2/(t.slow+1),l=e.map((u,d)=>d===0?null:Math.abs(u-e[d-1])),a=Qs(l,t.length);let c=null;for(let u=t.length;u<e.length;u++){if(a[u]===null)continue;c===null&&(c=e[u-1]);const d=Math.abs(e[u]-e[u-t.length]),f=a[u]===0?0:d/a[u],g=Math.pow(f*(i-o)+o,2);c=c+g*(e[u]-c),n[u]=c}return[W(s,n,"KAMA "+t.length,q[0])]}},{id:"hammingMa",title:"Moving Average Hamming",params:[{key:"length",name:"Length",type:"int",value:9,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=[];let o=0;for(let l=0;l<t.length;l++){const a=.54-.46*Math.cos(2*Math.PI*l/(t.length-1));i.push(a),o+=a}for(let l=t.length-1;l<e.length;l++){let a=0;for(let c=0;c<t.length;c++)a+=e[l-t.length+1+c]*i[c];n[l]=a/o}return[W(s,n,"Hamming "+t.length,q[0])]}},{id:"guppy",title:"Guppy Multiple Moving Average",params:[{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=[3,5,8,10,12,15],i=[30,35,40,45,50,60];return[...n.map(o=>W(s,ee(e,o),"EMA "+o,q[0])),...i.map(o=>W(s,ee(e,o),"EMA "+o,q[4]))]}},{id:"maChannel",title:"Moving Average Channel",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"method",name:"Method",type:"ma",value:"sma"}
6,{key:"offset",name:"Offset",type:"int",value:0,min:-500,max:500}],build:(s,t)=>{const e=Le(s.map(i=>i.high),t.length,t.method,s),n=Le(s.map(i=>i.low),t.length,t.method,s);return[W(s,e,"Upper",q[0],{offset:t.offset}),W(s,n,"Lower",q[0],{offset:t.offset})]}},{id:"priceChannel",title:"Price Channel",params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3}],build:(s,t)=>{const e=$s(s.map(l=>l.high),t.length),n=Ys(s.map(l=>l.low),t.length),i=e.map((l,a)=>a===0?null:e[a-1]),o=n.map((l,a)=>a===0?null:n[a-1]);return[W(s,i,"Upper",q[0]),W(s,o,"Lower",q[0])]}},{id:"chandeKroll",title:"Chande Kroll Stop",params:[{key:"length",name:"Length",type:"int",value:10,min:1,max:5e3},{key:"mult",name:"Multiplier",type:"float",value:1,min:.01,max:100,step:.5},{key:"stop",name:"Stop Length",type:"int",value:9,min:1,max:5e3}],build:(s,t)=>{const e=pl(s,t.length),n=$s(s.map(a=>a.high),t.length),i=Ys(s.map(a=>a.low),t.length),o=n.map((a,c)=>a===null||e[c]===null?null:a-t.mult*e[c]),l=i.map((a,c)=>a===null||e[c]===null?null:a+t.mult*e[c]);return[W(s,$s(o,t.stop),"Short Stop",Ss),W(s,Ys(l,t.stop),"Long Stop",Ge)]}},{id:"ichimoku",title:"Ichimoku Cloud",params:[{key:"conversion",name:"Conversion Line Length",type:"int",value:9,min:1,max:5e3},{key:"base",name:"Base Line Length",type:"int",value:26,min:1,max:5e3},{key:"span",name:"Leading Span B Length",type:"int",value:52,min:1,max:5e3},{key:"displacement",name:"Displacement",type:"int",value:26,min:0,max:500}],build:(s,t)=>{const e=s.map(u=>u.high),n=s.map(u=>u.low),i=u=>{const d=$s(e,u),f=Ys(n,u);return d.map((g,v)=>g===null||f[v]===null?null:(g+f[v])/2)},o=i(t.conversion),l=i(t.base),a=o.map((u,d)=>u===null||l[d]===null?null:(u+l[d])/2),c=i(t.span);return[W(s,o,"Conversion",q[0]),W(s,l,"Base",q[4]),W(s,a,"Lead A",q[3],{offset:t.displacement}),W(s,c,"Lead B",q[2],{offset:t.displacement}),W(s,s.map(u=>u.close),"Lagging",q[1],{offset:-t.displacement})]}},{id:"alligator",title:"Williams Alligator",params:[{key:"jaw",name:"Jaw Length",type:"int",value:13,min:1,max:5e3},{key:"jawShift",name:"Jaw Offset",type:"int",value:8,min:0,max:500},{key:"teeth",name:"Teeth Length",type:"int",value:8,min:1,max:5e3},{key:"teethShift",name:"Teeth Offset",type:"int",value:5,min:0,max:500},{key:"lips",name:"Lips Length",type:"int",value:5,min:1,max:5e3},{key:"lipsShift",name:"Lips Offset",type:"int",value:3,min:0,max:500}],build:(s,t)=>{const e=Ft(s,"hl2");return[W(s,en(e,t.jaw),"Jaw",q[0],{offset:t.jawShift}),W(s,en(e,t.teeth),"Teeth",q[4],{offset:t.teethShift}),W(s,en(e,t.lips),"Lips",q[3],{offset:t.lipsShift})]}},{id:"psar",title:"Parabolic SAR",params:[{key:"start",name:"Start Value",type:"float",value:.02,min:.001,max:1,step:.01},{key:"increment",name:"Increment",type:"float",value:.02,min:.001,max:1,step:.01},{key:"maximum",name:"Maximum",type:"float",value:.2,min:.001,max:1,step:.05}],build:(s,t)=>{const e=new Array(s.length).fill(null),n=new Array(s.length).fill(null);if(s.length<2)return[];let i=s[1].close>=s[0].close,o=t.start,l=i?s[0].high:s[0].low,a=i?s[0].low:s[0].high;for(let c=1;c<s.length;c++)a=a+o*(l-a),i?(a=Math.min(a,s[c-1].low,s[Math.max(0,c-2)].low),s[c].high>l&&(l=s[c].high,o=Math.min(o+t.increment,t.maximum)),s[c].low<a&&(i=!1,a=l,l=s[c].low,o=t.start)):(a=Math.max(a,s[c-1].high,s[Math.max(0,c-2)].high),s[c].low<l&&(l=s[c].low,o=Math.min(o+t.increment,t.maximum)),s[c].high>a&&(i=!0,a=l,l=s[c].high,o=t.start)),i?e[c]=a:n[c]=a;return[W(s,e,"SAR up",Ge,{kind:"dots"}),W(s,n,"SAR down",Ss,{kind:"dots"})]}},{id:"maDouble",title:"Moving Average Double",params:[{key:"first",name:"First Length",type:"int",value:10,min:1,max:5e3},{key:"second",name:"Second Length",type:"int",value:20,min:1,max:5e3},{key:"method",name:"Method",type:"ma",value:"sma"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source);return[W(s,Le(e,t.first,t.method,s),"MA "+t.first,q[0]),W(s,Le(e,t.second,t.method,s),"MA "+t.second,q[1])]}},{id:"maTriple",title:"Moving Average Triple",params:[{key:"first",name:"First Length",type:"int",value:10,min:1,max:5e3},{key:"second",name:"Second Length",type:"int",value:20,min:1,max:5e3},{key:"third",name:"Third Length",type:"int",value:30,min:1,max:5e3},{key:"method",name:"Method",type:"ma",value:"sma"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source);return[W(s,Le(e,t.first,t.method,s),"MA "+t.first,q[0]),W(s,Le(e,t.second,t.method,s),"MA "+t.second,q[1]),W(s,Le(e,t.third,t.method,s),"MA "+t.third,q[2])]}},{id:"stdErrorBands",title:"Standard Error Bands",params:[{key:"length",name:"Length",type:"int",value:21,min:3,max:5e3},{key:"smooth",name:"Smoothing",type:"int",value:3,min:1,max:5e3},{key:"mult",name:"Multiplier",type:"float",value:2,min:.01,max:50,step:.5},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=je(vl(e,t.length,0),t.smooth),i=je(Xh(e,t.length),t.smooth);return[W(s,n.map((o,l)=>o===null||i[l]===null?null:o+t.mult*i[l]),"Upper",q[0]),W(s,n,"Middle",q[1]),W(s,n.map((o,l)=>
6o===null||i[l]===null?null:o-t.mult*i[l]),"Lower",q[0])]}},{id:"week52",title:"52 Week High/Low",params:[{key:"weeks",name:"Weeks",type:"int",value:52,min:1,max:520},{key:"mid",name:"Midline",type:"bool",value:!0}],build:(s,t)=>{const e=s.length>1?s[1].time-s[0].time:86400,n=Math.max(1,Math.round(t.weeks*604800/e)),i=$s(s.map(a=>a.high),n),o=Ys(s.map(a=>a.low),n),l=[W(s,i,"High",Ss),W(s,o,"Low",Ge)];return t.mid&&l.push(W(s,i.map((a,c)=>a===null||o[c]===null?null:(a+o[c])/2),"Middle",q[5])),l}},{id:"zigzag",title:"Zig Zag",params:[{key:"deviation",name:"Deviation",type:"float",value:5,min:.01,max:100,step:.5},{key:"depth",name:"Depth",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=new Array(s.length).fill(null);if(s.length<2)return[];const n=t.deviation/100;let i=0,o=0,l=s[0].high;for(let a=1;a<s.length;a++)i!==-1?s[a].high>=l?(l=s[a].high,o=a,i===0&&(i=1)):s[a].low<=l*(1-n)&&a-o>=t.depth&&(e[o]=l,i=-1,l=s[a].low,o=a):s[a].low<=l?(l=s[a].low,o=a):s[a].high>=l*(1+n)&&a-o>=t.depth&&(e[o]=l,i=1,l=s[a].high,o=a);return e[o]=l,[W(s,e,"Zig Zag",q[1])]}},{id:"pivots",title:"Pivot Points Standard",params:[{key:"kind",name:"Type",type:"select",value:"traditional",options:[{key:"traditional",label:"Traditional"},{key:"classic",label:"Classic"},{key:"fibonacci",label:"Fibonacci"},{key:"woodie",label:"Woodie"},{key:"camarilla",label:"Camarilla"}]},{key:"period",name:"Anchor",type:"select",value:"day",options:[{key:"day",label:"Day"},{key:"week",label:"Week"},{key:"month",label:"Month"}]},{key:"levels",name:"Levels",type:"int",value:3,min:1,max:5}],build:(s,t)=>{const e=d=>{const f=new Date(d*1e3);return t.period==="month"?f.getUTCFullYear()*12+f.getUTCMonth():t.period==="week"?Math.floor((d-345600)/604800):Math.floor(d/86400)},n=new Array(s.length).fill(null),i=[1,2,3,4,5].map(()=>new Array(s.length).fill(null)),o=[1,2,3,4,5].map(()=>new Array(s.length).fill(null));let l=null,a=null;for(let d=0;d<s.length;d++){const f=e(s[d].time);if(l===null||l.key!==f?(a=l,l={key:f,high:s[d].high,low:s[d].low,close:s[d].close,open:s[d].open}):(l.high=Math.max(l.high,s[d].high),l.low=Math.min(l.low,s[d].low),l.close=s[d].close),!a)continue;const{high:g,low:v,close:b,open:w}=a,k=g-v;let y,S=[],j=[];t.kind==="fibonacci"?(y=(g+v+b)/3,S=[y+.382*k,y+.618*k,y+k,y+1.382*k,y+1.618*k],j=[y-.382*k,y-.618*k,y-k,y-1.382*k,y-1.618*k]):t.kind==="camarilla"?(y=(g+v+b)/3,S=[b+k*1.1/12,b+k*1.1/6,b+k*1.1/4,b+k*1.1/2,b+k*1.1],j=[b-k*1.1/12,b-k*1.1/6,b-k*1.1/4,b-k*1.1/2,b-k*1.1]):t.kind==="woodie"?(y=(g+v+2*w)/4,S=[2*y-v,y+k,g+2*(y-v),g+2*(y-v)+k],j=[2*y-g,y-k,v-2*(g-y),v-2*(g-y)-k]):t.kind==="classic"?(y=(g+v+b)/3,S=[2*y-v,y+k,y+2*k,y+3*k,y+4*k],j=[2*y-g,y-k,y-2*k,y-3*k,y-4*k]):(y=(g+v+b)/3,S=[2*y-v,y+k,g+2*(y-v),g+3*(y-v),g+4*(y-v)],j=[2*y-g,y-k,v-2*(g-y),v-3*(g-y),v-4*(g-y)]),n[d]=y;for(let E=0;E<Math.min(t.levels,S.length);E++)i[E][d]=S[E],o[E][d]=j[E]}const c=[W(s,n,"P",q[1])],u=t.kind==="woodie"?Math.min(t.levels,4):t.levels;for(let d=0;d<u;d++)c.push(W(s,i[d],"R"+(d+1),Ss)),c.push(W(s,o[d],"S"+(d+1),Ge));return c}},{id:"rsi",title:"Relative Strength Index",pane:!0,levels:[70,30],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"maLen",name:"MA Length",type:"int",value:0,min:0,max:5e3},{key:"maType",name:"MA Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=Or(Ft(s,t.source),t.length),n=[W(s,e,"RSI "+t.length,q[0])];return t.maLen>0&&n.push(W(s,Le(e,t.maLen,t.maType,s),"MA "+t.maLen,q[1])),n}},{id:"macd",title:"MACD",pane:!0,levels:[0],params:[{key:"fast",name:"Fast",type:"int",value:12,min:1,max:5e3},{key:"slow",name:"Slow",type:"int",value:26,min:1,max:5e3},{key:"signal",name:"Signal",type:"int",value:9,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"},{key:"oscMa",name:"Method",type:"ma",value:"ema"},{key:"sigMa",name:"Signal Method",type:"ma",value:"ema"}],build:(s,t)=>{const e=Ft(s,t.source),n=Le(e,t.fast,t.oscMa,s),i=Le(e,t.slow,t.oscMa,s),o=n.map((u,d)=>u===null||i[d]===null?null:u-i[d]),l=Le(o,t.signal,t.sigMa,s),a=o.map((u,d)=>u===null||l[d]===null?null:u-l[d]),c=a.map((u,d)=>{if(u===null)return null;const f=a[d-1],g=f==null||u>=f;return u>=0?g?Ge:"rgba(38,161,123,0.45)":g?"rgba(227,91,91,0.45)":Ss});
6return[W(s,a,"Histogram",Ge,{kind:"histogram",barColors:c}),W(s,o,"MACD",q[0]),W(s,l,"Signal",q[1])]}},{id:"stoch",title:"Stochastic",pane:!0,levels:[80,20],params:[{key:"length",name:"%K Length",type:"int",value:14,min:1,max:5e3},{key:"smoothK",name:"%K Smoothing",type:"int",value:1,min:1,max:5e3},{key:"smoothD",name:"%D Smoothing",type:"int",value:3,min:1,max:5e3}],build:(s,t)=>{const e=$s(s.map(a=>a.high),t.length),n=Ys(s.map(a=>a.low),t.length),i=s.map((a,c)=>{if(e[c]===null||n[c]===null)return null;const u=e[c]-n[c];return u===0?50:100*(a.close-n[c])/u}),o=je(i,t.smoothK),l=je(o,t.smoothD);return[W(s,o,"%K",q[0]),W(s,l,"%D",q[1])]}},{id:"stochRsi",title:"Stochastic RSI",pane:!0,levels:[80,20],params:[{key:"smoothK",name:"%K",type:"int",value:3,min:1,max:5e3},{key:"smoothD",name:"%D",type:"int",value:3,min:1,max:5e3},{key:"rsiLen",name:"RSI Length",type:"int",value:14,min:1,max:5e3},{key:"stochLen",name:"Stochastic Length",type:"int",value:14,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Or(Ft(s,t.source),t.rsiLen),n=$s(e,t.stochLen),i=Ys(e,t.stochLen),o=e.map((c,u)=>{if(c===null||n[u]===null||i[u]===null)return null;const d=n[u]-i[u];return d===0?50:100*(c-i[u])/d}),l=je(o,t.smoothK),a=je(l,t.smoothD);return[W(s,l,"%K",q[0]),W(s,a,"%D",q[1])]}},{id:"atr",title:"Average True Range",pane:!0,params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"method",name:"Smoothing",type:"ma",value:"rma"}],build:(s,t)=>[W(s,pl(s,t.length,t.method),"ATR "+t.length,q[0])]},{id:"adx",title:"Average Directional Index",pane:!0,levels:[25],params:[{key:"adxLen",name:"ADX Smoothing",type:"int",value:14,min:1,max:5e3},{key:"diLen",name:"DI Length",type:"int",value:14,min:1,max:5e3}],build:(s,t)=>[W(s,Gh(s,t.diLen,t.adxLen).adx,"ADX "+t.adxLen,q[0])]},{id:"dmi",title:"Directional Movement",pane:!0,levels:[25],params:[{key:"adxLen",name:"ADX Smoothing",type:"int",value:14,min:1,max:5e3},{key:"diLen",name:"DI Length",type:"int",value:14,min:1,max:5e3}],build:(s,t)=>{const e=Gh(s,t.diLen,t.adxLen);return[W(s,e.plusDi,"+DI",Ge),W(s,e.minusDi,"-DI",Ss),W(s,e.adx,"ADX",q[1])]}},{id:"cci",title:"Commodity Channel Index",pane:!0,levels:[100,-100],params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"hlc3"}],build:(s,t)=>{const e=Ft(s,t.source),n=je(e,t.length),i=new Array(s.length).fill(null);for(let o=0;o<s.length;o++){if(n[o]===null)continue;let l=0;for(let a=0;a<t.length;a++)l+=Math.abs(e[o-a]-n[o]);l/=t.length,i[o]=l===0?0:(e[o]-n[o])/(.015*l)}return[W(s,i,"CCI "+t.length,q[0])]}},{id:"williamsR",title:"Williams %R",pane:!0,levels:[-20,-80],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=$s(s.map(l=>l.high),t.length),i=Ys(s.map(l=>l.low),t.length),o=e.map((l,a)=>{if(n[a]===null||i[a]===null)return null;const c=n[a]-i[a];return c===0?-50:-100*(n[a]-l)/c});return[W(s,o,"%R "+t.length,q[0])]}},{id:"momentum",title:"Momentum",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:10,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,ov(Ft(s,t.source),t.length),"Mom "+t.length,q[0])]},{id:"roc",title:"Rate Of Change",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:9,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=e.map((i,o)=>o<t.length||!e[o-t.length]?null:100*(i-e[o-t.length])/e[o-t.length]);return[W(s,n,"ROC "+t.length,q[0])]}},{id:"ao",title:"Awesome Oscillator",pane:!0,levels:[0],params:[],build:s=>{const t=s.map(l=>(l.high+l.low)/2),e=je(t,5),n=je(t,34),i=e.map((l,a)=>l===null||n[a]===null?null:l-n[a]),o=i.map((l,a)=>{if(l===null)return null;const c=i[a-1];return c==null||l>=c?Ge:Ss});return[W(s,i,"AO",Ge,{kind:"histogram",barColors:o})]}},{id:"mfi",title:"Money Flow Index",pane:!0,levels:[80,20],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"hlc3"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=new Array(s.length).fill(null);for(let c=1;c<s.length;c++){const u=e[c]*(s[c].volume??0);n[c]=e[c]>e[c-1]?u:0,i[c]=e[c]<e[c-1]?u:0}const o=je(n,t.length),l=je(i,t.length),a=o.map((c,u)=>c===null||l[u]===null?null:l[u]===0?100:c===0?0:100-100/(1+c/l[u]));return[W(s,a,"MFI "+t.length,q[0])]}},{id:"obv",title:"On Balance Volume",pane:!0,format:"volume",params:[],build:s=>{const t=new Array(s.length).fill(null);let e=0;for(let n=0;n<s.length;n++){if(n>0){const i=s[n].volume??0;s[n].close>s[n-1].close?e+=i:s[n].close<s[n-1].close&&(e-=i)}t[n]=e}return[W(s,t,"OBV",q[0])]}},{id:"uo",title:"Ultimate Oscillator",pane:!0,levels:[70,30],params:[{key:"fast",name:"Fast",type:"int",value:7,min:1,max:5e3},{key:"middle",name:"Middle",type:"int",value:14,min:1,max:5e3},{key:"slow",name:"Slow",type:"int",value:28,min:1,max:5e3}],build:(s,t)=>{const e=new Array(s.length).fill(null),n=new Array(s.length).fill(null);for(let u=1;u<s.length;u++){const d=s[u-1].close,f=Math.min(s[u].low,d),g=Math.max(s[u].high,d);e[u]=s[u].close-f,n[u]=g-f}const i=u=>{const d=je(e,u),f=je(n,u);return d.map((g,v)=>g===null||f[v]===null||f[v]===0?null:g/f[v])},o=i(t.fast),l=i(t.middle),a=i(t.slow),c=o.map((u,d)=>u===null||l[d]===null||a[d]===null?null:100*(4*u+2*l[d]+a[d])/7);return[W(s,c,"UO",q[0])]}}
6,{id:"trix",title:"TRIX",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:18,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source).map(o=>o>0?Math.log(o):null),n=ee(ee(ee(e,t.length),t.length),t.length),i=n.map((o,l)=>o===null||l===0||n[l-1]===null?null:1e4*(o-n[l-1]));return[W(s,i,"TRIX "+t.length,q[0])]}},{id:"aroon",title:"Aroon",pane:!0,levels:[70,30],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3}],build:(s,t)=>{const e=new Array(s.length).fill(null),n=new Array(s.length).fill(null);for(let i=t.length;i<s.length;i++){let o=-1/0,l=1/0,a=i,c=i;for(let u=0;u<=t.length;u++){const d=i-u;s[d].high>o&&(o=s[d].high,a=d),s[d].low<l&&(l=s[d].low,c=d)}e[i]=100*(t.length-(i-a))/t.length,n[i]=100*(t.length-(i-c))/t.length}return[W(s,e,"Aroon Up",Ge),W(s,n,"Aroon Down",Ss)]}},{id:"vortex",title:"Vortex Indicator",pane:!0,levels:[1],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3}],build:(s,t)=>{const e=new Array(s.length).fill(null),n=new Array(s.length).fill(null);for(let u=1;u<s.length;u++)e[u]=Math.abs(s[u].high-s[u-1].low),n[u]=Math.abs(s[u].low-s[u-1].high);const i=Qs(tr(s),t.length),o=Qs(e,t.length),l=Qs(n,t.length),a=o.map((u,d)=>u===null||!i[d]?null:u/i[d]),c=l.map((u,d)=>u===null||!i[d]?null:u/i[d]);return[W(s,a,"VI+",Ge),W(s,c,"VI-",Ss)]}},{id:"chop",title:"Choppiness Index",pane:!0,levels:[61.8,38.2],params:[{key:"length",name:"Length",type:"int",value:14,min:2,max:5e3}],build:(s,t)=>{const e=Qs(tr(s),t.length),n=$s(s.map(l=>l.high),t.length),i=Ys(s.map(l=>l.low),t.length),o=e.map((l,a)=>{if(l===null||n[a]===null||i[a]===null)return null;const c=n[a]-i[a];return c<=0||l<=0?null:100*Math.log10(l/c)/Math.log10(t.length)});return[W(s,o,"CHOP "+t.length,q[0])]}},{id:"cmo",title:"Chande Momentum Oscillator",pane:!0,levels:[50,-50],params:[{key:"length",name:"Length",type:"int",value:9,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(e.length).fill(null),i=new Array(e.length).fill(null);for(let c=1;c<e.length;c++){const u=e[c]-e[c-1];n[c]=u>0?u:0,i[c]=u<0?-u:0}const o=Qs(n,t.length),l=Qs(i,t.length),a=o.map((c,u)=>{if(c===null||l[u]===null)return null;const d=c+l[u];return d===0?0:100*(c-l[u])/d});return[W(s,a,"CMO "+t.length,q[0])]}},{id:"bop",title:"Balance of Power",pane:!0,levels:[0],params:[{key:"smooth",name:"Smoothing",type:"int",value:14,min:1,max:5e3},{key:"method",name:"Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=s.map(n=>{const i=n.high-n.low;return i===0?0:(n.close-n.open)/i});return[W(s,Le(e,t.smooth,t.method,s),"BOP "+t.smooth,q[0])]}},{id:"bbPercent",title:"Bollinger Bands %B",pane:!0,levels:[1,0],params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"mult",name:"Deviation",type:"float",value:2,min:.001,max:50,step:.1},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=Ft(s,t.source),n=Le(e,t.length,t.method,s),i=gi(e,t.length),o=n.map((l,a)=>{if(l===null||i[a]===null)return null;const c=2*t.mult*i[a];return c===0?.5:(e[a]-(l-t.mult*i[a]))/c});return[W(s,o,"%B",q[0])]}},{id:"bbWidth",title:"Bollinger Bands Width",pane:!0,params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"mult",name:"Deviation",type:"float",value:2,min:.001,max:50,step:.1},{key:"source",name:"Source",type:"source",value:"close"},{key:"method",name:"Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=Ft(s,t.source),n=Le(e,t.length,t.method,s),i=gi(e,t.length),o=n.map((l,a)=>l===null||i[a]===null||l===0?null:2*t.mult*i[a]/l);return[W(s,o,"Width",q[0])]}},{id:"stdDev",title:"Standard Deviation",pane:!0,params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3},{key:"mult",name:"Deviation",type:"float",value:1,min:.001,max:50,step:.5},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=gi(Ft(s,t.source),t.length);return[W(s,e.map(n=>n===null?null:n*t.mult),"StdDev "+t.length,q[0])]}},{id:"dpo",title:"Detrended Price Oscillator",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:21,min:2,max:5e3},{key:"centered",name:"Centered",type:"bool",value:!1}],build:(s,t)=>{const e=s.map(l=>l.close),n=je(e,t.length),i=Math.floor(t.length/2)+1,o=e.map((l,a)=>a<i||n[a-i]===null?null:l-n[a-i]);return[W(s,o,"DPO "+t.length,q[0],{offset:t.centered?-i:0})]}},{id:"kst",title:"Know Sure Thing",pane:!0,levels:[0],params:[{key:"roc1",name:"ROC Length #1",type:"int",value:10,min:1,max:5e3},{key:"roc2",name:"ROC Length #2",type:"int",value:15,min:1,max:5e3},{key:"roc3",name:"ROC Length #3",type:"int",value:20,min:1,max:5e3},{key:"roc4",name:"ROC Length #4",type:"int",value:30,min:1,max:5e3},{key:"sma1",name:"SMA Length #1",type:"int",value:10,min:1,max:5e3},{key:"sma2",name:"SMA Length #2",type:"int",value:10,min:1,max:5e3},{key:"sma3",name:"SMA Length #3",type:"int",value:10,min:1,max:5e3},{key:"sma4",name:"SMA Length #4",type:"int",value:15,min:1,max:5e3},{key:"signal",name:"Signal Length",type:"int",value:9,min:1,max:5e3}],build:(s,t)=>{const e=s.map(u=>u.close),n=(u,d)=>je(Ir(e,u),d),i=n(t.roc1,t.sma1),o=n(t.roc2,t.sma2),l=n(t.roc3,t.sma3),a=n(t.roc4,t.sma4),c=i.map((u,d)=>u===null||o[d]===null||l[d]===null||a[d]===null?null:u+2*o[d]+3*l[d]+4*a[d]);return[W(s,c,"KST",q[0]),W(s,je(c,t.signal),"Signal",q[1])]}},{id:"coppock",title:"Coppock Curve",pane:!0,levels:[0],params:[{key:"wmaLen",name:"WMA Length",type:"int",value:10,min:1,max:5e3},{key:"long",name:"Long RoC Length",type:"int",value:14,min:1,max:5e3},{key:"short",name:"Short RoC Length",type:"int",value:11,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=Ir(e,t.long),i=Ir(e,t.short),o=n.map((l,a)=>l===null||i[a]===null?null:l+i[a]);return[W(s,Ti(o,t.wmaLen),"Coppock",q[0])]}},{id:"tsi",title:"True Strength Index",pane:!0,levels:[0],params:[{key:"long",name:"Long Length",type:"int",value:25,min:1,max:5e3},{key:"short",name:"Short Length",type:"int",value:13,min:1,max:5e3},{key:"signal",name:"Signal Length",type:"int",value:13,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=e.map((c,u)=>u===0?null:c-e[u-1]),i=n.map(c=>c===null?null:Math.abs(c)),o=ee(ee(n,t.long),t.short),l=ee(ee(i,t.long),t.short),a=o.map((c,u)=>c===null||!l[u]?null:100*c/l[u]);return[W(s,a,"TSI",q[0]),W(s,ee(a,t.signal),"Signal",q[1])]}},{id:"rvi",title:"Relative Vigor Index",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=gl(s.map(a=>a.close-a.open)),n=gl(s.map(a=>a.high-a.low)),i=je(e,t.length),o=je(n,t.length),l=i.map((a,c)=>a===null||!o[c]?null:a/o[c]);return[W(s,l,"RVI",q[0]),W(s,gl(l),"Signal",q[1])]}},{id:"efi",title:"Elder's Force Index",pane:!0,levels:[0],format:"volume",params:[{key:"length",name:"Length",type:"int",value:13,min:1,max:5e3}],build:(s,t)=>{const e=s.map((n,i)=>i===0?null:(n.close-s[i-1].close)*(n.volume??0));return[W(s,ee(e,t.length),"EFI "+t.length,q[0])]}},{id:"cmf",title:"Chaikin Money Flow",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:20,min:1,max:5e3}],build:(s,t)=>{const e=Qs(xl(s),t.length),n=Qs(s.map(o=>o.volume??0),t.length),i=e.map((o,l)=>
6o===null||!n[l]?null:o/n[l]);return[W(s,i,"CMF "+t.length,q[0])]}},{id:"adl",title:"Accumulation/Distribution",pane:!0,format:"volume",params:[],build:s=>{const t=xl(s),e=new Array(s.length).fill(null);let n=0;for(let i=0;i<s.length;i++)n+=t[i],e[i]=n;return[W(s,e,"A/D",q[0])]}},{id:"accelerator",title:"Accelerator Oscillator",pane:!0,levels:[0],params:[],build:s=>{const t=Ft(s,"hl2"),e=je(t,5).map((l,a)=>{const c=je(t,34)[a];return l===null||c===null?null:l-c}),n=je(e,5),i=e.map((l,a)=>l===null||n[a]===null?null:l-n[a]),o=i.map((l,a)=>{if(l===null)return null;const c=i[a-1];return c==null||l>=c?Ge:Ss});return[W(s,i,"AC",Ge,{kind:"histogram",barColors:o})]}},{id:"asi",title:"Accumulative Swing Index",pane:!0,levels:[0],params:[{key:"limit",name:"Limit Move Value",type:"float",value:300,min:1e-4,max:1e6,step:10}],build:(s,t)=>{const e=new Array(s.length).fill(null);for(let n=1;n<s.length;n++){const i=s[n-1],o=s[n],l=Math.abs(o.high-i.close),a=Math.abs(o.low-i.close),c=Math.abs(o.high-o.low),u=Math.abs(i.close-i.open);let d;if(l>a&&l>c?d=l-.5*a+.25*u:a>l&&a>c?d=a-.5*l+.25*u:d=c+.25*u,d===0){e[n]=0;continue}const f=Math.max(l,a);e[n]=50*(o.close-i.close+.5*(o.close-o.open)+.25*(i.close-i.open))/d*(f/t.limit)}return[W(s,yl(e),"ASI",q[0])]}},{id:"chaikinOsc",title:"Chaikin Oscillator",pane:!0,levels:[0],format:"volume",params:[{key:"short",name:"Short Length",type:"int",value:3,min:1,max:5e3},{key:"long",name:"Long Length",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=yl(xl(s)),n=ee(e,t.short),i=ee(e,t.long),o=n.map((l,a)=>l===null||i[a]===null?null:l-i[a]);return[W(s,o,"Chaikin Osc",q[0])]}},{id:"chaikinVol",title:"Chaikin Volatility",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:10,min:1,max:5e3},{key:"roc",name:"ROC Length",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=ee(s.map(i=>i.high-i.low),t.length),n=e.map((i,o)=>
6i===null||o<t.roc||!e[o-t.roc]?null:100*(i-e[o-t.roc])/e[o-t.roc]);return[W(s,n,"Chaikin Vol",q[0])]}},{id:"connorsRsi",title:"Connors RSI",pane:!0,levels:[90,10],params:[{key:"rsiLen",name:"RSI Length",type:"int",value:3,min:1,max:5e3},{key:"streakLen",name:"UpDown Length",type:"int",value:2,min:1,max:5e3},{key:"rocLen",name:"ROC Length",type:"int",value:100,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(e.length).fill(0);for(let c=1;c<e.length;c++)e[c]>e[c-1]?n[c]=n[c-1]>0?n[c-1]+1:1:e[c]<e[c-1]?n[c]=n[c-1]<0?n[c-1]-1:-1:n[c]=0;const i=Or(e,t.rsiLen),o=Or(n,t.streakLen),l=av(Ir(e,1),t.rocLen),a=i.map((c,u)=>c===null||o[u]===null||l[u]===null?null:(c+o[u]+l[u])/3);return[W(s,a,"CRSI",q[0])]}},{id:"eom",title:"Ease Of Movement",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"divisor",name:"Divisor",type:"float",value:1e4,min:1,max:1e9,step:1e3}],build:(s,t)=>{const e=Ft(s,"hl2"),n=s.map((i,o)=>{if(o===0)return null;const l=i.volume??0;return l?(e[o]-e[o-1])*(i.high-i.low)/l*t.divisor:0});return[W(s,je(n,t.length),"EOM "+t.length,q[0])]}},{id:"fisher",title:"Fisher Transform",pane:!0,levels:[1.5,-1.5],params:[{key:"length",name:"Length",type:"int",value:9,min:1,max:5e3}],build:(s,t)=>{const e=Ft(s,"hl2"),n=$s(e,t.length),i=Ys(e,t.length),o=new Array(s.length).fill(null),l=new Array(s.length).fill(null);let a=0,c=0;for(let u=0;u<s.length;u++){if(n[u]===null||i[u]===null)continue;const d=Math.max(n[u]-i[u],.001);a=.66*((e[u]-i[u])/d-.5)+.67*a,a=Math.max(-.999,Math.min(.999,a)),l[u]=c,c=.5*Math.log((1+a)/(1-a))+.5*c,o[u]=c}return[W(s,o,"Fisher",q[0]),W(s,l,"Trigger",q[1])]}},{id:"hv",title:"Historical Volatility",pane:!0,params:[{key:"length",name:"Length",type:"int",value:10,min:2,max:5e3}],build:(s,t)=>{const e=Math.sqrt(Br(s)),n=gi(bl(s).map(i=>i===null?null:i),t.length);return[W(s,n.map(i=>i===null?null:i*e*100),"HV "+t.length,q[0])]}},{id:"klinger",title:"Klinger Oscillator",pane:!0,levels:[0],format:"volume",params:[{key:"short",name:"Short Length",type:"int",value:34,min:1,max:5e3},{key:"long",name:"Long Length",type:"int",value:55,min:1,max:5e3},{key:"signal",name:"Signal Length",type:"int",value:13,min:1,max:5e3}],build:(s,t)=>{const e=Ft(s,"hlc3"),n=s.map((a,c)=>c===0?null:(e[c]>e[c-1]?1:-1)*(a.volume??0)),i=ee(n,t.short),o=ee(n,t.long),l=i.map((a,c)=>a===null||o[c]===null?null:a-o[c]);return[W(s,l,"KVO",q[0]),W(s,ee(l,t.signal),"Signal",q[1])]}},{id:"linregSlope",title:"Linear Regression Slope",pane:!0,levels:[0],params:[{key:"length",name:"Length",type:"int",value:100,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,lv(Ft(s,t.source),t.length),"Slope "+t.length,q[0])]},{id:"massIndex",title:"Mass Index",pane:!0,levels:[27,26.5],params:[{key:"length",name:"Length",type:"int",value:25,min:1,max:5e3},{key:"emaLen",name:"EMA Length",type:"int",value:9,min:1,max:5e3}],build:(s,t)=>{const e=s.map(l=>l.high-l.low),n=ee(e,t.emaLen),i=ee(n,t.emaLen),o=n.map((l,a)=>l===null||!i[a]?null:l/i[a]);return[W(s,Qs(o,t.length),"Mass "+t.length,q[0])]}},{id:"netVolume",title:"Net Volume",pane:!0,levels:[0],format:"volume",params:[],build:s=>{const t=s.map((n,i)=>{if(i===0)return null;const o=n.volume??0;return n.close>s[i-1].close?o:n.close<s[i-1].close?-o:0}),e=t.map(n=>n===null?null:n>=0?Ge:Ss);return[W(s,t,"Net Volume",Ge,{kind:"histogram",barColors:e})]}},{id:"priceOsc",title:"Price Oscillator",pane:!0,levels:[0],params:[{key:"short",name:"Short Length",type:"int",value:10,min:1,max:5e3},{key:"long",name:"Long Length",type:"int",value:21,min:1,max:5e3},{key:"method",name:"Method",type:"ma",value:"ema"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=Le(e,t.short,t.method,s),i=Le(e,t.long,t.method,s),o=n.map((l,a)=>l===null||!i[a]?null:100*(l-i[a])/i[a]);return[W(s,o,"PPO",q[0])]}},{id:"pvt",title:"Price Volume Trend",pane:!0,format:"volume",params:[],build:s=>{const t=s.map((e,n)=>n===0||!s[n-1].close?null:(e.close-s[n-1].close)/s[n-1].close*(e.volume??0));return[W(s,yl(t),"PVT",q[0])]}},{id:"rci",title:"Rank Correlation Index",pane:!0,levels:[80,-80],params:[{key:"length",name:"Length",type:"int",value:9,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null);for(let i=t.length-1;i<e.length;i++){const o=[];for(let d=0;d<t.length;d++)o.push({time:d+1,value:e[i-d]});const l=[...o].sort((d,f)=>f.value-d.value),a=new Map;l.forEach((d,f)=>a.set(d.time,f+1));let c=0;for(const d of o){const f=d.time-a.get(d.time);c+=f*f}const u=t.length;n[i]=(1-6*c/(u*(u*u-1)))*100}return[W(s,n,"RCI "+t.length,q[0])]}},{id:"rvix",title:"Relative Volatility Index",pane:!0,levels:[80,20],params:[{key:"length",name:"Length",type:"int",value:14,min:1,max:5e3},{key:"devLen",name:"StdDev Length",type:"int",value:10,min:2,max:5e3},{key:"method",name:"Smoothing",type:"ma",value:"ema"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=gi(e,t.devLen),i=new Array(e.length).fill(null),o=new Array(e.length).fill(null);for(let u=1;u<e.length;u++)n[u]!==null&&(i[u]=e[u]>e[u-1]?n[u]:0,o[u]=e[u]<e[u-1]?n[u]:0);const l=Le(i,t.length,t.method,s),a=Le(o,t.length,t.method,s),c=l.map((u,d)=>{if(u===null||a[d]===null)return null;const f=u+a[d];return f===0?50:100*u/f});return[W(s,c,"RVI "+t.length,q[0])]}},{id:"smiErgodic",title:"SMI Ergodic Indicator/Oscillator",pane:!0,levels:[0],params:[{key:"long",name:"Long Length",type:"int",value:20,min:1,max:5e3},{key:"short",name:"Short Length",type:"int",value:5,min:1,max:5e3},{key:"signal",name:"Signal Length",type:"int",value:5,min:1,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=e.map((f,g)=>g===0?null:f-e[g-1]),i=n.map(f=>f===null?null:Math.abs(f)),o=ee(ee(n,t.long),t.short),l=ee(ee(i,t.long),t.short),a=o.map((f,g)=>f===null||!l[g]?null:100*f/l[g]),c=ee(a,t.signal),u=a.map((f,g)=>f===null||c[g]===null?null:f-c[g]),d=u.map(f=>f===null?null:f>=0?Ge:Ss);
6return[W(s,u,"Oscillator",Ge,{kind:"histogram",barColors:d}),W(s,a,"Indicator",q[0]),W(s,c,"Signal",q[1])]}},{id:"stdError",title:"Standard Error",pane:!0,params:[{key:"length",name:"Length",type:"int",value:20,min:3,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>[W(s,Xh(Ft(s,t.source),t.length),"StdErr "+t.length,q[0])]},{id:"trendStrength",title:"Trend Strength Index",pane:!0,levels:[.5,-.5],params:[{key:"length",name:"Length",type:"int",value:20,min:3,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t)=>{const e=Ft(s,t.source),n=new Array(s.length).fill(null),i=t.length,o=i*(i-1)/2,l=(i-1)*i*(2*i-1)/6;for(let a=i-1;a<e.length;a++){let c=0,u=0,d=0;for(let g=0;g<i;g++){const v=e[a-i+1+g];c+=v,u+=v*v,d+=g*v}const f=Math.sqrt((i*l-o*o)*(i*u-c*c));n[a]=f===0?0:(i*d-o*c)/f}return[W(s,n,"TSI "+t.length,q[0])]}},{id:"volCC",title:"Volatility Close-to-Close",pane:!0,params:[{key:"length",name:"Length",type:"int",value:10,min:2,max:5e3}],build:(s,t)=>{const e=bl(s),n=Math.sqrt(Br(s)),i=new Array(s.length).fill(null),o=je(e,t.length);for(let l=0;l<s.length;l++){if(o[l]===null)continue;let a=0;for(let c=0;c<t.length;c++){const u=e[l-c]-o[l];a+=u*u}i[l]=Math.sqrt(a/(t.length-1))*n*100}return[W(s,i,"Vol C-C",q[0])]}},{id:"volZeroTrend",title:"Volatility Zero Trend Close-to-Close",pane:!0,params:[{key:"length",name:"Length",type:"int",value:10,min:2,max:5e3}],build:(s,t)=>{const e=bl(s),n=Math.sqrt(Br(s)),i=e.map(a=>a===null?null:a*a),l=Qs(i,t.length).map(a=>a===null?null:Math.sqrt(a/(t.length-1))*n*100);return[W(s,l,"Vol ZT",q[0])]}},{id:"volOHLC",title:"Volatility O-H-L-C",pane:!0,params:[{key:"length",name:"Length",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=s.map(l=>{if(!(l.high>0)||!(l.low>0)||!(l.open>0)||!(l.close>0))return null;const a=Math.log(l.high/l.low),c=Math.log(l.close/l.open);return .5*a*a-(2*Math.LN2-1)*c*c}),n=je(e,t.length),i=Math.sqrt(Br(s)),o=n.map(l=>l===null?null:Math.sqrt(Math.max(0,l))*i*100);return[W(s,o,"Vol OHLC",q[0])]}},{id:"volume",title:"Volume",pane:!0,format:"volume",params:[{key:"maLen",name:"MA Length",type:"int",value:20,min:0,max:5e3},{key:"maType",name:"MA Method",type:"ma",value:"sma"}],build:(s,t)=>{const e=s.map(o=>o.volume??0),n=s.map(o=>o.close>=o.open?"rgba(38,161,123,0.5)":"rgba(227,91,91,0.5)"),i=[W(s,e,"Volume",Ge,{kind:"histogram",barColors:n})];return t.maLen>0&&i.push(W(s,Le(e,t.maLen,t.maType,s),"MA "+t.maLen,q[1])),i}},{id:"volumeOsc",title:"Volume Oscillator",pane:!0,levels:[0],params:[{key:"short",name:"Short Length",type:"int",value:5,min:1,max:5e3},{key:"long",name:"Long Length",type:"int",value:10,min:1,max:5e3}],build:(s,t)=>{const e=s.map(l=>l.volume??0),n=ee(e,t.short),i=ee(e,t.long),o=n.map((l,a)=>l===null||!i[a]?null:100*(l-i[a])/i[a]);return[W(s,o,"Volume Osc",q[0])]}},{id:"ratio",title:"Ratio",pane:!0,params:[{key:"symbol",name:"Symbol",type:"symbol",value:"BTC"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t,e)=>{var l;const n=Wr(s,(l=e==null?void 0:e.symbols)==null?void 0:l.get(t.symbol));if(!n)return[];const o=Ft(s,t.source).map((a,c)=>n[c]===null||!n[c]?null:a/n[c]);return[W(s,o,Jh(t.symbol,"/"),q[0])]}},{id:"spread",title:"Spread",pane:!0,levels:[0],params:[{key:"symbol",name:"Symbol",type:"symbol",value:"BTC"},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t,e)=>{var l;const n=Wr(s,(l=e==null?void 0:e.symbols)==null?void 0:l.get(t.symbol));if(!n)return[];const o=Ft(s,t.source).map((a,c)=>n[c]===null?null:a-n[c]);return[W(s,o,Jh(t.symbol,"−"),q[0])]}},{id:"correlation",title:"Correlation Coefficient",pane:!0,levels:[.5,0,-.5],params:[{key:"symbol",name:"Symbol",type:"symbol",value:"BTC"},{key:"length",name:"Length",type:"int",value:20,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t,e)=>{var o;const n=Wr(s,(o=e==null?void 0:e.symbols)==null?void 0:o.get(t.symbol));if(!n)return[];const i=Zh(Ft(s,t.source),n,t.length);return[W(s,i,"Corr "+t.symbol,q[0])]}},{id:"correlationLog",title:"Correlation - Log",pane:!0,levels:[.5,0,-.5],params:[{key:"symbol",name:"Symbol",type:"symbol",value:"BTC"},{key:"length",name:"Length",type:"int",value:20,min:2,max:5e3},{key:"source",name:"Source",type:"source",value:"close"}],build:(s,t,e)=>{var l;
6const n=Wr(s,(l=e==null?void 0:e.symbols)==null?void 0:l.get(t.symbol));if(!n)return[];const i=Ft(s,t.source).map(a=>a>0?Math.log(a):null),o=n.map(a=>a>0?Math.log(a):null);return[W(s,Zh(i,o,t.length),"Corr log "+t.symbol,q[0])]}},{id:"fractal",title:"Williams Fractal",params:[{key:"periods",name:"Periods",type:"int",value:2,min:1,max:100}],build:(s,t)=>{const e=[],n=[],i=t.periods;for(let o=i;o<s.length-i;o++){let l=!0,a=!0;for(let c=1;c<=i&&((s[o].high<=s[o-c].high||s[o].high<=s[o+c].high)&&(l=!1),(s[o].low>=s[o-c].low||s[o].low>=s[o+c].low)&&(a=!1),!(!l&&!a));c++);l&&e.push({time:s[o].time,price:s[o].high}),a&&n.push({time:s[o].time,price:s[o].low})}return[{title:"Up",color:Ss,kind:"markers",shape:"arrowUp",at:"atPriceTop",data:e.map(o=>({time:o.time,value:o.price}))},{title:"Down",color:Ge,kind:"markers",shape:"arrowDown",at:"atPriceBottom",data:n.map(o=>({time:o.time,value:o.price}))}]}}];function Jh(s,t){return t+" "+s}function hv(s){const t=new Set;for(const e of s??[]){const n=ls(e==null?void 0:e.id);n&&(n.params??[]).forEach((i,o)=>{if(i.type!=="symbol")return;const l=(e.params??[])[o]??i.value,a=String(l??"").trim().toUpperCase();a&&t.add(a)})}return[...t]}const ls=s=>lo.find(t=>t.id===s)??null;function uf(s,t){const e={},n=s.params??[];for(let i=0;i<n.length;i++){const o=n[i],l=(t.params??[])[i],a=l===void 0||l===""?o.value:l;switch(o.type){case"float":{const c=typeof a=="number"?a:parseFloat(String(a).replace(",","."));if(!Number.isFinite(c)||o.min!==void 0&&c<o.min||o.max!==void 0&&c>o.max)return null;e[o.key]=c;break}case"bool":e[o.key]=a===!0||a==="true"||a===1||a==="1";break;case"symbol":{const c=String(a??"").trim().toUpperCase();if(!c)return null;e[o.key]=c;break}case"source":case"ma":case"select":e[o.key]=String(a);break;default:{const c=parseInt(a,10);if(!Number.isFinite(c)||o.min!==void 0&&c<o.min||o.max!==void 0&&c>o.max)return null;e[o.key]=c;break}}}return e}function uv(s,t,e=null){const n=ls(s.id);if(!n||!t.length)return[];const i=uf(n,s);if(i===null)return[];try{const o=n.build(t,i,e),l=Zl(s);return o.map((a,c)=>{var u;return{...a,color:J0(((u=s.colors)==null?void 0:u[c])||a.color,l),width:s.width||qa}})}catch{return[]}}function Jl(s){const t=ls(s.id);return t?(t.params??[]).map((e,n)=>({define:e,value:(s.params??[])[n]??e.value})).filter(({define:e})=>e.type==="int"||e.type==="float").map(({value:e})=>e):[]}function dv(s){const t=ls(s.id);if(!t)return s.id;const e=Jl(s);return e.length?t.title+" "+e.join("/"):t.title}const wl=new Map,tu=4e3;function fv(s){const t=[];for(let e=0;e<s;e++){const n=100+Math.sin(e/3)*8+Math.sin(e/11)*3+e*.05;t.push({time:e*60,open:n,high:n+1.5,low:n-1.5,close:n+Math.sin(e/5),volume:1e3+e%7*25})}return t}function mv(s){return(s??[]).some(t=>((t==null?void 0:t.data)??[]).some(e=>e&&e.value!==null&&e.value!==void 0&&Number.isFinite(e.value)))}function pv(s,t){if(!s||typeof s.build!="function")return 0;const e=uf(s,t);if(e===null)return 0;const n=s.id+"|"+JSON.stringify(e);if(wl.has(n))return wl.get(n);const i=l=>{try{return mv(s.build(fv(l),e,null))}catch{return!1}};let o=0;if(i(tu)){let l=1,a=tu;for(;l<a;){const c=Math.floor((l+a)/2);i(c)?a=c:l=c+1}o=l}return wl.set(n,o),o}function df(s){const t=ls(s);return{key:s+"_"+Date.now().toString(36)+Math.random().toString(36).slice(2,6),id:s,params:((t==null?void 0:t.params)??[]).map(e=>e.value),colors:[],width:qa,alpha:cf}}const gv=new Set(["ma","ema","ema4","bb","vwap","ichimoku","supertrend","donchian","psar","volume","rsi","macd","stoch","atr","adx","dmi","cci","mfi","obv","williamsR"]),eu=[{key:"all",label:"All"},{key:"favorites",label:"Favorites"},{key:"overlay",label:"On chart"},{key:"pane",label:"Panes"},{key:"popular",label:"Popular"}];function vv(s,t,e){const n=s.filter(u=>{var d;return(d=ls(u.id))==null?void 0:d.pane}),i=n.findIndex(u=>u.key===t),o=i+e;if(i<0||o<0||o>=n.length)return s;const l=s.indexOf(n[i]),a=s.indexOf(n[o]),c=[...s];return c[l]=s[a],c[a]=s[l],c}function su(s,t,e){switch(s){case"favorites":return e.has(t.id);case"overlay":return!t.pane;case"pane":return!!t.pane;case"popular":return gv.has(t.id);default:return!0}}const ff="futures_chart_indicator_favorites";function xv(){try{const s=localStorage.getItem(ff);return new Set(s?JSON.parse(s):[])}catch{return new Set}}function yv(s){try{localStorage.setItem(ff,JSON.stringify([...s]))}catch{}}function bv(){try{const s=localStorage.getItem(af);if(s===null)return[df(Z0)];const t=JSON.parse(s);return Array.isArray(t)?t.filter(e=>ls(e==null?void 0:e.id)):[]}catch{return[]}}function wv(s){try{localStorage.setItem(af,JSON.stringify(s))}catch{}}function _v({list:s,linesOf:t,onChange:e,onEdit:n,onClose:i}){Ps(i);const[o,l]=m.useState("catalog"),[a,c]=m.useState(""),[u,d]=m.useState("all"),[f,g]=m.useState(()=>xv()),v=j=>{const E=new Set(f);E.has(j)?E.delete(j):E.add(j),g(E),yv(E)},b=m.useMemo(()=>{const j=new Map;for(const E of s)j.set(E.id,(j.get(E.id)??0)+1);return j},[s]),w=m.useMemo(()=>{const j=a.trim().toLowerCase();return j?lo.filter(E=>h(E.title).toLowerCase().includes(j)||E.title.toLowerCase().includes(j)):lo.filter(E=>su(u,E,f))},[a,u,f]),k=m.useMemo(()=>{const j={};for(const E of eu)j[E.key]=lo.filter(z=>su(E.key,z,f)).length;return j},[f]),y=j=>
6{e([...s,df(j)]),l("added")},S=j=>e(s.filter(E=>E.key!==j));return r.jsx("div",{className:"fut-modal",onClick:i,children:r.jsxs("div",{className:"fut-modal__box",onClick:j=>j.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Indicators")}),r.jsx("button",{type:"button",onClick:i,children:"✕"})]}),r.jsxs("div",{className:"fut-ind__tabs",children:[r.jsx("button",{type:"button",className:o==="catalog"?"is-active":"",onClick:()=>l("catalog"),children:h("Indicators")}),r.jsxs("button",{type:"button",className:o==="added"?"is-active":"",onClick:()=>l("added"),children:[h("Added"),s.length>0&&r.jsx("i",{children:s.length})]})]}),o==="catalog"&&r.jsxs(r.Fragment,{children:[r.jsx("label",{className:"fut-form__field",children:r.jsx("input",{type:"text",value:a,autoFocus:!0,placeholder:h("Search"),onChange:j=>c(j.target.value)})}),!a.trim()&&r.jsx("div",{className:"fut-ind__cats",children:eu.map(j=>r.jsxs("button",{type:"button",className:j.key===u?"is-active":"",onClick:()=>d(j.key),children:[h(j.label),k[j.key]>0&&j.key!=="all"&&r.jsx("i",{children:k[j.key]})]},j.key))}),r.jsxs("div",{className:"fut-ind__list fut-scroll",children:[w.length===0&&r.jsx("div",{className:"fut-panel__empty",children:a.trim()?h("Nothing found"):h("No favorite indicators yet")}),w.map(j=>r.jsxs("div",{className:"fut-ind__item",children:[r.jsx("button",{type:"button",className:"fut-ind__star"+(f.has(j.id)?" is-on":""),title:h("Favorites"),"aria-label":h("Favorites"),onClick:()=>v(j.id),children:"★"}),r.jsxs("button",{type:"button",className:"fut-ind__pick",onClick:()=>y(j.id),children:[r.jsxs("span",{children:[h(j.title),j.pane&&r.jsx("b",{children:h("Pane")})]}),b.get(j.id)>0&&r.jsx("em",{children:b.get(j.id)}),r.jsx("i",{children:"+"})]})]},j.id))]})]}),o==="added"&&r.jsxs("div",{className:"fut-ind__list fut-scroll",children:[s.length===0&&r.jsx("div",{className:"fut-panel__empty",children:h("No indicators added yet")}),s.map(j=>
6{const E=ls(j.id),z=t(j.key);return r.jsxs("div",{className:"fut-ind__added",children:[r.jsx("span",{className:"fut-ind__dots",children:z.map((F,A)=>r.jsx("i",{style:{background:F.color}},A))}),r.jsxs("span",{className:"fut-ind__name",children:[h((E==null?void 0:E.title)??j.id),Jl(j).length>0&&r.jsx("em",{children:Jl(j).join(" / ")})]}),r.jsx("button",{type:"button",className:"fut-ind__icon",title:h("Settings"),"aria-label":h("Settings"),onClick:()=>n(j.key),children:r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"1.7"}),r.jsx("path",{d:"M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 9 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4.6 9a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("button",{type:"button",className:"fut-ind__icon fut-ind__icon--danger",title:h("Delete"),"aria-label":h("Delete"),onClick:()=>S(j.key),children:r.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})})]},j.key)})]}),s.length>0&&r.jsx("div",{className:"fut-ind__summary",children:s.map(dv).join("   ·   ")})]})})}function kv({instance:s,lines:t=[],onChange:e,onDelete:n,onClose:i}){const o=ls(s.id);m.useEffect(()=>{const f=g=>{g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),i())};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[i]);const l=f=>e({...s,...f}),a=(f,g)=>{l({params:((o==null?void 0:o.params)??[]).map((v,b)=>b===f?g:(s.params??[])[b]??v.value)})},c=(f,g)=>{const v=(f.min??0)<0;if(f.type==="float"){let w=g.replace(",",".").replace(v?/[^0-9.-]/g:/[^0-9.]/g,"");const k=w.indexOf(".");return k>=0&&(w=w.slice(0,k+1)+w.slice(k+1).replace(/\./g,"")),w.charAt(0)+w.slice(1).replace(/-/g,"")}const b=g.replace(v?/[^0-9-]/g:/\D/g,"");return b.charAt(0)+b.slice(1).replace(/-/g,"")},u=(f,g,v)=>{if(f.type==="bool"){const b=g===!0||g==="true"||g===1||g==="1";return r.jsxs("div",{className:"fut-draw-edit__choice",children:[r.jsx("button",{type:"button",className:b?"is-active":"",onClick:()=>a(v,!0),children:h("On")}),r.jsx("button",{type:"button",className:b?"":"is-active",onClick:()=>a(v,!1),children:h("Off")})]})}if(f.type==="symbol")return r.jsx("label",{className:"fut-ind__param",children:r.jsx("input",{type:"text",value:g,spellCheck:!1,autoCapitalize:"characters",onChange:b=>a(v,b.target.value.toUpperCase().replace(/[^A-Z0-9]/g,""))})});if(f.type==="source"||f.type==="ma"||f.type==="select"){const b=f.type==="source"?tv:f.type==="ma"?ev:f.options??[];return r.jsx("label",{className:"fut-ind__select",children:r.jsx("select",{value:g,onChange:w=>a(v,w.target.value),children:b.map(w=>r.jsx("option",{value:w.key,children:h(w.label)},w.key))})})}return r.jsx("label",{className:"fut-ind__param",children:r.jsx("input",{type:"text",inputMode:f.type==="float"?"decimal":"numeric",value:g,onChange:b=>a(v,c(f,b.target.value))})})},d=(f,g)=>{const v=[...s.colors??[]];v[f]=g,l({colors:v})};return r.jsx("div",{className:"fut-modal",onClick:i,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:f=>f.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h((o==null?void 0:o.title)??s.id)}),r.jsx("button",{type:"button",onClick:i,children:"✕"})]}),((o==null?void 0:o.params)??[]).map((f,g)=>{const v=(s.params??[])[g]??f.value;return r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h(f.name)}),u(f,v,g)]},f.key??g)}),r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Thickness")}),r.jsx("div",{className:"fut-draw-edit__choice",children:[1,2,3].map(f=>r.jsxs("button",{type:"button",className:(s.width||qa)===f?"is-active":"",onClick:()=>l({width:f}),children:[f,"px"]},f))})]}),r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Line transparency")}),r.jsxs("div",{className:"fut-draw-edit__alpha",children:[r.jsx("input",{type:"range",min:0,max:100,step:5,value:Math.round((1-Zl(s))*100),onChange:f=>l({alpha:1-Number(f.target.value)/100})}),r.jsxs("i",{children:[Math.round((1-Zl(s))*100),"%"]})]})]}),t.map((f,g)=>r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:f.title}),r.jsx("div",{className:"fut-draw-edit__colors",children:q.map(v=>r.jsx("button",{type:"button",className:"fut-draw-edit__color"+(f.color===v?" is-active":""),style:{background:v},"aria-label":v,onClick:()=>d(g,v)},v))})]},"line"+g)),r.jsxs("div",{className:"fut-draw-edit__foot",children:[r.jsx(Rt.Tooltip,{title:h("Delete"),position:"top",arrow:!0,tag:"span",distance:10,style:{display:"flex"},children:r.jsx("button",{type:"button",className:"fut-draw-edit__delete",onClick:n,"aria-label":h("Delete"),children:r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})})}),r.jsx("button",{type:"button",className:"fut-draw-edit__confirm",onClick:i,children:h("Confirm")})]})]})})}function Mv({drawing:s,offsetSeconds:t=0,onChange:e,onDelete:n,onClose:i}){var yt;const[o,l]=m.useState(s.text??""),[a,c]=m.useState(()=>(s.points??[]).map(P=>String(P.price??"")));m.useEffect(()=>{c((s.points??[]).map(P=>String(P.price??"")))},[s.id]),m.useEffect(()=>{l(s.text??"")},[s.id]),m.useEffect(()=>{const P=G=>{G.key==="Escape"&&(G.preventDefault(),G.stopPropagation(),i())};return window.addEventListener("keydown",P,!0),()=>window.removeEventListener("keydown",P,!0)},[i]);const u=s.tool==="text",d=s.points??[],f=s.tool!=="brush"&&d.length>0,g=s.tool!=="vline",v=s.tool!=="hline",b=Jd(s.tool),w=[{id:"style",title:"Style"},...b?[{id:"levels",title:"Fib levels"}]:[],...f?[{id:"coords",title:"Coordinates"}]:[]],[k,y]=m.useState("style");m.useEffect(()=>{y("style")},[s.id]);const S=P=>w.length<2||k===P,j=P=>{const G=Xl(s),nt=G.includes(P)?G.filter(bt=>bt!==P):[...G,P].sort((bt,$)=>bt-$);A({levels:nt})},E=P=>String(P).padStart(2,"0"),z=P=>{if(!Number.isFinite(P))return"";const G=new Date((P+t)*1e3);return G.getUTCFullYear()+"-"+E(G.getUTCMonth()+1)+"-"+E(G.getUTCDate())+"T"+E(G.getUTCHours())+":"+E(G.getUTCMinutes())},F=P=>{const G=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(:\d{2})?$/.exec(P);if(!G)return null;const nt=Date.parse(G[1]+(G[2]??":00")+"Z");return Number.isFinite(nt)?Math.round(nt/1e3)-t:null},A=P=>e({...s,...P}),J=(P,G)=>A({points:d.map((nt,bt)=>bt===P?{...nt,...G}:nt)}),O=(P,G,nt)=>r.jsx(Rt.Tooltip,{title:h(Ph[P]??P),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-draw-edit__color"+(G?" is-active":""),style:{background:P},"aria-label":h(Ph[P]??P),onClick:nt})},P);return r.jsx("div",{className:"fut-modal",onClick:i,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:P=>P.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h(((yt=oo(s.tool))==null?void 0:yt.title)??"Drawing")}),r.jsx("button",{type:"button",onClick:i,children:"✕"})]}),w.length>1&&r.jsx("div",{className:"fut-draw-edit__tabs",role:"tablist",children:w.map(P=>r.jsx("button",{type:"button",role:"tab","aria-selected":k===P.id,className:k===P.id?"is-active":"",onClick:()=>y(P.id),children:h(P.title)},P.id))}),b&&S("levels")&&r.jsxs("div",{className:"fut-draw-edit__levels",children:[r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:s.tool==="fibTime"?h("Bars from the start"):h("Fib levels")}),r.jsxs("div",{className:"fut-draw-edit__choice",children:[r.jsx("button",{type:"button",onClick:()=>A({levels:[...Oh[s.tool]??[]]}),children:h("Select all")}),r.jsx("button",{type:"button",onClick:()=>A({levels:[...Ia[s.tool]??[]]}),children:h("Reset")})]})]}),r.jsx("div",{className:"fut-draw-edit__level-list",children:(Oh[s.tool]??[]).map(P=>{const G=Xl(s).includes(P);return r.jsx("button",{type:"button",className:G?"is-active":"","aria-pressed":G,onClick:()=>j(P),children:P},P)})})]}),u&&S("style")&&r.jsxs("label",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Text")}),r.jsx("input",{type:"text",value:o,autoFocus:!0,onChange:P=>{l(P.target.value),A({text:P.target.value})},placeholder:h("Text")})]}),f&&S("coords")&&r.jsxs("div",{className:"fut-draw-edit__points",children:[r.jsx("span",{className:"fut-form__label",children:h("Points")}),d.map((P,G)=>r.jsxs("div",{className:"fut-draw-edit__point",children:[r.jsx("i",{children:G+1}),g&&r.jsx("input",{type:"text",inputMode:"decimal",value:a[G]??"",placeholder:h("Price"),"aria-label":h("Price"),onChange:nt=>{const bt=nt.target.value.replace(",",".");c(ht=>ht.map((tt,H)=>H===G?bt:tt));const $=parseFloat(bt);Number.isFinite($)&&$>0&&J(G,{price:$})}}),v&&r.jsx("input",{type:"datetime-local",value:z(P.time),"aria-label":h("Time"),onChange:nt=>{const bt=F(nt.target.value);bt!==null&&J(G,{time:bt})}})]},G))]}),b&&S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Colour levels")}),r.jsxs("div",{className:"fut-draw-edit__choice",children:[r.jsx("button",{type:"button",className:s.fibColors!==!1?"is-active":"",onClick:()=>A({fibColors:!0}),children:h("On")}),r.jsx("button",{type:"button",className:s.fibColors===!1?"is-active":"",onClick:()=>A({fibColors:!1}),children:h("Off")})]})]}),S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Color")}),r.jsx("div",{className:"fut-draw-edit__colors",children:cr.map(P=>O(P,s.color===P,()=>A({color:P})))})]}),Dh(s.tool)&&S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Backgroun
6d")}),r.jsxs("div",{className:"fut-draw-edit__colors",children:[r.jsx(Rt.Tooltip,{title:h("No background"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-draw-edit__color fut-draw-edit__color--none"+(s.fill===Zn?" is-active":""),"aria-label":h("No background"),onClick:()=>A({fill:Zn})})}),cr.map(P=>O(P,(s.fill??s.color)===P,()=>A({fill:P})))]})]}),Dh(s.tool)&&s.fill!==Zn&&S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Background opacity")}),r.jsxs("div",{className:"fut-draw-edit__alpha",children:[r.jsx("input",{type:"range",min:0,max:100,step:5,value:Math.round((1-Zs(s))*100),onChange:P=>A({fillAlpha:1-Number(P.target.value)/100})}),r.jsxs("i",{children:[Math.round((1-Zs(s))*100),"%"]})]})]}),S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Line transparency")}),r.jsxs("div",{className:"fut-draw-edit__alpha",children:[r.jsx("input",{type:"range",min:0,max:100,step:5,value:Math.round((1-Gl(s))*100),onChange:P=>A({lineAlpha:1-Number(P.target.value)/100})}),r.jsxs("i",{children:[Math.round((1-Gl(s))*100),"%"]})]})]}),Zd(s.tool)&&S("style")&&r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:s.tool==="text"?h("Font size"):h("Arrow size")}),r.jsx("div",{className:"fut-draw-edit__choice",children:(R0[s.tool]??[]).map(P=>r.jsx("button",{type:"button",className:Ni(s)===P?"is-active":"",onClick:()=>A({size:P}),children:P},P))})]}),!u&&S("style")&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Thickness")}),r.jsx("div",{className:"fut-draw-edit__choice",children:[1,2,3].map(P=>r.jsxs("button",{type:"button",className:s.width===P?"is-active":"",onClick:()=>A({width:P}),children:[P,"px"]},P))})]}),r.jsxs("div",{className:"fut-draw-edit__row",children:[r.jsx("span",{className:"fut-form__label",children:h("Line style")}),r.jsxs("div",{className:"fut-draw-edit__choice",children:[r.jsx("button",{type:"button",className:s.dash?"":"is-active",onClick:()=>A({dash:!1}),children:h("Solid")}),r.jsx("button",{type:"button",className:s.dash?"is-active":"",onClick:()=>A({dash:!0}),children:h("Dashed")})]})]})]}),r.jsxs("div",{className:"fut-draw-edit__foot",children:[r.jsx(Rt.Tooltip,{title:h("Delete"),position:"top",arrow:!0,tag:"span",distance:10,style:{display:"flex"},children:r.jsx("button",{type:"button",className:"fut-draw-edit__delete",onClick:n,"aria-label":h("Delete"),children:r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})})}),r.jsx("button",{type:"button",className:"fut-draw-edit__confirm",onClick:i,children:h("Confirm")})]})]})})}function nu({kind:s,coin:t,price:e,title:n,label:i,note:o,onCancel:l,onConfirm:a}){const[c,u]=m.useState(()=>String(e??"")),[d,f]=m.useState(!1),g=s==="tp",v=n??(g?h("Move take profit"):h("Move stop loss")),b=i??(g?h("Take profit"):h("Stop loss")),w=parseFloat(String(c).replace(",",".")),k=Number.isFinite(w)&&w>0;return m.useEffect(()=>{const y=S=>{if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),l();return}S.key==="Enter"&&k&&(S.preventDefault(),S.stopPropagation(),a(w,d))};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[l,a,w,d,k]),r.jsx("div",{className:"fut-modal",onClick:l,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:y=>y.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:v}),r.jsx("button",{type:"button",onClick:l,children:"✕"})]}),r.jsxs("label",{className:"fut-form__field",children:[r.jsxs("span",{className:"fut-form__label",children:[b,t&&r.jsx("em",{children:zt(t)})]}),r.jsx("input",{type:"text",inputMode:"decimal",value:c,autoFocus:!0,onChange:y=>u(y.target.value.replace(",","."))})]}),o&&r.jsx("div",{className:"fut-guard__note",children:o}),r.jsxs("label",{className:"fut-guard__skip",children:[r.jsx("input",{type:"checkbox",checked:d,onChange:y=>f(y.target.checked)}),r.jsx("span",{children:h("Do not ask again")})]}),r.jsxs("div",{className:"fut-guard__actions",children:[r.jsx("button",{type:"button",className:"fut-guard__cancel",onClick:l,children:h("Cancel")}),r.jsx("button",{type:"button",className:"fut-guard__ok",disabled:!k,onClick:()=>a(w,d),children:h("Confirm")})]})]})})}const jv=100;function To(s){const t=m.useMemo(()=>Array.from(new Set(s??[])).sort().join("|"),[s]),[e,n]=m.useState({}),i=m.useRef({}),o=m.useRef(null);return m.useEffect(()=>{const l=t?t.split("|"):[];if(!l.length)return;const a=d=>(i.current[d]||(i.current[d]={mark:null,mid:null,midAtMark:null}),i.current[d]),c=()=>{o.current===null&&(o.current=setTimeout(()=>{o.current=null;const d={};for(const[f,g]of Object.entries(i.current)){const v=Sv(g);v&&(d[f]=v)}n(d)},jv))},u=[];for(const d of l)u.push(Ai.subscribe(`ctx:${d}`,{op:"sub",channel:"ctx",coin:d},f=>{const g=parseFloat((f==null?void 0:f.markPx)??0)||0;if(!g)return;const v=a(d);v.mark=g,v.midAtMark=v.mid,c()}
6)),u.push(Ai.subscribe(`bbo:${d}`,{op:"sub",channel:"bbo",coin:d},f=>{var k,y,S,j;const g=parseFloat(((y=(k=f==null?void 0:f.bbo)==null?void 0:k[0])==null?void 0:y.px)??0)||0,v=parseFloat(((j=(S=f==null?void 0:f.bbo)==null?void 0:S[1])==null?void 0:j.px)??0)||0,b=g&&v?(g+v)/2:g||v;if(!b)return;const w=a(d);w.mid=b,w.mark&&w.midAtMark===null&&(w.midAtMark=b),c()}));return()=>{u.forEach(d=>d()),i.current={}}},[t]),m.useEffect(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),e}function Sv(s){if(!(s!=null&&s.mark))return(s==null?void 0:s.mid)??0;if(!s.mid||s.midAtMark===null)return s.mark;const t=s.mark+(s.mid-s.midAtMark);return Math.abs(t-s.mark)>s.mark*.05?s.mid:t}function Nv(s){const t=[];for(const e of(s==null?void 0:s.assetPositions)??[]){const n=e==null?void 0:e.position;n!=null&&n.coin&&parseFloat(n.szi)!==0&&t.push(n.coin)}return t}const mf="futures_tpsl_full",pf=(s,t)=>String(s??0)+"|"+String(t??"");function Va(){try{const s=JSON.parse(localStorage.getItem(mf));return s&&typeof s=="object"?s:{}}catch{return{}}}function gf(s){try{localStorage.setItem(mf,JSON.stringify(s))}catch{}}function Cv(s,t){const e=Va(),n=String(s??0)+"|",i=new Set(t??[]);let o=!1;for(const l of Object.keys(e))l.startsWith(n)&&(i.has(l.slice(n.length))||(delete e[l],o=!0));o&&gf(e)}function Tv(s,t){return Va()[pf(s,t)]===!0}function ta(s,t,e){const n=Va(),i=pf(s,t);e?n[i]=!0:delete n[i],gf(n)}const go=new Set,ea=new Set;function Lv(){const s=new Set(go);for(const t of ea)t(s)}function iu(s,t){s&&(t?go.add(s):go.delete(s),Lv())}function Ev(s){return ea.add(s),s(new Set(go)),()=>ea.delete(s)}const Js="#26a17b",tn="#e35b5b",qr="#e8eaf0",Fv="rgba(232,234,240,0.20)",vf="futures_chart_type",Ua=[{id:"bars",title:"Bars"},{id:"candles",title:"Candles"},{id:"hollow",title:"Hollow candles"},{id:"line",title:"Line"},{id:"line_marks",title:"Line with markers"},{id:"step",title:"Step line"},{id:"area",title:"Area"},{id:"baseline",title:"Baseline"},{id:"columns",title:"Columns"},{id:"high_low",title:"High-low"},{id:"heikin",title:"Heikin Ashi"}],Av="candles";function Vr(s){return(Ua.find(t=>t.id===s)??{title:"Candles"}).title}function Rv(){try{const s=localStorage.getItem(vf);if(s&&Ua.some(t=>t.id===s))return s}catch{}return Av}function Pv(s){try{localStorage.setItem(vf,s)}catch{}}function zv(s){return["bars","candles","hollow","heikin","high_low"].includes(s)}function xf(s,t){const e=(s.open+s.high+s.low+s.close)/4,n=t?(t.open+t.close)/2:(s.open+s.close)/2;return{time:s.time,open:n,high:Math.max(s.high,n,e),low:Math.min(s.low,n,e),close:e}}function Dv(s){const t=[];let e=null;for(const n of s)e=xf(n,e),t.push(e);return t}function yf(s,t,e){const n=e.close>=e.open;switch(s){case"line":case"line_marks":case"step":case"area":case"baseline":return{time:t.time,value:t.close};case"columns":return{time:t.time,value:t.close,color:n?Js:tn};case"high_low":return{time:t.time,open:t.low,high:t.high,low:t.low,close:t.high,color:n?Js:tn};default:return t}}function ru(s,t){const e=s==="heikin"?Dv(t):t,n=[],i=[],o=new Map;for(let l=0;l<t.length;l++){const a=e[l];n.push(yf(s,a,t[l])),i.push(a),o.set(a.time,a)}return{id:s,rows:n,legend:i,byTime:o}}function Ov(s,t){const e=s.legend[s.legend.length-1],n=!!e&&e.time===t.time,i=n?s.legend[s.legend.length-2]??null:e??null,o=s.id==="heikin"?xf(t,i):t,l=yf(s.id,o,t);return n?(s.rows[s.rows.length-1]=l,s.legend[s.legend.length-1]=o):(s.rows.push(l),s.legend.push(o)),s.byTime.set(o.time,o),{row:l,legendBar:o}}function ou(s,t){if(s!=="hollow"||!t)return null;const e=parseFloat(t.open);return{priceLineColor:parseFloat(t.close)>=e?Js:tn}}function lu(s){switch(s){case"bars":return{definition:Gg,options:{upColor:Js,downColor:tn,thinBars:!1}};case"hollow":return{definition:ol,options:{upColor:"rgba(0,0,0,0)",downColor:tn,borderVisible:!0,borderUpColor:Js,borderDownColor:tn,wickUpColor:Js,wickDownColor:tn}};case"high_low":return{definition:ol,options:{upColor:Js,downColor:tn,borderVisible:!1,wickVisible:!1}};case"line":return{definition:Si,options:{color:qr,lineWidth:2}};case"line_marks":return{definition:Si,options:{color:qr,lineWidth:2,pointMarkersVisible:!0,pointMarkersRadius:2}};case"step":return{definition:Si,options:{color:qr,lineWidth:2,lineType:Dl.WithSteps}};case"area":return{definition:$g,options:{lineColor:qr,lineWidth:2,topColor:Fv,bottomColor:"rgba(232,234,240,0)"}};case"baseline":return{definition:Ug,options:{lineWidth:2,topLineColor:Js,topFillColor1:"rgba(38,161,123,0.28)",topFillColor2:"rgba(38,161,123,0.02)",bottomLineColor:tn,bottomFillColor1:"rgba(227,91,91,0.02)",bottomFillColor2:"rgba(227,91,91,0.28)"}};case"columns":return{definition:$l,options:{color:Js}};case"candles":case"heikin":default:return{definition:ol,options:{upColor:Js,downColor:tn,borderVisible:!1,wickUpColor:Js,wickDownColor:tn}}}}function bf(s){return s==="baseline"||s==="columns"}function wf(s){if(!s.length)return null;let t=1/0,e=-1/0;for(const n of s)n.low<t&&(t=n.low),n.high>e&&(e=n.high);return Number.isFinite(t)&&Number.isFinite(e)?{min:t,max:e}:null}function Iv(s,t){return _f(s,wf(t))}function _f(s,t){if(!bf(s)||!t)return null;const{min:e,max:n}=t;return s==="columns"?{base:e}:{baseValue:{type:"price",price:(e+n)/2}}}function au(s){const t={stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",fill:"none"},e={bars:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M5 4v10M5 6h2.5M5 10H2.5",...t}),r.jsx("path",{d:"M12 3v10M12 6h2.5M12 9h-2.5",...t})]}),candles:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M5.5 2v12",...t}),r.jsx("rect",{x:"3.5",y:"5",width:"4",height:"6",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M12.5 3v11",...t}
6),r.jsx("rect",{x:"10.5",y:"6",width:"4",height:"5",fill:"currentColor",stroke:"none"})]}),hollow:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M5.5 2v12",...t}),r.jsx("rect",{x:"3.5",y:"5",width:"4",height:"6",...t}),r.jsx("path",{d:"M12.5 3v11",...t}),r.jsx("rect",{x:"10.5",y:"6",width:"4",height:"5",fill:"currentColor",stroke:"none"})]}),line:r.jsx("path",{d:"M2 12l4-5 3 3 5-7",...t}),line_marks:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M2 12l4-5 3 3 5-7",...t}),r.jsx("circle",{cx:"2",cy:"12",r:"1.4",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"6",cy:"7",r:"1.4",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"9",cy:"10",r:"1.4",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"14",cy:"3",r:"1.4",fill:"currentColor",stroke:"none"})]}),step:r.jsx("path",{d:"M2 12h4V7h3v3h5V3",...t}),area:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M2 12l4-5 3 3 5-7v8H2z",fill:"currentColor",stroke:"none",opacity:"0.3"}),r.jsx("path",{d:"M2 12l4-5 3 3 5-7",...t})]}),baseline:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M1 8h14",...t,strokeDasharray:"2 2"}),r.jsx("path",{d:"M2 12l4-6 3 4 5-7",...t})]}),columns:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"8",width:"2.6",height:"6",fill:"currentColor",stroke:"none"}),r.jsx("rect",{x:"6",y:"5",width:"2.6",height:"9",fill:"currentColor",stroke:"none"}),r.jsx("rect",{x:"10",y:"9",width:"2.6",height:"5",fill:"currentColor",stroke:"none"})]}),high_low:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3.5",y:"3",width:"3",height:"9",fill:"currentColor",stroke:"none"}),r.jsx("rect",{x:"10",y:"6",width:"3",height:"7",fill:"currentColor",stroke:"none"})]}),heikin:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4.5 3v11",...t}),r.jsx("rect",{x:"2.5",y:"5",width:"4",height:"6",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M11.5 4v10",...t}),r.jsx("rect",{x:"9.5",y:"7",width:"4",height:"5",...t})]})};return r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",children:e[s]??e.candles})}const Bv=["1m","5m","15m","1h","4h","1d","1w","1M"],Wv=Object.freeze([]),qv=new Map,Vv=["5m","15m","1h","1d"],kf="futures_chart_interval",cu="futures_chart_legend";function Uv(s){try{const t=localStorage.getItem(kf);return s.includes(t)?t:"15m"}catch{return"15m"}}const hu={"1m":60*1e3,"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3,"4h":14400*1e3,"1d":1440*60*1e3,"1w":10080*60*1e3,"1M":720*60*60*1e3},_l=500,sa=5e3,Qn=1440*60*1e3,uu=10,Hv=3,Kv=8,du=4e3,$v=[{id:"5y",ms:5*365*Qn},{id:"1y",ms:365*Qn},{id:"6m",ms:182*Qn},{id:"3m",ms:91*Qn},{id:"1m",ms:30*Qn},{id:"5d",ms:5*Qn},{id:"1d",ms:Qn}],Yv=["1y","1m","5d","1d"],Qv=400;function fu(s,t){let e=t[t.length-1],n=1/0;for(const i of t){const o=s/_n(i);if(o>sa||o<10)continue;const l=Math.abs(Math.log(o/Qv));l<n&&(n=l,e=i)}return e}function mu(s,t){let e=0,n=s.length;for(;e<n;){const i=e+n>>1;s[i].time<t?e=i+1:n=i}return e}const Gv=30,er='11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',jn='11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',dn=18,Gn=7,na=18,Mf=9,Sn=6,Ur=5,ao=4,ia=50,pu=6;function Xv(){try{return new URLSearchParams(window.location.search).get("canvasdebug")==="1"}catch{return!1}}const gu=ia+170+ia;let Hr=null;function ii(s,t=er){return Hr||(Hr=document.createElement("canvas").getContext("2d")),Hr.font=t,Hr.measureText(s).width}function ra(s){return Math.round(oa(s)+jf(s)+ii(s.tag,jn))}function jf(s){return s.pre?Math.round(ii(s.pre,jn)+Sn*2+1):0}function oa(s){return s.icon?Mf+Sn:0}function vo(s){const t=s.value?Sn+ii(s.value,jn):0;return Math.round(Gn+ra(s)+t+Zv(s)+Gn)}function Zv(s){return s.post?Math.round(Sn*2+1+ii(s.post,jn)):0}function vu(s){return vo(s)+(s.close?na:0)}function Jv(s,t){return s==="tp"?t?h("Remove take profit"):h("Drag to move take profit"):t?h("Remove stop loss"):h("Drag to move stop loss")}function kl(s,t,e){s.save(),s.font=er;const n=7,i=20,o=s.measureText(e.text).width+n*2,l=Math.min(Math.max(e.x-o/2,2),Math.max(2,t.width-o-2)),a=e.y-i-6,c=a>=2?a:e.y+16+6;s.fillStyle="rgba(20, 21, 28, 0.94)",hr(s,l,c,o,i,5),s.fill(),s.strokeStyle="rgba(255, 255, 255, 0.14)",s.lineWidth=1,s.stroke(),s.fillStyle="#e8eaf0",s.textBaseline="middle",s.fillText(e.text,l+n,c+i/2),s.restore(
6)}const xu="#1e1f2a",vi="#ffffff",Hi="#2ebd85",Ki="#f0616d",yu="#fd450d";function tx(s,t,e,n,i,o,l=ao){s.save(),s.shadowColor="rgba(0, 0, 0, 0.5)",s.shadowBlur=7,s.shadowOffsetY=1,s.fillStyle=o,hr(s,Math.round(t),Math.round(e),Math.round(n),Math.round(i),l),s.fill(),s.restore()}function Ml(s,t,e,n){tx(s,t.x,t.y,t.width,t.height,xu),s.strokeStyle=n,s.lineWidth=1,hr(s,Math.round(t.x)+.5,Math.round(t.y)+.5,Math.round(t.width)-1,Math.round(t.height)-1,ao),s.stroke();const i=t.y+t.height/2+3.5;if(s.textAlign="left",s.textBaseline="alphabetic",e.icon&&ex(s,t.x+Gn+Mf/2,t.y+t.height/2,e.iconActive?n:vi,e.iconActive),s.font=jn,s.fillStyle=vi,e.pre){const u=t.x+Gn+oa(e);s.fillText(e.pre,u,i);const d=Math.round(u+ii(e.pre,jn)+Sn)+.5;s.save(),s.globalAlpha=.45,s.strokeStyle=n,s.lineWidth=1,s.beginPath(),s.moveTo(d,t.y+3),s.lineTo(d,t.y+t.height-3),s.stroke(),s.restore(),s.fillStyle=vi}if(s.fillText(e.tag,t.x+Gn+oa(e)+jf(e),i),e.value&&(s.font=jn,s.fillStyle=vi,s.fillText(e.value,t.x+Gn+ra(e)+Sn,i)),e.post){const u=t.x+Gn+ra(e)+(e.value?Sn+ii(e.value,jn):0),d=Math.round(u+Sn)+.5;s.save(),s.globalAlpha=.45,s.strokeStyle=n,s.lineWidth=1,s.beginPath(),s.moveTo(d,t.y+3),s.lineTo(d,t.y+t.height-3),s.stroke(),s.restore(),s.save(),s.globalAlpha=.7,s.font=jn,s.fillStyle=vi,s.fillText(e.post,d+Sn,i),s.restore()}if(!e.close)return;const o=t.x+vo(e);e.closeActive&&(s.fillStyle=n,hr(s,Math.round(o),Math.round(t.y)+1,na-1,t.height-2,[0,ao-1,ao-1,0]),s.fill()),s.strokeStyle=n,s.lineWidth=1,s.beginPath(),s.moveTo(Math.round(o)+.5,t.y+1),s.lineTo(Math.round(o)+.5,t.y+t.height-1),s.stroke();const l=o+na/2,a=t.y+t.height/2,c=3.5;s.strokeStyle=e.closeActive?xu:vi,s.lineWidth=1.2,s.lineCap="round",s.beginPath(),s.moveTo(l-c,a-c),s.lineTo(l+c,a+c),s.moveTo(l+c,a-c),s.lineTo(l-c,a+c),s.stroke()}function ex(s,t,e,n,i){s.save(),s.globalAlpha=i?1:.45,s.strokeStyle=n,s.lineWidth=1,s.lineCap="round",s.lineJoin="round";const o=3.5,l=2;s.beginPath(),s.moveTo(t,e-o),s.lineTo(t,e+o),s.moveTo(t-l,e-o+l),s.lineTo(t,e-o),s.lineTo(t+l,e-o+l),s.moveTo(t-l,e+o-l),s.lineTo(t,e+o),s.lineTo(t+l,e+o-l),s.stroke(),s.restore()}function hr(s,t,e,n,i,o){const[l,a,c,u]=Array.isArray(o)?o:[o,o,o,o],d=Math.min(n,i)/2,f=Math.max(0,Math.min(l,d)),g=Math.max(0,Math.min(a,d)),v=Math.max(0,Math.min(c,d)),b=Math.max(0,Math.min(u,d));s.beginPath(),s.moveTo(t+f,e),s.lineTo(t+n-g,e),s.arcTo(t+n,e,t+n,e+i,g),s.lineTo(t+n,e+i-v),s.arcTo(t+n,e+i,t,e+i,v),s.lineTo(t+b,e+i),s.arcTo(t,e+i,t,e,b),s.lineTo(t,e+f),s.arcTo(t,e,t+n,e,f),s.closePath()}function _n(s){return hu[s]??hu["15m"]}const sx=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function nx(s,t,e){const n=new Date((s+t)*1e3);if(Number.isNaN(n.getTime()))return"";const i=n.getUTCDate(),o=sx[n.getUTCMonth()]??"";if(e>=864e5)return i+" "+o+" "+n.getUTCFullYear();const l=String(n.getUTCHours()).padStart(2,"0"),a=String(n.getUTCMinutes()).padStart(2,"0");return i+" "+o+"  "+l+":"+a}const bu=[{id:"local",title:"Local time"},{id:"UTC",title:"UTC"},{id:"Europe/London",title:"London"},{id:"Europe/Berlin",title:"Frankfurt"},{id:"Europe/Moscow",title:"Moscow"},{id:"Asia/Dubai",title:"Dubai"},{id:"Asia/Hong_Kong",title:"Hong Kong"},{id:"Asia/Tokyo",title:"Tokyo"}
6,{id:"America/New_York",title:"New York"},{id:"America/Chicago",title:"Chicago"},{id:"America/Los_Angeles",title:"Los Angeles"}],wu="futures_chart_tz";function _u(s,t=new Date){if(s==="local")return-t.getTimezoneOffset();if(s==="UTC")return 0;try{const e=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:s,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(t).map(i=>[i.type,i.value])),n=Date.UTC(+e.year,+e.month-1,+e.day,+e.hour%24,+e.minute,+e.second);return Math.round((n-t.getTime())/6e4)}catch{return-t.getTimezoneOffset()}}function ku(s){if(!s)return"UTC";const t=s>0?"+":"-",e=Math.abs(s),n=Math.floor(e/60),i=e%60;return"UTC"+t+n+(i?":"+String(i).padStart(2,"0"):"")}function ix(s){const t=new Date(Date.now()+s*6e4);return[t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds()].map(e=>String(e).padStart(2,"0")).join(":")}function Kr(s,t=0){const e=[],n=[];for(const i of s??[]){const o=Math.floor(i.t/1e3)+t;e.push({time:o,open:parseFloat(i.o),high:parseFloat(i.h),low:parseFloat(i.l),close:parseFloat(i.c),volume:parseFloat(i.v)}),n.push({time:o,value:parseFloat(i.v),color:parseFloat(i.c)>=parseFloat(i.o)?"rgba(38,161,123,0.35)":"rgba(227,91,91,0.35)"})}return{candles:e,volumes:n}}function Mu({coin:s,compact:t=!1,height:e=380,fill:n=!1,position:i=null,orders:o=[],accountId:l=0,onChanged:a=null,markPx:c=0,feePct:u=0,onClosePosition:d=null,szDecimals:f=0}){const g=m.useRef(null),v=m.useRef(null),b=m.useRef(null),w=m.useRef(null),k=ur(),y=t?Vv:Bv,[S,j]=m.useState(()=>Uv(y)),[E,z]=m.useState(!0);m.useEffect(()=>{try{localStorage.setItem(kf,S)}catch{}},[S]);const[F,A]=m.useState(Rv),J=m.useMemo(()=>{const p=parseFloat(c)||0;return p?Math.max(2,bo(p,f)):2},[c,f]),O=m.useMemo(()=>({type:"price",precision:J,minMove:Math.pow(10,-J)}),[J]),yt=m.useRef(O);m.useEffect(()=>{var p;yt.current=O,(p=b.current)==null||p.applyOptions({priceFormat:O})},[O,F,s]);const[P,G]=m.useState(()=>{try{return localStorage.getItem(cu)!=="0"}catch{return!0}});m.useEffect(()=>{try{localStorage.setItem(cu,P?"1":"0")}catch{}},[P]);const[nt,bt]=m.useState(!1),$=m.useRef(null);m.useEffect(()=>{Pv(F)},[F]);const ht=m.useRef(F);m.useEffect(()=>{ht.current=F},[F]);const tt=m.useRef(F),[H,et]=m.useState(null),[rt,Nt]=m.useState(0),X=m.useRef(null),[st,Ot]=m.useState(!1),[St,At]=m.useState(""),Yt=m.useRef(null),[Mt,Gt]=m.useState(null),[jt,Be]=m.useState(null),[de,ie]=m.useState(!1),ce=g0()==="open",[Ne,se]=m.useState(()=>{try{const p=localStorage.getItem(wu);return bu.some(x=>x.id===p)?p:"local"}catch{return"local"}}),[We,Re]=m.useState(!1),ze=m.useRef(null),[he,N]=m.useState(""),[mt,Pt]=m.useState("normal"),qt=m.useRef("normal");m.useEffect(()=>{qt.current=mt},[mt]);const[pt,te]=m.useState(!0),Tt=_u(Ne),Ht=Tt*60,xt=m.useRef(Ht),Bt=m.useRef(Ht),re=m.useRef(!0);m.useEffect(()=>{xt.current=Ht},[Ht]),m.useEffect(()=>{re.current=pt},[pt]);const[Vt,Ee]=m.useState(()=>bv()),qe=m.useRef(1),[we,ye]=m.useState([]),fe=m.useRef(null);m.useEffect(()=>{let p=null;const x=()=>{var M;(M=fe.current)==null||M.call(fe),_()},_=()=>{var L;if(typeof window.matchMedia!="function")return;const M=window.devicePixelRatio||1;p=window.matchMedia(`(resolution: ${M}dppx)`),(L=p.addEventListener)==null||L.call(p,"change",x,{once:!0})};return _(),()=>{var M;return(M=p==null?void 0:p.removeEventListener)==null?void 0:M.call(p,"change",x)}},[]);const De=m.useCallback(()=>{const p=v.current;if(!p)return;const x=[];let _=0;for(const M of p.panes()){const L=M.getHeight();x.push({top:_,height:L}),_+=L+1}ye(M=>M.length===x.length&&M.every((L,C)=>L.top===x[C].top&&L.height===x[C].height)?M:x)},[]),[nn,Ws]=m.useState(-1),ws=m.useRef(we);ws.current=we;const zs=m.useCallback(p=>{const x=g.current;if(!x)return;const _=p.clientY-x.getBoundingClientRect().top,M=ws.current;let L=-1;for(let C=0;C<M.length;C++)if(_>=M[C].top&&_<M[C].top+M[C].height){L=C;break}Ws(C=>C===L?C:L)},[]),gs=m.useCallback(()=>Ws(-1),[]),Jt=m.useRef(new Map),Ls=m.useRef(new Map),Ds=m.useRef(new Map),[qs,vn]=m.useState(!1),ms=m.useRef(new Map),[Oe,Xt]=m.useState(null),as=m.useRef(new Map),le=m.useCallback(p=>as.current.get(p)??[],[]),cs=m.useCallback((p,x,_,M)=>{const L=p.data;if(L.length<2)return!1;const C=x.fromX(_);if(C===null)return!1;const D=C+Bt.current;let I=0,B=L.length-1;for(;B-I>1;){const U=I+B>>1;L[U].time<=D?I=U:B=U}for(const[U,ft]of[[I-1,I],[I,B],[B,B+1]]){const it=L[U],K=L[ft];if(!it||!K)continue;const gt=x.toX(it.time-Bt.current),Y=x.toX(K.time-Bt.current),at=x.toY(it.value),dt=x.toY(K.value);if(![gt,Y,at,dt].every(Number.isFinite))continue;
6const kt=Y-gt,_t=dt-at,$t=kt*kt+_t*_t,Ae=$t?Math.max(0,Math.min(1,((_-gt)*kt+(M-at)*_t)/$t)):0;if(Math.hypot(_-(gt+Ae*kt),M-(at+Ae*_t))<=7)return!0}return!1},[]),T=m.useRef(null);m.useEffect(()=>{wv(Vt)},[Vt]);const[Z,Q]=m.useState({coin:null,list:[]}),vt=Z.coin===s?Z.list:[],[wt,It]=m.useState(null),[ot,Dt]=m.useState(null),[Qt,Et]=m.useState(null),[Wt,_e]=m.useState({drawings:!1,indicators:!1,orders:!1}),Ue=m.useCallback(p=>{_e(x=>{if(p!=="all")return{...x,[p]:!x[p]};const _=!(x.drawings&&x.indicators&&x.orders);return{drawings:_,indicators:_,orders:_}})},[]),[ue,Xe]=m.useState(!1),[rn,Os]=m.useState(!1),ts=m.useRef(!1),Ve=m.useRef(null),ae=m.useRef(null),ke=m.useRef(e);ke.current=e;const xe=m.useRef(1);xe.current=t?Hv:1;const ps=m.useRef(null),es=m.useRef(null),Me=m.useRef(null),Qe=m.useRef(null),Pe=m.useRef(null),Ie=m.useRef(0),ss=m.useRef(null),En=m.useRef(null),hs=m.useRef(null),vs=m.useCallback(()=>{requestAnimationFrame(()=>requestAnimationFrame(()=>{var p;return(p=hs.current)==null?void 0:p.call(hs)}))},[]),me=m.useRef(null),us=m.useRef(null),He=m.useRef(vt),oe=m.useRef(null),_s=m.useRef(null),V=m.useRef(!1),ut=m.useRef(null),Ct=m.useRef(null);m.useEffect(()=>{He.current=vt},[vt]),m.useEffect(()=>{oe.current=ot},[ot]),m.useEffect(()=>{_s.current=wt},[wt]);const ne=m.useCallback(()=>Wt.drawings?Wv:He.current,[Wt.drawings]),[Zt,ks]=m.useState(!1);m.useEffect(()=>{const p=M=>{M.key==="Shift"&&ks(!0)},x=M=>{M.key==="Shift"&&ks(!1)},_=()=>ks(!1);return window.addEventListener("keydown",p),window.addEventListener("keyup",x),window.addEventListener("blur",_),()=>{window.removeEventListener("keydown",p),window.removeEventListener("keyup",x),window.removeEventListener("blur",_)}},[]);const ns=vt.find(p=>p.id===Qt)??null,is=m.useRef(!1);m.useEffect(()=>{is.current=de},[de]);const[Bn,oi]=m.useState(!1),Fe=m.useRef({candles:[],volumes:[]}),R=m.useRef({id:"candles",rows:[],legend:[],byTime:new Map}),Lt=m.useRef(null),Ce=m.useCallback(()=>{const p=b.current;if(!p)return;const x=Fe.current.candles,_=ru(F,x);R.current=_,Lt.current=bf(F)?wf(x):null;const M=Iv(F,x);M&&p.applyOptions(M);const L=ou(F,x[x.length-1]);L&&p.applyOptions(L),p.setData(_.rows)},[F]),Ze=m.useRef(null);m.useEffect(()=>{Ze.current=Ce},[Ce]);const Es=m.useRef(""),on=m.useRef(!1),Vs=m.useRef(!1),ln=m.useRef(null);m.useEffect(()=>{if(!g.current)return;const p=Pg(g.current,{width:g.current.clientWidth,height:n&&g.current.clientHeight||ke.current,layout:{background:{color:"transparent"},textColor:"#8b93a7",fontSize:t?10:11},grid:{vertLines:{color:"rgba(255,255,255,0.04)"},horzLines:{color:"rgba(255,255,255,0.04)"}},crosshair:{mode:Ol.Normal},rightPriceScale:{borderColor:"rgba(255,255,255,0.08)",scaleMargins:{top:.1,bottom:t?.1:.25}},timeScale:{borderColor:"rgba(255,255,255,0.08)",timeVisible:!0,secondsVisible:!1},handleScale:{axisPressedMouseMove:!0},handleScroll:{vertTouchDrag:!0}}),x=lu(ht.current),_=p.addSeries(x.definition,{...x.options,priceFormat:yt.current});if(tt.current=ht.current,v.current=p,b.current=_,!t){const it=p.addSeries($l,{priceFormat:{type:"volume"},priceScaleId:""});it.priceScale().applyOptions({scaleMargins:{top:.8,bottom:0}}),w.current=it}let M=0;const L=()=>{var it;De(),(it=fe.current)==null||it.call(fe),M=requestAnimationFrame(L)},C=()=>{M&&(cancelAnimationFrame(M),M=0,requestAnimationFrame(()=>{var it;De(),(it=fe.current)==null||it.call(fe)}))},D=()=>{M||(M=requestAnimationFrame(L))},I=g.current;I.addEventListener("pointerdown",D),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C);const B=new ResizeObserver(it=>{var K;for(const gt of it){const Y={width:gt.contentRect.width};(n||is.current)&&gt.contentRect.height>0?Y.height=gt.contentRect.height:Y.height=ke.current,p.applyOptions(Y)}De(),(K=fe.current)==null||K.call(fe)});B.observe(g.current);const U=it=>{var K;!it||it.from>Gv||(K=ln.current)==null||K.call(ln)};p.timeScale().subscribeVisibleLogicalRangeChange(U);const ft=it=>{Gt(it!=null&&it.time?R.current.byTime.get(it.time)??null:null)};return p.subscribeCrosshairMove(ft),()=>{B.disconnect(),I.removeEventListener("pointerdown",D),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C),M&&cancelAnimationFrame(M),p.unsubscribeCrosshairMove(ft),p.timeScale().unsubscribeVisibleLogicalRangeChange(U),p.remove(),ms.current.clear(),v.current=null,b.current=null,w.current=null}},[t,n]),m.useEffect(()=>{const p=v.current;
6if(!p)return;if(de||p.applyOptions({height:e}),!n&&!de){De();return}let x=requestAnimationFrame(()=>{x=requestAnimationFrame(()=>{var L,C;const _=g.current,M=(_==null?void 0:_.clientHeight)??0;M>0&&((L=v.current)==null||L.applyOptions({height:M})),De(),(C=hs.current)==null||C.call(hs)})});return()=>cancelAnimationFrame(x)},[de,n,e,De]),m.useEffect(()=>{var p,x;(p=b.current)==null||p.setData([]),(x=w.current)==null||x.setData([]),R.current=ru(F,[]),vs(),Gt(null),Be(null)},[s]);const Us=m.useCallback((p,x,_,M)=>{var L;return ge.post("/x/futures/candles",{miniAppData:(L=ve())==null?void 0:L.initData,coin:p,interval:x,startTime:_,endTime:M}).then(({data:C})=>(C==null?void 0:C.candles)??[])},[]),Ke=m.useCallback(()=>{const p=hv(Vt);if(!p.length)return;const x=Fe.current.candles;if(!x.length)return;const _=s+"|"+S,M=Bt.current,L=(x[0].time-M)*1e3,C=(x[x.length-1].time-M)*1e3;for(const D of p){if(D===s)continue;const I=Ls.current.get(D);I&&I.key===_&&I.from<=L||(Ls.current.set(D,{key:_,from:L}),Us(D,S,L,C).then(B=>{var U;Es.current===_&&(Jt.current.set(D,Kr(B,M).candles),(U=T.current)==null||U.call(T))}).catch(()=>{Ls.current.delete(D)}))}},[Vt,s,S,Us]),Is=m.useRef(null);m.useEffect(()=>{Is.current=Ke},[Ke]),m.useEffect(()=>{Ke()},[Ke]),m.useEffect(()=>{var D;if(!s||!b.current)return;const p=s+"|"+S;Es.current=p,Fe.current={candles:[],volumes:[]},Vs.current=!1,on.current=!1,Jt.current.clear(),Ls.current.clear(),(D=T.current)==null||D.call(T);let x=!1;z(!0),oi(!1);const _=Date.now(),M=X.current,L=M?Math.min(sa,Math.max(_l,Math.ceil(M.span/_n(S))+150)):_l,C=_-L*_n(S);return Us(s,S,C,_).then(I=>{var it,K,gt,Y,at,dt,kt;if(x||Es.current!==p||!b.current)return;const B=Kr(I,xt.current);Fe.current=B,Bt.current=xt.current,(it=Ze.current)==null||it.call(Ze),(K=w.current)==null||K.setData(B.volumes),(gt=T.current)==null||gt.call(T),(Y=Is.current)==null||Y.call(Is),vs(),(at=v.current)==null||at.priceScale("right").applyOptions({autoScale:re.current});const U=R.current.legend;Be(U[U.length-1]??null);const ft=B.candles.length;if(M&&ft){const _t=Te=>mu(B.candles,Math.floor(Te/1e3)+xt.current),$t=M.focus?{from:_t(M.focus)-100,to:_t(M.focus)+100}:{from:_t(_-M.span),to:ft+4},Ae=Math.max(0,$t.from);(dt=v.current)==null||dt.timeScale().setVisibleLogicalRange({from:Ae,to:Math.max($t.to,Ae+10)})}else{const _t=Math.min(ft,t?90:180);(kt=v.current)==null||kt.timeScale().setVisibleLogicalRange({from:ft-_t,to:ft+4})}X.current=null,z(!1)}).catch(()=>{x||z(!1)}),()=>{x=!0}},[s,S,Us,rt]),m.useEffect(()=>{ln.current=()=>{if(on.current||Vs.current)return;const p=Fe.current;if(!p.candles.length||!b.current)return;const x=s+"|"+S;if(Es.current!==x)return;on.current=!0,oi(!0);const M=(p.candles[0].time-Bt.current)*1e3-1,L=M-_l*_n(S);Us(s,S,L,M).then(C=>{var it,K,gt,Y,at,dt;if(Es.current!==x||!b.current)return;const D=Kr(C,xt.current),I=((it=Fe.current.candles[0])==null?void 0:it.time)??1/0;let B=D.candles.length;for(;B>0&&D.candles[B-1].time>=I;)B--;if(B<=0){Vs.current=!0;return}const U={candles:D.candles.slice(0,B),volumes:D.volumes.slice(0,B)},ft=(K=v.current)==null?void 0:K.timeScale().getVisibleLogicalRange();Fe.current={candles:U.candles.concat(Fe.current.candles),volumes:U.volumes.concat(Fe.current.volumes)},(gt=Ze.current)==null||gt.call(Ze),(Y=w.current)==null||Y.setData(Fe.current.volumes),(at=T.current)==null||at.call(T),vs(),ft&&((dt=v.current)==null||dt.timeScale().setVisibleLogicalRange({from:ft.from+U.candles.length,to:ft.to+U.candles.length}))}).catch(()=>{}).finally(()=>{on.current=!1,oi(!1)})}},[s,S,Us]);const Wn=m.useRef([]),fr=m.useCallback(()=>{const p=b.current;if(!p)return;const x=k.priceLines&&!Wt.orders;for(const M of Wn.current)try{p.removePriceLine(M)}catch{}Wn.current=[];const _=(M,L,C,D,I=1)=>{if(!x)return;const B=parseFloat(M);!Number.isFinite(B)||B<=0||Wn.current.push(p.createPriceLine({price:B,color:L,lineWidth:I,lineStyle:C,axisLabelVisible:!0,title:D}))};if(i){const M=parseFloat(i.szi)||0;_(i.entryPx,M>0?"#2ebd85":"#f0616d",yi.Solid,""),_(i.liquidationPx,yu,yi.Dashed,"")}for(const M of o??[]){const L=String(M.orderType??"");if(M.isTrigger){if(Pa(M))continue;const C=L.includes("Take Profit");_(M.triggerPx,C?"rgba(46,189,133,0.85)":"rgba(240,97,109,0.85)",yi.Dotted,C?h("Take profit"):h("Stop loss"));continue}}},[i,o,k.priceLines,Wt.orders]),[mr,pr]=m.useState({coin:null,list:[]}),Eo=m.useRef(s);Eo.current=s,m.useEffect(()=>{var M;if(!k.tradeMarks||!s){pr({coin:null,list:[]});return}let p=!0;const x=Math.min(_n(S)*600,2160*60*60*1e3),_=Date.now()-x;return ge.post("/x/futures/history",{miniAppData:(M=ve())==null?void 0:M.initData,account_id:l,startTime:_}).then(({data:L})=>{p&&pr({coin:s,list:((L==null?void 0:L.fills)??[]).filter(C=>(C==null?void 0:C.coin)===s)})}).catch(()=>{p&&pr({coin:s,list:[]})}),()=>{p=!1}},[s,S,l,k.tradeMarks]);const Xf=m.useCallback(p=>{if(p!=null&&p.isSnapshot)return;const _=(Array.isArray(p)?p:(p==null?void 0:p.fills)??[p]).filter(M=>(M==null?void 0:M.coin)===Eo.current&&(M==null?void 0:M.sz));_.length&&pr(M=>M.coin===Eo.current?{coin:M.coin,list:[...M.list,..._]}:M)},[]);sn("user",{sub:"fills"},Xf,!!k.tradeMarks);const Ya=m.useMemo(()=>
6{if(!k.tradeMarks||mr.coin!==s||!mr.list.length)return[];const p=Math.max(1,Math.round(_n(S)/1e3)),x=new Map;for(const _ of mr.list){const M=Math.floor((Number(_.time)||0)/1e3/p)*p;if(!M)continue;const L=_.side==="B",C=M+":"+(L?"B":"S"),D=x.get(C)??{time:M,isBuy:L,size:0,sum:0},I=Math.abs(parseFloat(_.sz)||0);D.size+=I,D.sum+=I*(parseFloat(_.px)||0),x.set(C,D)}return[...x.values()].sort((_,M)=>_.time-M.time)},[k.tradeMarks,mr,s,S]),Qa=m.useRef([]);Qa.current=Ya;const qn=m.useRef(null),Ri=m.useRef(!1),Vn=m.useRef(i),Ga=m.useRef(k),Xa=m.useRef(c),Za=m.useRef(u),Zf=m.useMemo(()=>s?[s]:[],[s]),Fo=To(Zf);Vn.current=i,Ga.current=k,Xa.current=parseFloat((Fo==null?void 0:Fo[s])??0)||c,Za.current=u;const Ja=m.useCallback((p,x)=>{var it;const _=Vn.current;if(!_||!Ga.current.priceLines){qn.current=null;return}const M=parseFloat(_.entryPx)||0;if(!M)return;const L=Fe.current.candles,C=parseFloat(Xa.current)||parseFloat(((it=L[L.length-1])==null?void 0:it.close)??0)||0,D=(parseFloat(_.szi)||0)>0,I=po(_,C,Za.current||void 0).gross,B=parseFloat(_.liquidationPx)||0;p.save(),p.setLineDash([]),p.textAlign="left",p.textBaseline="alphabetic";let U=null;const ft=[{price:M,align:"left",chips:[{pre:t?"":D?"LONG":"SHORT",tag:"PNL",value:$e(I,3),color:D?Hi:Ki,close:!0}]},{price:B,chips:[{tag:h("Liquidation"),value:"",color:yu}]}];for(const K of ft){if(!(K.price>0))continue;const gt=x.toY(K.price);if(gt===null||!Number.isFinite(gt))continue;const Y=K.chips.map(_t=>({..._t,width:vu(_t)})),at=Y.reduce((_t,$t)=>_t+$t.width,0)+Ur*(Y.length-1),dt=Math.max(2,x.width-at-4);let kt=t?pu:K.align==="left"?gu:Math.max(gu,dt);kt=Math.min(kt,dt);for(const _t of Y){const $t={x:kt,y:gt-dn/2,width:_t.width,height:dn};Ml(p,$t,{..._t,closeActive:Ri.current},_t.color),_t.close&&(qn.current={x:$t.x+vo(_t),y:$t.y,size:dn},Ri.current&&(U={x:qn.current.x+dn/2,y:qn.current.y,text:h("Close position")})),kt+=_t.width+Ur}}U&&kl(p,x,U),p.restore()},[t]),tc=m.useCallback((p,x)=>{const _=Qa.current;if(!_.length)return;const M=Fe.current.candles;if(!M.length)return;const L=Bt.current,C=B=>{const U=B+L;if(U<M[0].time)return null;let ft=0,it=M.length-1;if(U>=M[it].time)return M[it];for(;it-ft>1;){const K=ft+it>>1;M[K].time<=U?ft=K:it=K}return M[ft]},D=8,I=(B,U,ft)=>{p.beginPath();for(let it=0;it<6;it++){const K=Math.PI/180*(-90+60*it),gt=B+ft*Math.cos(K),Y=U+ft*Math.sin(K);it===0?p.moveTo(gt,Y):p.lineTo(gt,Y)}p.closePath()};p.save(),p.setLineDash([]),p.textAlign="center",p.textBaseline="middle",p.font="700 10px "+er.replace(/^[^ ]+ /,"");for(const B of _){const U=C(B.time);if(!U)continue;const ft=x.toX(U.time-L);if(ft===null||!Number.isFinite(ft))continue;const it=Math.round(ft);if(it<-D||it>x.width+D)continue;const K=B.isBuy?U.low:U.high,gt=B.size>0?B.sum/B.size:0,Y=Number.isFinite(K)?K:U.close??gt,at=x.toY(Y);if(at===null)continue;const dt=Math.round(B.isBuy?at+D+6:at-D-6);p.fillStyle=B.isBuy?"#2ebd85":"#f0616d",I(it,dt,D),p.fill(),p.strokeStyle="rgba(13,17,23,.55)",p.lineWidth=1,p.stroke(),p.fillStyle="#0d1117",p.fillText(B.isBuy?"B":"S",it,dt+.5)}p.restore()},[]),ec=m.useRef(new Map),gr=m.useCallback(()=>{var L;const p=b.current;if(!p)return;const x=ec.current,_=new Set;for(const C of ne())(C.tool==="hline"||C.tool==="hray"?C.points.slice(0,1):C.id===oe.current&&z0(C.tool)?C.points:[]).forEach((B,U)=>{const ft=B==null?void 0:B.price;if(!Number.isFinite(ft)||ft<=0)return;const it=C.id+":"+U;_.add(it);const K={price:ft,lineVisible:!1,axisLabelVisible:!0,axisLabelColor:C.color,axisLabelTextColor:"#0f1015",title:""},gt=x.get(it);gt?gt.applyOptions(K):x.set(it,p.createPriceLine(K))});const M=(parseFloat((L=Vn.current)==null?void 0:L.szi)||0)>0;for(const C of As.current){C.kind;const D=Ro(C.key);if(!Number.isFinite(D)||D<=0)continue;const I="guard:"+C.key;_.add(I);const B={price:D,lineVisible:!1,axisLabelVisible:!0,axisLabelColor:M?Ki:Hi,axisLabelTextColor:"#0f1015",title:""},U=x.get(I);U?U.applyOptions(B):x.set(I,p.createPriceLine(B))}for(const C of Hs.current??[]){const D=Di(C);if(!Number.isFinite(D)||D<=0)continue;const I="order:"+C.oid;_.add(I);const B={price:D,lineVisible:!1,axisLabelVisible:!0,axisLabelColor:C.isBuy?Hi:Ki,axisLabelTextColor:"#0f1015",title:""},U=x.get(I);
6U?U.applyOptions(B):x.set(I,p.createPriceLine(B))}for(const[C,D]of x)if(!_.has(C)){try{p.removePriceLine(D)}catch{}x.delete(C)}},[ne]),Fs=m.useRef(null);m.useEffect(()=>{Fs.current=gr},[gr]),m.useEffect(()=>{gr()},[gr,vt,ot,s,S,Wt.drawings]);const vr=m.useRef(null);m.useEffect(()=>{vr.current=fr},[fr]),m.useEffect(()=>{fr()},[fr,s,S]),m.useEffect(()=>{var L,C,D,I,B;const p=v.current;if(!p||!b.current||tt.current===F)return;const x=lu(F),_=b.current,M=((L=_.seriesOrder)==null?void 0:L.call(_))??0;b.current=p.addSeries(x.definition,{...x.options,priceFormat:yt.current}),tt.current=F,Ce(),Wn.current=[],ec.current.clear(),p.removeSeries(_),(D=(C=b.current).setSeriesOrder)==null||D.call(C,M),(I=vr.current)==null||I.call(vr),(B=Fs.current)==null||B.call(Fs),vs()},[F,Ce,vs]);const Jf=m.useCallback(p=>{X.current={span:p.ms,focus:null},et(p.id),j(fu(p.ms,y)),Nt(x=>x+1)},[y]),sc=m.useCallback(p=>{const x=Date.parse(p+"T00:00:00Z");if(!Number.isFinite(x))return;const _=Date.now()-x;if(_<=0)return;const M=_/_n(S)<=sa;X.current={span:_,focus:x},et(null),Ot(!1),j(M?S:fu(_,y)),Nt(L=>L+1)},[S,y]),tm=m.useCallback(p=>{et(null),j(p)},[]);m.useEffect(()=>{et(null)},[s]),m.useEffect(()=>{if(!st)return;const p=_=>{Yt.current&&!Yt.current.contains(_.target)&&Ot(!1)},x=_=>{_.key==="Escape"&&Ot(!1)};return document.addEventListener("mousedown",p),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",x)}},[st]),sn("candle",{coin:s,interval:S},p=>{var ft,it;if(!p||!b.current)return;const{candles:x,volumes:_}=Kr([p],xt.current),M=x[0],L=_[0],{row:C,legendBar:D}=Ov(R.current,M);b.current.update(C);const I=ou((ft=R.current)==null?void 0:ft.id,M);if(I&&b.current.applyOptions(I),Lt.current&&(M.low<Lt.current.min||M.high>Lt.current.max)){const K={min:Math.min(Lt.current.min,M.low),max:Math.max(Lt.current.max,M.high)},gt=_f(R.current.id,K);gt&&b.current.applyOptions(gt),Lt.current=K}(it=T.current)==null||it.call(T),Be(D),w.current&&w.current.update(L);const B=Fe.current,U=B.candles[B.candles.length-1];U&&U.time===M.time?(B.candles[B.candles.length-1]=M,B.volumes[B.volumes.length-1]=L):(!U||M.time>U.time)&&(B.candles.push(M),B.volumes.push(L))},!!s);const xr=m.useCallback(()=>{const p=v.current;if(!p)return;const x=Fe.current.candles,_=new Set,M=Vt.filter(B=>{var U;return(U=ls(B.id))==null?void 0:U.pane}),L=1+M.length;for(;p.panes().length<L;)p.addPane();const C=new Map;M.forEach((B,U)=>C.set(B.key,U+1));const D={symbols:Jt.current};for(const B of Vt){const U=ls(B.id),ft=uv(B,x,D);as.current.set(B.key,ft);const it=C.get(B.key)??0;ft.forEach((K,gt)=>{var kt;const Y=B.key+"#"+gt+"@"+it+(K.kind??"line");_.add(Y);let at=ms.current.get(Y);if(!at){const _t={priceLineVisible:!1,lastValueVisible:!1};if((U==null?void 0:U.format)==="volume"&&(_t.priceFormat={type:"volume"}),K.kind==="histogram"?at=p.addSeries($l,_t,it):K.kind==="dots"?at=p.addSeries(Si,{..._t,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:1.6,crosshairMarkerVisible:!1},it):K.kind==="markers"?(at=p.addSeries(Si,{..._t,lineVisible:!1,pointMarkersVisible:!1,crosshairMarkerVisible:!1},it),Ds.current.set(Y,h0(at,[]))):at=p.addSeries(Si,{..._t,crosshairMarkerVisible:!1},it),ms.current.set(Y,at),it>0&&gt===0)for(const $t of(U==null?void 0:U.levels)??[])at.createPrice
6Line({price:$t,color:"rgba(255,255,255,0.16)",lineWidth:1,lineStyle:yi.Dashed,axisLabelVisible:!0})}const dt=!B.hidden&&!Wt.indicators;K.kind==="histogram"?at.applyOptions({color:K.color}):K.kind==="markers"?(kt=Ds.current.get(Y))==null||kt.setMarkers(dt?K.data.map(_t=>({time:_t.time,position:K.at??"atPriceTop",price:_t.value,shape:K.shape??"circle",color:K.color})):[]):K.kind==="dots"?at.applyOptions({color:K.color,pointMarkersRadius:1+K.width*.6}):at.applyOptions({color:K.color,lineWidth:K.width}),at.applyOptions({visible:dt}),at.setData(K.data)})}const I=new Set(Vt.map(B=>B.key));for(const B of as.current.keys())I.has(B)||as.current.delete(B);for(const[B,U]of ms.current)_.has(B)||(p.removeSeries(U),ms.current.delete(B),Ds.current.delete(B));for(;p.panes().length>L;)p.removePane(p.panes().length-1);qe.current!==L&&(qe.current=L,p.panes().forEach((U,ft)=>U.setStretchFactor(ft===0?3:1))),De()},[Vt,De,Wt.indicators]);m.useEffect(()=>{T.current=xr},[xr]),m.useEffect(()=>{xr()},[xr]);const xn=m.useMemo(()=>Yd(o,s),[o,s]),nc=m.useRef({}),ic=m.useRef(null);m.useEffect(()=>{nc.current=Object.fromEntries(xn.map(p=>[p.key,p.size||0]))},[xn]);const yr=!!i&&(parseFloat(i.szi)||0)!==0,em=(jt==null?void 0:jt.close)??parseFloat((i==null?void 0:i.entryPx)??0)??0,rc=(parseFloat(i==null?void 0:i.szi)||0)>0,Fn=m.useRef(null),[br,oc]=m.useState(null),As=m.useRef(xn),lc=m.useRef(null),li=m.useRef(null),[ai,Ao]=m.useState(null),wr=m.useRef(null),ac=m.useRef(k.tpslConfirm);m.useEffect(()=>{ac.current=k.tpslConfirm},[k.tpslConfirm]),m.useEffect(()=>{var p;(p=w.current)==null||p.applyOptions({visible:k.volume})},[k.volume,t,e,n]);const Pi=m.useRef({});m.useEffect(()=>{const p=Pi.current,x=[...xn],_=(M,L,C)=>M.findIndex(D=>D.kind===L&&Math.abs(D.price-C)<=1e-9);for(const M of Object.keys(p)){const L=p[M];if(!L)continue;const C=Number(L.price)||0,D=Number(L.was)||0,I=L.until||0,B=_(xn,L.kind,C)>=0;if(I){if(B||Date.now()>I){delete p[M];continue}_(x,L.kind,C)<0&&x.push({key:M,kind:L.kind,price:C,size:L.size||0});continue}const U=_(xn,L.kind,D);if(B||U<0){delete p[M];continue}const ft=_(x,L.kind,D);ft>=0&&(x[ft]={...x[ft],price:C})}As.current=x},[xn]),m.useEffect(()=>{lc.current=br},[br]),m.useEffect(()=>{var p;(p=Fs.current)==null||p.call(Fs)},[xn,br]);const Ro=m.useCallback(p=>{var M;const x=Fn.current;if((x==null?void 0:x.key)===p)return x.price;const _=li.current;return(_==null?void 0:_.key)===p&&_.price>0?_.price:((M=As.current.find(L=>L.key===p))==null?void 0:M.price)??0},[]);m.useCallback(p=>As.current.find(x=>x.key===p)??null,[]);const{showError:yn}=Ln(),ci=m.useCallback((p,x,_)=>{const M=p.toY(_);if(M===null||!Number.isFinite(M))return null;const L=vu(x),C=t?pu:ia;return{y:M,label:x,chip:{x:C,y:M-dn/2,width:L,height:dn},move:{x:C,y:M-dn/2,size:dn},close:{x:C+vo(x),y:M-dn/2,size:dn}}},[t]),[sm,nm]=m.useState(()=>new Set);m.useEffect(()=>Ev(nm),[]);const cc=sm.has(s),Po=m.useRef(!1);Po.current=cc;const hc=m.useCallback(p=>{var L,C;if(Po.current)return h("Updating")+"…";const x=Math.abs(parseFloat(((L=Vn.current)==null?void 0:L.szi)??0)||0);let _=((C=nc.current)==null?void 0:C[p])||0;const M=ic.current;return!_&&M&&Date.now()<M.until&&(_=Number(M[p])||0),!x||!_||_>=x*.995?h("All"):lt(_)},[]),_r=m.useCallback((p,x,_,M)=>ci(p,{tag:x==="tp"?"TP":"SL",value:lt(_),post:t?"":hc(M),icon:!0,close:!0},_),[ci,hc,t]),zi=m.useCallback((p,x,_,M=0)=>{if(!yr||Wt.orders)return null;const L=C=>x>=C.x-M&&x<=C.x+C.size+M&&_>=C.y-M&&_<=C.y+C.size+M;for(const C of As.current){const D=C.kind,I=Ro(C.key);if(!I)continue;const B=_r(p,D,I,C.key);if(!B)continue;if(L(B.close))return{key:C.key,kind:D,close:!0};if(L(B.move))return{key:C.key,kind:D,close:!1};if(x>=B.chip.x-M&&x<=B.chip.x+B.chip.width+M&&_>=B.chip.y-M&&_<=B.chip.y+B.chip.height+M)return{key:C.key,kind:D,close:!1}}return null},[yr,_r,Wt.orders]),zo=m.useCallback(async(p,x)=>{var C,D,I,B;oc(x);const _=p.find(U=>U.key===x)??null,M=Date.now()+du,L={...Pi.current};for(const U of p)U.key===x||!(U.price>0)||(L[U.key]={kind:U.kind,price:U.price,was:U.price,size:U.size||0,until:M});Pi.current=L,li.current=_?{key:x,price:Number(_.price)||0}:null;try{const U=Math.abs(parseFloat(((C=Vn.current)==null?void 0:C.szi)??0)||0);ic.current={...Object.fromEntries(p.map(it=>[it.key,it.size||0])),until:Date.now()+du};const{data:ft}=await ge.post("/x/futures/tpsl",{miniAppData:(D=ve())==null?void 0:D.initData,account_id:l,coin:s,levels:Qd(p,U)});if(ft!=null&&ft.err)yn(ft.errText||ft.err);else{const it=Math.abs(parseFloat(((I=Vn.current)==null?void 0:I.szi)??0)||0),K=p.filter(dt=>Number(dt.price)>0);if(it>0&&K.length>0&&K.every(dt=>Number(dt.size)>0)){const dt=K.every(kt=>Number(kt.size)>=it*.9975);ta(l,s,dt)}
6const Y=Number(_==null?void 0:_.price)||0,at=Number((B=As.current.find(dt=>dt.key===x))==null?void 0:B.price)||0;Y>0&&(Pi.current={...Pi.current,[x]:{kind:_.kind,price:Y,was:at,size:_.size||0}}),As.current=p,ys((_==null?void 0:_.kind)==="sl"?h("Stop loss updated"):h("Take profit updated")),a&&a()}}catch{yn(h("Network error"))}finally{li.current=null,oc(null)}},[l,s,a,yn]),uc=m.useCallback((p,x)=>{var D;if(!yr)return;const _=(parseFloat((D=Vn.current)==null?void 0:D.szi)||0)>0,L=Fn.current?null:wr.current;let C=null;for(const I of As.current){const B=I.kind,U=Ro(I.key);if(!U)continue;const ft=_r(x,B,U,I.key);if(!ft)continue;const it=_?Ki:Hi,K=(L==null?void 0:L.key)===I.key&&!L.close,gt=(L==null?void 0:L.key)===I.key&&L.close;p.save(),p.globalAlpha=lc.current===I.key||Po.current?.4:1;const Y=p.globalAlpha;if(p.globalAlpha=Y*.45,p.strokeStyle=it,p.lineWidth=1,p.setLineDash([4,4]),p.beginPath(),p.moveTo(0,ft.y),p.lineTo(ft.chip.x-2,ft.y),p.moveTo(ft.close.x+ft.close.size+Ur+2,ft.y),p.lineTo(x.width,ft.y),p.stroke(),p.globalAlpha=Y,p.setLineDash([]),Ml(p,ft.chip,{...ft.label,iconActive:K,closeActive:gt}
6,it),p.restore(),(L==null?void 0:L.key)===I.key){const at=L.close?ft.close:ft.move;C={x:at.x+at.size/2,y:at.y,text:Jv(B,L.close)}}}C&&kl(p,x,C)},[yr,_r]),kr=m.useRef(null),[Un,Do]=m.useState(null),dc=m.useRef(k.orderMoveConfirm);m.useEffect(()=>{dc.current=k.orderMoveConfirm},[k.orderMoveConfirm]);const bn=m.useMemo(()=>(o??[]).filter(p=>p&&!p.isTrigger&&!p.isPositionTpsl&&p.coin===s).map(p=>({oid:p.oid,isBuy:p.side==="B",size:parseFloat(p.sz??0)||0,price:parseFloat(p.limitPx??0)||0})).filter(p=>p.oid&&p.price>0),[o,s]),Hs=m.useRef(bn);m.useEffect(()=>{const p=an.current;if(!(p!=null&&p.replaces)){Hs.current=bn;return}if(bn.some(_=>_.oid===p.oid)||!bn.some(_=>_.oid===p.replaces)){an.current=null,Hs.current=bn;return}Hs.current=bn.map(_=>_.oid===p.replaces?{..._,oid:p.oid,price:p.price}:_)},[bn]),m.useEffect(()=>{var p;(p=Fs.current)==null||p.call(Fs)},[bn]);const An=m.useRef(null),an=m.useRef(null),[Oo,Mr]=m.useState(null),fc=m.useRef(null);m.useEffect(()=>{fc.current=Oo},[Oo]);const Di=m.useCallback(p=>{const x=An.current;if((x==null?void 0:x.oid)===p.oid)return x.price;const _=an.current;return(_==null?void 0:_.oid)===p.oid&&_.price>0?_.price:p.price},[]),jr=m.useCallback(p=>({tag:p.isBuy?h("Buy"):h("Sell"),value:lt(p.size),icon:!0,close:!0}),[]),Oi=m.useCallback((p,x,_,M=0)=>{if(Wt.orders)return null;const L=C=>x>=C.x-M&&x<=C.x+C.size+M&&_>=C.y-M&&_<=C.y+C.size+M;for(const C of Hs.current){const D=Di(C);if(!D)continue;const I=ci(p,jr(C),D);if(!I)continue;if(L(I.close))return{oid:C.oid,close:!0};if(L(I.move))return{oid:C.oid,close:!1};if(x>=I.chip.x-M&&x<=I.chip.x+I.chip.width+M&&_>=I.chip.y-M&&_<=I.chip.y+I.chip.height+M)return{oid:C.oid,close:!1}}return null},[ci,jr,Di,Wt.orders]),mc=m.useCallback(async(p,x)=>{var _;Mr(p),an.current={oid:p,price:x};try{const{data:M}=await ge.post("/x/futures/move-order",{miniAppData:(_=ve())==null?void 0:_.initData,account_id:l,oid:p,price:x});if(M!=null&&M.err)an.current=null,yn(M.errText||M.err);else{const L=(M==null?void 0:M.oid)??p;Hs.current=Hs.current.map(C=>C.oid===p?{...C,oid:L,price:x}:C),an.current={oid:L,price:x,replaces:p},ys(h("Order moved"))}}catch{an.current=null,yn(h("Network error"))}finally{Mr(null),a&&a()}},[l,a,yn]),im=m.useCallback(async p=>{var x;Mr(p);try{const{data:_}=await ge.post("/x/futures/cancel",{miniAppData:(x=ve())==null?void 0:x.initData,account_id:l,coin:s,oid:p});_!=null&&_.err?yn(_.errText||_.err):ys(h("Order cancelled"))}catch{yn(h("Network error"))}finally{Mr(null),a&&a()}},[l,s,a,yn]),pc=m.useCallback((p,x)=>{const M=An.current?null:kr.current;let L=null;for(const C of Hs.current){const D=Di(C);if(!D)continue;const I=ci(x,jr(C),D);if(!I)continue;const B=C.isBuy?Hi:Ki,U=(M==null?void 0:M.oid)===C.oid&&!M.close,ft=(M==null?void 0:M.oid)===C.oid&&M.close;p.save(),p.globalAlpha=fc.current===C.oid?.4:1;const it=p.globalAlpha;if(p.globalAlpha=it*.45,p.strokeStyle=B,p.lineWidth=1,p.setLineDash([2,4]),p.beginPath(),p.moveTo(0,I.y),p.lineTo(I.chip.x-2,I.y),p.moveTo(I.close.x+I.close.size+Ur+2,I.y),p.lineTo(x.width,I.y),p.stroke(),p.globalAlpha=it,p.setLineDash([]),Ml(p,I.chip,{...I.label,iconActive:U,closeActive:ft},B),p.restore(),(M==null?void 0:M.oid)===C.oid){const K=M.close?I.close:I.move;L={x:K.x+K.size/2,y:K.y,text:M.close?h("Cancel order"):h("Drag to move the order")}}}L&&kl(p,x,L)},[ci,jr,Di]),Ks=_n(S)/1e3,gc=m.useCallback(p=>{const x=Fe.current.candles;if(!x.length)return null;const _=p+Bt.current,M=x.length-1;if(_<=x[0].time)return(_-x[0].time)/Ks;if(_>=x[M].time)return M+(_-x[M].time)/Ks;let L=0,C=M;for(;C-L>1;){const I=L+C>>1;x[I].time<=_?L=I:C=I}const D=x[C].time-x[L].time||Ks;return L+(_-x[L].time)/D},[Ks]),vc=m.useCallback(p=>{const x=Fe.current.candles;if(!x.length||p===null||p===void 0)return null;const _=x.length-1,M=Math.floor(p);let L;return M<0?L=x[0].time+p*Ks:M>=_?L=x[_].time+(p-_)*Ks:L=x[M].time+(p-M)*(x[M+1].time-x[M].time),Math.round(L)-Bt.current},[Ks]),Ms=m.useCallback(()=>{var at,dt;const p=v.current,x=b.current,_=g.current;if(!p||!x||!_)return null;const M=p.timeScale(),L=_.clientWidth-p.priceScale("right").width(),C=((dt=(at=p.panes()[0])==null?void 0:at.getHeight)==null?void 0:dt.call(at))??0,D=C>0?C:_.clientHeight-M.height();if(L<=0||D<=0)return null;const I=M.getVisibleLogicalRange();if(!I||I.to===I.from)return null;const B=M.logicalToCoordinate(I.from),U=M.logicalToCoordinate(I.to),ft=Number.isFinite(B)&&Number.isFinite(U)&&U!==B,it=ft?(U-B)/(I.to-I.from):L/(I.to-I.from),K=ft?B:0,gt=kt=>K+(kt-I.from)*it,Y=kt=>I.from+(kt-K)/it;return{width:L,height:D,barSeconds:Ks,toX:kt=>{const _t=gc(kt);return _t===null?null:gt(_t)},toY:kt=>x.priceToCoordinate(kt),fromX:kt=>vc(Y(kt)),fromY:kt=>x.coordinateToPrice(kt)}},[Ks,gc,vc]),Rn=m.useRef({x:k.actsX||0,y:k.actsY||0,pinned:!!k.actsPinned}),Sr=m.useRef(null),rm=p=>{var x,_;p.preventDefault(),p.stopPropagation(),Rn.current={...Rn.current,pinned:!0},Sr.current={x:p.clientX,y:p.clientY},(_=(x=p.currentTarget).setPointerCapture)==null||_.call(x,p.pointerId)},om=p=>{const x=Sr.current;if(!x)return;const _=Rn.current;Rn.current={pinned:!0,x:_.x+(p.clientX-x.x),y:_.y+(p.clientY-x.y)},x.x=p.clientX,x.y=p.clientY,Kt()},xc=p=>{var M,L;if(!Sr.current)return;Sr.current=null,(L=(M=p.currentTarget).releasePointerCapture)==null||L.call(M,p.pointerId);const{x,y:_}=Rn.current;
6pn({...mn(),actsX:Math.round(x),actsY:Math.round(_),actsPinned:!0})},lm=()=>{Rn.current={x:0,y:0,pinned:!1},pn({...mn(),actsX:0,actsY:0,actsPinned:!1}),Kt()},yc=m.useCallback(p=>{const x=En.current;if(!x)return;const _=Rn.current,M=ne().find(Y=>Y.id===oe.current),L=!!us.current||!!_s.current||!!me.current,C=M&&!L?H0(M,p):null;if(!C){x.style.visibility="hidden";return}const D=x.offsetWidth||76,I=x.offsetHeight||30,B=D/2,U=Math.min(Math.max((C.left+C.right)/2,B+4),p.width-B-4),ft=C.top-I-8,it=ft>=4?ft:Math.min(C.bottom+8,p.height-I-4),K=Math.min(Math.max(_.pinned?_.x:U-B,4),Math.max(4,p.width-D-4)),gt=Math.min(Math.max(_.pinned?_.y:it,4),Math.max(4,p.height-I-4));Rn.current={..._,x:K,y:gt},x.style.visibility="visible",x.style.transform="translate("+Math.round(K)+"px,"+Math.round(gt)+"px)"},[ne]),bc=m.useCallback(p=>{const x=ss.current,_=v.current;if(!x||!_)return;const M=_.timeScale().height();if(!(M>0)||p.width<=0){x.style.display="none";return}const L=[],C=K=>{var at;if(!K||K.tool!=="vline")return;const gt=(at=K.points[0])==null?void 0:at.time;if(!Number.isFinite(gt))return;const Y=p.toX(gt);Y===null||!Number.isFinite(Y)||Y<0||Y>p.width||L.push({x:Y,color:K.color,text:nx(gt,Bt.current,_n(S))})};for(const K of ne())C(K);if(C(me.current),x.style.display=L.length?"block":"none",!L.length)return;const D=window.devicePixelRatio||1,I=Math.round(p.width*D),B=Math.round(M*D);(x.width!==I||x.height!==B)&&(x.width=I,x.height=B),x.style.width=I/D+"px",x.style.height=B/D+"px";const U=x.getContext("2d");U.setTransform(D,0,0,D,0,0),U.clearRect(0,0,p.width,M),U.font=er,U.textBaseline="middle";const ft=Math.min(18,M-2),it=Math.max(1,(M-ft)/2);for(const K of L){if(!K.text)continue;const gt=ii(K.text)+12,Y=Math.min(Math.max(K.x-gt/2,0),p.width-gt);U.fillStyle=K.color,hr(U,Y,it,gt,ft,3),U.fill(),U.fillStyle="#0f1015",U.fillText(K.text,Y+6,it+ft/2)}},[S,ne]);m.useEffect(()=>{const p=Pe.current;if(!p)return;const x=_=>{const M=p.style.pointerEvents;p.style.pointerEvents="none";const L=document.elementFromPoint(_.clientX,_.clientY);p.style.pointerEvents=M,!(!L||L===p||p.contains(L))&&(_.preventDefault(),L.dispatchEvent(new WheelEvent("wheel",{deltaX:_.deltaX,deltaY:_.deltaY,deltaZ:_.deltaZ,deltaMode:_.deltaMode,clientX:_.clientX,clientY:_.clientY,screenX:_.screenX,screenY:_.screenY,ctrlKey:_.ctrlKey,shiftKey:_.shiftKey,altKey:_.altKey,metaKey:_.metaKey,bubbles:!0,cancelable:!0,composed:!0})))};return p.addEventListener("wheel",x,{passive:!1}),()=>p.removeEventListener("wheel",x)},[]);const wc=m.useCallback((p,x)=>{var I,B;if(qt.current!=="percent")return;const _=Fe.current.candles;if(!_.length)return;const M=(I=v.current)==null?void 0:I.timeScale().getVisibleLogicalRange();if(!M)return;const L=Math.min(_.length-1,Math.max(0,Math.ceil(M.from))),C=(B=_[L])==null?void 0:B.close;if(!Number.isFinite(C)||C<=0)return;const D=x.toY(C);D===null||!Number.isFinite(D)||(p.save(),p.globalAlpha=.5,p.strokeStyle="#8c93a8",p.lineWidth=1,p.setLineDash([4,4]),p.beginPath(),p.moveTo(0,D),p.lineTo(x.width,D),p.stroke(),p.setLineDash([]),p.font=er,p.textBaseline="middle",p.fillStyle="#8c93a8",p.fillText("0%",4,D-8),p.restore(
6))},[]),Nr=m.useCallback(()=>{const p=Pe.current,x=Ms();if(!p||!x)return;const _=window.devicePixelRatio||1,M=Math.round(x.width*_),L=Math.round(x.height*_);(p.width!==M||p.height!==L)&&(p.width=M,p.height=L),p.style.width=M/_+"px",p.style.height=L/_+"px";const C=p.getContext("2d");C.setTransform(_,0,0,_,0,0),C.clearRect(0,0,x.width,x.height);try{const D=v.current,I=g.current;D&&I&&(I.style.setProperty("--fut-axis-w",(D.priceScale("right").width()||0)+"px"),I.style.setProperty("--fut-axis-h",(D.timeScale().height()||0)+"px"))}catch{}wc(C,x);for(const D of ne())Uh(C,D,x,D.id===oe.current,D.id===ut.current,xe.current);if(me.current&&Uh(C,me.current,x,!1,!1,xe.current),Wt.orders||(uc(C,x),pc(C,x),Ja(C,x),tc(C,x)),bc(x),yc(x),Xv()){const D=p.getBoundingClientRect(),I=D.width>0?p.width/D.width:0,B=typeof window<"u"&&window.visualViewport?window.visualViewport.scale:1,U=["dpr    "+_,"плотн  "+I.toFixed(3)+(Math.abs(I-_)<.01?" ok":" !!"),"vvscale "+B,"буфер  "+p.width+"×"+p.height,"css    "+p.style.width+"×"+p.style.height,"факт   "+D.width.toFixed(2)+"×"+D.height.toFixed(2),"map    "+x.width.toFixed(2)+"×"+x.height.toFixed(2)];C.save(),C.font="10px monospace",C.textBaseline="top";const ft=12,it=4;let K=0;for(const gt of U)K=Math.max(K,C.measureText(gt).width);C.fillStyle="#000000",C.fillRect(0,0,K+it*2,U.length*ft+it*2),C.fillStyle="#FEE083",U.forEach((gt,Y)=>C.fillText(gt,it,it+Y*ft)),C.restore()}},[Ms,wc,uc,pc,Ja,tc,bc,yc,ne,Wt.orders]);m.useEffect(()=>{hs.current=Nr},[Nr]),m.useEffect(()=>(window.futChartDebug=()=>{const p=Ms(),x=v.current,_=Fe.current.candles;if(!p||!x)return"график ещё не готов";const M=x.timeScale().getVisibleLogicalRange(),L=C=>new Date(C*1e3).toISOString();return{interval:S,zone:Ne,appliedOffsetSec:Bt.current,barSeconds:Ks,pane:{width:p.width,height:p.height},visibleRange:M?{from:M.from,to:M.to}:null,bars:{count:_.length,first:_.length?L(_[0].time-Bt.current):null,last:_.length?L(_[_.length-1].time-Bt.current):null},drawings:He.current.map(C=>{const D=C.points[0],I=C.points[C.points.length-1];return{tool:C.tool,first:{time:L(D.time),x:p.toX(D.time),y:p.toY(D.price)},last:{time:L(I.time),x:p.toX(I.time),y:p.toY(I.price)}}})}},()=>{delete window.futChartDebug}),[Ms,S,Ne,Ks]);const Kt=m.useCallback(()=>{Ie.current||(Ie.current=requestAnimationFrame(()=>{Ie.current=0,(hs.current||Nr)()}))},[Nr]);m.useEffect(()=>{fe.current=Kt},[Kt]),m.useEffect(()=>{let p=0,x=0;const _=()=>{var L;for(const C of[Pe,ss]){const D=C.current;D&&D.width>0&&(D.width=D.width)}(L=fe.current)==null||L.call(fe)};p=requestAnimationFrame(()=>{x=requestAnimationFrame(_)});const M=setTimeout(_,500);return()=>{cancelAnimationFrame(p),cancelAnimationFrame(x),clearTimeout(M)}},[s,t]),m.useEffect(()=>{Kt()},[vt,ot,wt,xn,br,cc,bn,Oo,Ya,i,Kt]),m.useEffect(()=>{Q({coin:s,list:B0(s)}),Dt(null),Et(null),me.current=null,hi.current=[]},[s]),m.useEffect(()=>{Z.coin&&W0(Z.coin,Z.list)},[Z]);const cn=m.useCallback(p=>{Q(x=>({...x,list:typeof p=="function"?p(x.list):p}))},[]),hi=m.useRef([]),am=50,Hn=m.useCallback(p=>{hi.current.push(p??He.current),hi.current.length>am&&hi.current.shift()},[]);m.useEffect(()=>{hi.current=[]},[s]),m.useEffect(()=>{Qt&&Hn()},[Qt]);const _c=m.useCallback(()=>{const p=hi.current.pop();p&&(cn(p),Dt(x=>p.some(_=>_.id===x)?x:null),Et(x=>p.some(_=>_.id===x)?x:null),Kt())},[cn,Kt]),hn=p=>{var _;const x=(_=Pe.current)==null?void 0:_.getBoundingClientRect();return x?{x:p.clientX-x.left,y:p.clientY-x.top}:null},Kn=(p,x)=>{const _=hn(p);if(!_)return null;const M=x.fromX(_.x),L=x.fromY(_.y);return!Number.isFinite(M)||!Number.isFinite(L)?null:{time:M,price:L}};function Ii(){const p=me.current;if(me.current=null,ps.current=null,!p)return;const x=p.tool==="brush";if(p.tool==="brush"&&p.points.length<2){x||It(null),Kt();return}const _=F0(p);Hn(),cn(M=>[...M,_]),_e(M=>M.drawings?{...M,drawings:!1}:M),x||It(null),Dt(x?null:_.id),oe.current=x?null:_.id,_.tool==="text"&&Et(_.id),Kt()}const cm=!!wt||Zt||ue||!!us.current||!!Fn.current||!!An.current,kc=p=>{var ft,it,K;const x=Ms();if(!x)return;const _=hn(p),M=Kn(p,x);if(!_||!M)return;p.preventDefault(),(it=(ft=Pe.current)==null?void 0:ft.setPointerCapture)==null||it.call(ft,p.pointerId),p.shiftKey&&!_s.current&&!me.current&&(_s.current="measure",It("measure"));const L=oo(_s.current);if(L){if(L.id==="brush"){me.current={id:ul(),tool:"brush",points:[M],...hl("brush")},us.current={brush:!0},Kt();return}if(!me.current){ps.current={x:_.x,y:_.y,touch:p.pointerType!=="mouse"},me.current={id:ul(),tool:L.id,points:L.points===1?[M]:[M,M],...hl(L.id)},L.points===1?Ii():Kt();return}const gt=me.current;if(gt.points[gt.points.length-1]=M,gt.points.length>=L.points){Ii();return}gt.points.push(M),Kt();return}const C=qn.current;if(C&&_.x>=C.x&&_.x<=C.x+C.size&&_.y>=C.y&&_.y<=C.y+C.size){d&&d();return}const D=p.pointerType==="mouse"?0:uu,I=zi(x,_.x,_.y,D);
6if(I){if(I.close){const gt=As.current.filter(Y=>Y.key!==I.key);zo(gt,I.key);return}Fn.current={key:I.key,kind:I.kind,price:((K=As.current.find(gt=>gt.key===I.key))==null?void 0:K.price)??0},Dt(null),oe.current=null,Kt();return}const B=Oi(x,_.x,_.y,D);if(B){if(B.close){im(B.oid);return}const gt=Hs.current.find(Y=>Y.oid===B.oid);An.current={oid:B.oid,price:(gt==null?void 0:gt.price)??0},Dt(null),oe.current=null,Kt();return}const U=ne();for(let gt=U.length-1;gt>=0;gt--){const Y=mi(U[gt],x,_.x,_.y,D);if(Y){Dt(U[gt].id),oe.current=U[gt].id,us.current={id:U[gt].id,handle:Y.handle,from:M,fromPx:_,points:U[gt].points.map(at=>({...at})),before:U},Kt();return}}Dt(null),oe.current=null,Kt()};es.current=kc;const Mc=p=>{var Y,at;const x=Ms();if(!x)return;const _=Kn(p,x);if(_&&b.current){const dt=Fe.current.candles,kt=_.time+Bt.current,_t=mu(dt,kt),$t=dt[_t-1],Ae=dt[_t],Te=Ae?$t&&kt-$t.time<=Ae.time-kt?$t:Ae:$t;Te&&((Y=v.current)==null||Y.setCrosshairPosition(_.price,Te.time,b.current))}const M=Fn.current;if(M){const dt=hn(p);if(dt){const kt=x.fromY(dt.y);if(kt!==null&&kt>0){const _t=em,$t=M.kind==="tp"?rc:!rc;M.price=_t>0?$t?Math.max(kt,_t):Math.min(kt,_t):kt}}Kt();return}const L=An.current;if(L){const dt=hn(p);if(dt){const kt=x.fromY(dt.y);kt!==null&&kt>0&&(L.price=kt)}Kt();return}const C=us.current;if(C!=null&&C.brush&&me.current){const dt=Kn(p,x);dt&&me.current.points.push(dt),Kt();return}if(!C&&me.current&&me.current.points.length>=2){const dt=Kn(p,x);dt&&(me.current.points[me.current.points.length-1]=dt),Kt();return}if(!C)return;const D=Kn(p,x),I=hn(p);if(!D||!I)return;const B=He.current,U=B.findIndex(dt=>dt.id===C.id);if(U<0)return;const ft=B[U],it=dt=>{const kt=x.toX(dt.time),_t=x.toY(dt.price);if(kt===null||_t===null||!Number.isFinite(kt)||!Number.isFinite(_t))return dt;const $t=x.fromX(kt+(I.x-C.fromPx.x)),Ae=x.fromY(_t+(I.y-C.fromPx.y));return $t===null||Ae===null||!Number.isFinite(Ae)?dt:{time:$t,price:Ae}},K=C.handle>=0?{...ft,points:ft.points.map((dt,kt)=>kt===C.handle?D:dt)}:{...ft,points:C.points.map(it)};K.tool==="channel"&&(K.points=za(K.points)),Da(K.tool)&&(K.points=Xd(K.points));const gt=B.slice();gt[U]=K,He.current=gt,C.dirty=gt,(at=Fs.current)==null||at.call(Fs),Kt()};function jc(){var x,_,M,L;try{(_=(x=v.current)==null?void 0:x.clearCrosshairPosition)==null||_.call(x)}catch{}const p=Ve.current;if(p!==null)try{(L=(M=g.current)==null?void 0:M.releasePointerCapture)==null||L.call(M,p)}catch{}ts.current=!1,Ve.current=null,Os(!1)}function Sc(){const p=us.current;p!=null&&p.before&&(He.current=p.before),us.current=null,Fn.current=null,An.current=null,jc(),Kt()}const Nc=m.useCallback(p=>{var L;const x=(L=v.current)==null?void 0:L.timeScale();if(!x)return;const _=x.options().barSpacing||6,M=Math.max(.5,Math.min(100,_*p));Math.abs(M-_)<1e-6||x.applyOptions({barSpacing:M})},[]);Me.current=Mc;const hm=()=>{var p;(p=v.current)==null||p.clearCrosshairPosition()},Io=p=>{var D,I,B,U,ft;(I=(D=Pe.current)==null?void 0:D.releasePointerCapture)==null||I.call(D,p.pointerId),ts.current&&jc();const x=me.current,_=ps.current;if(x&&(_!=null&&_.touch)&&x.tool!=="brush"){const it=oo(x.tool),K=hn(p),gt=K&&Math.hypot(K.x-_.x,K.y-_.y)>=Kv;if(it&&gt&&x.points.length>=it.points){const Y=Ms(),at=Y?Kn(p,Y):null;at&&(x.points[x.points.length-1]=at),ps.current=null,Ii(),Kt();return}}const M=Fn.current;if(Fn.current=null,M){const it=((B=As.current.find(gt=>gt.key===M.key))==null?void 0:B.price)??0,K=As.current.map(gt=>gt.key===M.key?{...gt,price:M.price}:gt);M.price&&Math.abs(M.price-it)>1e-12&&(ac.current?(li.current={key:M.key,price:M.price},Ao({key:M.key,kind:M.kind,price:M.price})):zo(K,M.key)),Kt();return}const L=An.current;if(An.current=null,L){const it=((U=Hs.current.find(K=>K.oid===L.oid))==null?void 0:U.price)??0;if(L.price&&Math.abs(L.price-it)>1e-12)if(dc.current){an.current={oid:L.oid,price:L.price};const K=Hs.current.find(gt=>gt.oid===L.oid);Do({oid:L.oid,price:L.price,isBuy:!!(K!=null&&K.isBuy),size:(K==null?void 0:K.size)??0})}else mc(L.oid,L.price);Kt();return}const C=us.current;if(us.current=null,C!=null&&C.brush){Ii();return}if(C!=null&&C.dirty){const it=(ft=C.before)==null?void 0:ft.find(Y=>Y.id===C.id),K=C.dirty.find(Y=>Y.id===C.id);!it||!K||it.points.length!==K.points.length||it.points.some((Y,at)=>Y.time!==K.points[at].time||Y.price!==K.points[at].price)?(Hn(C.before),cn(C.dirty)):He.current=C.before}Kt()};Qe.current=Io;const um=p=>{const x=Ms(),_=hn(p);if(!x||!_)return;const M=ne();for(let L=M.length-1;L>=0;L--)if(mi(M[L],x,_.x,_.y)){Et(M[L].id);return}};m.useEffect(()=>{const p=g.current;
6if(!p)return;const x=Y=>{Kt();const at=Ms(),dt=hn(Y),kt=!!at&&!!dt&&dt.x>=0&&dt.y>=0&&dt.x<=at.width&&dt.y<=at.height;if(Ct.current=kt?Kn(Y,at):null,kt||(wr.current=null,kr.current=null,ut.current!==null&&(ut.current=null,Kt())),_s.current||us.current||!at||!dt)return;let _t=!1;if(kt){const $t=zi(at,dt.x,dt.y),Ae=$t?null:Oi(at,dt.x,dt.y),Te=qn.current,js=!!Te&&dt.x>=Te.x&&dt.x<=Te.x+Te.size&&dt.y>=Te.y&&dt.y<=Te.y+Te.size;Ri.current!==js&&(Ri.current=js,Kt()),_t=!!$t||!!Ae||js;const wn=$t||Ae;Pe.current&&(Pe.current.style.cursor=wn||js?js||wn.close?"pointer":"ns-resize":""),wr.current=$t,kr.current=Ae;let $n=null;const ui=ne();for(let Cr=ui.length-1;Cr>=0;Cr--)if(mi(ui[Cr],at,dt.x,dt.y)){$n=ui[Cr].id;break}_t=_t||$n!==null,$n!==ut.current&&(ut.current=$n,Kt())}_t!==V.current&&(V.current=_t,Xe(_t))},_=Y=>{const at=Ms(),dt=hn(Y);if(!at||!dt)return;for(const _t of ne())if(mi(_t,at,dt.x,dt.y))return;const kt=Wt.indicators?qv:as.current;for(const[_t,$t]of kt)for(const Ae of $t)if(cs(Ae,at,dt.x,dt.y)){Xt(_t);return}},M=Y=>{var kt,_t;if(_s.current||us.current||oe.current===null||(_t=(kt=Y.target)==null?void 0:kt.closest)!=null&&_t.call(kt,".fut-chart__acts"))return;const at=Ms(),dt=hn(Y);if(!(!at||!dt)&&!zi(at,dt.x,dt.y)&&!Oi(at,dt.x,dt.y)){for(const $t of ne())if(mi($t,at,dt.x,dt.y))return;oe.current=null,Dt(null),Kt()}},L=()=>{Ct.current=null,wr.current=null,kr.current=null,Ri.current=!1,ut.current=null,Kt()},C=Y=>{var js,wn,$n;if(Y.pointerType==="mouse"||_s.current)return;if(ts.current){Y.isPrimary===!1&&Sc();return}if(Y.isPrimary===!1)return;const at=Ms(),dt=(js=Pe.current)==null?void 0:js.getBoundingClientRect();if(!at||!dt)return;const kt={x:Y.clientX-dt.left,y:Y.clientY-dt.top},_t=uu,$t=qn.current;let Te=!!($t&&kt.x>=$t.x-_t&&kt.x<=$t.x+$t.size+_t&&kt.y>=$t.y-_t&&kt.y<=$t.y+$t.size+_t);if(!Te&&zi(at,kt.x,kt.y,_t)&&(Te=!0),!Te&&Oi(at,kt.x,kt.y,_t)&&(Te=!0),!Te){for(const ui of ne())if(mi(ui,at,kt.x,kt.y,_t)){Te=!0;break}}if(Te){Y.stopPropagation(),ts.current=!0,Ve.current=Y.pointerId,Os(!0),(wn=es.current)==null||wn.call(es,Y);try{($n=p.setPointerCapture)==null||$n.call(p,Y.pointerId)}catch{}}},D=Y=>{if(ts.current){if(Y.touches&&Y.touches.length>=2){Sc();return}Y.cancelable&&Y.preventDefault(),Y.stopPropagation()}},I=()=>{var Y,at;return((at=(Y=b.current)==null?void 0:Y.priceScale)==null?void 0:at.call(Y))??null},B=Y=>{var js,wn;if(!Y.touches||Y.touches.length!==2){ae.current=null;return}const at=I(),dt=Ms();if(!at||!dt)return;const kt=Math.abs(Y.touches[0].clientY-Y.touches[1].clientY);if(kt<12){ae.current=null;return}const _t=(js=at.getVisibleRange)==null?void 0:js.call(at);if(!_t||!Number.isFinite(_t.from)||!Number.isFinite(_t.to))return;const $t=(wn=Pe.current)==null?void 0:wn.getBoundingClientRect();if(!$t)return;const Ae=(Y.touches[0].clientY+Y.touches[1].clientY)/2-$t.top,Te=dt.fromY(Ae);ae.current={dist:kt,from:_t.from,to:_t.to,focal:Number.isFinite(Te)?Te:(_t.from+_t.to)/2}},U=Y=>{var Te,js;const at=ae.current;if(!at||!Y.touches||Y.touches.length!==2)return;const dt=I();if(!dt)return;const kt=Math.abs(Y.touches[0].clientY-Y.touches[1].clientY);if(kt<12)return;const _t=kt/at.dist,$t=at.focal-(at.focal-at.from)/_t,Ae=at.focal+(at.to-at.focal)/_t;if(Ae>$t)try{(Te=dt.setAutoScale)==null||Te.call(dt,!1),(js=dt.setVisibleRange)==null||js.call(dt,{from:$t,to:Ae})}catch{}},ft=Y=>{(!Y.touches||Y.touches.length<2)&&(ae.current=null)},it=Y=>ts.current&&Y.pointerId===Ve.current,K=Y=>{var at;it(Y)&&((at=Me.current)==null||at.call(Me,Y))},gt=Y=>{var at;it(Y)&&((at=Qe.current)==null||at.call(Qe,Y))};return p.addEventListener("pointerdown",C,!0),p.addEventListener("touchmove",D,{capture:!0,passive:!1}),p.addEventListener("touchstart",B,{passive:!0}),p.addEventListener("touchmove",U,{passive:!0}),p.addEventListener("touchend",ft),p.addEventListener("touchcancel",ft),p.addEventListener("pointermove",K),p.addEventListener("pointerup",gt),p.addEventListener("pointercancel",gt),p.addEventListener("pointermove",x),p.addEventListener("pointerleave",L),p.addEventListener("pointerdown",M),p.addEventListener("dblclick",_),p.addEventListener("wheel",Kt,{passive:!0}),()=>{p.removeEventListener("pointerdown",C,!0),p.removeEventListener("touchmove",D,{capture:!0}),p.removeEventListener("touchstart",B),p.removeEventListener("touchmove",U),p.removeEventListener("touchend",ft),p.removeEventListener("touchcancel",ft),p.removeEventListener("pointermove",K),p.removeEventListener("pointerup",gt),p.removeEventListener("pointercancel",gt),p.removeEventListener("pointermove",x),p.removeEventListener("pointerleave",L),p.removeEventListener("pointerdown",M),p.removeEventListener("dblclick",_),p.removeEventListener("wheel",Kt)}},[Ms,Kt,zi,Oi,cs,ne,Wt.indicators]),m.useEffect(()=>{const p=g.current;
6if(!p)return;let x=0,_=0,M=null;const L=()=>{var ft;const I=b.current,B=Fe.current.candles;if(!I||!B.length)return null;const U=(ft=B[B.length-1])==null?void 0:ft.close;return Number.isFinite(U)?I.priceToCoordinate(U):null},C=()=>{var B;const I=L();I!==M&&(M=I,(B=hs.current)==null||B.call(hs)),x=performance.now()<_?requestAnimationFrame(C):0},D=()=>{_=performance.now()+500,!x&&(M=L(),x=requestAnimationFrame(C))};return p.addEventListener("pointerdown",D),p.addEventListener("pointermove",D),p.addEventListener("pointerup",D),p.addEventListener("wheel",D,{passive:!0}),p.addEventListener("dblclick",D),()=>{x&&cancelAnimationFrame(x),p.removeEventListener("pointerdown",D),p.removeEventListener("pointermove",D),p.removeEventListener("pointerup",D),p.removeEventListener("wheel",D),p.removeEventListener("dblclick",D)}},[]);const Bo=m.useCallback(()=>{var p;(p=v.current)==null||p.timeScale().scrollToRealTime(),Kt()},[Kt]);m.useEffect(()=>{const p=x=>{var M,L,C;const _=(M=document.activeElement)==null?void 0:M.tagName;if(!(_==="INPUT"||_==="TEXTAREA")){if((x.ctrlKey||x.metaKey)&&(x.code==="KeyZ"||((L=x.key)==null?void 0:L.toLowerCase())==="z")){x.preventDefault(),_c();return}if(x.altKey&&!x.ctrlKey&&!x.metaKey&&x.code==="KeyR"){x.preventDefault(),Bo();return}if(x.altKey&&!x.ctrlKey&&!x.metaKey&&Bh[x.code]){x.preventDefault();const D=Bh[x.code],I=Ct.current;if(me.current=null,I&&((C=oo(D))==null?void 0:C.points)===1){me.current={id:ul(),tool:D,points:[I],...hl(D)},Ii();return}It(B=>B===D?null:D),Dt(null),oe.current=null,Kt();return}if(x.key==="Escape"){me.current&&(me.current=null,Kt()),It(null),Dt(null),oe.current=null;return}if((x.key==="Delete"||x.key==="Backspace")&&oe.current){const D=oe.current;Hn(),cn(I=>I.filter(B=>B.id!==D)),Dt(null),oe.current=null,Et(null)}}};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[cn,Kt,_c,Bo]),m.useEffect(()=>{var p;(p=v.current)==null||p.priceScale("right").applyOptions({mode:mt==="log"?Xi.Logarithmic:mt==="percent"?Xi.Percentage:Xi.Normal,autoScale:pt}),Kt()},[mt,pt,s,S,Kt]),m.useEffect(()=>{var _,M;const p=Ht-Bt.current;if(!p)return;const x=Fe.current;if(!x.candles.length){Bt.current=Ht;return}x.candles=x.candles.map(L=>({...L,time:L.time+p})),x.volumes=x.volumes.map(L=>({...L,time:L.time+p})),(_=Ze.current)==null||_.call(Ze),(M=w.current)==null||M.setData(x.volumes),Bt.current=Ht},[Ht]),m.useEffect(()=>{const p=()=>N(ix(Tt));p();const x=window.setInterval(p,1e3);return()=>window.clearInterval(x)},[Tt]),m.useEffect(()=>{try{localStorage.setItem(wu,Ne)}catch{}},[Ne]),m.useEffect(()=>{if(!nt)return;const p=_=>{$.current&&!$.current.contains(_.target)&&bt(!1)},x=_=>{_.key==="Escape"&&bt(!1)};return document.addEventListener("mousedown",p),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",x)}},[nt]),m.useEffect(()=>{if(!We)return;const p=_=>{ze.current&&!ze.current.contains(_.target)&&Re(!1)},x=_=>{_.key==="Escape"&&Re(!1)};return document.addEventListener("mousedown",p),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",x)}},[We]),m.useEffect(()=>{if(!de)return;const p=_=>{_.key==="Escape"&&!We&&!nt&&!st&&ie(!1)},x=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",p),()=>{document.body.style.overflow=x,document.removeEventListener("keydown",p)}},[de,We,nt,st]);const Wo=Vt.filter(p=>{var x;return(x=ls(p.id))==null?void 0:x.pane}),Cc=(p,x)=>{Ee(_=>vv(_,p,x))},rs=Mt??jt,dm=rs?rs.close>=rs.open:!0,Tc=rs?rs.close-rs.open:0,Lc=rs&&rs.open?Tc/rs.open*100:0,fm=zv(F),mm=p=>(p>=0?"+":"")+lt(p);return r.jsxs("div",{className:"fut-chart"+(n?" fut-chart--fill":"")+(de?" fut-chart--expanded":""),children:[r.jsxs("div",{className:"fut-chart__bar",children:[y.map(p=>r.jsx("button",{type:"button",className:"fut-chart__interval"+(p===S?" is-active":""),onClick:()=>tm(p),children:p},p)),r.jsxs("div",{className:"fut-chart__typewrap",ref:$,children:[r.jsx(Rt.Tooltip,{title:h("Chart type")+" · "+h(Vr(F)
6)+(h(Vr(F))===Vr(F)?"":" ("+Vr(F)+")"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsxs("button",{type:"button",className:"fut-chart__type"+(nt?" is-open":""),onClick:()=>bt(p=>!p),"aria-label":h("Chart type"),children:[au(F),r.jsx("i",{className:"fut-chart__type-caret"})]})}),nt&&r.jsx("div",{className:"fut-chart__types fut-scroll",role:"listbox",children:Ua.map(p=>r.jsxs("button",{type:"button",role:"option","aria-selected":p.id===F,className:p.id===F?"is-active":"",onClick:()=>{A(p.id),bt(!1)},children:[au(p.id),r.jsxs("b",{children:[h(p.title),h(p.title)!==p.title&&r.jsx("em",{children:p.title})]})]},p.id))})]}),r.jsxs("button",{type:"button",className:"fut-chart__indicators"+(Vt.length?" is-active":""),onClick:()=>vn(!0),children:[r.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M4 17l4-6 4 3 4-7 4 4",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("span",{children:h("Indicators")}),Vt.length>0&&r.jsx("i",{children:Vt.length})]}),r.jsx("button",{type:"button",className:"fut-chart__expand",onClick:()=>ie(p=>!p),title:de?h("Exit full screen"):h("Full screen"),"aria-label":de?h("Exit full screen"):h("Full screen"),children:de?r.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M9 3v4a2 2 0 0 1-2 2H3M15 3v4a2 2 0 0 0 2 2h4M9 21v-4a2 2 0 0 0-2-2H3M15 21v-4a2 2 0 0 1 2-2h4",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}):r.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M3 9V5a2 2 0 0 1 2-2h4M21 9V5a2 2 0 0 0-2-2h-4M3 15v4a2 2 0 0 0 2 2h4M21 15v4a2 2 0 0 1-2 2h-4",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),r.jsxs("div",{className:"fut-chart__work",children:[r.jsx(X0,{compact:t,active:wt,count:vt.length,onBack:Bo,hide:Wt,onToggleHide:p=>{Ue(p),Dt(null),oe.current=null,ut.current=null,Kt()},onPick:p=>{me.current=null,It(p),Dt(null),oe.current=null,p&&_e(x=>({...x,drawings:!1})),Kt()},onRemoveAll:()=>{Hn(),cn([]),Dt(null),oe.current=null,Et(null)}}),r.jsxs("div",{className:"fut-chart__canvas",ref:g,style:n||de?void 0:{height:e},onMouseMove:zs,onMouseLeave:gs,children:[t&&r.jsxs("div",{className:"fut-chart__zoom",children:[r.jsx("button",{type:"button","aria-label":h("Zoom in"),onPointerDown:p=>p.preventDefault(),onClick:()=>Nc(1.4),children:"+"}),r.jsx("button",{type:"button","aria-label":h("Zoom out"),onPointerDown:p=>p.preventDefault(),onClick:()=>Nc(1/1.4),children:"−"})]}),r.jsx("canvas",{ref:Pe,className:"fut-chart__draw-layer"+(cm?" is-live":"")+(wt||Zt?" is-drawing":""),onPointerDown:kc,onPointerMove:Mc,onPointerLeave:hm,onPointerUp:Io,onPointerCancel:Io,onDoubleClick:um}),r.jsx("canvas",{ref:ss,className:"fut-chart__time-layer"}),ot&&r.jsxs("div",{className:"fut-chart__acts",ref:En,children:[r.jsx("span",{className:"fut-chart__acts-grip",title:h("Drag to move the panel. Double click returns it to the shape."),onPointerDown:rm,onPointerMove:om,onPointerUp:xc,onPointerCancel:xc,onDoubleClick:lm,children:r.jsx("svg",{width:"6",height:"14",viewBox:"0 0 6 14","aria-hidden":"true",children:[2,7,12].map(p=>r.jsxs("g",{fill:"currentColor",children:[r.jsx("circle",{cx:"1.5",cy:p,r:"1.1"}),r.jsx("circle",{cx:"4.5",cy:p,r:"1.1"})]},p))})}),r.jsx("button",{type:"button",title:h("Settings"),"aria-label":h("Settings"),onClick:()=>Et(ot),children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("path",{d:"M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 9 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4.6 9a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.
66 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("button",{type:"button",className:"is-danger",title:h("Delete"),"aria-label":h("Delete"),onClick:()=>{const p=oe.current;p&&(Hn(),cn(x=>x.filter(_=>_.id!==p)),Dt(null),oe.current=null,Et(null),Kt())},children:r.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),r.jsxs("div",{className:"fut-chart__legend",children:[r.jsxs("span",{className:"fut-chart__legend-name",children:[zt(s),r.jsx("em",{children:"·"}),S]}),r.jsx("i",{className:"fut-chart__legend-dot"+(ce?" is-live":""),title:ce?h("Live data"):h("No connection")}),rs&&r.jsxs("span",{className:"fut-chart__legend-ohlc is-"+(dm?"up":"down"),children:[fm&&r.jsxs(r.Fragment,{children:[r.jsx("em",{children:"O"}),lt(rs.open),r.jsx("em",{children:"H"}),lt(rs.high),r.jsx("em",{children:"L"}),lt(rs.low)]}),r.jsx("em",{children:"C"}),lt(rs.close),r.jsxs("b",{children:[mm(Tc)," (",Lc>=0?"+":"",Lc.toFixed(2),"%",")"]})]}),P&&Vt.some(p=>{var x;return!((x=ls(p.id))!=null&&x.pane)})&&r.jsx("span",{className:"fut-chart__legend-ind",children:Vt.filter(p=>{var x;return!((x=ls(p.id))!=null&&x.pane)}).map(p=>r.jsxs("span",{className:"fut-chart__legend-row"+(p.hidden||Wt.indicators?" is-hidden":""),children:[r.jsx("button",{type:"button",className:"fut-chart__legend-vals",title:h("Settings"),onClick:()=>Xt(p.key),children:le(p.key).map((x,_)=>{const M=rs?x.data.find(L=>L.time===rs.time):x.data[x.data.length-1];return r.jsxs("span",{style:{color:x.color},children:[x.title,M?" "+lt(M.value):" —"]},_)})}),r.jsxs("span",{className:"fut-chart__legend-acts",children:[r.jsx("button",{type:"button",title:p.hidden?h("Show indicator"):h("Hide indicator"),"aria-label":p.hidden?h("Show indicator"):h("Hide indicator"),onClick:()=>Ee(x=>x.map(_=>_.key===p.key?{..._,hidden:!_.hidden}:_)),children:p.hidden?r.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M3 3l18 18M10.6 6.2A9.6 9.6 0 0 1 12 6c5 0 9 4.5 9 6 0 .8-1.1 2.4-2.9 3.7M6.5 8.3C4.6 9.6 3 11.2 3 12c0 1.5 4 6 9 6 1.1 0 2.1-.2 3-.5M9.9 9.9a3 3 0 0 0 4.2 4.2",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})}):r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M3 12s4-6 9-6 9 6 9 6-4 6-9 6-9-6-9-6z",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("circle",{cx:"12",cy:"12",r:"2.5",stroke:"currentColor",strokeWidth:"1.8"})]})}),r.jsx("button",{type:"button",title:h("Settings"),"aria-label":h("Settings"),onClick:()=>Xt(p.key),children:r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("path",{d:"M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 9 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4.6 9a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.
66 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("button",{type:"button",className:"is-danger",title:h("Delete"),"aria-label":h("Delete"),onClick:()=>{Ee(x=>x.filter(_=>_.key!==p.key)),Oe===p.key&&Xt(null)},children:r.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]},p.key))}),Vt.some(p=>{var x;return!((x=ls(p.id))!=null&&x.pane)})&&r.jsx("span",{className:"fut-chart__legend-foot",children:r.jsxs("button",{type:"button",className:"fut-chart__legend-toggle",title:P?h("Hide indicators"):h("Show indicators"),"aria-label":P?h("Hide indicators"):h("Show indicators"),onClick:()=>G(p=>!p),children:[r.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:P?"M6 15l6-6 6 6":"M6 9l6 6 6-6",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})}),!P&&r.jsx("i",{children:Vt.filter(p=>{var x;return!((x=ls(p.id))!=null&&x.pane)}).length})]})})]}),Wo.map((p,x)=>{const _=we[x+1];if(!_)return null;const M=le(p.key);if(!(!M.length||M.every(B=>!(B.data??[]).length)))return null;const C=ls(p.id),D=Fe.current.candles.length,I=pv(C,p);return r.jsx("div",{className:"fut-chart__pane-empty",style:{top:_.top+"px",height:_.height+"px"},children:r.jsx("span",{children:I>0?h("Not enough history: {need} bars needed, {have} available. Switch to a smaller timeframe or reduce the settings.",{need:I,have:D}):h("Not enough data to build this indicator.")})},p.key+"_empty")}),Wo.map((p,x)=>{const _=we[x+1];if(!_)return null;const M=ls(p.id);return r.jsxs("div",{className:"fut-chart__pane-head"+(nn===x+1?" is-hover":""),style:{top:_.top+"px"},children:[r.jsxs("button",{type:"button",className:"fut-chart__pane-title",title:h("Settings"),onClick:()=>Xt(p.key),children:[r.jsx("b",{children:h((M==null?void 0:M.title)??p.id)}),le(p.key).map((L,C)=>{const D=rs?L.data.find(I=>I.time===rs.time):L.data[L.data.length-1];return r.jsxs("span",{style:{color:L.color},children:[L.title,D?" "+lt(D.value):" —"]},C)})]}),r.jsxs("span",{className:"fut-chart__pane-acts",children:[r.jsx("button",{type:"button",title:h("Move up"),"aria-label":h("Move up"),disabled:x===0,onClick:()=>Cc(p.key,-1),children:r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M12 19V5M5 12l7-7 7 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsx("button",{type:"button",title:h("Move down"),"aria-label":h("Move down"),disabled:x===Wo.length-1,onClick:()=>Cc(p.key,1),children:r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M12 5v14M5 12l7 7 7-7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsx("button",{type:"button",title:h("Settings"),"aria-label":h("Settings"),onClick:()=>Xt(p.key),children:r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("path",{d:"M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 9 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4.6 9a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.
66 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("button",{type:"button",className:"is-danger",title:h("Delete"),"aria-label":h("Delete"),onClick:()=>{Ee(L=>L.filter(C=>C.key!==p.key)),Oe===p.key&&Xt(null)},children:r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]},p.key)}),E&&r.jsxs("div",{className:"fut-chart__loading",children:[h("Loading"),"…"]}),!E&&Bn&&r.jsxs("div",{className:"fut-chart__more",children:[h("Loading"),"…"]})]})]}),r.jsxs("div",{className:"fut-chart__foot",children:[r.jsx("div",{className:"fut-chart__ranges",children:$v.filter(p=>!t||Yv.includes(p.id)).map(p=>r.jsx("button",{type:"button",className:"fut-chart__range"+(H===p.id?" is-active":""),onClick:()=>Jf(p),children:p.id},p.id))}),r.jsx("span",{className:"fut-chart__foot-sep"}),r.jsxs("div",{className:"fut-chart__gotowrap",ref:Yt,children:[r.jsx(Rt.Tooltip,{title:h("Go to date"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-chart__goto"+(st?" is-open":""),onClick:()=>Ot(p=>!p),"aria-label":h("Go to date"),children:r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M4 6.5A1.5 1.5 0 0 1 5.5 5h13A1.5 1.5 0 0 1 20 6.5V10H4V6.5zM4 10v8.5A1.5 1.5 0 0 0 5.5 20H11M8 3v4M16 3v4",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M14 17h6m0 0-2.4-2.4M20 17l-2.4 2.4",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),st&&r.jsxs("div",{className:"fut-chart__gotobox",children:[r.jsx("input",{type:"date",value:St,max:new Date().toISOString().slice(0,10),onChange:p=>At(p.target.value),onKeyDown:p=>{p.key==="Enter"&&sc(St)},autoFocus:!0}),r.jsx("button",{type:"button",disabled:!St,onClick:()=>sc(St),children:h("Go")})]})]}),r.jsxs("div",{className:"fut-chart__tzwrap",ref:ze,children:[r.jsx(Rt.Tooltip,{title:h("Chart time zone"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsxs("button",{type:"button",className:"fut-chart__tz"+(We?" is-open":""),onClick:()=>Re(p=>!p),children:[r.jsx("span",{children:he}),r.jsxs("i",{children:["(",ku(Tt),")"]})]})}),We&&r.jsx("div",{className:"fut-chart__zones fut-scroll",role:"listbox",children:bu.map(p=>r.jsxs("button",{type:"button",role:"option","aria-selected":Ne===p.id,className:Ne===p.id?"is-active":"",onClick:()=>{se(p.id),Re(!1)},children:[r.jsx("b",{children:h(p.title)}),r.jsx("i",{children:ku(_u(p.id))})]},p.id))})]}),r.jsx("span",{className:"fut-chart__foot-sep"}),r.jsx(Rt.Tooltip,{title:h("Percentage scale"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-chart__mode"+(mt==="percent"?" is-active":""),onClick:()=>Pt(p=>p==="percent"?"normal":"percent"),children:"%"})}),r.jsx(Rt.Tooltip,{title:h("Logarithmic scale"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-chart__mode"+(mt==="log"?" is-active":""),onClick:()=>Pt(p=>p==="log"?"normal":"log"),children:"log"})}),r.jsx(Rt.Tooltip,{title:h("Fit the price scale to visible candles"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-chart__mode"+(pt?" is-active":""),onClick:()=>te(p=>!p),children:"auto"})})]}),qs&&r.jsx(_v,{list:Vt,linesOf:le,onChange:Ee,onEdit:p=>{vn(!1),Xt(p)},onClose:()=>vn(!1)}),Oe&&Vt.some(p=>p.key===Oe)&&r.jsx(kv,{instance:Vt.find(p=>p.key===Oe),lines:le(Oe),onChange:p=>Ee(x=>x.map(_=>_.key===p.key?p:_)),onDelete:()=>{Ee(p=>p.filter(x=>x.key!==Oe)),Xt(null)},onClose:()=>Xt(null)}),ai&&r.jsx(nu,{kind:ai.kind,coin:s,price:ai.price,onCancel:()=>{li.current=null,Ao(null),Kt()},onConfirm:(p,x)=>{x&&pn({...mn(),tpslConfirm:!1}),li.current={key:ai.key,price:p},Ao(null),zo(As.current.map(_=>_.key===ai.key?{..._,price:p}:_),ai.key)}}),Un&&r.jsx(nu,{coin:s,price:Un.price,title:h("Move the order"),label:Un.isBuy?h("Buy"):h("Sell"),note:(Un.isBuy?h("Buy"):h("Sell"))+" · "+lt(Un.size)+" "+zt(s),onCancel:()=>{an.current=null,Do(null),Kt()},onConfirm:(p,x)=>{x&&pn({...mn(),orderMoveConfirm:!1}),an.current={oid:Un.oid,price:p},Do(null),mc(Un.oid,p)}}),ns&&r.jsx(Mv,{drawing:ns,offsetSeconds:Ht,onChange:p=>{V0(p.tool,p),cn(x=>x.map(_=>_.id===p.id?p:_))},onDelete:()=>{Hn(),cn(p=>p.filter(x=>
6x.id!==ns.id)),Et(null),Dt(null),oe.current=null},onClose:()=>Et(null)})]})}const rx=[1,10,100,1e3],Sf="futures_book_unit";function ox(){try{return localStorage.getItem(Sf)==="coin"?"coin":"usd"}catch{return"usd"}}function lx(s){try{localStorage.setItem(Sf,s)}catch{}}const $r=20,ax=236,cx=100;function ju(s,t,e){if(!(t!=null&&t.px))return s;const n=parseFloat(t.px);if(!Number.isFinite(n))return s;const i=a=>{const c=parseFloat(a.px);return e?c>n:c<n},o=s.filter(a=>!i(a));return o.length&&parseFloat(o[0].px)===n?[t,...o.slice(1)]:[t,...o]}function Su(s,t,e,n,i){var d;if(s.length>=i)return s;const o=parseFloat(((d=s[s.length-1])==null?void 0:d.px)??NaN),l=f=>{const g=parseFloat(f.px);return Number.isFinite(g)?Number.isFinite(o)?n?g<o:g>o:!0:!1},a=[...s,...(e??[]).filter(l)];if(a.length>=i)return a;const c=new Set(a.map(f=>f.px)),u=t.filter(f=>l(f)&&!c.has(f.px)).map(f=>({...f,stale:!0}));return[...a,...u].sort((f,g)=>n?parseFloat(g.px)-parseFloat(f.px):parseFloat(f.px)-parseFloat(g.px))}function hx(s){var n;let t=0;for(let i=1;i<s.length;i++){const o=Math.abs(parseFloat(s[i].px)-parseFloat(s[i-1].px));o>0&&(t===0||o<t)&&(t=o)}if(t>0)return ux(t);const e=parseFloat(((n=s[0])==null?void 0:n.px)??0);return e?Math.pow(10,Math.floor(Math.log10(e))-4):0}function ux(s){const t=Math.floor(Math.log10(s)),e=s/Math.pow(10,t),n=e<1.5?1:e<3.5?2:e<7.5?5:10;return parseFloat((n*Math.pow(10,t)).toPrecision(12))}function dx(s){if(!(s>0))return 2;const t=Math.floor(Math.log10(s)+1e-9);return Math.max(0,Math.min(8,-t))}function xo(s,t){const e=typeof s=="number"?s:parseFloat(s);return Number.isFinite(e)?yo(e.toFixed(t)):"—"}function la(s){return xo(s,Math.abs(parseFloat(s)||0)>=1e4?0:2)}function fx(s,t,e){if(!t||t<=0)return s;const n=new Map;for(const i of s){const o=parseFloat(i.px),l=parseFloat(i.sz);if(!Number.isFinite(o)||!Number.isFinite(l))continue;const a=e?Math.floor(o/t)*t:Math.ceil(o/t)*t,c=a.toFixed(10),u=n.get(c);u?(u.sz+=l,u.stale=u.stale&&!!i.stale):n.set(c,{px:a,sz:l,stale:!!i.stale})}return Array.from(n.values()).map(i=>({px:String(i.px),sz:String(i.sz),stale:i.stale}))}const mx=ad.memo(function({side:t,index:e,px:n,sz:i,value:o,totalUsd:l,totalCoin:a,depth:c,unit:u,decimals:d,stale:f,onPick:g,onHover:v}){return r.jsxs("div",{className:"fut-book__row fut-book__row--"+t+(f?" is-stale":""),onClick:()=>!f&&g&&g(n),onMouseEnter:b=>{var y;const w=b.currentTarget.getBoundingClientRect(),k=(y=b.currentTarget.closest(".fut-book"))==null?void 0:y.getBoundingClientRect();v(t,e,{top:Math.round(w.top),panelLeft:Math.round(k?k.left:0)})},onMouseMove:b=>{var y;const w=b.currentTarget.getBoundingClientRect(),k=(y=b.currentTarget.closest(".fut-book"))==null?void 0:y.getBoundingClientRect();v(t,e,{top:Math.round(w.top),panelLeft:Math.round(k?k.left:0)})},children:[r.jsx("span",{className:"fut-book__depth",style:{width:c+"%"}}),r.jsx("span",{className:"fut-book__px",children:xo(n,d)}),r.jsx("span",{className:"fut-book__sz",children:u==="usd"?la(o):lt(i)}),r.jsx("span",{className:"fut-book__total",children:u==="usd"?la(l):lt(a)})]})});function Nu({coin:s,rows:t=12,compact:e=!1,fill:n=!1,onPickPrice:i}){var mt,Pt,qt,pt,te,Tt,Ht;const o=m.useRef(null),l=m.useRef(null),a=m.useRef(null),c=m.useRef(0),u=m.useRef(0),[d,f]=m.useState(null),[g,v]=m.useState(null),[b,w]=m.useState(1),[k,y]=m.useState(ox);m.useEffect(()=>{lx(k)},[k]);const[S,j]=m.useState(null),E=m.useCallback((xt,Bt,re)=>{j(Vt=>Vt&&Vt.side===xt&&Vt.index===Bt&&Vt.top===re.top&&Vt.panelLeft===re.panelLeft?Vt:{side:xt,index:Bt,top:re.top,panelLeft:re.panelLeft})},[]),z=m.useCallback(()=>{a.current=null,o.current&&f(o.current),l.current&&v(l.current)},[]),F=m.useCallback(()=>{a.current===null&&(a.current=requestAnimationFrame(z))},[z]);sn("bbo",{coin:s},xt=>{l.current=xt,F()},!!s),m.useEffect(()=>{o.current=null,l.current=null,f(null),v(null),w(1)},[s]),m.useEffect(()=>()=>{a.current!==null&&cancelAnimationFrame(a.current)},[]);const A=(d==null?void 0:d.levels)??[[],[]],J=((mt=g==null?void 0:g.bbo)==null?void 0:mt[0])??null,O=((Pt=g==null?void 0:g.bbo)==null?void 0:Pt[1])??null,yt=((qt=d==null?void 0:d.coarse)==null?void 0:qt.levels)??[[],[]],P=u.current?A[0]??[]:ju(A[0]??[],J,!0),G=u.current?A[1]??[]:ju(A[1]??[],O,!1),nt=Su(P,A[0]??[],yt[0]??[],!0,$r),bt=Su(G,A[1]??[],yt[1]??[],!1,$r);m.useEffect(()=>{if(!s||!d)return;const xt=(re,Vt)=>re.length<$r/3&&!!Vt;if(!xt(P,J)&&!xt(G,O))return;const Bt=Date.now();Bt-c.current<300||(c.current=Bt,Ai.send({op:"refresh",channel:"book",coin:s,sig:u.current}))},[s,d,g]);const $=parseFloat(((pt=nt[0])==null?void 0:pt.px)??0),ht=parseFloat(((te=bt[0])==null?void 0:te.px)??0),tt=$&&ht?($+ht)/2:$||ht,H=ht&&$?ht-$:0,et=$?H/$*100:0,rt=m.useMemo(()=>({current:0}),[s]),Nt=m.useMemo(()=>hx((A[1]??[]).length>1?A[1]:A[0]??[]),[A]);!u.current&&Nt>0&&(rt.current=Nt);const X=rt.current||Nt,st=m.useMemo(()=>
6{var Ee,qe,we,ye;const xt=parseFloat(((qe=(Ee=A[0])==null?void 0:Ee[0])==null?void 0:qe.px)??0)||parseFloat(((ye=(we=A[1])==null?void 0:we[0])==null?void 0:ye.px)??0);if(!(xt>0)||b<=1||!(X>0))return 0;const Bt=Math.floor(Math.log10(xt))+1,re=Math.floor(Math.log10(X*b)),Vt=Bt-re;return Vt>=2&&Vt<=5?Vt:0},[b,s,X,A]);u.current=st,sn("book",{coin:s,sig:st},xt=>{o.current=xt,F()},!!s);const Ot=m.useRef(null),[St,At]=m.useState(0),Yt=!!d,Mt=n&&St?St:t,Gt=n?Math.max(Mt,$r):t;m.useEffect(()=>{if(!n||!Yt)return;const xt=Ot.current;if(!xt)return;const Bt=()=>{const Vt=xt.querySelector(".fut-book__side");if(!Vt)return;const Ee=Vt.querySelector(".fut-book__row"),qe=(Ee==null?void 0:Ee.getBoundingClientRect().height)||17,we=Vt.clientHeight;if(!we||!qe)return;const ye=Math.max(4,Math.min(40,Math.floor(we/qe)));At(fe=>fe===ye?fe:ye)};Bt();const re=new ResizeObserver(Bt);return re.observe(xt),()=>re.disconnect()},[n,Yt]);const jt=X*b,Be=dx(jt),de=(xt,Bt)=>{const re=fx(xt,jt,Bt).slice(0,Gt);let Vt=0,Ee=0;return re.map(qe=>{const we=parseFloat(qe.px),ye=parseFloat(qe.sz);return Vt+=ye,Ee+=ye*we,{px:we,sz:ye,value:ye*we,totalCoin:Vt,totalUsd:Ee,avgPx:Vt?Ee/Vt:we,distPct:tt?Math.abs((we-tt)/tt)*100:0,stale:!!qe.stale}})},ie=m.useMemo(()=>de(nt,!0),[nt,jt,Gt,tt]),ce=m.useMemo(()=>de(bt,!1),[bt,jt,Gt,tt]),Ne=Math.max(((Tt=ie[ie.length-1])==null?void 0:Tt.totalUsd)??0,((Ht=ce[ce.length-1])==null?void 0:Ht.totalUsd)??0,1e-6),se=zt(s),We=k==="usd"?"USDC":se,Re=xt=>xt.length>=Mt?xt:xt.concat(Array.from({length:Mt-xt.length},()=>null)),ze=(xt,Bt,re)=>xt?r.jsx(mx,{side:Bt,index:re,px:xt.px,sz:xt.sz,value:xt.value,totalUsd:xt.totalUsd,totalCoin:xt.totalCoin,depth:Math.min(100,xt.totalUsd/Ne*100),unit:k,decimals:Be,stale:!!xt.stale,onPick:i,onHover:E},Bt+"-"+re):r.jsx("div",{className:"fut-book__row fut-book__row--empty","aria-hidden":"true",children:r.jsx("span",{children:" "})},Bt+"-empty-"+re),he=S?(S.side==="ask"?ce:ie)[S.index]??null:null,N=m.useMemo(()=>{if(!S)return null;const xt=typeof window<"u"?window.innerWidth:0,Bt=typeof window<"u"?window.innerHeight:0,re=Math.max(8,Math.min(S.top,Bt-cx));return S.panelLeft>=ax+20?{top:re,right:xt-S.panelLeft+10,left:"auto"}:{top:re,left:S.panelLeft+8,right:"auto"}},[S]);return d?r.jsxs("div",{ref:Ot,className:"fut-book"+(e?" fut-book--compact":"")+(n?" fut-book--fill":""),onMouseLeave:()=>j(null),children:[he&&ld.createPortal(r.jsxs("div",{className:"fut-book__hint fut-book__hint--fixed",style:N,children:[r.jsxs("div",{children:[r.jsx("span",{children:h("Distance from mid")}),r.jsxs("b",{children:[he.distPct.toFixed(4),"%"]})]}),r.jsxs("div",{children:[r.jsx("span",{children:h("Average price")}),r.jsx("b",{children:lt(he.avgPx)})]}),r.jsxs("div",{children:[r.jsxs("span",{children:[h("Total")," (",se,")"]}),r.jsx("b",{children:lt(he.totalCoin)})]}),r.jsxs("div",{children:[r.jsxs("span",{children:[h("Total")," (USDC)"]}),r.jsx("b",{children:la(he.totalUsd)})]})]}),document.body),r.jsxs("div",{className:"fut-book__toolbar",children:[r.jsx("select",{className:"fut-book__group",value:b,onChange:xt=>w(Number(xt.target.value)),title:h("Price grouping"),children:rx.map(xt=>r.jsx("option",{value:xt,children:X?lt(X*xt):xt},xt))}),r.jsxs("div",{className:"fut-book__units",children:[r.jsx("button",{type:"button",className:k==="usd"?"is-active":"",onClick:()=>y("usd"),children:"USDC"}),r.jsx("button",{type:"button",className:k==="coin"?"is-active":"",onClick:()=>y("coin"),children:se})]})]}),r.jsxs("div",{className:"fut-book__head",children:[r.jsx("span",{children:h("Price")}),r.jsxs("span",{children:[h("Size")," (",We,")"]}),r.jsxs("span",{children:[h("Total")," (",We,")"]})]}),r.jsx("div",{className:"fut-book__side fut-book__side--ask",children:Re(ce).map((xt,Bt)=>ze(xt,"ask",Bt))}),r.jsxs("div",{className:"fut-book__spread",children:[r.jsx("span",{className:"fut-book__mid",children:ht?xo(ht,Be):"—"}),r.jsx("span",{className:"fut-book__spreadval",children:H?xo(H,Be)+" ("+et.toFixed(3)+"%)":""})]}),r.jsx("div",{className:"fut-book__side fut-book__side--bid",children:Re(ie).map((xt,Bt)=>ze(xt,"bid",Bt))})]}):r.jsx("div",{className:"fut-book fut-book--empty",children:r.jsxs("div",{className:"fut-book__placeholder",children:[h("Loading"),"…"]})})}const Cu={taker:ri,maker:Ra};function Ha(s,t=null,e=null){const n=e==null?void 0:e.rates,i=(n==null?void 0:n.crypto)??{taker:(e==null?void 0:e.taker)??Cu.taker,maker:(e==null?void 0:e.maker)??Cu.maker};return!ar(s)||!(n!=null&&n.rwa)?i:(t==null?void 0:t.growthMode)==="enabled"?n.rwaGrowth??n.rwa:n.rwa}function px(s,t=null,e=null){return Ha(s,t,e).taker}function aa(s,t=null,e=null){const n=Array.isArray(t)?t.find(i=>(i==null?void 0:i.name)===s)??null:null;return Ha(s,n,e)}function Nf({title:s,text:t,note:e,danger:n=!1,confirmLabel:i,skippable:o=!1,extra:l=null,onCancel:a,onConfirm:c}){const[u,d]=m.useState(!1);return m.useEffect(()=>{const f=g=>{if(g.key==="Escape"){g.preventDefault(),g.stopPropagation(),a();return}g.key==="Enter"&&(g.preventDefault(),g.stopPropagation(),c(u))};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[a,c,u]),r.jsx("div",{className:"fut-modal",onClick:a,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:f=>f.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:s}),r.jsx("button",{type:"button",onClick:a,children:"✕"})]}),r.jsx("div",{className:"fut-guard__text",children:t}),e&&r.jsx("div",{className:"fut-guard__note",children:e}),l,o&&r.jsxs("label",{className:"fut-guard__skip",children:[r.jsx("input",{type:"checkbox",checked:u,onChange:f=>d(f.target.checked)}),r.jsx("span",{children:h("Do not show again")})]}),r.jsxs("div",{className:"fut-guard__actions",children:[r.jsx("button",{type:"button",className:"fut-guard__cancel",onClick:a,children:h("Cancel")}),r.jsx("button",{type:"button",className:"fut-guard__ok"+(n?" is-danger":""),onClick:()=>c(u),children:i||h("Confirm")})]})]})})}const gx=[1,2,3,5,10,20,25,40,50];function vx({coin:s,asset:t,leverage:e,isCross:n,onApply:i,onClose:o}){Ps(o);const l=(t==null?void 0:t.maxLeverage)??20,a=!!(t!=null&&t.onlyIsolated),[c,u]=m.useState(Math.min(e||1,l)),d=a?!1:!!n,f=gx.filter(w=>w<=l);f.includes(l)||f.push(l);const g=l>1?(c-1)/(l-1)*100:0,v=c>0?100/c:0,b=c>=20;return r.jsx("div",{className:"fut-modal",onClick:o,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:w=>w.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsxs("b",{children:[h("Leverage")," · ",zt(s)]}),r.jsx("button",{type:"button",onClick:o,children:"✕"})]}),a&&r.jsx("div",{className:"fut-lev__note",children:h("This market supports isolated margin only")}),r.jsxs("div",{className:"fut-lev__value",children:[r.jsx("b",{children:c}),r.jsx("span",{children:"×"})]}),r.jsxs("div",{className:"fut-lev__slider",style:{"--f-fill":g+"%"},children:[r.jsx("span",{className:"fut-lev__slider-track"}),r.jsx("input",{type:"range",min:1,max:l,step:1,value:c,onChange:w=>u(parseInt(w.target.value,10))})]}),r.jsxs("div",{className:"fut-lev__scale",children:[r.jsx("span",{children:"1×"}),r.jsxs("span",{children:[l,"×"]})]}),r.jsx("div",{className:"fut-lev__presets",children:f.map(w=>r.jsxs("button",{type:"button",className:w===c?"is-active":"",onClick:()=>u(w),children:[w,"×"]},w))}),r.jsx("div",{className:"fut-lev__risk"+(b?" is-high":""),children:h("A move of about {pct}% against your position leads to liquidation",{pct:v.toFixed(v<10?1:0)})}),r.jsx("div",{className:"fut-lev__hint",children:d?h("Cross: all your balance backs the position, and losses can affect other positions"):h("Isolated: only the margin of this position is at risk")}),r.jsx("button",{type:"button",className:"fut-lev__apply",onClick:()=>i(c,d),children:h("Confirm")})]})})}function Tn(s){return s?{xyz:h("Stocks & commodities")}[s]??s:h("Crypto")}function Cf({accountId:s,currentDex:t="",onDone:e,compact:n=!1,balancesOnl
6y:i=!1,onMove:o=null,actions:l=null,activeDex:a=null,onPick:c=null,withBalances:u=!0}){const{showError:d}=Ln(),[f,g]=m.useState(null),[v,b]=m.useState(""),[w,k]=m.useState("xyz"),[y,S]=m.useState(""),[j,E]=m.useState(!1),z=m.useCallback(()=>{var $;ge.post("/x/futures/balances",{miniAppData:($=ve())==null?void 0:$.initData,account_id:s}).then(({data:ht})=>{if(ht!=null&&ht.err)return;g(ht.balances??[]);const tt=ht.enabled??[];t&&tt.includes(t)?(b(""),k(t)):tt.length>0&&(b(tt[0]),k(""))}).catch(()=>{})},[s,t]);m.useEffect(()=>{z()},[z]);const A=($=>{var ht;return((ht=f==null?void 0:f.find(tt=>tt.dex===$))==null?void 0:ht.withdrawable)??0})(v),J=_i(A),O=parseFloat(y)||0,yt=O>A,P=O>0&&!yt&&v!==w&&!j,G=()=>{b(w),k(v),S("")},nt=async()=>{var $;if(P){E(!0);try{const{data:ht}=await ge.post("/x/futures/move",{miniAppData:($=ve())==null?void 0:$.initData,account_id:s,from:v,to:w,amount:O});ht!=null&&ht.err?d(ht.errText||ht.err):(ys(h("Funds moved")),S(""),z(),e&&e())}catch{d(h("Network error"))}finally{E(!1)}}};if(!f)return r.jsxs("div",{className:"fut-panel__empty",children:[h("Loading"),"…"]});const bt=$=>r.jsxs("div",{className:"fut-venues__item"+($.dex===t?" is-current":""),children:[r.jsxs("div",{className:"fut-venues__name",children:[Tn($.dex),$.dex===t&&r.jsx("span",{className:"fut-venues__badge",children:h("Current market")})]}),r.jsxs("div",{className:"fut-venues__equity",children:["$",lt($.equity)]}),r.jsxs("div",{className:"fut-venues__meta",children:[r.jsxs("span",{children:[h("Available")," ",r.jsxs("b",{children:["$",lt($.withdrawable)]})]}),r.jsxs("span",{children:[h("Positions")," ",r.jsx("b",{children:$.positions})]})]})]},$.dex||"main");if(i){const $=f.reduce((rt,Nt)=>({equity:rt.equity+(parseFloat(Nt.equity)||0),free:rt.free+(parseFloat(Nt.withdrawable)||0),count:rt.count+(Number(Nt.positions)||0),maint:rt.maint+(parseFloat(Nt.maintenance)||0)}),{equity:0,free:0,count:0,maint:0}),ht=(rt,Nt)=>Nt>0?rt/Nt*100:0,tt=rt=>rt>=80?"high":rt>=50?"mid":"low",H=rt=>tt(rt)==="high"?h("Very close to liquidation. Reduce position size or add margin."):tt(rt)==="mid"?h("Significant margin usage. A move against you may trigger liquidation."):h("Margin usage is comfortable."),et=({id:rt,title:Nt,equity:X,free:st,count:Ot,maint:St=0,total:At=!1})=>{const Yt=ht(St,X),Mt=a!==null?rt===a:rt===t,Gt=c?"button":"div";return r.jsxs(Gt,{className:"fut-vtable__row"+(Mt?" is-current":"")+(c?" is-pickable":"")+(At?" fut-vtable__row--total":""),...c?{type:"button",onClick:()=>c(rt),"aria-pressed":Mt}:{},children:[r.jsx("span",{className:"fut-vtable__name","data-label":h("Account"),children:Nt}),r.jsx("span",{"data-label":h("Equity"),children:r.jsxs("b",{children:["$",lt(X)]})}),r.jsxs("span",{"data-label":h("Available"),children:["$",lt(st)]}),r.jsx("span",{"data-label":h("Positions"),children:Ot}),r.jsx("span",{className:"fut-vtable__usage is-"+tt(Yt),"data-label":h("Margin usage"),children:r.jsxs(Rt.Tooltip,{title:X>0?H(Yt):"",position:"top",arrow:!0,tag:"span",distance:10,style:{display:"flex",flexDirection:"column",gap:"5px"},children:[r.jsx("b",{children:X>0?Yt.toFixed(1)+"%":"—"}),r.jsx("i",{children:r.jsx("em",{style:{width:Math.min(100,Yt)+"%"}})})]})})]},rt||"main")};return r.jsxs("div",{className:"fut-venues fut-venues--strip",children:[r.jsxs("div",{className:"fut-venues__strip-head",children:[r.jsx("h4",{className:"fut-venues__title",children:h("Margin accounts")}),r.jsxs("div",{className:"fut-venues__acts",children:[l,o&&r.jsx("button",{type:"button",className:"fut-venues__open",onClick:o,children:h("Move between accounts")})]})]}),r.jsxs("div",{className:"fut-vtable",children:[r.jsxs("div",{className:"fut-vtable__head",children:[r.jsx("span",{children:h("Account")}),r.jsx("span",{children:h("Equity")}),r.jsx("span",{children:h("Available")}),r.jsx("span",{children:h("Positions")}),r.jsx("span",{children:h("Margin usage")})]}),f.map(rt=>et({id:rt.dex,title:Tn(rt.dex),equity:rt.equity,free:rt.withdrawable,count:rt.positions,maint:rt.maintenance})),f.length>1&&et({id:"all",title:h("Total"),equity:$.equity,free:$.free,count:$.count,maint:$.maint,total:!0})]})]})}return r.jsxs("div",{className:"fut-venues"+(n?" fut-venues--compact":""),children:[r.jsx("div",{className:"fut-venues__explain",children:h("Each trading venue keeps a 
6separate margin balance. Money on one venue cannot back positions on another — move it here first.")}),r.jsxs("div",{className:"fut-venues__body",children:[u&&r.jsxs("section",{className:"fut-venues__col",children:[r.jsx("h4",{className:"fut-venues__title",children:h("Margin accounts")}),r.jsx("div",{className:"fut-venues__list",children:f.map(bt)})]}),r.jsxs("section",{className:"fut-venues__col fut-venues__move",children:[r.jsx("h4",{className:"fut-venues__title",children:h("Move between accounts")}),r.jsxs("div",{className:"fut-venues__dir",children:[r.jsx("span",{className:"fut-venues__side",children:Tn(v)}),r.jsx("button",{type:"button",className:"fut-venues__swap",onClick:G,"aria-label":h("Swap"),children:"⇄"}),r.jsx("span",{className:"fut-venues__side",children:Tn(w)})]}),r.jsxs("label",{className:"fut-venues__field",children:[r.jsxs("span",{className:"fut-venues__flabel",children:[r.jsxs("span",{children:[h("Amount")," ",r.jsx("em",{children:"USDC"})]}),r.jsxs("button",{type:"button",className:"fut-venues__max",onClick:()=>S(String(J)),children:[h("Available"),": ",lt(J)]})]}),r.jsx("input",{type:"text",inputMode:"decimal",value:y,onChange:$=>S($.target.value.replace(",",".")),placeholder:"0"})]}
6),yt&&r.jsx("div",{className:"fut-form__warn",children:h("Amount exceeds available balance")}),r.jsx("button",{type:"button",className:"fut-venues__submit",disabled:!P,onClick:nt,children:j?h("Sending")+"…":h("Move funds")}),r.jsx("div",{className:"fut-venues__note",children:h("Transfers between venues are instant and free — no blockchain transaction involved.")})]})]})]})}function Tf(s){return Math.max(1,parseFloat(s)||1)}function Lf(s,t,e,n){const i=parseFloat(t)||0;if(!i||!Number.isFinite(s))return"";const o=i*(1+(e?1:-1)*s/Tf(n)/100);return o>0?String(be(o)):""}function Ef(s,t,e,n){const i=parseFloat(s)||0,o=parseFloat(t)||0;if(!i||!o)return"";const l=(i-o)/o*100*Tf(n);return String((e?l:-l).toFixed(2))}const Ff=(s,t)=>t?s:-s,Af=(s,t)=>t?s:-s,Tu=s=>s?200:100;function ca({kind:s,isLong:t,refPrice:e,size:n,value:i,onChange:o,wrong:l,hint:a,maxPercent:c=0,enabled:u=!0,onToggle:d=null,leverage:f=1,bipolar:g=!1}){const v=s==="tp",b=Math.max(1,parseFloat(f)||1),[w,k]=m.useState("price"),[y,S]=m.useState(""),j=st=>Lf(st,e,t,b),E=st=>Ef(st,e,t,b),z=st=>Ff(st,v),F=st=>Af(st,v);m.useEffect(()=>{w==="percent"&&S(st=>{if(st)return st;const Ot=parseFloat(E(i));return Number.isFinite(Ot)?String(z(Ot)):""})},[w]);const A=st=>{S(st);const Ot=parseFloat(st.replace(",","."));o(st===""?"":j(F(Ot)))},J=st=>{if(!st){S(""),o("");return}S(String(z(st))),o(j(st))},yt=(()=>{const st=parseFloat(i)||0;return!st||!e||!n?null:(t?1:-1)*n*(st-e)})(),P=E(i),G=!!g&&c>0,nt=parseFloat(P)||0,bt=G?Math.max(-c,Math.min(nt,c)):Math.min(Math.abs(nt),c),$=P?String(Math.abs(parseFloat(P))):"",ht=c>0?(bt+c)/(2*c)*100:50,tt=Math.min(50,ht),H=Math.max(50,ht),et=c>0?bt/c*100:0,rt=yt===null?v?1:-1:Math.sign(yt),Nt=rt>=0?h("Profit"):h("Loss"),X=rt>0?"+":rt<0?"−":"";return r.jsxs("div",{className:"fut-tpsl__field",children:[r.jsxs("div",{className:"fut-tpsl__label",children:[d?r.jsxs("label",{className:"fut-form__check fut-tpsl__toggle",children:[r.jsx("input",{type:"checkbox",checked:u,onChange:st=>d(st.target.checked)}),r.jsx("span",{children:v?h("Take profit"):h("Stop loss")})]}):r.jsx("span",{children:v?h("Take profit"):h("Stop loss")}),r.jsxs("span",{className:"fut-tpsl__modes"+(u?"":" is-hidden"),children:[r.jsx("button",{type:"button",className:w==="price"?"is-active":"",onClick:()=>k("price"),children:h("Price")}),r.jsx("button",{type:"button",className:w==="percent"?"is-active":"",onClick:()=>k("percent"),disabled:!e,children:"%"})]})]}),u&&(w==="price"?r.jsx("input",{type:"text",inputMode:"decimal",value:i,placeholder:h("Price"),onChange:st=>{S(""),o(st.target.value.replace(",","."))}}):r.jsxs("div",{className:"fut-tpsl__percent",children:[r.jsx("input",{type:"text",inputMode:"decimal",value:y,placeholder:"0",onChange:st=>A(st.target.value)}),r.jsx("span",{children:"%"}),r.jsx("em",{children:i?lt(i):"—"})]})),u&&c>0&&r.jsxs("div",{className:"fut-tpsl__range",children:[r.jsxs("div",{className:"fut-tpsl__range-head",children:[r.jsx("span",{children:Nt}),r.jsx("b",{children:$?X+$+"%":"—"}),i&&r.jsx("button",{type:"button",className:"is-clear",onClick:()=>{S(""),o("")},children:h("Clear")})]}),r.jsxs("div",{className:"fut-slider"+(G?" fut-slider--bipolar":""),style:G?{"--f-from":tt+"%","--f-to":H+"%","--f-tone":rt>=0?"var(--f-up)":"var(--f-down)"}:{"--f-fill":et+"%"},children:[r.jsx("span",{className:"fut-slider__track"}),r.jsx("input",{type:"range",min:G?-c:0,max:c,step:1,value:bt,"aria-label":Nt,onChange:st=>J(G?Number(st.target.value):F(Number(st.target.value)))})]})]}),u&&l&&r.jsx("div",{className:"fut-form__warn",children:a}),u&&!l&&yt!==null&&r.jsxs("div",{className:"fut-tpsl__outcome "+(yt>=0?"is-up":"is-down"),children:[h("Expected result"),": ",yt>=0?"+":"−","$",lt(Math.abs(yt)),w==="price"&&$&&r.jsxs("i",{children:[" · ",$,"%"]})]})]})}const Rf="futures_form_prefs";function Pf(){try{return JSON.parse(localStorage.getItem(Rf))??{}}catch{return{}}}function Lu(s){try{localStorage.setItem(Rf,JSON.stringify({...Pf(),...s}))}catch{}}const xx=[{key:"Gtc",title:"GTC",hint:"Good till cancel — висит в стакане, пока не исполнится или не отменят"},{key:"Ioc",title:"IOC",hint:"Immediate or cancel — исполняется сразу, остаток отменяется"},{key:"Alo",title:"ALO",hint:"Add liquidity only — только мейкер, при пересечении спреда отменяется"}],Ka=[{key:"scale",title:"Scale",hint:"Splits the size into several limit orders spread across a price range."},{key:"stop_limit",title:"Stop Limit",hint:"Triggers at the stop price and then rests as a limit order at your price."},{key:"stop_market",title:"Stop Market",hint:"Triggers at the stop price and fills at market."},{key:"take_limit",title:"Take Limit",hint:"Triggers at the target price and then rests as a limit order at your price."},{key:"take_market",title:"Take Market",hint:"Triggers at the target price and fills at market."},{key:"twap",title:"TWAP",hint:"The exchange fills the size in slices over the duration you set."}],yx=["market","limit",...Ka.map(s=>s.key)],Eu=s=>s.startsWith("stop_")||s.startsWith("take_"),Fu=s=>s==="stop_limit"||s==="take_limit",bx=s=>Ka.find(t=>t.key===s)??null,Au=2,wx=20,Ru=5,Pu=10080,_x=100;function kx(s,t,e,n,i){if(!(s>0)||!(t>0)||!(e>0)||n<2)return[];const o=[];let l=0;for(let a=0;a<n;a++){const c=1+(i-1)*(a/(n-1));o.push(c),l+=c}return o.map((a,c)=>({price:t+(e-t)*(c/(n-1)),size:s*a/l}))}function zu(s,t,e){m.useEffect(()=>{if(!t)return;const n=o=>
6{s.current&&!s.current.contains(o.target)&&e()},i=o=>{o.key==="Escape"&&e()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",i)}},[t])}function Du({coin:s,asset:t,ctx:e,accountId:n,state:i,equity:o=0,pickedPrice:l,preset:a,isMobile:c=!1,vip:u=null,authed:d=!0,onboarded:f=!0,onNeedAuth:g,onNeedAccount:v,onDeposit:b,onWithdraw:w,onMove:k,onCalculator:y,onDone:S}){var Bn,oi,Fe;const j=m.useMemo(()=>Pf(),[]),E=m.useMemo(()=>Ha(s,t,u),[s,t,u]),z=E.taker??ri,F=E.maker??Ra,[A,J]=m.useState(j.side==="sell"?"sell":"buy"),[O,yt]=m.useState(yx.includes(j.orderType)?j.orderType:"market"),[P,G]=m.useState(""),[nt,bt]=m.useState(j.sizeUnit==="coin"&&j.sizeUnitByUser?"coin":"usd"),[$,ht]=m.useState(""),[tt,H]=m.useState(""),[et,rt]=m.useState(""),[Nt,X]=m.useState(""),[st,Ot]=m.useState(String(j.scaleCount??5)),[St,At]=m.useState(String(j.scaleSkew??1)),[Yt,Mt]=m.useState(String(j.twapMinutes??30)),[Gt,jt]=m.useState(j.twapRandomize===!0),Be=Math.min(wx,Math.max(Au,parseInt(st,10)||Au)),de=Math.min(10,Math.max(.1,parseFloat(St)||1)),ie=parseInt(Yt,10)||0,[ce,Ne]=m.useState(["Gtc","Ioc","Alo"].includes(j.tif)?j.tif:"Gtc"),[se,We]=m.useState(!1),[Re,ze]=m.useState(!1),[he,N]=m.useState(""),[mt,Pt]=m.useState(""),[qt,pt]=m.useState(j.isCross!==!1),[te,Tt]=m.useState(j.leverage||5),Ht=ur(),[xt,Bt]=m.useState(null),[re,Vt]=m.useState(!1),[Ee,qe]=m.useState(!1),[we,ye]=m.useState(!1),fe=m.useRef(null);zu(fe,we,()=>ye(!1));const[De,nn]=m.useState(!1),Ws=m.useRef(null);zu(Ws,De,()=>nn(!1));const ws=m.useRef(null),{showError:zs}=Ln(),gs=(t==null?void 0:t.maxLeverage)??20;m.useEffect(()=>{var Lt;!Ht.defaultLeverage&&!Ht.defaultMargin||(Lt=i==null?void 0:i.assetPositions)!=null&&Lt.some(Ce=>{var Ze,Es;return((Ze=Ce.position)==null?void 0:Ze.coin)===s&&parseFloat((Es=Ce.position)==null?void 0:Es.szi)!==0})||(Ht.defaultLeverage&&Tt(Math.min(Ht.defaultLeverage,gs)),Ht.defaultMargin&&pt(Ht.defaultMargin==="cross"))},[s,Ht.defaultLeverage,Ht.defaultMargin,gs]);const Jt=parseFloat((e==null?void 0:e.markPx)??0),Ls=m.useRef(0);sn("trades",{coin:s},R=>{var Ce;if(!Array.isArray(R)||R.length===0)return;const Lt=parseFloat((Ce=R[R.length-1])==null?void 0:Ce.px)||0;Lt>0&&(Ls.current=Lt)},!!s),m.useEffect(()=>{Ls.current=0},[s]);const Ds=R=>R>0?String(parseFloat(R.toFixed(bo(R,(t==null?void 0:t.szDecimals)??0)))):"",qs=()=>Ls.current||parseFloat((e==null?void 0:e.midPx)??0)||Jt||0,vn=!!(Jt||parseFloat((e==null?void 0:e.midPx)??0)),ms=R=>r.jsx(Rt.Tooltip,{position:"top",tag:"span",arrow:!0,distance:10,style:{display:"flex",alignItems:"center"},popperOptions:{modifiers:{preventOverflow:{boundariesElement:"viewport"},flip:{boundariesElement:"viewport"},hide:{enabled:!1}}},title:h("Use the last trade price"),children:r.jsx("button",{type:"button",className:"fut-form__lastpx",disabled:!vn,onClick:()=>{const Lt=Ds(qs());Lt&&R(Lt)},children:h("Last")})}),Oe=Eu(O),Xt=Fu(O),as=bx(O),le=O==="scale",cs=O==="twap",T=O==="limit"||Xt,Z=O==="limit"||le,Q=O==="market"||O==="limit",vt=parseFloat((i==null?void 0:i.withdrawable)??0),wt=m.useMemo(()=>{for(const R of(i==null?void 0:i.assetPositions)??[]){const Lt=R==null?void 0:R.position,Ce=parseFloat((Lt==null?void 0:Lt.szi)??0)||0;if((Lt==null?void 0:Lt.coin)===s&&Ce!==0)return{size:Math.abs(Ce),isLong:Ce>0}}return null},[i,s]),It=!!(t!=null&&t.onlyIsolated);m.useEffect(()=>{It&&pt(!1)},[It]);const ot=(oi=(Bn=i==null?void 0:i.assetPositions)==null?void 0:Bn.find(R=>{var Lt,Ce;return((Lt=R.position)==null?void 0:Lt.coin)===s&&parseFloat((Ce=R.position)==null?void 0:Ce.szi)!==0}))==null?void 0:oi.position,Dt=!!ot;m.useEffect(()=>{var R;ot&&pt((((R=ot.leverage)==null?void 0:R.type)??"")==="cross")},[s,(Fe=ot==null?void 0:ot.leverage)==null?void 0:Fe.type]);const Qt=R=>{if(ye(!1),R!==qt){if(Dt){zs("Cannot switch leverage type with open position.");return}pt(R)}};m.useEffect(()=>{Tt(R=>Math.min(R,gs))},[gs]),m.useEffect(()=>{Lu({side:A,orderType:O,sizeUnit:nt,leverage:te,isCross:qt,tif:ce,scaleCount:st,scaleSkew:St,twapMinutes:Yt,twapRandomize:Gt})},[A,O,nt,te,qt,ce,st,St,Yt,Gt]),m.useEffect(()=>{G(""),ht(""),H(""),rt(""),X(""),N(""),Pt(""),ze(!1),We(!1),ws.current=null},[s]),m.useEffect(()=>{!le||!(Jt>
60)||et!==""||Nt!==""||(rt(String(be(Jt))),X(String(be(Jt*(A==="buy"?.98:1.02)))))},[le,Jt,A,et,Nt]),m.useEffect(()=>{ws.current!==s&&Jt>0&&(ws.current=s,ht(String(be(Jt))))},[s,Jt]),m.useEffect(()=>{const R=l==null?void 0:l.price;if(!R)return;const Lt=String(be(R));if(Fu(O)){ht(Lt);return}if(Eu(O)){H(Lt);return}if(O==="scale"){rt(Lt);return}O!=="twap"&&(yt("limit"),ht(Lt))},[l==null?void 0:l.seq]),m.useEffect(()=>{if(a!=null&&a.seq){if(a.side&&J(a.side),a.leverage&&Tt(Math.min(a.leverage,gs)),a.price&&(yt("limit"),ht(String(be(a.price)))),a.size){const R=parseFloat(a.price)||Et;nt==="usd"&&R>0?G(String(be(a.size*R))):(nt!=="coin"&&bt("coin"),G(String(be(a.size))))}(a.takeProfit||a.stopLoss)&&(O!=="market"&&O!=="limit"&&yt(a.price?"limit":"market"),ze(!0),a.takeProfit&&N(String(be(a.takeProfit))),a.stopLoss&&Pt(String(be(a.stopLoss))))}},[a==null?void 0:a.seq]);const Et=m.useMemo(()=>{if(O==="market"||cs)return Jt;if(le){const R=parseFloat(et)||0,Lt=parseFloat(Nt)||0;return R>0&&Lt>0?(R+Lt)/2:Jt}return Xt?parseFloat($)||parseFloat(tt)||Jt:Oe?parseFloat(tt)||Jt:parseFloat($)||Jt},[O,Oe,Xt,le,cs,$,tt,et,Nt,Jt]),Wt=O.startsWith("stop_")?A==="buy":A==="sell",_e=m.useMemo(()=>{const R=parseFloat(tt)||0;return!Oe||!R||!Jt?!1:Wt?R<=Jt:R>=Jt},[Oe,tt,Jt,Wt]),Ue=m.useMemo(()=>{if(O!=="stop_limit")return!1;const R=parseFloat(tt)||0,Lt=parseFloat($)||0;return!R||!Lt?!1:A==="buy"?Lt<R:Lt>R},[O,tt,$,A]),ue=m.useMemo(()=>{const R=parseFloat(P)||0;return R?nt==="usd"?Et?R/Et:0:R:0},[P,nt,Et]),Xe=ue*Et,rn=!!wt&&(wt.isLong?A==="sell":A==="buy"),Os=rn?Math.min(ue,wt.size):0,ts=Math.max(0,ue-Os),Ve=te>0?ts*Et/te:0,ae=Ve>vt&&!se,ke=m.useMemo(()=>le?kx(ue,parseFloat(et)||0,parseFloat(Nt)||0,Be,de):[],[le,ue,et,Nt,Be,de]),xe=m.useMemo(()=>ke.length?Math.min(...ke.map(R=>R.size*R.price)):0,[ke]),ps=m.useMemo(()=>se?!1:cs?Xe<_x:le?ke.length>0&&xe<Ji:Xe<Ji,[se,cs,le,Xe,ke,xe]),es=cs?h("Minimum TWAP size is $100"):le?h("Every order in the ladder must be worth at least $10"):h("Minimum order value is $10"),Me=le&&parseFloat(et)>0&&parseFloat(et)===parseFloat(Nt),Qe=cs&&ie>0&&(ie<Ru||ie>Pu),Pe=ps&&Xe>0,Ie=rn?wt.size*Et:0,ss=se?Ie:Ie+vt*te,En=ss>0?Math.min(100,Math.round(Xe/ss*100)):0,hs=R=>{if(!Et||!ss)return;const Lt=ss*(R/100);G(R>0?String(be(nt==="usd"?Lt:Lt/Et)):"")},[vs,me]=m.useState(null);sn("book",{coin:s},me,!!s&&O==="market"),m.useEffect(()=>{me(null)},[s]);const us=m.useMemo(()=>{var on;
6if(O!=="market"||!ue)return null;const R=((on=vs==null?void 0:vs.levels)==null?void 0:on[A==="buy"?1:0])??[];if(!R.length)return null;const Lt=parseFloat(R[0].px)||0;if(!Lt)return null;let Ce=ue,Ze=0;for(const Vs of R){const ln=parseFloat(Vs.px)||0,Us=parseFloat(Vs.sz)||0,Ke=Math.min(Ce,Us);if(Ze+=Ke*ln,Ce-=Ke,Ce<=0)break}if(Ce>0)return null;const Es=Ze/ue;return Math.abs((Es-Lt)/Lt)*100},[vs,A,ue,O]),He=Re&&!se&&Q,oe=A==="buy",_s=m.useMemo(()=>{const R=parseFloat(he)||0;return!He||!R||!Et?!1:oe?R<=Et:R>=Et},[he,He,Et,oe]),V=m.useMemo(()=>{const R=parseFloat(mt)||0;return!He||!R||!Et?!1:oe?R>=Et:R<=Et},[mt,He,Et,oe]),ut=m.useMemo(()=>{if(!wt||se||!(wt.isLong?A==="sell":A==="buy"))return null;const Lt=parseFloat($)||0;return O==="limit"&&Lt>0&&Jt>0&&(A==="buy"?Lt>=Jt:Lt<=Jt)?{flips:ue>wt.size*1.000001}:null},[wt,se,A,O,$,Jt,ue]),Ct=m.useMemo(()=>se?0:Kd({entryPx:Et,size:ue,leverage:te,maxLeverage:gs,isLong:A==="buy",isCross:qt,equity:o,usedMaintenance:parseFloat((i==null?void 0:i.crossMaintenanceMarginUsed)??0)||0}),[ue,Et,te,gs,qt,o,i,A,se]),ne=m.useMemo(()=>{const R=parseFloat(mt)||0;return!He||!R||!Ct?!1:oe?R<=Ct:R>=Ct},[mt,He,Ct,oe]),Zt=R=>{if(R===nt)return;Lu({sizeUnitByUser:!0});const Lt=parseFloat(P)||0;Lt&&Et&&G(String(be(R==="usd"?Lt*Et:Lt/Et))),bt(R)},ks=async()=>{if(re)return;if(!d){g&&g();return}if(!f){v&&v();return}const R=ue;if(R<=0){Dn(h("Enter size"));return}if(T&&!(parseFloat($)>0)){Dn(h("Enter price"));return}if(Oe&&!(parseFloat(tt)>0)){Dn(h("Enter trigger price"));return}if(le){if(!(parseFloat(et)>0)||!(parseFloat(Nt)>0)){Dn(h("Set the price range"));return}if(Me){Dn(h("The range bounds must differ"));return}}if(cs&&(ie<Ru||ie>Pu)){Dn(h("TWAP duration must be between 5 minutes and 7 days"));return}if(O==="market"&&Ht.marketConfirm){Bt({side:A,size:R,price:Jt});return}await ns(R)},ns=async R=>{var Lt,Ce,Ze,Es,on;Vt(!0);try{const Vs=(Ze=(Ce=(Lt=i==null?void 0:i.assetPositions)==null?void 0:Lt.find(Is=>{var Wn;return((Wn=Is.position)==null?void 0:Wn.coin)===s}))==null?void 0:Ce.position)==null?void 0:Ze.leverage;if(!Vs||Vs.value!==te||Vs.type==="cross"!==qt){const{data:Is}=await ge.post("/x/futures/leverage",{miniAppData:(Es=ve())==null?void 0:Es.initData,account_id:n,coin:s,leverage:te,is_cross:qt});if(Is!=null&&Is.err){zs(Is.errText||Is.err);return}}const ln={miniAppData:(on=ve())==null?void 0:on.initData,account_id:n,coin:s,side:A,size:R,reduce_only:se,leverage:te,is_cross:qt},Us=le?["/x/futures/scale",{...ln,start_px:parseFloat(et),end_px:parseFloat(Nt),count:Be,skew:de,tif:ce}]:cs?["/x/futures/twap",{...ln,minutes:ie,randomize:Gt}]:["/x/futures/order",{...ln,order_type:O,price:T?parseFloat($):void 0,trigger_px:Oe?parseFloat(tt):void 0,tif:Oe?void 0:ce,take_profit:He&&parseFloat(he)||0,stop_loss:He&&parseFloat(mt)||0}],{data:Ke}=await ge.post(Us[0],Us[1]);Ke!=null&&Ke.err?zs(Ke.errText||Ke.err):(Ke==null?void 0:Ke.placed)!==void 0&&Ke.placed<Ke.total?(zs(h("Placed {placed} of {total} orders. {reason}",{placed:Ke.placed,total:Ke.total,reason:(Ke.errors??[]).join("; ")})),S&&S()):(ys(cs?h("TWAP started"):le?h("Ladder placed"):h("Order placed")),G(""),H(""),N(""),Pt(""),S&&S())}catch{zs(h("Network error"))}finally{Vt(!1)}},is={position:c?"top":"left",tag:"span",arrow:!0,distance:12,popperOptions:{modifiers:{preventOverflow:{boundariesElement:"viewport"},flip:{boundariesElement:"viewport"},hide:{enabled:!1}}}};return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-form",children:[(!d||!f)&&r.jsxs("div",{className:"fut-form__gate",children:[r.jsx("span",{children:d?h("Trading needs a funded futures account."):h("Trading needs an account.")}),r.jsx("button",{type:"button",onClick:()=>d?v&&v():g&&g(),children:d?h("Fund the account"):h("Sign in")})]}),r.jsxs("div",{className:"fut-form__sides",children:[r.jsxs("button",{type:"button",className:"fut-form__side fut-form__side--buy"+(A==="buy"?" is-active":""),onClick:()=>J("buy"),children:[r.jsx("b",{children:h("Long")}),r.jsx("i",{children:h("Buy")})]}),r.jsxs("button",{type:"button",className:"fut-form__side fut-form__side--sell"+(A==="sell"?" is-active":""),onClick:()=>J("sell"),children:[r.jsx("b",{children:h("Short")}),r.jsx("i",{children:h("Sell")})]})]}),r.jsxs("div",{className:"fut-form__types",ref:Ws,children:[["market","limit"].map(R=>r.jsx("button",{type:"button",className:"fut-form__type"+(R===O?" is-active":""),onClick:()=>{yt(R),nn(!1)},children:R==="limit"?h("Limit"):h("Market")},R)),r.jsxs("button",{type:"button",className:"fut-form__type fut-form__type--pro"+(as?" is-active":""),onClick:()=>nn(R=>!R),"aria-haspopup":"listbox","aria-expanded":De,children:[as?as.title:h("Pro"),r.jsx("i",{className:"fut-form__pick-caret"})]}),De&&r.jsx("div",{className:"fut-form__pop fut-form__pop--types",role:"listbox",children:Ka.map(R=>r.jsxs("button",{type:"button",role:"option","aria-selected":O===R.key,className:O===R.key?"is-active":"",onClick:()=>{yt(R.key),nn(!1)},children:[r.jsx("b",{children:R.title}),r.jsx("i",{children:h(R.hint)})]},R.key))}),y&&r.jsx("button",{type:"button",className:"fut-form__calc",onClick:y,title:h("Calculator"),"aria-label":h("Calculator"),children:r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"2.5",stroke:"currentColor",strokeWidth:"1.7"}),r.jsx("rect",{x:"7.5",y:"6.5",width:"9",height:"3.2",rx:"1",stroke:"currentColor",strokeWidth:"1.5"}),r.jsx("circle",{cx:"8.8",cy:"13.6",r:"1.05",fill:"currentColor"}),r.jsx("circle",{cx:"12",cy:"13.6",r:"1.05",fill:"currentColor"}),r.jsx("circle",{cx:"15.2",cy:"13.6",r:"1.05",fill:"currentColor"}),r.jsx("circle",{cx:"8.8",cy:"17.4",r:"1.05",fill:"currentColor"}),r.jsx("circle",{cx:"12",cy:"17.4",r:"1.05",fill:"currentColor"}),r.jsx("circle",{cx:"15.2",cy:"17.4",r:"1.05",fill:"currentColor"})]})})]}),r.jsxs("div",{className:"fut-form__risk",children:[r.jsxs("div",{className:"fut-form__pickwrap",ref:fe,children:[r.jsxs("button",{type:"button",className:"fut-form__pick"+(It?" is-locked":""),disabled:It,t
6itle:It?h("The exchange allows only isolated margin on this market."):h("Margin mode"),onClick:()=>ye(R=>!R),children:[r.jsx("span",{className:"fut-form__pick-value",children:qt?h("Cross (short)"):h("Isolated (short)")}),!It&&r.jsx("i",{className:"fut-form__pick-caret"})]}),we&&!It&&r.jsx("div",{className:"fut-form__pop",role:"listbox",children:[{cross:!0,title:h("Cross"),hint:h("Whole account balance backs the position")},{cross:!1,title:h("Isolated"),hint:h("Only the margin of this position is at risk")}].map(R=>r.jsxs("button",{type:"button",role:"option","aria-selected":qt===R.cross,className:qt===R.cross?"is-active":"",onClick:()=>Qt(R.cross),children:[r.jsx("b",{children:R.title}),r.jsx("i",{children:R.hint})]},String(R.cross)))})]}),r.jsxs("button",{type:"button",className:"fut-form__pick fut-form__pick--lev",title:h("Leverage"),onClick:()=>qe(!0),children:[r.jsxs("span",{className:"fut-form__pick-value",children:[Number(te).toFixed(2),"x"]}),r.jsx("i",{className:"fut-form__pick-caret"})]})]}),It&&r.jsx("span",{className:"fut-form__note",children:h("The exchange allows only isolated margin on this market.")}),Ee&&r.jsx(vx,{coin:s,asset:t,leverage:te,isCross:qt,onApply:(R,Lt)=>{Tt(R),pt(Lt),qe(!1)},onClose:()=>qe(!1)}),Oe&&r.jsxs("label",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Trigger price")}),r.jsx("input",{type:"text",inputMode:"decimal",value:tt,onChange:R=>H(R.target.value.replace(",",".")),placeholder:Jt?String(be(Jt)):"0"}),r.jsx("span",{className:"fut-form__fieldnote"+(_e?" is-bad":""),children:_e?Wt?h("Must be above the current price, otherwise the order fires at once."):h("Must be below the current price, otherwise the order fires at once."):Wt?h("Fires when the price rises to this level."):h("Fires when the price falls to this level.")})]}),T&&r.jsxs("div",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:Xt?h("Limit price"):h("Price")}),r.jsxs("div",{className:"fut-form__amount",children:[r.jsx("input",{type:"text",inputMode:"decimal",value:$,onChange:R=>ht(R.target.value.replace(",",".")),placeholder:Jt?String(be(Jt)):"0"}),ms(ht)]}),Xt&&r.jsx("span",{className:"fut-form__fieldnote"+(Ue?" is-bad":""),children:Ue?A==="buy"?h("For a stop the limit price must be no lower than the trigger, otherwise the order will rest in the book and never fill."):h("For a stop the limit price must be no higher than the trigger, otherwise the order will rest in the book and never fill."):h("The price the order rests at once it fires.")})]}),le&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-form__pair fut-form__pair--wrap",children:[r.jsxs("div",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Range from")}),r.jsxs("div",{className:"fut-form__amount",children:[r.jsx("input",{type:"text",inputMode:"decimal",value:et,onChange:R=>rt(R.target.value.replace(",",".")),placeholder:Jt?String(be(Jt)):"0"}),ms(rt)]})]}),r.jsxs("div",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Range to")}),r.jsxs("div",{className:"fut-form__amount",children:[r.jsx("input",{type:"text",inputMode:"decimal",value:Nt,onChange:R=>X(R.target.value.replace(",",".")),placeholder:Jt?String(be(Jt)):"0"}),ms(X)]})]})]}),Me&&r.jsx("span",{className:"fut-form__fieldnote is-bad",children:h("The range bounds must differ")})]}),r.jsxs("div",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Size")}),r.jsxs("div",{className:"fut-form__amount",children:[r.jsx("input",{type:"text",inputMode:"decimal",value:P,onChange:R=>G(R.target.value.replace(",",".")),placeholder:"0"}),r.jsxs("select",{className:"fut-form__unit",value:nt,onChange:R=>Zt(R.target.value),"aria-label":h("Size"),children:[r.jsx("option",{value:"coin",children:zt(s)}),r.jsx("option",{value:"usd",children:"USDC"})]})]}),ue>0&&Et>0&&r.jsxs("span",{className:"fut-form__equiv",children:["≈ ",nt==="usd"?lt(ue)+" "+zt(s):"$"+lt(Xe)]})]}),r.jsxs("div",{className:"fut-form__sizer",children:[r.jsxs("div",{className:"fut-form__sizer-track",children:[r.jsx("input",{type:"range",className:"fut-form__slider",min:"0",max:"100",step:"1",value:En,disabled:!ss,onChange:R=>
6hs(parseInt(R.target.value,10)),style:{"--f-fill":En+"%"}}),r.jsx("div",{className:"fut-form__scale",children:[0,25,50,75,100].map(R=>r.jsxs("button",{type:"button",style:{left:R+"%"},onClick:()=>hs(R),children:[R,"%"]},R))})]}),r.jsxs("label",{className:"fut-form__pctbox",children:[r.jsx("input",{type:"text",inputMode:"numeric",value:En,disabled:!ss,onChange:R=>{const Lt=parseInt(R.target.value.replace(/\D/g,""),10);hs(Number.isFinite(Lt)?Math.min(100,Lt):0)}}),r.jsx("span",{children:"%"})]})]}),le&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-form__pair",children:[r.jsxs("label",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Order count")}),r.jsx("input",{type:"text",inputMode:"numeric",value:st,onChange:R=>Ot(R.target.value.replace(/\D/g,"")),placeholder:"5"})]}),r.jsxs("label",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:r.jsx(Rt.Tooltip,{position:"top",tag:"span",arrow:!0,title:h("How many times bigger the last order is than the first. 1 means equal sizes."),children:r.jsx("span",{className:"fut-form__hinted",children:h("Size skew")})})}),r.jsx("input",{type:"text",inputMode:"decimal",value:St,onChange:R=>At(R.target.value.replace(",",".")),placeholder:"1"})]})]}),ke.length>0&&r.jsxs("div",{className:"fut-ladder",children:[r.jsxs("div",{className:"fut-ladder__head",children:[r.jsx("span",{children:h("Price")}),r.jsx("span",{children:zt(s)}),r.jsx("span",{children:"USDC"})]}),r.jsx("div",{className:"fut-ladder__body",children:ke.map((R,Lt)=>r.jsxs("div",{className:"fut-ladder__row",children:[r.jsx("span",{children:lt(R.price)}),r.jsx("span",{children:lt(R.size)}),r.jsxs("span",{className:R.size*R.price<Ji?"is-bad":"",children:["$",lt(R.size*R.price)]})]},Lt))})]})]}),cs&&r.jsxs("div",{className:"fut-form__field",children:[r.jsx("span",{className:"fut-form__label",children:h("Duration")}),r.jsxs("div",{className:"fut-form__amount",children:[r.jsx("input",{type:"text",inputMode:"numeric",value:Yt,onChange:R=>Mt(R.target.value.replace(/\D/g,"")),placeholder:"30"}),r.jsx("span",{className:"fut-form__unit fut-form__unit--static",children:h("min")})]}),r.jsx("div",{className:"fut-form__ticks",children:[15,30,60,240,1440].map(R=>r.jsx("button",{type:"button",className:ie===R?"is-active":"",onClick:()=>Mt(String(R)),children:R<60?R+h("m"):R/60+h("h")},R))}),r.jsx("span",{className:"fut-form__fieldnote"+(Qe?" is-bad":""),children:Qe?h("TWAP duration must be between 5 minutes and 7 days"):h("The exchange splits the size into slices, one at most every 30 seconds.")}),r.jsxs("label",{className:"fut-form__check",children:[r.jsx("input",{type:"checkbox",checked:Gt,onChange:R=>jt(R.target.checked)}),r.jsx(Rt.Tooltip,{position:"top",tag:"span",arrow:!0,title:h("The exchange varies each slice by up to ±20% so the execution does not look mechanical."),children:r.jsx("span",{className:"fut-form__hinted",children:h("Randomize slice size")})})]})]}),Z&&r.jsx("div",{className:"fut-form__tifs",children:xx.map(R=>r.jsx(Rt.Tooltip,{title:h(R.hint),position:"top",arrow:!0,children:r.jsx("button",{type:"button",className:R.key===ce?"is-active":"",onClick:()=>Ne(R.key),children:R.title})},R.key))}),r.jsxs("label",{className:"fut-form__check",children:[r.jsx("input",{type:"checkbox",checked:se,onChange:R=>We(R.target.checked)}),r.jsx(Rt.Tooltip,{position:"top",tag:"span",arrow:!0,title:h("Reduce Only. The order can only close an existing position and will never open a new one or flip its direction. Anything beyond the position size is cancelled."),children:r.jsx("span",{className:"fut-form__hinted",children:h("Reduce only")})})]}),!se&&Q&&r.jsxs("label",{className:"fut-form__check",children:[r.jsx("input",{type:"checkbox",checked:Re,onChange:R=>ze(R.target.checked)}),r.jsx("span",{children:h("Take profit / Stop loss")})]}),He&&r.jsxs("div",{className:"fut-form__tpsl",children:[r.jsx(ca,{kind:"tp",isLong:oe,refPrice:Et,leverage:te,size:ue,value:he,onChange:N,wrong:_s,maxPercent:200,hint:oe?h("Take profit for a long must be above the current price."):h("Take profit for a short must be below the current price.")}),r.jsx(ca,{kind:"sl",isLong:oe,refPrice:Et,leverage:te,size:ue,value:mt,onChange:Pt,wrong:V,maxPercent:100,hint:oe?h("Stop loss for a long must be below the current price."):h("Stop loss for a short must be above the current price.")}),ne&&r.jsx("div",{className:"fut-form__warn",children:h("The stop loss is beyond the liquidation price of {price} — the exchange will close the position before it triggers.",{price:lt(Ct)})}),te>1&&r.jsx("div",{className:"fut-tpsl__note",children:h("Percentages are counted on margin, at {lev}× leverage.",{lev:lt(te)})})]}),r.jsxs("div",{className:"fut-form__summary",children:[r.jsxs("div",{children:[r.jsx(Rt.Tooltip,{...is,title:h("Estimate for this order alone. The real price also depen
6ds on your other positions and on the fill price."),children:r.jsx("span",{className:"is-hint",children:h("Liquidation price")})}),r.jsx("b",{className:Ct?"is-liq":"",children:Ct?lt(Ct):"—"})]}),r.jsxs("div",{children:[r.jsx(Rt.Tooltip,{...is,title:h("Size of the position in dollars: size × price. This is what you trade with — not what you put up."),children:r.jsx("span",{className:"is-hint",children:h("Order value")})}),r.jsx("b",{children:Xe?"$"+lt(Xe):"—"})]}),r.jsxs("div",{children:[r.jsx(Rt.Tooltip,{...is,title:h("Your own funds locked for this order: order value divided by leverage. They are freed when the position closes."),children:r.jsx("span",{className:"is-hint",children:h("Margin required")})}),r.jsx("b",{className:ae?"is-bad":"",children:Ve?"$"+lt(Ve):"—"})]}),(O==="market"||Oe&&!Xt)&&r.jsxs("div",{children:[r.jsx(Rt.Tooltip,{...is,title:h("Estimate is calculated from the order book for your size. Max is the limit above which the order is rejected instead of filling at a worse price."),children:r.jsx("span",{className:"is-hint",children:h("Slippage")})}),r.jsxs("b",{children:[O==="market"&&r.jsxs(r.Fragment,{children:[h("Est."),": ",us===null?"—":us.toFixed(2)+"%"," / "]}),h("Max"),": ",S0.toFixed(2),"%"]})]}),r.jsxs("div",{children:[r.jsx(Rt.Tooltip,{...is,title:h("Taker / maker rate for this market. It already includes everything charged on the order — nothing is added on top."),children:r.jsx("span",{className:"is-hint",children:h("Fees")})}),r.jsxs("b",{children:[u&&u.level>0&&r.jsx("em",{className:"fut-form__vip",children:u.name}),z.toFixed(3),"% / ",F.toFixed(3),"%"]})]})]}),ut&&r.jsx("div",{className:"fut-form__warn fut-form__warn--closing",children:ut.flips?wt.isLong?h("Your long will close immediately and the rest will open a short."):h("Your short will close immediately and the rest will open a long."):wt.isLong?h("This order fills at once and closes your long instead of opening a short."):h("This order fills at once and closes your short instead of opening a long.")}),r.jsx("button",{type:"button",className:"fut-form__submit fut-form__submit--"+A,disabled:re||ae||Pe||_s||V||_e||Ue||Me||Qe,onClick:ks,children:re?h("Sending")+"…":(A==="buy"?h("Long"):h("Short"))+" "+zt(s)}),ae?r.jsx("div",{className:"fut-form__warn",children:h("Not enough margin for this order")}):Pe&&r.jsx("div",{className:"fut-form__warn",children:es})]}),r.jsxs("div",{className:"fut-balance",children:[r.jsx("div",{className:"fut-balance__venue",children:Tn(ar(s))}),r.jsxs("div",{className:"fut-balance__row",children:[r.jsx("span",{children:h("Equity")}),r.jsxs("b",{children:["$",lt(o)]})]}),r.jsxs("div",{className:"fut-balance__row",children:[r.jsx("span",{children:h("Available")}),r.jsxs("b",{children:["$",lt(vt)]})]}),(b||w)&&r.jsxs("div",{className:"fut-balance__actions",children:[b&&r.jsx("button",{type:"button",className:"fut-balance__deposit",onClick:b,children:h("Deposit")}),w&&r.jsx("button",{type:"button",className:"fut-balance__withdraw",onClick:w,children:h("Withdraw")})]}),k&&r.jsx("button",{type:"button",className:"fut-balance__move",onClick:k,children:h("Move funds")})]}),xt&&r.jsx(Nf,{title:xt.side==="buy"?h("Buy at market"):h("Sell at market"),text:h("The order will be executed immediately at the current market price."),note:zt(s)+" · "+lt(xt.size)+(xt.price>0?" · ≈ "+pe(xt.size*xt.price):""),confirmLabel:xt.side==="buy"?h("Buy"):h("Sell"),skippable:!0,onCancel:()=>Bt(null),onConfirm:R=>{const Lt=xt.size;R&&pn({...mn(),marketConfirm:!1}),Bt(null),ns(Lt)}})]})}function Mx({levels:s,onChange:t,size:e,isLong:n,mark:i,liq:o,coin:l,entry:a,leverage:c}){const[u,d]=m.useState("tp"),f=u==="tp",g=m.useMemo(()=>(String(e).split(".")[1]||"").length,[e]),v=X=>{const st=parseFloat(X)||0;return st>0?parseFloat(st.toFixed(g)):0},b=s??[],w=X=>b.filter(st=>st.kind===X).length,k=m.useRef(null),y=X=>[...X].sort((st,Ot)=>(parseFloat(Ot.price)||0)-(parseFloat(st.price)||0)).map(st=>st.id);k.current===null&&(k.current=y(b));const[S,j]=m.useState(0),E=()=>{k.current=y(b),j(X=>X+1)},z=m.useMemo(()=>{const X=k.current,st=b.filter(At=>At.kind===u),Ot=[],St=[];for(const At of st)(X.includes(At.id)?Ot:St).push(At);return Ot.sort((At,Yt)=>X.indexOf(At.id)-X.indexOf(Yt.id)),[...Ot,...St]},[s,u,S]),F=(X,st)=>{t(b.map(Ot=>Ot.id===X?{...Ot,...st}:Ot))},A=X=>t(b.filter(st=>st.id!==X)),J=()=>t(b.filter(X=>X.kind!==u)),yt=(X=>X.map(st=>parseFloat(st.size)||0))(b.filter(X=>X.kind===u)).reduce((X,st)=>X+st,0),P=Math.max(0,e-yt),G=yt>e*1.0025,nt=()=>{const X="new_"+Math.random().toString(36).slice(2,10);k.current=[...k.current,X],t([...b,{id:X,kind:u,price:"",size:P>0?String(v(P)):""}])},bt=X=>{const st=parseFloat(Ef(X.price,a,n,c));return Number.isFinite(st)?Math.round(Ff(st,f)):0},$=(X,st)=>F(X.id,{price:Lf(Af(st,f),a,n,c)}),ht=X=>{const st=parseFloat(X.size)||0;return e>0?Math.round(st/e*100):0}
6,tt=(X,st)=>F(X.id,{size:st>0?String(v(e*st/100)):""}),H=X=>{const st=parseFloat(X.price)||0,Ot=parseFloat(X.size)||0;return!st||!Ot||!a?null:(n?1:-1)*(st-a)*Ot},et=X=>{const st=parseFloat(X.price)||0;return!st||!i?!1:f?n?st<=i:st>=i:n?st>=i:st<=i},rt=X=>{const st=parseFloat(X.price)||0;return f||!st||!o?!1:n?st<=o:st>=o},Nt=e>0?Math.round(yt/e*100):0;return r.jsxs("div",{className:"tpsl-levels",children:[r.jsx("div",{className:"tpsl-levels__sides",children:[["tp","Take profit"],["sl","Stop loss"]].map(([X,st])=>r.jsxs("button",{type:"button",className:"tpsl-levels__side is-"+X+(u===X?" is-active":""),onClick:()=>d(X),children:[h(st),w(X)>0&&r.jsx("i",{children:w(X)})]},X))}),r.jsxs("div",{className:"tpsl-levels__meter"+(G?" is-over":""),children:[r.jsx("div",{className:"tpsl-levels__meter-bar",children:r.jsx("span",{style:{width:Math.min(100,Nt)+"%"}})}),r.jsxs("div",{className:"tpsl-levels__meter-text",children:[r.jsxs("span",{children:[h("Covered")," ",Nt,"%"]}),r.jsxs("b",{children:[h("left")," ",lt(P)," ",l]})]})]}),!z.length&&r.jsx("div",{className:"tpsl-levels__empty",children:f?h("No take profit levels yet."):h("No stop loss levels yet.")}),z.map((X,st)=>{const Ot=et(X),St=rt(X),At=H(X),Yt=bt(X);return r.jsxs("div",{className:"tpsl-level"+(Ot?" is-wrong":""),children:[r.jsxs("div",{className:"tpsl-level__top",children:[r.jsxs("b",{className:"tpsl-level__no",children:[h("Level")," ",st+1]}),At!==null&&!Ot&&r.jsx("span",{className:"tpsl-level__result "+(At>=0?"is-up":"is-down"),children:$e(At)}),r.jsx("button",{type:"button",className:"tpsl-level__remove",onClick:()=>A(X.id),title:h("Remove"),children:"✕"})]}),r.jsxs("div",{className:"tpsl-level__row",children:[r.jsxs("label",{children:[r.jsx("span",{children:h("Trigger price")}),r.jsx("input",{type:"text",inputMode:"decimal",value:X.price,placeholder:"0",onChange:Mt=>F(X.id,{price:Mt.target.value.replace(",",".")})})]}),a>0&&r.jsxs("div",{className:"tpsl-level__slider",children:[r.jsx("em",{children:Yt?Yt+"%":"—"}),r.jsx("input",{type:"range",min:0,max:Tu(f),step:1,value:Math.max(0,Math.min(Tu(f),Yt)),onChange:Mt=>$(X,Number(Mt.target.value))})]})]}),r.jsxs("div",{className:"tpsl-level__row",children:[r.jsxs("label",{children:[r.jsxs("span",{children:[h("Quantity")," ",r.jsx("em",{children:l})]}),r.jsx("input",{type:"text",inputMode:"decimal",value:X.size,placeholder:"0",onChange:Mt=>F(X.id,{size:Mt.target.value.replace(",",".")})})]}),r.jsxs("div",{className:"tpsl-level__slider",children:[r.jsx("em",{children:ht(X)?ht(X)+"%":"—"}),r.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.max(0,Math.min(100,ht(X))),onChange:Mt=>tt(X,Number(Mt.target.value))})]})]}),r.jsx("div",{className:"tpsl-level__quick",children:[25,50,75,100].map(Mt=>r.jsxs("button",{type:"button",className:ht(X)===Mt?"is-active":"",onClick:()=>tt(X,Mt),children:[Mt,"%"]},Mt))}),Ot&&r.jsx("div",{className:"tpsl-level__warn",children:f?n?h("Take profit for a long must be above the current price."):h("Take profit for a short must be below the current price."):n?h("Stop loss for a long must be below the current price."):h("Stop loss for a short must be above the current price.")}),!Ot&&St&&r.jsx("div",{className:"tpsl-level__note",children:h("This stop is beyond the liquidation price and will not fire.")})]},X.id)}),r.jsxs("div",{className:"tpsl-levels__foot",children:[r.jsxs("button",{type:"button",className:"tpsl-levels__add",onClick:nt,children:["+ ",h("Add level")]}),r.jsxs("button",{type:"button",className:"tpsl-levels__sort",disabled:z.length<2,onClick:E,title:h("Sort by price"),children:[r.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M7 4v16M7 20l-3-3M7 20l3-3M17 20V4M17 4l-3 3M17 4l3 3",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})}),h("Sort")]}),r.jsx("button",{type:"button",className:"tpsl-levels__clear",disabled:!z.length,onClick:J,children:f?h("Clear take profits"):h("Clear stop losses")})]})]})}function jx({accountId:s,position:t,current:e,levels:n,onClose:i,onDone:o}){var Ot;Ps(i);const{showError:l}=Ln(),a=parseFloat((t==null?void 0:t.szi)??0)||0,c=a>0,u=Math.abs(a),d=parseFloat((t==null?void 0:t.entryPx)??0)||0,f=parseFloat(((Ot=t==null?void 0:t.leverage)==null?void 0:Ot.value)??0)||1,g=parseFloat((t==null?void 0:t.liquidationPx)??0)||0,[v,b]=m.useState(e!=null&&e.tp?String(e.tp):""),[w,k]=m.useState(e!=null&&e.sl?String(e.sl):""),[
6y,S]=m.useState(!!(e!=null&&e.tp)),[j,E]=m.useState(!!(e!=null&&e.sl)),z=St=>{S(St),St||b("")},F=St=>{E(St),St||k("")},[A,J]=m.useState(!1),[O,yt]=m.useState(()=>T0(n,Math.abs(parseFloat((t==null?void 0:t.szi)??0)||0))?"whole":"part"),[P,G]=m.useState(()=>(n??[]).map(St=>({id:St.key,kind:St.kind,price:String(St.price),size:St.size>0?String(St.size):""}))),nt=m.useMemo(()=>[t==null?void 0:t.coin].filter(Boolean),[t==null?void 0:t.coin]),bt=To(nt),$=parseFloat((bt==null?void 0:bt[t==null?void 0:t.coin])??0)||(e==null?void 0:e.mark)||d,ht=m.useMemo(()=>{const St=parseFloat(v)||0;return!St||!$?!1:c?St<=$:St>=$},[v,$,c]),tt=m.useMemo(()=>{const St=parseFloat(w)||0;return!St||!$?!1:c?St>=$:St<=$},[w,$,c]),H=m.useMemo(()=>{const St=parseFloat(w)||0;return!St||!g?!1:c?St<=g:St>=g},[w,g,c]),et=!A&&!ht&&!tt,rt=m.useMemo(()=>Qd(P.map(St=>({kind:St.kind,price:parseFloat(St.price)||0,size:parseFloat(St.size)||0})).filter(St=>St.price>0&&St.size>0),u),[P,u]),Nt=async()=>{var St;if(!A){J(!0);try{const{data:At}=await ge.post("/x/futures/tpsl",{miniAppData:(St=ve())==null?void 0:St.initData,account_id:s,coin:t.coin,levels:rt});At!=null&&At.err?l(At.errText||At.err):(ta(s,t.coin,!1),ys(At.cleared?h("Take profit and stop loss removed"):h("Take profit and stop loss saved")),o&&o(),i&&i())}catch{l(h("Network error"))}finally{J(!1)}}},X=async()=>{var St;if(O==="part")return Nt();if(et){J(!0);try{const{data:At}=await ge.post("/x/futures/tpsl",{miniAppData:(St=ve())==null?void 0:St.initData,account_id:s,coin:t.coin,take_profit:parseFloat(v)||0,stop_loss:parseFloat(w)||0});At!=null&&At.err?l(At.errText||At.err):(ta(s,t.coin,!At.cleared&&(y||j)),ys(At.cleared?h("Take profit and stop loss removed"):h("Take profit and stop loss saved")),o&&o(),i&&i())}catch{l(h("Network error"))}finally{J(!1)}}},st=St=>{const At=St==="tp",Yt=At?y:j;return r.jsx("div",{className:"fut-tpsl__group"+(Yt?"":" is-off"),children:r.jsx(ca,{kind:St,enabled:At?y:j,onToggle:At?z:F,isLong:c,refPrice:d,leverage:f,size:u,value:At?v:w,onChange:At?b:k,wrong:At?ht:tt,maxPercent:At?200:100,bipolar:!0,hint:At?c?h("Take profit for a long must be above the current price. A level below it is a loss — put it into stop loss."):h("Take profit for a short must be below the current price. A level above it is a loss — put it into stop loss."):c?h("Stop loss for a long must be below the current price. A level above it is a profit — put it into take profit."):h("Stop loss for a short must be above the current price. A level below it is a profit — put it into take profit.")})})};return r.jsx("div",{className:"fut-modal",onClick:i,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:St=>St.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsxs("b",{children:[h("Take profit / Stop loss")," · ",zt(t.coin)]}),r.jsx("button",{type:"button",onClick:i,children:"✕"})]}),r.jsxs("div",{className:"fut-tpsl__scroll fut-scroll",children:[r.jsxs("div",{className:"fut-tpsl__pos",children:[r.jsxs("div",{children:[r.jsx("span",{children:h("Size")}),r.jsxs("b",{children:[lt(u)," ",zt(t.coin)]})]}),r.jsxs("div",{children:[r.jsx("span",{children:h("Entry price")}),r.jsx("b",{children:lt(d)})]}),r.jsxs("div",{children:[r.jsx("span",{children:h("Mark price")}),r.jsx("b",{children:$?lt($):"—"})]})]}),r.jsxs("div",{className:"fut-tpsl__tabs",children:[r.jsx("button",{type:"button",className:O==="whole"?"is-active":"",onClick:()=>yt("whole"),children:h("Whole position")}),r.jsx("button",{type:"button",className:O==="part"?"is-active":"",onClick:()=>yt("part"),children:h("Part of position")})]}),O==="part"?r.jsx(Mx,{levels:P,onChange:G,size:u,isLong:c,mark:$,liq:g,coin:zt(t.coin),entry:d,leverage:f}):r.jsxs(r.Fragment,{children:[st("tp"),st("sl")]}),j&&H&&r.jsx("div",{className:"fut-form__warn",children:h("The stop loss is beyond the liquidation price of {price} — the exchange will close the position before it triggers.",{price:lt(g)})}),f>1&&r.jsx("div",{className:"fut-tpsl__note",children:h("Percentages are counted on margin, at {lev}× leverage.",{lev:lt(f)})}),r.jsx("div",{className:"fut-tpsl__note",children:O==="part"?h("Each level closes its own size and stays fixed — it will not follow the position if you add to it. Levels work independently: when one fires, the rest keep standing."):h("Both orders close the whole position at market. When one fires, the other is cancelled automatically.")})]}),r.jsx("button",{type:"button",className:"fut-form__submit fut-form__submit--buy",disabled:O==="part"?A:!et,onClick:X,children:A?h("Sending")+"…":O==="part"?rt.length?h("Save"):h("Remove TP/SL"):!v&&!w?h("Remove TP/SL"):h("Save")})]})})}function Sx({accountId:s,position:t,markPx:e,onClose:n,onDone:i}){Ps(n);const{showError:o}=Ln(),[l,a]=m.useState("add"),[c,u]=m.useState(""),[d,f]=m.useState(!1),g=t==null?void 0:t.coin,v=parseFloat((t==null?void 0:t.szi)??0)||0,b=v>0,w=Math.abs(v),k=parseFloat((t==null?void 0:t.entryPx)??0)||0,y=parseFloat((t==null?void 0:t.marginUsed)??0)||0,S=parseFloat((t==null?void 0:t.liquidationPx)??0)||0,j=Math.abs(parseFloat((t==null?void 0:t.positionValue)??0)||0),E=parseFloat((t==null?void 0:t.maxLeverage)??0)||0;parseFloat(e??0)||parseFloat((t==null?void 0:t.positionValue)??0)/(w||1);const z=parseFloat(c)||0,F=j>0&&E>0?j/(2*E):0,A=_i(Math.max(0,y-F)),J=_i(y),O=l==="remove"&&z>A,yt=l==="remove"&&J>0&&z>=J-1e-9,P=m.useMemo(()=>
6{if(!w||!k||!z)return null;const ht=l==="add"?z:-z,tt=y+ht;if(tt<=0)return null;const H=tt/w;return b?k-H:k+H},[w,k,y,z,l,b]),G=z>0&&!O&&!yt&&!d,nt=J>0?Math.min(100,z/J*100):0,bt=ht=>{const tt=J*(Math.max(0,Math.min(100,ht))/100);u(tt>0?String(_i(tt)):"")},$=async()=>{var ht;if(G){f(!0);try{const{data:tt}=await ge.post("/x/futures/margin",{miniAppData:(ht=ve())==null?void 0:ht.initData,account_id:s,coin:g,amount:l==="add"?z:-z});tt!=null&&tt.err?o(tt.errText||tt.err):(ys(l==="add"?h("Margin added"):h("Margin removed")),i&&i(),n&&n())}catch{o(h("Network error"))}finally{f(!1)}}};return r.jsx("div",{className:"fut-modal",onClick:n,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:ht=>ht.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsxs("b",{children:[h("Position margin")," · ",zt(g)]}),r.jsx("button",{type:"button",onClick:n,children:"✕"})]}),r.jsxs("div",{className:"fut-margin__facts",children:[r.jsxs("div",{children:[r.jsx("span",{children:h("Allocated margin")}),r.jsx("b",{children:pe(y)})]}),r.jsxs("div",{children:[r.jsx("span",{children:h("Liq. price")}),r.jsx("b",{className:"is-down",children:S?lt(S):"—"})]})]}),r.jsxs("div",{className:"fut-transfer__modes",children:[r.jsx("button",{type:"button",className:l==="add"?"is-active":"",onClick:()=>{a("add"),u("")},children:h("Add margin")}),r.jsx("button",{type:"button",className:l==="remove"?"is-active":"",onClick:()=>{a("remove"),u("")},children:h("Remove margin")})]}),r.jsxs("label",{className:"fut-form__field",children:[r.jsxs("span",{className:"fut-form__label",children:[h("Amount")," ",r.jsx("em",{children:"USDC"})]}),r.jsx("input",{type:"text",inputMode:"decimal",value:c,onChange:ht=>u(ht.target.value.replace(",",".")),placeholder:"0",autoFocus:!0})]}),l==="remove"&&J>0&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-margin__slider",children:[r.jsx("input",{type:"range",min:0,max:100,step:1,value:Math.round(nt),onChange:ht=>bt(Number(ht.target.value)),"aria-label":h("Amount")}),r.jsx("div",{className:"fut-margin__scale",children:[0,25,50,75,100].map(ht=>r.jsxs("button",{type:"button",className:Math.round(nt)===ht?"is-active":"",onClick:()=>bt(ht),children:[ht,"%"]},ht))})]}),r.jsxs("button",{type:"button",className:"fut-transfer__max",onClick:()=>u(String(A)),children:[h("Available to remove"),": ",A," USDC"]})]}),P!==null&&r.jsxs("div",{className:"fut-margin__preview",children:[r.jsx("span",{children:h("Liq. price")}),r.jsxs("b",{children:[r.jsx("s",{children:S?lt(S):"—"}),r.jsx("i",{children:"→"}),r.jsx("em",{className:l==="add"?"is-up":"is-down",children:lt(P)})]})]}),yt?r.jsx("div",{className:"fut-form__warn",children:h("The entire margin cannot be removed — the position would be left with no collateral. Leave at least the maintenance margin.")}):O&&r.jsx("div",{className:"fut-form__warn",children:h("Cannot remove more than the allocated margin")}),l==="remove"&&z>0&&!O&&!yt&&r.jsx("div",{className:"fut-margin__note",children:h("Removing margin moves the liquidation price closer to the current price.")}),r.jsx("button",{type:"button",className:"fut-lev__apply",disabled:!G,onClick:$,children:d?h("Sending")+"…":l==="add"?h("Add margin"):h("Remove margin")})]})})}const xs="/images/pnl/bg/",Ns="/images/pnl/char/",ha=[{id:"plain",title:"Без фона",src:null},{id:"bg-01-nebula",title:"Туманность",src:xs+"bg-01-nebula.jpg"},{id:"bg-02-gold",title:"Золото",src:xs+"bg-02-gold.jpg"},{id:"bg-03-synth",title:"Синтвейв",src:xs+"bg-03-synth.jpg"},{id:"bg-04-carbon",title:"Карбон",src:xs+"bg-04-carbon.jpg"},{id:"bg-05-aurora",title:"Сияние",src:xs+"bg-05-aurora.jpg"},{id:"bg-06-crystal",title:"Кристаллы",src:xs+"bg-06-crystal.jpg"},{id:"bg-07-surge",title:"Импульс",src:xs+"bg-07-surge.jpg"},{id:"bg-08-ember",title:"Угли",src:xs+"bg-08-ember.jpg"},{id:"bg-09-bokeh",title:"Боке",src:xs+"bg-09-bokeh.jpg"},{id:"bg-10-orbit",title:"Орбита",src:xs+"bg-10-orbit.jpg"},{id:"bg-11-matrix",title:"Матрица",src:xs+"bg-11-matrix.jpg"},{id:"bg-12-dawn",title:"Рассвет",src:xs+"bg-12-dawn.jpg"},{id:"bg-13-candles",title:"Свечи",src:xs+"bg-13-candles.jpg"},{id:"bg-14-chain",title:"Блокчейн",src:xs+"bg-14-chain.jpg"},{id:"bg-15-vault",title:"Хранилище",src:xs+"bg-15-vault.jpg"}],ua=[{id:"none",title:"Без героя",src:null},{id:"char-01-bull",title:"Бык",src:Ns+"char-01-bull.png"},{id:"char-02-bear",title:"Медведь",src:Ns+"char-02-bear.png"},{id:"char-03-astronaut",title:"Космонавт",src:Ns+"char-03-astronaut.png"},{id:"char-04-whale",title:"Кит",src:Ns+"char-04-whale.png"},{id:"char-05-robot",title:"Робот",src:Ns+"char-05-robot.png"}
6,{id:"char-06-shiba",title:"Сиба",src:Ns+"char-06-shiba.png"},{id:"char-07-miner",title:"Майнер",src:Ns+"char-07-miner.png"},{id:"char-08-coin",title:"Монета",src:Ns+"char-08-coin.png"},{id:"char-09-rocket",title:"Ракета",src:Ns+"char-09-rocket.png"},{id:"char-10-wizard",title:"Маг",src:Ns+"char-10-wizard.png"},{id:"char-11-penguin",title:"Пингвин",src:Ns+"char-11-penguin.png"},{id:"char-12-pepe-surf",title:"Пепе на свече",src:Ns+"char-12-pepe-surf.png"},{id:"char-13-pepe-laser",title:"Пепе-лазер",src:Ns+"char-13-pepe-laser.png"},{id:"char-14-pepe-diamond",title:"Пепе с алмазом",src:Ns+"char-14-pepe-diamond.png"}],Nx=s=>ha.find(t=>t.id===s)??ha[0],Cx=s=>ua.find(t=>t.id===s)??ua[0],Tx=s=>s>=0?"bg-07-surge":"bg-08-ember",Lx="svg",Ex="svg",Fx="svg",Ax="svg",Rx="png",Px="png",zx="svg",Dx="svg",Ox="svg",Ix="svg",Bx="svg",Wx="png",qx="svg",Vx="svg",Ux="svg",Hx="svg",Kx="svg",$x="svg",Yx="png",Qx="svg",Gx="svg",Xx="png",Zx="svg",Jx="svg",ty="svg",ey="svg",sy="png",ny="svg",iy="svg",ry="svg",oy="svg",ly="svg",ay="png",cy="svg",hy="svg",uy="svg",dy="png",fy="svg",my="svg",py="svg",gy="svg",vy="png",xy="png",yy="png",by="svg",wy="svg",_y="svg",ky="svg",My="svg",jy="svg",Sy="svg",Ny="svg",Cy="png",Ty="svg",Ly="svg",Ey="svg",Fy="svg",Ay="svg",Ry="png",Py="svg",zy="svg",Dy="svg",Oy="svg",Iy="svg",By="svg",Wy="svg",qy="svg",Vy="svg",Uy="svg",Hy="svg",Ky="svg",$y="svg",Yy="svg",Qy="png",Gy="svg",Xy="svg",Zy="svg",Jy="svg",tb="svg",eb="svg",sb="svg",nb="svg",ib="svg",rb="svg",ob="png",lb="svg",ab="svg",cb="svg",hb="svg",ub="svg",db="svg",fb="svg",mb="svg",pb="png",gb="svg",vb="svg",xb="png",yb="svg",bb="svg",wb="svg",_b="svg",kb="png",Mb="svg",jb="svg",Sb="svg",Nb="svg",Cb="svg",Tb="svg",Lb="svg",Eb="svg",Fb="svg",Ab="svg",Rb="png",Pb="svg",zb="svg",Db="svg",Ob="png",Ib="svg",Bb="png",Wb="png",qb="svg",Vb="svg",Ub="svg",Hb="svg",Kb="svg",$b="svg",Yb="svg",Qb="svg",Gb="svg",Xb="svg",Zb="svg",Jb="svg",t1="png",e1="svg",s1="svg",n1="svg",i1="png",r1="svg",o1="svg",l1="png",a1="svg",c1="png",h1="svg",u1="svg",d1="svg",f1="svg",m1="svg",p1="svg",g1="svg",v1="svg",x1="svg",y1="svg",b1="svg",w1="svg",_1="svg",k1="svg",M1="svg",j1="png",S1="svg",N1="svg",C1="svg",T1="svg",L1="svg",E1="svg",F1="svg",A1="png",R1="svg",P1="svg",z1="png",D1="svg",O1="svg",I1="png",B1="svg",W1="png",q1="png",V1="svg",U1="svg",H1="svg",K1="svg",$1="svg",Y1="svg",Q1="svg",G1="svg",X1="svg",Z1="svg",J1="svg",tw="svg",ew="svg",sw="svg",nw="svg",iw="svg",rw="svg",ow="svg",lw="svg",aw="svg",cw="svg",hw="svg",uw="svg",dw="svg",fw="svg",mw="svg",pw="svg",gw="svg",vw="png",xw="svg",yw="svg",bw="svg",ww="svg",_w="svg",kw="svg",Mw="svg",jw="svg",Sw="svg",Nw="svg",Cw="svg",Tw="svg",Lw="png",Ew="svg",Fw="svg",Aw="png",Rw="png",Pw="svg",zw="svg",Dw="png",Ow="png",Iw="png",Bw="svg",Ww="svg",qw="svg",Vw="svg",Uw="svg",Hw="svg",Kw="png",$w="svg",Yw="svg",Qw="svg",Gw="svg",Xw="svg",Zw="svg",Jw="svg",t_="svg",e_="svg",s_="svg",n_="svg",i_="png",r_="svg",o_="svg",l_="svg",a_="svg",c_="png",h_="svg",zf={"0g":"svg","2z":"svg",aapl:Lx,aave:Ex,ace:Fx,ada:Ax,aero:Rx,aixbt:Px,algo:zx,alt:Dx,amat:Ox,amd:Ix,amzn:Bx,anime:Wx,ape:qx,apex:Vx,apt:Ux,ar:Hx,arb:Kx,asml:$x,aster:Yx,atom:Qx,avax:Gx,avnt:Xx,axs:Zx,aztec:Jx,baba:ty,baby:ey,banana:sy,bb:ny,bch:iy,bera:ry,bigtime:oy,bio:ly,blur:ay,bnb:cy,bome:hy,brentoil:uy,brett:dy,bsv:fy,btc:my,bx:py,cake:gy,cashcat:vy,cbrs:xy,cc:yy,celo:by,cfx:wy,chip:_y,cl:ky,coin:My,comp:jy,cost:Sy,crcl:Ny,crv:Cy,crwv:Ty,cxmt:Ly,dash:Ey,dell:Fy,dkng:Ay,doge:Ry,dot:Py,dram:zy,dydx:Dy,dym:Oy,eigen:Iy,ena:By,ens:Wy,etc:qy,eth:Vy,ethfi:Uy,eur:Hy,ewj:Ky,ewy:$y,ewz:Yy,fartcoin:Qy,fet:Gy,fil:Xy,fogo:Zy,gala:Jy,gas:tb,gbp:eb,gev:sb,gme:nb,gmt:ib,gmx:rb,goat:ob,gold:lb,googl:ab,gram:cb,grass:hb,griffain:ub,hbar:db,hemi:fb,hims:mb,hmstr:pb,hood:gb,hype:vb,hyper:xb,hyundai:yb,ibm:bb,icp:wb,imx:_b,init:kb,inj:Mb,intc:jb,io:Sb,iota:Nb,jp225:Cb,jpy:Tb,jto:Lb,jup:Eb,kaito:Fb,kas:Ab,kbonk:Rb,kfloki:Pb,kioxia:zb,klunc:Db,kneiro:Ob,koru:Ib,kpepe:Bb,kr200:Wb,kshib:qb,layer:Vb,ldo:Ub,linea:Hb,link:Kb,lit:$b,lite:Yb,lly:Qb,ltc:Gb,manta:Xb,me:Zb,mega:Jb,melania:t1,meme:e1,merl:s1,met:n1,meta:i1,mina:r1,minimax:o1,mnt:l1,mon:a1,moodeng:c1,morpho:h1,move:u1,mrvl:d1,msft:f1,mstr:m1,mu:p1,nbis:g1,near:v1,neo:x1,nflx:y1,nil:b1,nok:w1,not:_1,now:k1,nvda:M1,nxpc:j1,ondo:S1,op:N1,orcl:C1,ordi:T1,palladium:L1,paxg:E1,pendle:F1,pengu:A1,platinum:R1,pltr:P1,pnut:z1,pol:D1,polyx:O1,popcat:I1,prove:B1,pump:W1,purr:q1,pyth:V1,qnt:U1,render:H1,resolv:K1,rez:$1,rivn:Y1,rklb:Q1,rsr:G1,rune:X1,s:Z1,saga:J1,sand:tw,sei:ew,shaz:sw,silver:nw,skhx:iw,skhy:rw,skr:ow,sky:lw,smh:aw,smsn:cw,sndk:hw,snx:uw,softbank:dw,sol:fw,soph:mw,sp500:pw,spcx:gw,spx:vw,stable:xw,stbl:yw,strc:bw,strk:ww,stx:_w,sui:kw,super:"png",sushi:Mw,syrup:jw,tao:Sw,tia:Nw,tnsr:Cw,trb:Tw,trump:Lw,trx:Ew,tsla:Fw,tsm:Aw,turbo:Rw,uma:Pw,uni:zw,unitree:Dw,usar:Ow,usual:Iw,vine:Bw,virtual:Ww,vvv:qw,w:Vw,wct:Uw,wdc:Hw,wif:Kw,wld:$w,wlfi:Yw,xai:Qw,xle:Gw,xlm:Xw,xmr:Zw,xpl:Jw,xrp:t_,xyz100:e_,ygg:s_,zec:n_,zen:i_,zeta:r_,zhipu:o_,zk:l_,zm:a_,zora:c_,zro:h_},Xs=1200,kn=675,Yr=2,os=64,Gs={base:"#0b0c11",up:"#2ebd85",down:"#f0616d",text:"#e8eaf0",muted:"#8b94a8"},u_='"Inter", -apple-system, "Segoe UI", sans-serif',Bs=(s,t)=>s+" "+t+"px "+u_,jl=s=>{const t=parseFloat(s)||0;return t===0?"$0":(t>0?"+":"−")+"$"+lt(Math.abs(t))},Sl=new Map;function Qr(s){if(!s)return Promise.resolve(null);if(Sl.has(s))return Sl.get(s);const t=new Promise(e=>{const n=new Image;n.crossOrigin="anonymous",n.onload=()=>e(n),n.onerror=()=>e(null),n.src=s});return Sl.set(s,t),t}function d_(s){const t=(zt(s)||"").toLowerCase(),e=zf[t];return e?"/images/futures/"+t+"."+e:null}function da(s,t,e,n,i,o){s.beginPath(),s.moveTo(t+o,e),s.arcTo(t+n,e,t+n,e+i,o),s.arcTo(t+n,e+i,t,e+i,o),s.arcTo(t,e+i,t,e,o),s.arcTo(t,e,t+n,e,o),s.closePath()}function f_(s,t,e,n,i,o){const l=Math.max(i/t.width,o/t.height),a=t.width*l,c=t.height*l;s.drawImage(t,e+(i-a)/2,n+(o-c)/2,a,c)}function m_(s,t,e,n,i,o){const l=Math.min(i/t.width,o/t.height),a=t.width*l,c=t.height*l;s.drawImage(t,e-a/2,n-c,a,c)}function p_(s,t,e){if(s.measureText(t).width<=e)return t;let n=t;for(;n.length>1&&s.measureText(n+"…").width>e;)n=n.slice(0,-1);return n+"…"}async function g_(){if(document.fonts)try{await Promise.all([document.fonts.load('800 132px "Inter"'),document.fonts.load('700 40px "Inter"'),document.fonts.load('600 32px "Inter"'),document.fonts.load('500 22px "Inter"')]),await document.fonts.ready}catch{}}function v_(s,t,e,n,i){const o=pm(0,"M");o.addData(t),o.make();const l=o.getModuleCount(),a=Math.round(i*.1),c=(i-a*2)/l;s.save(),s.shadowColor="rgba(0,0,0,.45)",s.shadowBlur=24,s.shadowOffsetY=6,s.fillStyle="#ffffff",da(s,e,n,i,i,18),s.fill(),s.restore(
6),s.fillStyle="#0b0c11";for(let u=0;u<l;u++)for(let d=0;d<l;d++)o.isDark(u,d)&&s.fillRect(e+a+d*c,n+a+u*c,c+1,c+1)}async function x_(s,t,e){const n=s.getContext("2d");s.width=Xs*Yr,s.height=kn*Yr,n.setTransform(Yr,0,0,Yr,0,0),n.clearRect(0,0,Xs,kn);const i=(t.pnlUsd??0)>=0,o=i?Gs.up:Gs.down,l=t.isLong?h("Long"):h("Short"),[a,c,u,d]=await Promise.all([Qr(e.backgroundSrc),Qr(e.characterSrc),Qr(d_(t.coin)),Qr("/images/logo_yellow.svg")]);n.fillStyle=Gs.base,n.fillRect(0,0,Xs,kn),a&&f_(n,a,0,0,Xs,kn);const f=n.createLinearGradient(0,0,Xs,0);f.addColorStop(0,"rgba(8,9,13,.94)"),f.addColorStop(.45,"rgba(8,9,13,.72)"),f.addColorStop(1,"rgba(8,9,13,.30)"),n.fillStyle=f,n.fillRect(0,0,Xs,kn),c&&m_(n,c,Xs*.72,kn-36,380,430);const g=n.createRadialGradient(os+180,330,0,os+180,330,420);g.addColorStop(0,i?"rgba(46,189,133,.22)":"rgba(240,97,109,.22)"),g.addColorStop(1,"rgba(0,0,0,0)"),n.fillStyle=g,n.fillRect(0,0,Xs,kn);let v=os;if(d){const $=d.width*(30/d.height);n.drawImage(d,os,os-6,$,30),v=os+$+16}if(n.fillStyle="rgba(255,255,255,.22)",n.fillRect(v,os-4,1,26),n.fillStyle=Gs.muted,n.font=Bs(600,20),n.textBaseline="alphabetic",n.fillText(h("Futures").toUpperCase(),v+16,os+16),e.showDate&&t.closedAt){const bt=new Date(t.closedAt);n.textAlign="right",n.fillStyle=Gs.muted,n.font=Bs(500,20),n.fillText(bt.toLocaleDateString()+" "+bt.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),Xs-os,os+16),n.textAlign="left"}const b=176;let w=os;u&&(n.save(),n.beginPath(),n.arc(w+26,b-9,26,0,Math.PI*2),n.clip(),n.drawImage(u,w,b-35,52,52),n.restore(),w+=68),n.fillStyle=Gs.text,n.font=Bs(700,42),n.fillText(zt(t.coin),w,b+6),w+=n.measureText(zt(t.coin)).width+20;const k=l.toUpperCase()+(e.showLeverage&&t.leverage?"  "+lt(t.leverage)+"×":"");n.font=Bs(700,24);const y=n.measureText(k).width+36;n.fillStyle=i?"rgba(46,189,133,.16)":"rgba(240,97,109,.16)",da(n,w,b-30,y,46,12),n.fill(),n.strokeStyle=i?"rgba(46,189,133,.45)":"rgba(240,97,109,.45)",n.lineWidth=1.5,da(n,w,b-30,y,46,12),n.stroke(),n.fillStyle=o,n.fillText(k,w+18,b+2);const S=t.pnlPct,j=Number.isFinite(S),E=e.showPercent&&j,z=E?(S>=0?"+":"")+S.toFixed(2)+"%":jl(t.pnlUsd??0),F=E&&t.pctBase==="volume"?h("of position volume"):"";let A=128;for(n.font=Bs(800,A);A>64&&n.measureText(z).width>620;)A-=4,n.font=Bs(800,A);n.fillStyle=o,n.fillText(z,os-4,350);let J=os;E&&e.showAmount&&(n.fillStyle=Gs.text,n.font=Bs(600,42),n.fillText(jl(t.pnlUsd??0),J,406),J+=n.measureText(jl(t.pnlUsd??0)).width+16),F&&(n.fillStyle=Gs.muted,n.font=Bs(500,26),n.fillText(F,J,406));const O=[];e.showEntry&&t.entryPx&&O.push([h("Entry price"),lt(t.entryPx)]),e.showExit&&t.exitPx&&O.push([t.exitLabel||h("Mark price"),lt(t.exitPx)]),e.showSize&&t.size&&O.push([h("Size"),lt(t.size)+" "+zt(t.coin)]);let yt=os;for(const[bt,$]of O)n.fillStyle=Gs.muted,n.font=Bs(600,20),n.fillText(bt,yt,470),n.fillStyle=Gs.text,n.font=Bs(600,32),n.fillText($,yt,510),yt+=Math.max(200,n.measureText($).width+60);e.note&&(n.fillStyle="rgba(232,234,240,.86)",n.font="italic "+Bs(500,26),n.fillText(p_(n,e.note,620),os,562));const P=156,G=Xs-os-P,nt=kn-os-P+10;e.showQr&&e.link&&v_(n,e.link,G,nt,P),n.fillStyle=Gs.muted,n.font=Bs(600,22),n.fillText(h("Trade perps on Radex"),os,622)}let Gr=null;function y_(){return Gr||(Gr=ge.post("/x/profile",{miniAppData:ve().initData,lang:fd(),getProfile:1}).then(({data:s})=>{var e;const t=((e=s==null?void 0:s.profile)==null?void 0:e.referral_code)??(s==null?void 0:s.referral_code)??null;return t?gm(t):"https://app.radex.global/futures"}).catch(()=>"https://app.radex.global/futures"),Gr)}function Df({card:s,onClose:t}){const e=ur(),n=m.useRef(null),[i,o]=m.useState(null),[l,a]=m.useState(""),[c,u]=m.useState(!1),d=e.pnlBg||Tx(s.pnlUsd??0),f=e.pnlChar||"none",g=m.useCallback((y,S)=>{pn({...nr(),[y]:S})},[]);m.useEffect(()=>{let y=!0;return y_().then(S=>{y&&o(S)}),()=>{y=!1}},[]),Ps(t),m.useEffect(()=>{let y=!0;return(async()=>{const S=n.current;S&&(await g_(),y&&await x_(S,s,{backgroundSrc:Nx(d).src,characterSrc:Cx(f).src,showLeverage:e.pnlLeverage,showEntry:e.pnlEntry,showExit:e.pnlExit,showSize:e.pnlSize,showAmount:e.pnlAmount,showPercent:e.pnlPercent,showQr:e.pnlQr,showDate:e.pnlDate,note:l.trim(),link:i}))})(),()=>{y=!1}},[s,d,f,l,i,e.pnlLeverage,e.pnlEntry,e.pnlExit,e.pnlSize,e.pnlAmount,e.pnlPercent,e.pnlQr,e.pnlDate]);const v="radex-"+zt(s.coin).toLowerCase().replace(/[^a-z0-9]+/g,"-")+"-"+((s.pnlUsd??0)>=0?"profit":"loss")+".png",b=()=>{const y=n.current;y&&(u(!0),y.toBlob(S=>{if(u(!1),!S){Dn(h("Could not build the image. Try again."));return}const j=URL.createObjectURL(S),E=document.createElement("a");E.href=j,E.download=v,document.body.appendChild(E),E.click(),document.body.removeChild(E),setTimeout(()=>URL.revokeObjectURL(j),2e4)},"image/png"))},w=async()=>
6{if(i)try{await navigator.clipboard.writeText(i),ys(h("Link copied"))}catch{const S=document.createElement("textarea");S.value=i,S.style.position="fixed",S.style.opacity="0",document.body.appendChild(S),S.select();try{document.execCommand("copy"),ys(h("Link copied"))}catch{Dn(i)}document.body.removeChild(S)}},k=[...Number.isFinite(s.pnlPct)?[{key:"pnlPercent",title:h("PnL in %")}]:[],{key:"pnlAmount",title:h("PnL in $")},{key:"pnlLeverage",title:h("Leverage")},{key:"pnlEntry",title:h("Entry price")},{key:"pnlExit",title:s.exitLabel||h("Mark price")},{key:"pnlSize",title:h("Size")},{key:"pnlDate",title:h("Date")},{key:"pnlQr",title:h("My referral QR")}];return r.jsx("div",{className:"fut-modal",onClick:t,children:r.jsxs("div",{className:"fut-modal__box fut-pnl",onClick:y=>y.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Share PnL card")}),r.jsx("button",{type:"button",onClick:t,children:"✕"})]}),r.jsxs("div",{className:"fut-pnl__body",children:[r.jsx("div",{className:"fut-pnl__preview",children:r.jsx("canvas",{ref:n,className:"fut-pnl__canvas",style:{aspectRatio:Xs+" / "+kn}})}),r.jsxs("div",{className:"fut-pnl__side fut-scroll",children:[r.jsxs("div",{className:"fut-pnl__group",children:[r.jsx("span",{className:"fut-pnl__label",children:h("Background")}),r.jsx("div",{className:"fut-pnl__thumbs",children:ha.map(y=>r.jsx("button",{type:"button",title:y.title,className:"fut-pnl__thumb"+(y.id===d?" is-on":""),style:y.src?{backgroundImage:"url("+y.src+")"}:void 0,onClick:()=>g("pnlBg",y.id),children:!y.src&&r.jsx("i",{children:"✕"})},y.id))})]}),r.jsxs("div",{className:"fut-pnl__group",children:[r.jsx("span",{className:"fut-pnl__label",children:h("Character")}),r.jsx("div",{className:"fut-pnl__thumbs",children:ua.map(y=>r.jsx("button",{type:"button",title:y.title,className:"fut-pnl__thumb fut-pnl__thumb--char"+(y.id===f?" is-on":""),style:y.src?{backgroundImage:"url("+y.src+")"}:void 0,onClick:()=>g("pnlChar",y.id),children:!y.src&&r.jsx("i",{children:"✕"})},y.id))})]}),r.jsxs("div",{className:"fut-pnl__group",children:[r.jsx("span",{className:"fut-pnl__label",children:h("Show on the card")}),r.jsx("div",{className:"fut-pnl__checks",children:k.map(y=>r.jsxs("label",{className:"fut-pnl__check",children:[r.jsx("input",{type:"checkbox",checked:!!e[y.key],onChange:S=>g(y.key,S.target.checked)}),r.jsx("span",{children:y.title})]},y.key))})]}),r.jsxs("div",{className:"fut-pnl__group",children:[r.jsxs("span",{className:"fut-pnl__label",children:[h("Your text")," ",r.jsxs("i",{children:["(",h("optional"),")"]})]}),r.jsx("input",{type:"text",className:"fut-pnl__note",value:l,maxLength:70,placeholder:h("For example: caught the whole move"),onChange:y=>a(y.target.value)})]}),r.jsx("div",{className:"fut-pnl__acts",children:r.jsx("button",{type:"button",className:"fut-pnl__btn fut-pnl__btn--main",disabled:c,onClick:b,children:c?h("Saving")+"…":h("Download image")})}),i&&r.jsxs("div",{className:"fut-pnl__hint",children:[r.jsx("button",{type:"button",className:"fut-pnl__copy",title:h("Copy link"),"aria-label":h("Copy link"),onClick:w,children:r.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2.5",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("path",{d:"M5 15H4.5A1.5 1.5 0 0 1 3 13.5v-9A1.5 1.5 0 0 1 4.5 3h9A1.5 1.5 0 0 1 15 4.5V5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]})}),r.jsxs("span",{children:[h("The QR code on the card points to your referral invite."),r.jsx("em",{children:i.replace(/^https?:\/\//,"")})]})]})]})]})]})})}function Ou(s,t){const e=Math.abs(parseFloat(t)||0);if(!e)return"";const n=(l,a)=>l&&a>0?Math.round(a/e*100):100,i=s.tp?n(s.tpPartial,s.tpSize):null,o=s.sl?n(s.slPartial,s.slSize):null;return(i===null||i===100)&&(o===null||o===100)?"":i!==null&&o!==null&&i!==o?i+"% / "+o+"%":(i??o)+"%"}const co=.05,Iu=3,b_=.05,Bu=.2;function Wu(s,t,e,n=0){const i=parseFloat(s)||0;if(!(i>0))return 0;const o=Math.max(parseFloat(t)||0,co)/100,l=e?i*(1+o):i*(1-o),a=Math.pow(10,bo(l,n));let c=e?Math.ceil(l*a)/a:Math.floor(l*a)/a;return c===i&&(c=e?c+1/a:c-1/a),c>0?c:i}function qu(s,t,e){const n=parseFloat(s)||0,i=parseFloat(t)||0;return!(n>0)||!(i>0)?!1:e?n<=i:n>=i}const xi={modifiers:{flip:{enabled:!1},preventOverflow:{enabled:!1},hide:{enabled:!1}}},w_=["positions","orders","twap","history","funding"];function fa({accountId:s,positions:t=[],openOrders:e,twaps:n=[],onChanged:i,compact:o=!1,coin:l=null,onPickCoin:a=null,history:c=null,vip:u=null,universe:d=null,onboarded:f=!0,closeRequest:g=null}){const[v,b]=m.useState("positions"),[w,k]=m.useState(null),y=m.useRef(!1),[S,j]=m.useState(null),[E,z]=m.useState(null),F=c??w,[A,J]=m.useState([]),O=m.useRef(0),yt=m.useRef(Date.now()),P=m.useCallback(T=>{let Q=(Array.isArray(T)?T:(T==null?void 0:T.fills)??[T]).filter(vt
6=>(vt==null?void 0:vt.coin)&&(vt==null?void 0:vt.sz));if(T!=null&&T.isSnapshot){const vt=O.current||yt.current;Q=Q.filter(wt=>(Number(wt.time)||0)>vt)}Q.length&&J(vt=>[...vt,...Q].slice(-500))},[]);sn("user",{sub:"fills"},P);const G=m.useMemo(()=>{const T=wt=>String(wt.tid??wt.time+":"+wt.coin+":"+wt.px+":"+wt.sz);let Z=0;for(const wt of(F==null?void 0:F.fills)??[])Z=Math.max(Z,Number(wt.time)||0);for(const wt of A)Z=Math.max(Z,Number(wt.time)||0);if(O.current=Z,!F||!A.length)return F;const Q=new Set((F.fills??[]).map(T)),vt=[];for(const wt of A){const It=T(wt);Q.has(It)||(Q.add(It),vt.push(wt))}return vt.length?{...F,fills:[...F.fills??[],...vt]}:F},[F,A]),[nt,bt]=m.useState({key:null,dir:"desc"}),$=T=>{bt(Z=>Z.key===T?{key:T,dir:Z.dir==="desc"?"asc":"desc"}:{key:T,dir:T==="market"?"asc":"desc"})},[ht,tt]=m.useState(null),[H,et]=m.useState(null),[rt,Nt]=m.useState(!1),[X,st]=m.useState(""),{showError:Ot}=Ln(),St=rt&&l,At=X.trim().toLowerCase(),Yt=T=>St&&T!==l?!1:At?zt(String(T??"")).toLowerCase().includes(At):!0,Mt=t.filter(T=>Yt(T.coin)),Gt=(e??[]).filter(T=>Yt(T.coin)),jt=(n??[]).filter(T=>Yt(T.coin)),Be=((G==null?void 0:G.fills)??[]).filter(T=>Yt(T.coin)),de=((G==null?void 0:G.funding)??[]).filter(T=>{var Z;return Yt((Z=T.delta)==null?void 0:Z.coin)}),ie=(T,Z)=>r.jsx("div",{className:"fut-panel__empty",children:St&&T>0?h("Nothing on this market. Switch the filter to «All» to see the rest."):h(Z)}),[ce,Ne]=m.useState(()=>new Set),se=m.useCallback(T=>{Ne(Z=>{const Q=new Set(Z);return Q.has(T)?Q.delete(T):Q.add(T),Q})},[]),We=m.useMemo(()=>t.map(T=>T.coin),[t]),Re=To(We),ze=m.useMemo(()=>{const T={},Z={};for(const Q of t??[])Z[Q.coin]=Math.abs(parseFloat(Q.szi??0)||0);for(const Q of e??[]){if(!(Q!=null&&Q.coin)||!Pa(Q))continue;const vt=parseFloat(Q.triggerPx??0)||0;if(!vt)continue;T[Q.coin]||(T[Q.coin]={tp:0,sl:0,tpCount:0,slCount:0,tpSize:0,slSize:0,tpPartial:!1,slPartial:!1});const wt=$d(Q);if(!wt)continue;T[Q.coin][wt]=vt,T[Q.coin][wt+"Count"]+=1;const It=parseFloat(Q.sz??0)||0,ot=Z[Q.coin]??0;T[Q.coin][wt+"Size"]=It,It>0&&ot>0&&It<ot*.995&&(T[Q.coin][wt+"Partial"]=!0)}return T},[e,t]),he=m.useRef(new Set),N=m.useRef({});m.useEffect(()=>{var T;for(const Z of t??[]){const Q=Z==null?void 0:Z.coin,vt=Math.abs(parseFloat((Z==null?void 0:Z.szi)??0)||0);if(!Q||!vt)continue;const wt=ze[Q];if(!wt||!(wt.tp||wt.sl)||!Tv(s,Q)||(wt.tpCount||0)>1||(wt.slCount||0)>1||he.current.has(Q))continue;const It=Math.max(wt.tpSize||0,wt.slSize||0);It&&(Math.abs(It-vt)<=vt*.005||N.current[Q]!==vt&&(he.current.add(Q),iu(Q,!0),ge.post("/x/futures/tpsl",{miniAppData:(T=ve())==null?void 0:T.initData,account_id:s,coin:Q,take_profit:wt.tp||0,stop_loss:wt.sl||0}).then(({data:ot})=>{if(ot!=null&&ot.err){N.current[Q]=vt;return}delete N.current[Q],ys(h("Protection moved to the full position size")),i&&i()}).catch(()=>{N.current[Q]=vt}).finally(()=>{he.current.delete(Q),iu(Q,!1)})))}},[t,ze,s,i]),m.useEffect(()=>{Cv(s,(t??[]).map(T=>T==null?void 0:T.coin).filter(Boolean))},[t,s]);const mt=v==="history"||v==="funding"||t.length>0;m.useEffect(()=>{var T;if(!f){w||(y.current=!0,k({fills:[],funding:[]}));return}if(y.current){y.current=!1,k(null);return}c||!mt||w||ge.post("/x/futures/history",{miniAppData:(T=ve())==null?void 0:T.initData,account_id:s}).then(({data:Z})=>{k({fills:(Z==null?void 0:Z.fills)??[],funding:(Z==null?void 0:Z.funding)??[]})}).catch(()=>k({fills:[],funding:[]}))},[f,c,mt,w,s]);const Pt=m.useMemo(()=>{const T={};if(!G)return T;const Z=new Map;for(const Q of G.fills??[])Z.has(Q.coin)||Z.set(Q.coin,[]),Z.get(Q.coin).push(Q);for(const Q of t){const vt=(Z.get(Q.coin)??[]).slice().sort((Qt,Et)=>Et.time-Qt.time);let wt=parseFloat(Q.szi)||0,It=0,ot=!1;const Dt=Math.max(Math.abs(wt)*1e-8,1e-12);for(const Qt of vt){const Et=(Qt.side==="B"?1:-1)*(parseFloat(Qt.sz)||0),Wt=wt-Et;if(It+=(parseFloat(Qt.closedPnl)||0)-(parseFloat(Qt.fee)||0),Math.abs(Wt)<=Dt){ot=!0;break}wt=Wt}T[Q.coin]={value:It,complete:ot}}return T},[G,t]),qt=async(T,Z="market",Q=0,vt=0,wt=0)=>{var Wt;const It=Math.abs(parseFloat(T.szi)),ot=wt>0?Math.min(wt,It):It;if(!ot)return null;const Dt=Z==="limit"&&Q>0,Qt=parseFloat(T.szi)>0,Et=Dt&&!qu(Q,vt,Qt);try{const{data:_e}=await ge.post("/x/futures/order",{miniAppData:(Wt=ve())==null?void 0:Wt.initData,account_id:s,coin:T.coin,side:Qt?"sell":"buy",order_type:Dt?"limit":"market",...Dt?{price:Q,tif:Et?"Alo":"Gtc"}:{},size:ot,reduce_only:!0}),Ue=_e!=null&&_e.err?_e.errText||_e.err:null;return Ue&&Et&&/post[\s-]?only|immediately match/i.test(Ue)?h("The order would have crossed the market and was not placed. Increase the offset from the price."):Ue}catch{return h("Network error")}},[pt,te]=m.useState(null),[Tt,Ht]=m.useState("market"),[xt,Bt]=m.useState(""),[re,Vt]=m.useState(100),Ee=m.useRef("market"),qe=m.useRef(""),we=m.useRef(100);Ee.current=Tt,qe.current=xt,we.current=re;const ye=(T,Z,Q)=>{const vt=String((T==null?void 0:T.szi)??""),wt=Math.abs(parseFloat(vt)||0);if(!wt)return 0;if(Z>=100)return wt;const It=vt.indexOf("."),ot=It<0?0:vt.length-It-1,Dt=Math.max(Q??0,ot),Qt=Math.pow(10,Dt),Et=wt*(Z/100),Wt=Math.floor(Et*Qt+1e-9)/Qt;return Math.min(wt,Math.max(1/Qt,Wt))},fe=ur(),[De,nn]=m.useState(()=>fe.closeOffsetPct||Bu),Ws=T=>{nn(T),pn({...fe,closeOffsetPct:T}
6),pt!=null&&pt.mark&&Bt(String(Wu(pt.mark,T,pt.isLong,pt.szDecimals)))},ws=(T,Z,Q)=>te({...Z,run:Q}),zs=async(T,Z="market",Q=0,vt=0,wt=0)=>{j(T.coin);const It=await qt(T,Z,Q,vt,wt);if(j(null),It){Ot(It);return}const ot=Math.abs(parseFloat(T.szi)||0),Dt=wt>0&&ot>0&&wt<ot*.995;ys(Z==="limit"?h("Closing order placed at {price}",{price:lt(Q)}):Dt?h("Closed {size} of the position",{size:lt(wt)}):h("Position closed")),i&&i()},gs=m.useCallback((T,Z)=>{var It;const Q=parseFloat(T.szi)>0,vt=((It=d==null?void 0:d.find(ot=>ot.name===T.coin))==null?void 0:It.szDecimals)??0,wt=De||Bu;Ht("market"),Vt(100),Bt(Z?String(Wu(Z,wt,Q,vt)):""),ws(!0,{kind:"close",title:h("Close position"),text:h("Choose how to close: at the market price right now, or with a limit order at your price."),note:zt(T.coin)+" · "+lt(Math.abs(parseFloat(T.szi)))+" · "+(Q?h("Long"):h("Short")),danger:!0,confirmLabel:h("Close"),position:T,mark:Z,isLong:Q,szDecimals:vt},()=>zs(T,Ee.current,parseFloat(qe.current)||0,Z,ye(T,we.current,vt)))},[d,De]);m.useEffect(()=>{if(!(g!=null&&g.coin))return;const T=Mt.find(Z=>Z.coin===g.coin);T&&gs(T,parseFloat(Re[T.coin]??0)||parseFloat(T.entryPx)||0)},[g==null?void 0:g.n]);const Jt=async()=>{if(!Mt.length)return;j("__all__");const T=[];for(const Z of Mt){const Q=await qt(Z);Q&&T.push(zt(Z.coin)+": "+Q)}j(null),i&&i(),T.length?Ot(T.join(`
7`)):ys(h("Position closed"))},Ls=async T=>{var Z;j(T.oid);try{const{data:Q}=await ge.post("/x/futures/cancel",{miniAppData:(Z=ve())==null?void 0:Z.initData,account_id:s,coin:T.coin,oid:T.oid});Q!=null&&Q.err?Ot(Q.errText||Q.err):i&&i()}catch{Ot(h("Network error"))}finally{j(null)}},Ds=async T=>{var Z;j("twap_"+T.id);try{const{data:Q}=await ge.post("/x/futures/twap/stop",{miniAppData:(Z=ve())==null?void 0:Z.initData,account_id:s,coin:T.coin,twap_id:T.id});Q!=null&&Q.err?Ot(Q.errText||Q.err):i&&i()}catch{Ot(h("Network error"))}finally{j(null)}},qs=T=>T?a?r.jsx("span",{className:"fut-table__ticker",role:"button",tabIndex:0,onClick:()=>a(T),onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&a(T)},title:h("Open chart"),children:zt(T)}):zt(T):"—",vn=()=>{if(!Mt.length)return ie(t.length,"No open positions");const T=[{key:"market",label:h("Market"),hint:h("Instrument, direction of the position and its leverage.")},{key:"size",label:h("Size"),hint:h("Position size in the instrument itself. A minus means a short.")},{key:"value",label:h("Value"),hint:h("What the position is worth right now at the mark price.")},{key:"entry",label:h("Entry price"),hint:h("Average price the position was opened at.")},{key:"mark",label:h("Mark price"),hint:h("The exchange’s fair price. Profit and liquidation are counted from it, not from the last trade.")},{key:"pnl",label:h("Unrealized PnL"),hint:h("Profit or loss counted from the pure price move, before any fees.")},{key:"real",label:h("Realized PnL"),hint:h("Profit or loss already locked in, net of fees.")},{key:"funding",label:h("Funding"),hint:h("Funding accrued on the position since it was opened: a plus means it was paid to you, a minus means it was charged. It is credited or charged once an hour.")},{key:"liq",label:h("Liq. price"),hint:h("If the mark price reaches this level, the position is force-closed and the margin is lost.")},{key:"margin",label:h("Margin"),hint:h("The funds held as collateral for this position. On isolated margin you can add or release them.")},{label:"TP / SL",hint:h("Take profit and stop loss: the prices at which the position closes on its own, without you watching the chart.")}],Z=ot=>{var Pe,Ie,ss;const Dt=parseFloat(ot.szi),Qt=parseFloat(ot.entryPx),Et=parseFloat(ot.liquidationPx??0),Wt=Re[ot.coin]||0,_e=Wt||Qt,Ue=Wt&&Qt?Dt*(Wt-Qt):parseFloat(ot.unrealizedPnl??0),ue=parseFloat(ot.marginUsed??0),Xe=parseFloat(((Pe=ot.leverage)==null?void 0:Pe.value)??0),rn=Xe>0&&Qt?Math.abs(Dt)*Qt/Xe:ue,Os=(((Ie=ot.leverage)==null?void 0:Ie.type)??"")==="isolated",ts=Et>0&&_e>
70?Math.abs(_e-Et)/_e*100:null,Ve=Math.abs(Dt)*_e,ae=aa(ot.coin,d,u).taker??ri,{fee:ke}=po(ot,Wt,ae),xe=Wt&&Qt&&rn?Ue/rn*100:parseFloat(ot.returnOnEquity??0)*100,ps=Pt[ot.coin]??null,es=ze[ot.coin]??{tp:0,sl:0},Me=-parseFloat(((ss=ot.cumFunding)==null?void 0:ss.sinceOpen)??0),Qe=Dt>0;return{p:ot,szi:Dt,entry:Qt,liq:Et,mark:_e,live:Wt,pnl:Ue,feeCost:ke,margin:ue,roeBase:rn,isIsolated:Os,buffer:ts,roe:xe,value:Ve,real:ps,guard:es,funding:Me,isLong:Qe}},Q=Mt.map(Z),vt=(ot,Dt)=>{var Qt;switch(Dt){case"market":return zt(ot.p.coin);case"size":return ot.szi;case"value":return ot.value;case"entry":return ot.entry;case"mark":return ot.mark;case"pnl":return ot.pnl;case"real":return((Qt=ot.real)==null?void 0:Qt.value)??0;case"funding":return ot.funding;case"liq":return ot.liq;case"margin":return ot.margin;default:return 0}},wt=nt.key===null?Q:[...Q].sort((ot,Dt)=>{const Qt=vt(ot,nt.key),Et=vt(Dt,nt.key),Wt=typeof Qt=="string"?Qt.localeCompare(Et):(Number.isFinite(Qt)?Qt:0)-(Number.isFinite(Et)?Et:0);return nt.dir==="asc"?Wt:-Wt}),It=S==="__all__";return r.jsx("div",{className:"fut-postable",children:r.jsxs("div",{className:"fut-postable__scroll",children:[r.jsxs("div",{className:"fut-postable__head",children:[T.map(ot=>r.jsx("span",{children:r.jsx(Rt.Tooltip,{position:"top",tag:"span",title:ot.hint,arrow:!0,distance:12,popperOptions:xi,children:ot.key?r.jsxs("button",{type:"button",className:"fut-postable__hcell"+(nt.key===ot.key?" is-sorted":""),onClick:()=>$(ot.key),children:[ot.label,nt.key===ot.key&&r.jsx("i",{children:nt.dir==="desc"?"↓":"↑"})]}):ot.label})},ot.label)),r.jsx("span",{className:"fut-postable__act",children:r.jsx(Rt.Tooltip,{position:"top",tag:"span",arrow:!0,distance:12,popperOptions:xi,title:h("Closes every open position at the market price."),children:r.jsx("button",{type:"button",className:"fut-postable__closeall",disabled:It,onClick:()=>te({title:h("Close all positions"),text:h("Every open position will be closed at the market price right now."),note:Mt.map(ot=>zt(ot.coin)).join(" · "),danger:!0,confirmLabel:h("Close all"),run:Jt}),children:It?h("Closing")+"…":h("Close all")})})})]}),wt.map(({p:ot,szi:Dt,entry:Qt,liq:Et,mark:Wt,live:_e,pnl:Ue,feeCost:ue,margin:Xe,roeBase:rn,isIsolated:Os,buffer:ts,roe:Ve,value:ae,real:ke,guard:xe,funding:ps,isLong:es})=>{var Qe,Pe;const Me=o&&!ce.has(ot.coin);return r.jsxs("div",{className:"fut-postable__row"+(Me?" is-collapsed":""),children:[r.jsxs("span",{"data-label":h("Market"),className:"fut-postable__market",onClick:o?()=>se(ot.coin):void 0,children:[a?r.jsx("b",{className:"fut-postable__ticker",role:"button",tabIndex:0,onClick:Ie=>{Ie.stopPropagation(),a(ot.coin)},onKeyDown:Ie=>{(Ie.key==="Enter"||Ie.key===" ")&&(Ie.stopPropagation(),a(ot.coin))},title:h("Open chart"),children:zt(ot.coin)}):r.jsx("b",{children:zt(ot.coin)}),r.jsx("i",{className:"fut-postable__side fut-postable__side--"+(es?"long":"short"),children:es?h("Long"):h("Short")}),r.jsxs("i",{className:"fut-postable__lev",children:[(Qe=ot.leverage)==null?void 0:Qe.value,"× ",((Pe=ot.leverage)==null?void 0:Pe.type)==="cross"?h("Cross"):h("Isolated")]}),o&&r.jsxs(r.Fragment,{children:[Me&&r.jsxs("em",{className:"fut-postable__mini "+(Ue>=0?"is-up":"is-down"),children:[$e(Ue,3),Number.isFinite(Ve)&&r.jsxs("i",{children:["(",Ve>=0?"+":"",Ve.toFixed(2),"%)"]})]}),r.jsx("i",{className:"fut-postable__caret"+(Me?"":" is-open"),"aria-hidden":"true"})]})]}),r.jsxs("span",{"data-label":h("Size"),className:es?"is-up":"is-down",children:[es?"":"-",lt(Math.abs(Dt))]}),r.jsx("span",{"data-label":h("Value"),children:pe(ae)}),r.jsx("span",{"data-label":h("Entry price"),children:Qt?lt(Qt):"—"}),r.jsx("span",{"data-label":h("Mark price"),children:Wt?lt(Wt):"—"}),r.jsxs("span",{"data-label":h("Unrealized PnL"),className:"fut-postable__pnl "+(Ue>=0?"is-up":"is-down"),children:[r.jsx(Rt.Tooltip,{position:"top",tag:"span",distance:12,popperOptions:xi,title:h("Price move on the open position, before fees — the same number the exchange shows. Closing it now would cost about {fee}.",{fee:pe(ue)}),children:$e(Ue,3)}),r.jsxs("span",{className:"fut-postable__pnlx",children:[r.jsxs("i",{children:["(",Ve>=0?"+":"",Ve.toFixed(2),"%)"]}),r.jsx(Rt.Tooltip,{position:"top",arrow:!0,distance:8,tag:"span",popperOptions:xi,title:h("Share PnL card"),children:r.jsx("button",{type:"button",className:"fut-share","aria-label":h("Share PnL card"),onClick:()=>{var Ie;return z({coin:ot.coin,isLong:es,leverage:((Ie=ot.leverage)==null?void 0:Ie.value)??0,entryPx:Qt,exitPx:Wt,exitLabel:h("Mark price"),size:Math.abs(Dt),pnlUsd:Ue,pnlPct:Ve,pctBase:"margin",closedAt:Date.now()})},children:r.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M14 4h6v6M20 4l-9 9M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})})]})]}),r.jsx("span",{"data-label":h("Realized PnL"),className:ke===null||ke.value===0?"is-muted":ke.value>0?"is-up":"is-down",children:r.jsx(Rt.Tooltip,{position:"top",tag:"span",distance:12,popperOptions:xi,title:ke&&!ke.complete?h("The position is older than the 30-day history window, so some closes are not included in this sum."):
7h("Already locked in on this position: fees paid plus the result of any partial closes since it was opened."),children:ke===null?"…":ke.value===0?"—":(ke.complete?"":"≥")+$e(ke.value,3)})}),r.jsx("span",{"data-label":h("Funding"),className:ps===0?"is-muted":ps>0?"is-up":"is-down",children:r.jsx(Rt.Tooltip,{position:"top",tag:"span",distance:12,popperOptions:xi,title:h("Funding paid on this position since it was opened. A minus means it was charged to you."),children:ps===0?"—":$e(ps)})}),r.jsx("span",{"data-label":h("Liq. price"),className:"fut-postable__liq",children:Et?lt(Et):"—"}),r.jsx("span",{"data-label":h("Margin"),className:"fut-postable__margin",children:Os?r.jsxs("button",{type:"button",onClick:()=>et({position:ot,mark:Wt}),title:h("Add or remove margin"),children:[r.jsx("b",{children:pe(Xe)}),r.jsx("i",{className:ts!==null&&ts<10?"is-down":"",children:ts===null?h("Isolated (short)"):h("Isolated (short)")+" · "+ts.toFixed(1)+"%"}),r.jsx("em",{children:h("Change")})]}):r.jsxs(r.Fragment,{children:[r.jsx("b",{children:pe(Xe)}),r.jsx("i",{children:h("Cross (short)")})]})}),r.jsx("span",{"data-label":"TP / SL",className:"fut-postable__tpsl",children:r.jsx("button",{type:"button",className:xe.tp||xe.sl?"is-set":"",onClick:()=>tt({position:ot,mark:Wt}),children:xe.tp||xe.sl?r.jsxs(r.Fragment,{children:[r.jsxs("i",{className:"is-up",children:[xe.tp?lt(xe.tp):"—",(xe.tpCount||0)>1&&r.jsxs("b",{children:[" ×",xe.tpCount]})]})," / ",r.jsxs("i",{className:"is-down",children:[xe.sl?lt(xe.sl):"—",(xe.slCount||0)>1&&r.jsxs("b",{children:[" ×",xe.slCount]})]}),Ou(xe,Dt)&&r.jsx("em",{children:Ou(xe,Dt)})]}):h("Set")})}),r.jsx("span",{className:"fut-postable__act",children:r.jsx("button",{type:"button",disabled:S===ot.coin||It,onClick:()=>gs(ot,Wt),children:S===ot.coin?h("Closing")+"…":h("Close")})})]},ot.coin)})]})})},ms=T=>{const Z=String((T==null?void 0:T.orderType)??"");if(T!=null&&T.isTrigger){const Q=T.reduceOnly||T.isPositionTpsl;return Q&&Z.includes("Take Profit")?{label:h("Take profit"),tone:"up",price:T.triggerPx}:Q&&Z.includes("Stop")?{label:h("Stop loss"),tone:"down",price:T.triggerPx}:{label:Z||h("Trigger"),tone:"",price:T.triggerPx}}return{label:(T==null?void 0:T.side)==="B"?h("Buy"):h("Sell"),tone:(T==null?void 0:T.side)==="B"?"up":"down",price:T==null?void 0:T.limitPx}},Oe=()=>Gt.length?r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Type")}),r.jsx("span",{children:h("Price")}),r.jsx("span",{children:h("Size")}),r.jsx("span",{className:"fut-table__act"})]}),Gt.map(T=>{const Z=ms(T);return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{children:qs(T.coin)}),r.jsxs("span",{"data-label":h("Type"),className:Z.tone?"is-"+Z.tone:"",children:[Z.label,T.isTrigger&&r.jsx("i",{className:"fut-table__sub",children:T.side==="B"?h("Buy"):h("Sell")})]}),r.jsx("span",{"data-label":h("Price"),children:Z.price?lt(parseFloat(Z.price)):"—"}),r.jsx("span",{"data-label":h("Size"),children:lt(parseFloat(T.sz))}),r.jsx("span",{className:"fut-table__act",children:r.jsx("button",{type:"button",disabled:S===T.oid,onClick:()=>ws(!0,{title:h("Cancel order"),text:h("The order will be removed from the book."),note:zt(T.coin)+" · "+lt(parseFloat(T.sz))+" · "+(T.side==="B"?h("Buy"):h("Sell"))+(Z.price?" · "+lt(parseFloat(Z.price)):""),danger:!0,confirmLabel:h("Cancel order")},()=>Ls(T)),children:h("Cancel")})})]},T.oid)})]}):ie((e==null?void 0:e.length)??0,"No open orders"),Xt=()=>jt.length?r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Side")}),r.jsx("span",{children:h("Filled")}),r.jsx("span",{children:h("Duration")}),r.jsx("span",{className:"fut-table__act"})]}),jt.map(T=>{const Z=T.size>0?Math.min(100,T.executedSz/T.size*100):0;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{children:qs(T.coin)}),r.jsxs("span",{"data-label":h("Side"),className:T.isBuy?"is-up":"is-down",children:[T.isBuy?h("Buy"):h("Sell"),T.reduceOnly&&r.jsx("i",{className:"fut-table__sub",children:h("Reduce only")})]}),r.jsxs("span",{"data-label":h("Filled"),children:[lt(T.executedSz)," / ",lt(T.size),r.jsxs("i",{className:"fut-table__sub",children:[Z.toFixed(0),"% · ",pe(T.executedNtl)]})]}),r.jsxs("span",{"data-label":h("Duration"),children:[T.minutes," ",h("min"),T.randomize&&r.jsx("i",{className:"fut-table__sub",children:h("randomized")})]}),r.jsx("span",{className:"fut-table__act",children:r.jsx("button",{type:"button",disabled:S==="twap_"+T.id,onClick:()=>Ds(T),children:h("Stop")})})]},T.id)})]}):ie((n==null?void 0:n.length)??0,"No running TWAP orders"),as=()=>G?Be.length?r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{children:h("Time")}),r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Side")}),r.jsx("span",{children:h("Price")}),r.jsx("span",{children:h("Size")}),r.jsx("span",{children:h("Fee")}),r.jsx("span",{children:h("Realized PnL")})]}),Be.slice(0,100).map(T=>{const Z=parseFloat(T.closedPnl??0)||0,Q=parseFloat(T.fee??0)||0;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{children:Li(T.time).format("DD.MM HH:mm")}
7),r.jsx("span",{"data-label":h("Market"),children:qs(T.coin)}),r.jsx("span",{"data-label":h("Side"),className:T.side==="B"?"is-up":"is-down",children:T.side==="B"?h("Buy"):h("Sell")}),r.jsx("span",{"data-label":h("Price"),children:lt(parseFloat(T.px))}),r.jsx("span",{"data-label":h("Size"),children:lt(parseFloat(T.sz))}),r.jsx("span",{"data-label":h("Fee"),className:"is-muted",children:Q?pe(Q):"—"}),r.jsx("span",{"data-label":h("Realized PnL"),className:Z===0?"is-muted":Z>0?"is-up":"is-down",children:Z===0?"—":$e(Z)})]},T.tid)})]}):ie(G.fills.length,"No trades yet"):r.jsxs("div",{className:"fut-panel__empty",children:[h("Loading"),"…"]}),le=()=>G?de.length?r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{children:h("Time")}),r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Payment")})]}),G.funding.slice(0,100).map((T,Z)=>{var vt,wt;const Q=parseFloat(((vt=T.delta)==null?void 0:vt.usdc)??0)||0;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{children:Li(T.time).format("DD.MM HH:mm")}),r.jsx("span",{"data-label":h("Market"),children:qs((wt=T.delta)==null?void 0:wt.coin)}),r.jsx("span",{"data-label":h("Payment"),className:Q>=0?"is-up":"is-down",children:$e(Q)})]},T.time+"_"+Z)})]}):ie(G.funding.length,"No funding payments"):r.jsxs("div",{className:"fut-panel__empty",children:[h("Loading"),"…"]}),cs={positions:h("Positions"),orders:h("Orders"),twap:"TWAP",history:h("Trades"),funding:h("Funding")};return r.jsxs("div",{className:"fut-panel"+(o?" fut-panel--compact":""),children:[r.jsxs("div",{className:"fut-panel__tabs",children:[w_.map(T=>r.jsxs("button",{type:"button",className:T===v?"is-active":"",onClick:()=>b(T),children:[cs[T],T==="positions"&&t.length>0&&r.jsx("i",{children:t.length}),T==="orders"&&(e==null?void 0:e.length)>0&&r.jsx("i",{children:e.length}),T==="twap"&&(n==null?void 0:n.length)>0&&r.jsx("i",{children:n.length})]},T)),r.jsxs("div",{className:"fut-panel__tools",children:[l&&r.jsxs("div",{className:"fut-panel__filter",children:[r.jsx("button",{type:"button",className:rt?"":"is-active",title:h("Show positions on all markets"),onClick:()=>Nt(!1),children:h("All")}),r.jsx("button",{type:"button",className:rt?"is-active":"",title:h("Show only this market"),onClick:()=>Nt(!0),children:zt(l)})]}),r.jsx("label",{className:"fut-panel__search",children:r.jsx("input",{type:"search",value:X,onChange:T=>st(T.target.value),placeholder:h("Ticker"),"aria-label":h("Ticker")})})]})]}),r.jsxs("div",{className:"fut-panel__body",children:[v==="positions"&&vn(),v==="orders"&&Oe(),v==="twap"&&Xt(),v==="history"&&as(),v==="funding"&&le()]}),pt&&r.jsx(Nf,{title:pt.title,text:pt.text,note:pt.note,danger:pt.danger,confirmLabel:pt.confirmLabel,extra:pt.kind==="close"?r.jsxs("div",{className:"fut-guard__extra",children:[r.jsxs("div",{className:"fut-guard__kinds",children:[r.jsx("button",{type:"button",className:Tt==="market"?"is-active":"",onClick:()=>Ht("market"),children:h("Market")}),r.jsx("button",{type:"button",className:Tt==="limit"?"is-active":"",onClick:()=>Ht("limit"),children:h("Limit")})]}),(()=>{var ot;const T=Math.abs(parseFloat(((ot=pt.position)==null?void 0:ot.szi)??0)||0),Z=parseFloat(pt.mark)||0;if(!T)return null;const Q=ye(pt.position,re,pt.szDecimals),vt=Q*Z,wt=Z>0&&vt>0&&vt<Ji,It=(re-1)/99*100;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-guard__offset",children:[r.jsx("span",{children:h("Size to close")}),r.jsx("b",{children:re>=100?h("All"):re+"%"})]}),r.jsxs("div",{className:"fut-slider",style:{"--f-fill":It+"%"},children:[r.jsx("span",{className:"fut-slider__track"}),r.jsx("input",{type:"range",min:1,max:100,step:1,value:re,"aria-label":h("Size to close"),onChange:Dt=>Vt(parseInt(Dt.target.value,10)||1)})]}),r.jsxs("div",{className:"fut-guard__outcome",children:[r.jsx("span",{children:zt(pt.position.coin)}),r.jsxs("b",{children:[lt(Q),vt>0&&r.jsxs("i",{children:[" · ",pe(vt)]})]})]}),wt&&r.jsx("div",{className:"fut-guard__warn",children:h("The exchange rejects orders under ${min}. Increase the share.",{min:Ji})})]})})(),Tt==="limit"&&(()=>{const T=parseFloat(xt)||0,Z=parseFloat(pt.mark)||0,Q=Z&&T?(T-Z)/Z*100*(pt.isLong?1:-1):0,vt=qu(T,Z,pt.isLong),wt=aa(
7pt.position.coin,d,u).maker??Ra,It=ye(pt.position,re,pt.szDecimals),ot={...pt.position,szi:(pt.isLong?1:-1)*It},Dt=T?po(ot,T,wt):null,Qt=Dt?Dt.gross:0,Et=Dt?Dt.fee:0,Wt=(De-co)/(Iu-co)*100;return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-guard__offset",children:[r.jsx("span",{children:h("Offset from price")}),r.jsxs("b",{children:[De.toFixed(2),"%"]})]}),r.jsxs("div",{className:"fut-slider",style:{"--f-fill":Wt+"%"},children:[r.jsx("span",{className:"fut-slider__track"}),r.jsx("input",{type:"range",min:co,max:Iu,step:b_,value:De,"aria-label":h("Offset from price"),onChange:_e=>Ws(parseFloat(_e.target.value))})]}),r.jsx("input",{type:"text",inputMode:"decimal",className:"fut-guard__price"+(vt?" is-wrong":""),value:xt,placeholder:h("Price"),onChange:_e=>Bt(_e.target.value.replace(",","."))}),T>0&&r.jsxs("div",{className:"fut-guard__outcome",children:[r.jsx("span",{children:h("Result if filled")}),r.jsxs("b",{className:Qt>=0?"is-up":"is-down",children:[$e(Qt,3),Et>0&&r.jsxs("i",{children:[" · ",h("Fees")," ≈ ",pe(Et)]})]})]}),vt?r.jsx("div",{className:"fut-guard__warn",children:h("This price is on the wrong side of the market: the order will fill immediately and at the taker fee.")}):r.jsx("div",{className:"fut-guard__hint",children:h("Maker order {pct}% in your favour — it waits until the price comes to it.",{pct:Math.abs(Q).toFixed(2)})}),r.jsx("div",{className:"fut-guard__hint",children:h("The position stays open until the price is reached. The order can be cancelled on the Orders tab.")})]})})()]}):null,onCancel:()=>te(null),onConfirm:()=>{const T=pt.run;te(null),T()}}),H&&r.jsx(Sx,{accountId:s,position:H.position,markPx:H.mark,onClose:()=>et(null),onDone:()=>i&&i()}),ht&&r.jsx(jx,{accountId:s,position:ht.position,current:{...ze[ht.position.coin]??{tp:0,sl:0},mark:ht.mark},levels:Yd(Gt,ht.position.coin),onClose:()=>tt(null),onDone:()=>i&&i()}),E&&r.jsx(Df,{card:E,onClose:()=>z(null)})]})}const __="/images/futures/";function k_(s){let t=0;for(let e=0;e<s.length;e++)t=t*31+s.charCodeAt(e)|0;return`hsl(${Math.abs(t)%360}, 34%, 42%)`}function $a({coin:s,size:t=20,className:e=""}){const[n,i]=m.useState(!1),o=zt(s)||"",l=o.toLowerCase(),a=zf[l],c={width:t,height:t},u="fut-coin"+(e?" "+e:"");return!a||n?r.jsx("span",{className:u+" fut-coin--stub",style:{...c,background:k_(l),fontSize:Math.round(t*.4)},"aria-hidden":"true",children:o.slice(0,2).toUpperCase()}):r.jsx("img",{className:u,style:c,src:__+l+"."+a,alt:"",loading:"lazy",onError:()=>i(!0)})}const M_={major:["BTC","ETH","SOL","BNB","XRP","DOGE","ADA","AVAX","LTC","BCH","TRX","DOT","LINK","TON","HYPE"],meme:["DOGE","WIF","kPEPE","kSHIB","kBONK","kFLOKI","POPCAT","MEW","BRETT","MOG","TRUMP","PNUT","GOAT","SPX","FARTCOIN","MELANIA","kNEIRO","MOODENG","PEOPLE","TURBO","BOME","ANIME"],defi:["AAVE","UNI","CRV","MKR","LDO","SNX","COMP","SUSHI","CAKE","PENDLE","ENA","ETHFI","EIGEN","JUP","RAY","MORPHO","HYPER","DYDX","GMX","JTO","ONDO","USUAL","RESOLV"],layer1:["ETH","SOL","AVAX","NEAR","APT","SUI","SEI","TIA","INJ","ATOM","DOT","ADA","ALGO","FTM","S","KAS","TON","ICP","HBAR","STX","ARB","OP","MATIC","POL","STRK","ZK","BLAST","SCR","MNT","BERA","MOVE","IP","TAO"],ai:["TAO","FET","RENDER","WLD","AI16Z","VIRTUAL","GRASS","IO","AIXBT","ARC","GRIFFAIN","ZEREBRO","NEAR","AKT","PROMPT","KAITO"]},Of={xindices:["XYZ100","SP500","JP225","KR200","NIFTY","IBOV","VIX","VOL","SMH","XLE","SOXL","KORU","EWY","EWJ","EWZ","EWT","URNM"],xcommodities:["GOLD","SILVER","PLATINUM","PALLADIUM","COPPER","ALUMINIUM","URANIUM","CL","BRENTOIL","NATGAS","TTF","CORN","WHEAT","DRAM","H100"],xforex:["JPY","EUR","GBP","KRW","DXY"]},ma=[{key:"all",label:"All"},{key:"@fav",label:"Favorites"},{key:"@mine",label:"My positions"},{key:"major",label:"Top"},{key:"layer1",label:"Layer 1 & 2"},{key:"defi",label:"DeFi"},{key:"meme",label:"Meme"},{key:"ai",label:"AI"},{key:"@stocks",label:"Stocks"},{key:"xindices",label:"Indices"},{key:"xcommodities",label:"Commodities"},{key:"xforex",label:"Currencies"},{key:"@leverage",label:"High leverage"}],j_=Object.fromEntries(Object.entries(M_).map(([s,t])=>[s,new Set(t)])),Vu=Object.fromEntries(Object.entries(Of).map(([s,t])=>[s,new Set(t)])),S_=new Set(Object.values(Of).flat()),N_=20;function pa(s,t,e,n,i){var o;switch(s){case"all":return!0;case"@fav":return n.has(t.name);case"@mine":return i.has(t.name);case"@leverage":return(t.maxLeverage??0)>=N_;case"@stocks":return ar(t.name)!==""&&!S_.has(zt(t.name));default:return Vu[s]?ar(t.name)!==""&&Vu[s].has(zt(t.name)):((o=j_[s])==null?void 0:o.has(t.name))??!1}}const If="futures_favorites";function Bf(){try{const s=localStorage.getItem(If);return new Set(s?JSON.parse(s):[])}catch{return new Set}}function Wf(s){try{localStorage.setItem(If,JSON.stringify(Array.from(s)))}catch{}}const C_=[{key:"name",label:"Market",cell:"name"},{key:"volume",label:"Vol 24h",cell:"vol"},{key:"mark",label:"Price",cell:"px"},{key:"change",label:"24h change",cell:"chg"}];function Uu({meta:s,ctxs:t,current:e,ownedCoins:n,onPick:i,onClose:o}){Ps(o);const[l,a]=m.useState(""),[c,u]=m.useState("all"),[d,f]=m.useState(()=>Bf()),[g,v]=m.useState({key:"volume",dir:"desc"}),b=j=>{v(E=>E.key===j?{key:j,dir:E.dir==="desc"?"asc":"desc"}:{key:j,dir:j==="name"?"asc":"desc"})},w=n??new Set,k=(j,E)=>{j.stopPropagation();const z=new Set(d);z.has(E)?z.delete(E):z.add(E),f(z),Wf(z)},y=m.useMemo(()=>((s==null?void 0:s.universe)??[]).map((E,z)=>({asset:E,ctx:(t==null?void 0:t[z])??null})).filter(E=>!E.asset.isDelisted).filter(E=>pa(c,E.asset,E.ctx,d,w)).filter(E=>!l||E.asset.name.toLowerCase().includes(l.toLowerCase())).map(E=>{var A,J,O;const z=parseFloat(((A=E.ctx)==null?void 0:A.markPx)??0),F=parseFloat(((J=E.ctx)==null?void 0:J.prevDayPx)??0);return{...E,mark:z,change:F?(z-F)/F*100:0,volume:parseFloat(((O=E.ctx)==null?void 0:O.dayNtlVlm)??0)}}).sort((E,z)=>{const F=g.dir==="asc"?1:-1;return g.key==="name"?zt(E.asset.name).localeCompare(zt(z.asset.name))*F:((E[g.key]??0)-(z[g.key]??0))*F}),[s,t,l,c,d,w,g]),S=m.useMemo(()=>{const j=((s==null?void 0:s.universe)??[]).filter(z=>!z.isDelisted),E={};for(const z of ma)E[z.key]=j.filter(F=>pa(z.key,F,null,d,w)).length;return E},[s,d,w]);return r.jsx("div",{className:"fut-modal",onClick:o,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--markets",onClick:j=>j.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Select market")}),r.jsx("button",{type:"button",onClick:o,children:"✕"})]}),r.jsx("input",{className:"fut-modal__search",type:"text",value:l,onCh
7ange:j=>a(j.target.value),placeholder:h("Search"),autoFocus:!0}),r.jsx("div",{className:"fut-markets__tabs",children:ma.map(j=>r.jsxs("button",{type:"button",className:j.key===c?"is-active":"",onClick:()=>u(j.key),children:[h(j.label),S[j.key]>0&&j.key!=="all"&&r.jsx("i",{children:S[j.key]})]},j.key))}),r.jsxs("div",{className:"fut-markets",children:[r.jsxs("div",{className:"fut-markets__head",children:[r.jsx("span",{className:"fut-markets__star","aria-hidden":"true",children:"★"}),r.jsx("span",{className:"fut-markets__hicon","aria-hidden":"true"}),C_.map(j=>r.jsxs("button",{type:"button",className:"fut-markets__"+j.cell+" fut-markets__hcell"+(g.key===j.key?" is-sorted":""),onClick:()=>b(j.key),children:[h(j.label),g.key===j.key&&r.jsx("i",{children:g.dir==="desc"?"↓":"↑"})]},j.key))]}),y.length===0&&r.jsx("div",{className:"fut-panel__empty",children:c==="@fav"?h("Add markets to favorites with the star"):h("Nothing found")}),y.map(j=>r.jsxs("div",{className:"fut-markets__row"+(j.asset.name===e?" is-active":""),onClick:()=>i(j.asset.name),children:[r.jsx("button",{type:"button",className:"fut-markets__star"+(d.has(j.asset.name)?" is-on":""),onClick:E=>k(E,j.asset.name),"aria-label":h("Favorites"),children:"★"}),r.jsx($a,{coin:j.asset.name,size:20}),r.jsxs("span",{className:"fut-markets__name",children:[zt(j.asset.name),r.jsxs("i",{children:[j.asset.maxLeverage,"×"]}),w.has(j.asset.name)&&r.jsx(Rt.Tooltip,{title:h("You have an open position on this market"),position:"top",arrow:!0,tag:"span",children:r.jsx("em",{className:"fut-markets__owned"})})]}),r.jsx("span",{className:"fut-markets__vol",children:j.volume?"$"+T_(j.volume):""}),r.jsx("span",{className:"fut-markets__px",children:j.mark?be(j.mark):"—"}),r.jsxs("span",{className:"fut-markets__chg "+(j.change>=0?"is-up":"is-down"),children:[j.change>=0?"+":"",j.change.toFixed(2),"%"]})]},j.asset.name))]})]})})}function T_(s){return s>=1e9?(s/1e9).toFixed(1)+"B":s>=1e6?(s/1e6).toFixed(1)+"M":s>=1e3?(s/1e3).toFixed(0)+"K":Math.round(s)}const Hu=1,ho=10,Ku=1,L_=["","xyz"];function $u({accountId:s,state:t,states:e=null,onClose:n,onDone:i,depositOnly:o=!1,initialMode:l="deposit"}){Ps(n);const[a,c]=m.useState(o?"deposit":l),[u,d]=m.useState(""),[f,g]=m.useState(""),[v,b]=m.useState(!1),[w,k]=m.useState(null),{showError:y}=Ln(),[S,j]=m.useState(null);m.useEffect(()=>{var H;let tt=!1;return ge.post("/x/futures/wallet",{miniAppData:(H=ve())==null?void 0:H.initData,account_id:s}).then(({data:et})=>{!tt&&!(et!=null&&et.err)&&j(et)}).catch(()=>{}),()=>{tt=!0}},[s]);const E=e?e[f]??null:f===""?t:null,z=parseFloat((E==null?void 0:E.withdrawable)??0),F=_i(z),A=_i(S==null?void 0:S.usdc),J=parseFloat(u)||0,O=J>0?Hu:0,yt=a==="withdraw"?Ku:0,P=J-O-yt,G=a==="deposit"&&J>0&&J<ho,nt=a==="deposit"&&J>0&&J-O<=0,bt=a==="withdraw"&&J>z,$=a==="withdraw"&&J>0&&P<=0,ht=async()=>{var tt;if(!(v||J<=0||G||bt||$||nt)){b(!0);try{const{data:H}=await ge.post(a==="deposit"?"/x/futures/deposit":"/x/futures/withdraw",{miniAppData:(tt=ve())==null?void 0:tt.initData,account_id:s,amount:J,dex:f});H!=null&&H.err?y(H.errText||H.err):k({mode:a,amount:J})}catch{y(h("Network error"))}finally{b(!1)}}};if(w){const tt=()=>{i&&i()};return r.jsx("div",{className:"fut-modal",onClick:tt,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow fut-sent",onClick:H=>H.stopPropagation(),children:[r.jsx("div",{className:"fut-sent__icon","aria-hidden":"true",children:r.jsxs("svg",{width:"26",height:"26",viewBox:"0 0 24 24",fill:"none",children:[r.jsx("circle",{cx:"12",cy:"12",r:"9.2",stroke:"currentColor",strokeWidth:"1.7"}),r.jsx("path",{d:"M12 6.8V12l3.4 2",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"})]})}),r.jsx("b",{className:"fut-sent__title",children:w.mode==="deposit"?h("Deposit sent"):h("Withdrawal sent")}),r.jsxs("div",{className:"fut-sent__amount",children:[be(w.amount)," USDC"]}),r.jsx("div",{className:"fut-sent__text",children:w.mode==="deposit"?h("Funds usually arrive within a minute. The balance will update automatically."):h("Funds are on their way to your Arbitrum wallet. This usually takes 5 to 15 minutes — please be patient.")}),w.mode==="withdraw"&&(S==null?void 0:S.address)&&r.jsxs("button",{type:"button",className:"fut-transfer__addr fut-transfer__addr--sent",onClick:()=>Pl(S.address),title:h("Copy"),children:[r.jsx("span",{children:h("USDC will arrive here (Arbitrum)")}),r.jsx("b",{children:S.address})]}),r.jsx("button",{type:"button",className:"fut-sent__ok",onClick:tt,children:h("Got it")})]})})}return r.jsx("div",{className:"fut-modal",onClick:n,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--narrow",onClick:tt=>tt.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Futures balance")}),r.jsx("button",{type:"button",onClick:n,children:"✕"})]}),!o&&r.jsxs("div",{className:"fut-transfer__modes",children:[r.jsx("button",{type:"button",className:a==="deposit"?"is-active":"",onClick:()=>c("deposit"),children:h("Deposit")}),r.jsx("button",{type:"button",className:a==="withdraw"?"is-active":"",onClick:()=>c("withdraw"),children:h("Withdraw")})]}),!o&&r.jsxs("div",{className:"fut-transfer__venues",children:[r.jsx("span",{className:"fut-form__label",children:a==="deposit"?h("Deposit to"):h("Withdraw from")}),r.jsx("div",{className:"fut-transfer__venue-list",children:L_.map(tt=>{var et;const H=e?parseFloat(((et=e[tt])==null?void 0:et.withdrawable)??0):null;return r.jsxs("button",{type:"button",className:tt===f?"is-active":"",onClick:()=>
7g(tt),children:[r.jsx("b",{children:Tn(tt)}),H!==null&&r.jsxs("i",{children:[be(H)," USDC"]})]},tt||"main")})})]}),a==="deposit"&&f!==""&&!o&&r.jsx("div",{className:"fut-transfer__note",children:h("USDC arrive on {main} first — the exchange bridge accepts only that account. We will move them to {target} automatically once credited, it takes a minute or two.",{main:Tn(""),target:Tn(f)})}),r.jsxs("label",{className:"fut-form__field",children:[r.jsxs("span",{className:"fut-form__label",children:[h("Amount")," ",r.jsx("em",{children:"USDC"})]}),r.jsx("input",{type:"text",inputMode:"decimal",value:u,onChange:tt=>d(tt.target.value.replace(",",".")),placeholder:"0",autoFocus:!0})]}),a==="withdraw"&&r.jsxs("button",{type:"button",className:"fut-transfer__max",onClick:()=>d(String(F)),children:[h("Available"),": ",F," USDC"]}),a==="deposit"&&S&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{type:"button",className:"fut-transfer__max",onClick:()=>d(String(A)),children:[h("On your Arbitrum wallet"),": ",A," USDC"]}),!S.hasGas&&r.jsx("div",{className:"fut-form__warn",style:{textAlign:"left"},children:h("No ETH for the network fee on Arbitrum. Top up a small amount of ETH — a few cents is enough.")})]}),r.jsxs("div",{className:"fut-form__summary",children:[r.jsxs("div",{children:[r.jsx("span",{children:h("Fee")}),r.jsxs("b",{children:[be(Hu+(a==="withdraw"?Ku:0))," USDC"]})]}),r.jsxs("div",{children:[r.jsx("span",{children:a==="deposit"?h("Will be credited"):h("You receive")}),r.jsx("b",{children:P>0?be(P)+" USDC":"—"})]})]}),a==="deposit"&&r.jsx("div",{className:"fut-transfer__note",children:h("USDC will be sent from your Arbitrum wallet. Minimum")+" "+ho+" USDC."}),(S==null?void 0:S.address)&&r.jsxs("button",{type:"button",className:"fut-transfer__addr",onClick:()=>Pl(S.address),title:h("Copy"),children:[r.jsx("span",{children:a==="deposit"?h("The deposit will be sent from this wallet (Arbitrum)"):h("USDC will arrive here (Arbitrum)")}),r.jsx("b",{children:S.address})]}),G&&r.jsxs("div",{className:"fut-form__warn",children:[h("Minimum deposit is")," ",ho," USDC"]}
7),bt&&r.jsx("div",{className:"fut-form__warn",children:h("Amount exceeds available balance")}),$&&!bt&&r.jsx("div",{className:"fut-form__warn",children:h("Amount is too small: the fees would take all of it")}),nt&&!G&&r.jsx("div",{className:"fut-form__warn",children:h("Amount is too small: the fees would take all of it")}),r.jsx("button",{type:"button",className:"fut-form__submit fut-form__submit--buy",disabled:v||J<=0||G||bt||$||nt,onClick:ht,children:v?h("Sending")+"…":h("Confirm")})]})})}function ga({accountId:s,currentDex:t="",onClose:e,onDone:n,withBalances:i=!0}){return Ps(e),r.jsx("div",{className:"fut-modal",onClick:e,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--move",onClick:o=>o.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:i?h("Margin accounts"):h("Move between accounts")}),r.jsx("button",{type:"button",onClick:e,children:"✕"})]}),r.jsx(Cf,{accountId:s,currentDex:t,onDone:n,withBalances:i})]})})}function Yu(s){const t=Math.abs(s);return t>=1e9?(s/1e9).toFixed(2)+"B":t>=1e6?(s/1e6).toFixed(2)+"M":t>=1e3?(s/1e3).toFixed(1)+"K":lt(s)}function E_(){const[s,t]=m.useState("");return m.useEffect(()=>{const e=()=>{const i=new Date,o=59-i.getUTCMinutes(),l=59-i.getUTCSeconds();t(String(o).padStart(2,"0")+":"+String(l).padStart(2,"0"))};e();const n=setInterval(e,1e3);return()=>clearInterval(n)},[]),s}function F_({ctx:s,asset:t,compactView:e=!1}){const n=E_(),i=parseFloat((s==null?void 0:s.markPx)??0),o=parseFloat((s==null?void 0:s.oraclePx)??0),l=parseFloat((s==null?void 0:s.dayNtlVlm)??0),a=parseFloat((s==null?void 0:s.openInterest)??0),c=parseFloat((s==null?void 0:s.funding)??0)*100,u=a*(i||0),d=[{key:"mark",label:h("Mark"),value:i?lt(i):"—",hint:h("Price used for margin and liquidation, not the last trade")},{key:"oracle",label:h("Oracle"),value:o?lt(o):"—",hint:h("External index price the funding rate is based on")},{key:"vol",label:h("24h volume"),value:l?"$"+Yu(l):"—",hint:h("Notional traded on this market over the last 24 hours")},{key:"oi",label:h("Open interest"),value:u?"$"+Yu(u):"—",hint:h("Total size of all open positions on this market")},{key:"funding",label:h("Funding")+" / 1h",value:(s==null?void 0:s.funding)!==void 0?c.toFixed(4)+"%":"—",tone:c>0?"down":c<0?"up":"",extra:n,hint:c>0?h("Positive rate: longs pay shorts"):h("Negative rate: shorts pay longs")}];return!e&&(t!=null&&t.maxLeverage)&&d.push({key:"lev",label:h("Max leverage"),value:t.maxLeverage+"×",hint:h("The highest leverage this market allows. The higher it is, the closer the liquidation price sits to your entry.")}),r.jsx("div",{className:"fut-stats"+(e?" fut-stats--compact":""),children:d.map(f=>r.jsxs("div",{className:"fut-stats__item",children:[r.jsx("span",{className:"fut-stats__label",children:f.hint?r.jsx(Rt.Tooltip,{title:f.hint,position:"bottom",arrow:!0,tag:"span",distance:32,popperOptions:{modifiers:{preventOverflow:{boundariesElement:"viewport"},flip:{boundariesElement:"viewport"},hide:{enabled:!1}}},children:r.jsx("span",{className:"fut-stats__hinted",children:f.label})}):f.label}),r.jsxs("span",{className:"fut-stats__value"+(f.tone?" is-"+f.tone:""),children:[f.value,f.extra&&r.jsx("i",{className:"fut-stats__extra",children:f.extra})]})]},f.key))})}const Nl=60,A_=400;function Qu({coin:s,rows:t=24,compactView:e=!1,fill:n=!1}){const i=m.useRef([]),o=m.useRef(null),[l,a]=m.useState([]),c=m.useRef(null),[u,d]=m.useState(0);m.useEffect(()=>{if(!n)return;const b=c.current;if(!b)return;const w=()=>{const y=b.querySelector(".fut-trades__row"),S=(y==null?void 0:y.getBoundingClientRect().height)||18;if(!b.clientHeight||!S)return;const j=Math.max(6,Math.min(Nl,Math.floor(b.clientHeight/S)));d(E=>E===j?E:j)};w();const k=new ResizeObserver(w);return k.observe(b),()=>k.disconnect()},[n]);const f=n&&u?u:t,g=m.useCallback(()=>{o.current=null,a(i.current.slice(0,Nl))},[]);sn("trades",{coin:s},b=>{!Array.isArray(b)||b.length===0||(i.current=[...b].reverse().concat(i.current).slice(0,Nl),o.current===null&&(o.current=setTimeout(g,A_)))},!!s),m.useEffect(()=>{i.current=[],a([])},[s]),m.useEffect(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]);const v=l.slice(0,f);return r.jsxs("div",{className:"fut-trades"+(e?" fut-trades--compact":"")+(n?" fut-trades--fill":""),children:[r.jsxs("div",{className:"fut-trades__head",children:[r.jsx("span",{children:h("Price")}),r.jsx("span",{children:h("Size")}),r.jsx("span",{children:h("Time")})]}),r.jsxs("div",{className:"fut-trades__body",ref:c,children:[v.length===0&&r.jsxs("div",{className:"fut-trades__empty",children:[h("Waiting for trades"),"…"]}),v.map((b,w)=>{const k=b.side==="B",y=new Date(b.time);return r.jsxs("div",{className:"fut-trades__row fut-trades__row--"+(k?"buy":"sell"),children:[r.jsx("span",{className:"fut-trades__px",children:lt(parseFloat(b.px))}),r.jsx("span",{className:"fut-trades__sz",children:lt(parseFloat(b.sz))}),r.jsxs("span",{className:"fut-trades__time",children:[String(y.getHours()).padStart(2,"0"),":",String(y.getMinutes()).padStart(2,"0"),":",String(y.getSeconds()).padStart(2,"0")]})]},(b.tid??"")+"_"+w)})]})]})}const qf=[{to:"/futures",label:"Trade",trade:!0},{to:"/futures/portfolio",label:"Portfolio"},{to:"/futures/history",label:"History"},{to:"/futures/markets",label:"Markets"}],Gu=[{to:"/futures/docs",label:"Documentation"},{to:"/fees",label:"Fees & VIP",needsAuth:!0},{to:"/",label:"Wallet"},{to:"/referrals",label:"Referral program",needsAuth:!0},{to:"/security",label:"Security",needsAuth:!0}],R_=qf.filter(s=>!s.trade).map(s=>s.to);function P_({compact:s=!1,authed:t=!0}){const{pathname:e}=cd(),[n,i]=m.useState(!1),o=m.useRef(null),l=m.useRef(null),a=m.useRef(null),c=m.useCallback(()=>{a.current!==null&&(clearTimeout(a.current),a.current=null)},[]),u=m.useCallback((y=!1)=>{var S;c(),i(!1),y&&((S=l.current)==null||S.focus())},[c]),d=()=>{try{return window.matchMedia("(hover: hover) and (pointer: fine)").matches}catch{return!1}},f=()=>{d()&&(c(),i(!0))},g=()=>{d()&&(c(),a.current=setTimeout(()=>{a.current=null,i(!1)},180))};m.useEffect(()=>c,[c]),m.useEffect(()=>{if(!n)return;const y=E=>{var z;(z=o.current)!=null&&z.contains(E.target)||u()},S=E=>{E.key==="Escape"&&u(!0)},j=()=>u();return document.addEventListener("mousedown",y),document.addEventListener("keydown",S),window.addEventListener("scroll",j,!0),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",S),window.removeEventListener("scroll",j,!0)}},[n,u]);const v=e.replace(/\/+$/,""),b=y=>v===y||v.startsWith(y+"/"),w=Gu.some(y=>
7b(y.to)),k=!w&&!R_.some(b);return r.jsxs("nav",{className:"fut-nav"+(s?" fut-nav--compact":"")+(n?" fut-nav--open":""),children:[qf.map(y=>r.jsx(Ec,{to:y.to,className:({isActive:S})=>"fut-nav__link"+((y.trade?k:S)?" is-active":""),children:h(y.label)},y.to)),!s&&r.jsxs("div",{className:"fut-nav__more",ref:o,onMouseEnter:f,onMouseLeave:g,children:[r.jsxs("button",{type:"button",ref:l,className:"fut-nav__link fut-nav__morebtn"+(w?" is-active":"")+(n?" is-open":""),onClick:()=>i(y=>!y),"aria-haspopup":"true","aria-expanded":n,children:[h("More"),r.jsx("i",{"aria-hidden":"true",children:"▾"})]}),n&&r.jsx("div",{className:"fut-nav__drop",role:"menu",children:Gu.filter(y=>!y.needsAuth||t!==!1).map(y=>r.jsx(Ec,{to:y.to,end:!0,role:"menuitem",className:({isActive:S})=>"fut-nav__dropitem"+(S?" is-active":""),onClick:()=>u(),children:h(y.label)},y.to))})]})]})}function z_({accountId:s,state:t,states:e=null,allPositions:n=[],openOrders:i,mids:o,currentDex:l="",onChanged:a,onPickCoin:c,onDeposit:u,onWithdraw:d,universe:f=null,vip:g=null}){const[v,b]=m.useState(!1),[w,k]=m.useState("all"),y=H=>{const et=String(H??"").indexOf(":");return et===-1?"":String(H).slice(0,et)},S=m.useMemo(()=>{const H=new Set(["","xyz"]);for(const et of n)H.add(y(et==null?void 0:et.coin));return[...H]},[n]),j=m.useMemo(()=>w==="all"?n:n.filter(H=>y(H==null?void 0:H.coin)===w),[n,w]),E=m.useMemo(()=>w==="all"?i:(i??[]).filter(H=>y(H==null?void 0:H.coin)===w),[i,w]),z=m.useMemo(()=>{if(w!=="all"||!e)return w==="all"?t:(e==null?void 0:e[w])??null;const H=Object.values(e).filter(Boolean);if(!H.length)return t;const et=rt=>H.reduce((Nt,X)=>Nt+(parseFloat(rt(X))||0),0);return{marginSummary:{accountValue:et(rt=>{var Nt;return(Nt=rt==null?void 0:rt.marginSummary)==null?void 0:Nt.accountValue}),totalNtlPos:et(rt=>{var Nt;return(Nt=rt==null?void 0:rt.marginSummary)==null?void 0:Nt.totalNtlPos}),totalMarginUsed:et(rt=>{var Nt;return(Nt=rt==null?void 0:rt.marginSummary)==null?void 0:Nt.totalMarginUsed})},withdrawable:et(rt=>rt==null?void 0:rt.withdrawable),crossMaintenanceMarginUsed:et(rt=>rt==null?void 0:rt.crossMaintenanceMarginUsed),assetPositions:H.flatMap(rt=>(rt==null?void 0:rt.assetPositions)??[])}},[w,t,e]),F=(z==null?void 0:z.marginSummary)??{},A=parseFloat(F.accountValue??0),J=parseFloat(F.totalNtlPos??0),O=parseFloat(F.totalMarginUsed??0),yt=parseFloat((z==null?void 0:z.withdrawable)??0),P=m.useMemo(()=>((z==null?void 0:z.assetPositions)??[]).map(H=>H==null?void 0:H.position).filter(H=>H&&parseFloat(H.szi)!==0),[z]),G=m.useMemo(()=>{let H=0,et=0;for(const rt of P){const Nt=po(rt,parseFloat((o==null?void 0:o[rt.coin])??0)||0,aa(rt.coin,f,g).taker??void 0);H+=Nt.gross,et+=Nt.fee}return{gross:H,fee:et,net:H-et}},[P,o,f,g]),[nt,bt]=m.useState(null);m.useEffect(()=>{var et;let H=!1;return ge.post("/x/futures/history",{miniAppData:(et=ve())==null?void 0:et.initData,account_id:s}).then(({data:rt})=>{H||bt({fills:(rt==null?void 0:rt.fills)??[],funding:(rt==null?void 0:rt.funding)??[]})}).catch(()=>{H||bt({fills:[],funding:[]})}),()=>{H=!0}},[s]);const $=m.useMemo(()=>((nt==null?void 0:nt.fills)??[]).filter(H=>w==="all"||y(H==null?void 0:H.coin)===w).reduce((H,et)=>H+(parseFloat(et.closedPnl)||0),0),[nt,w]),ht=A>0?J/A:0,tt=[{key:"equity",label:h("Equity"),value:"$"+lt(A),hint:h("Total account value including unrealized PnL")},{key:"pnl",label:h("Unrealized PnL"),value:$e(G.gross),tone:G.gross>0?"up":G.gross<0?"down":"",hint:h("Price move on the open position, before fees — the same number the exchange shows. Closing it now would cost about {fee}.",{fee:pe(G.fee)})},{key:"realized",label:h("Realized PnL (30 days)"),value:nt===null?"…":$e($),tone:nt===null?"":$>0?"up":$<0?"down":"",hint:h("Profit and loss locked in on closed trades over the last 30 days. Fees and funding are not included.")},{key:"free",label:h("Available"),value:"$"+lt(yt),hint:h("Free margin you can use for new positions or withdraw")},{key:"used",label:h("Margin used"),value:"$"+lt(O),hint:h("Collateral locked by open positions. It is released when they are closed.")},{key:"notional",label:h("Position value"),value:"$"+lt(J),hint:h("Total size of open positions at current prices — with leverage applied, not the money you put in.")},{key:"lev",label:h("Account leverage"),value:ht?ht.toFixed(2)+"×":"—",hint:h("Position value divided by equity: how much exposure each dollar of the account carries.")}];return r.jsxs("div",{className:"fut-portfolio",children:[r.jsx(Cf,{accountId:s,currentDex:l,onDone:a,balancesOnl
7y:!0,onMove:()=>b(!0),activeDex:w,onPick:k,actions:r.jsxs(r.Fragment,{children:[u&&r.jsx("button",{type:"button",className:"fut-venues__deposit",onClick:u,children:h("Deposit")}),d&&r.jsx("button",{type:"button",className:"fut-venues__withdraw",onClick:d,children:h("Withdraw")})]})}),r.jsx("div",{className:"fut-portfolio__cards",children:tt.map(H=>{const et=r.jsxs("div",{className:"fut-card",children:[r.jsx("span",{className:"fut-card__label",children:H.label}),r.jsx("b",{className:"fut-card__value"+(H.tone?" is-"+H.tone:""),children:H.value})]});return H.hint?r.jsx(Rt.Tooltip,{title:H.hint,position:"top",arrow:!0,tag:"div",distance:10,style:{display:"flex"},children:et},H.key):r.jsx(ad.Fragment,{children:et},H.key)})}),S.length>1&&r.jsx("div",{className:"fut-portfolio__venue-tabs",role:"tablist",children:["all",...S].map(H=>r.jsx("button",{type:"button",role:"tab","aria-selected":w===H,className:w===H?"is-active":"",onClick:()=>k(H),children:H==="all"?h("All"):Tn(H)},H||"main"))}),r.jsx(fa,{accountId:s,positions:j,openOrders:E,onChanged:a,onPickCoin:c,history:nt,universe:f,vip:g}),v&&r.jsx(ga,{accountId:s,currentDex:l,onClose:()=>b(!1),onDone:a,withBalances:!1})]})}const D_={hl:{id:"hl",title:"Hyperliquid"}},va="hl";function O_(s){return Object.prototype.hasOwnProperty.call(D_,String(s??"").toLowerCase())}function xa(s,t=va){return"/futures/"+(O_(t)?String(t).toLowerCase():va)+"/"+encodeURIComponent(M0(s))}const I_=s=>parseFloat((s==null?void 0:s.startPosition)??0)||0,B_=s=>{const t=parseFloat((s==null?void 0:s.sz)??0)||0;return(s==null?void 0:s.side)==="B"?t:-t};function Xu(s,t,e){return{coin:s,isLong:t,openedAt:e,closedAt:null,entrySize:0,entryNotional:0,exitSize:0,exitNotional:0,realized:0,fee:0,builder:0,notional:0,fills:0,liquidated:!1,leverage:0,carried:0,parts:[]}}function Zu(s,t,e,n=!1){return{tid:(s==null?void 0:s.tid)??null,time:(s==null?void 0:s.time)??null,crossed:!!(s!=null&&s.crossed),liq:!!(s!=null&&s.liquidation),px:parseFloat((s==null?void 0:s.px)??0)||0,sz:parseFloat((s==null?void 0:s.sz)??0)||0,fee:t,kind:e,carried:n}}function Cl(s){return{...s,entryPx:s.entrySize?s.entryNotional/s.entrySize:0,exitPx:s.exitSize?s.exitNotional/s.exitSize:0,net:s.realized-s.fee,open:s.closedAt===null,partial:s.carried>0}}function W_(s,t,e,n,i){const o=Math.min(Math.abs(e),i);if(!o)return!1;const l=e>0?1:-1,a=n-(parseFloat((t==null?void 0:t.closedPnl)??0)||0)/(l*o);return a>0?(s.entrySize=Math.abs(e),s.entryNotional=Math.abs(e)*a,s.carried=0,!0):!1}function q_(s,t,e){var a,c;const n=parseFloat(((a=s==null?void 0:s.oid)==null?void 0:a[t==null?void 0:t.oid])??0)||0;if(n>0)return n;const i=(c=s==null?void 0:s.coin)==null?void 0:c[e];if(!Array.isArray(i))return 0;const o=(t==null?void 0:t.time)??0;let l=0;for(const u of i){if(((u==null?void 0:u.t)??0)>o)break;l=parseFloat((u==null?void 0:u.v)??0)||l}return l}function V_(s=[],t=[],e={}){const n=[...s].sort((l,a)=>(l.time??0)-(a.time??0)),i=new Map,o=[];for(const l of n){const a=l==null?void 0:l.coin;if(!a)continue;const c=I_(l),u=B_(l),d=Math.abs(u),f=parseFloat((l==null?void 0:l.px)??0)||0;if(!d)continue;let g=i.get(a);if(!g||c===0){const k=!g&&c!==0?Math.abs(c):0;g=Xu(a,k?c>0:u>0,l.time),g.carried=k,i.set(a,g)}const v=parseFloat((l==null?void 0:l.fee)??0)||0,b=c===0||c>0==u>0;g.fills+=1,g.fee+=v,g.builder+=parseFloat((l==null?void 0:l.builderFee)??0)||0,g.notional+=d*f,g.realized+=parseFloat((l==null?void 0:l.closedPnl)??0)||0,g.parts.push(Zu(l,v,b?"entry":"exit")),l!=null&&l.liquidation&&(g.liquidated=!0);const w=q_(e,l,a);if(w>
70&&(g.leverage=w),b)g.entrySize+=d,g.entryNotional+=d*f;else{g.carried&&W_(g,l,c,f,d);const k=Math.min(Math.abs(c),d);g.exitSize+=k,g.exitNotional+=k*f;const y=c+u;if(y===0||Math.abs(y)<1e-12)g.closedAt=l.time,o.push(Cl(g)),i.delete(a);else if(y>0!=c>0){g.closedAt=l.time,o.push(Cl(g));const S=Xu(a,y>0,l.time);S.fills=1,S.entrySize=Math.abs(y),S.entryNotional=Math.abs(y)*f,S.notional=Math.abs(y)*f,S.parts=[Zu(l,0,"entry",!0)],S.leverage=g.leverage,i.set(a,S)}}}for(const[l,a]of i){const c=t.find(u=>(u==null?void 0:u.coin)===l);if(a.carried&&c){const u=Math.abs(parseFloat(c.szi??0)||0),d=parseFloat(c.entryPx??0)||0;u&&d&&(a.entrySize=u,a.entryNotional=u*d,a.carried=0)}o.push({...Cl(a),unrealized:parseFloat((c==null?void 0:c.unrealizedPnl)??0)||0})}return o.sort((l,a)=>(a.closedAt??a.openedAt??0)-(l.closedAt??l.openedAt??0))}const Vf="YYYY-MM-DD HH:mm:ss",Uf=s=>Li(s).format(Vf),Hf=s=>Li(s).utc().format(Vf)+" UTC";function U_({fee:s,coin:t=null,fills:e=0,onClose:n}){Ps(n);const i=Math.max(0,parseFloat((s==null?void 0:s.total)??0)||0),o=Math.max(0,parseFloat((s==null?void 0:s.notional)??0)||0),l=Math.max(0,parseFloat((s==null?void 0:s.volume)??0)||0)||o,a=l>0?i/l*100:0,c=(Array.isArray(s==null?void 0:s.parts)?s.parts:[]).map(v=>{const b=Math.max(0,parseFloat((v==null?void 0:v.fee)??0)||0),w=(parseFloat((v==null?void 0:v.px)??0)||0)*(parseFloat((v==null?void 0:v.sz)??0)||0);return{...v,fee:b,notional:w,rate:!(v!=null&&v.carried)&&w>0?b/w*100:null}}),u=c.map(v=>v.rate).filter(v=>v!==null),d=[...new Set(u.map(v=>v.toFixed(3)))].length>1,f=d?Math.min(...u).toFixed(3)+"%–"+Math.max(...u).toFixed(3)+"%":null,g=[t?{key:"coin",label:h("Market"),value:zt(t)}:null,l>0?{key:"volume",label:h("Volume, $"),value:pe(l),hint:o>l?h("Turnover of all fills together: {turnover}. It is larger than the volume of the trade because the entry and the exit are counted separately.",{turnover:pe(o)}):null}:null,l>0?{key:"pct",label:h("Fee, %"),value:a.toFixed(3)+"%",hint:d?h("Counted against the volume of the trade. The rates of the fills differ: {range}.",{range:f}):h("Counted against the volume of the trade.")}:null,{key:"sum",label:h("Fee, $"),value:pe(i),tone:"is-strong"}].filter(Boolean);return r.jsx("div",{className:"fut-modal",onClick:n,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--fee",onClick:v=>v.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Fee")}),r.jsx("button",{type:"button",onClick:n,children:"✕"})]}),r.jsxs("div",{className:"fut-fee__hero",children:[r.jsx("b",{children:pe(i)}),l>0&&r.jsxs("i",{children:[a.toFixed(3),"% ",h("of")," ",pe(l)]})]}),r.jsx("div",{className:"fut-fee__stats",children:g.map(v=>r.jsxs("div",{className:"fut-fee__stat",children:[r.jsxs("em",{children:[v.label,v.hint&&r.jsx(Rt.Tooltip,{title:v.hint,position:"top",arrow:!0,tag:"span",distance:8,className:"fut-help",style:{display:"inline-flex"},children:"?"})]}),r.jsx("b",{className:v.tone||"",children:v.value})]},v.key))}),c.length>0&&r.jsxs("div",{className:"fut-fee__parts",children:[r.jsxs("div",{className:"fut-fee__parts-head",children:[c.length>1?h("Fills and their IDs"):h("Trade ID"),c.length>1&&r.jsxs("i",{children:["(",e||c.length,")"]})]}),r.jsx("div",{className:"fut-fee__parts-list",children:c.map((v,b)=>r.jsxs("div",{className:"fut-fee__part",children:[r.jsxs("div",{className:"fut-fee__part-top",children:[v.time?r.jsx(Rt.Tooltip,{title:Hf(v.time),position:"top",arrow:!0,tag:"span",distance:8,className:"fut-fee__part-time",style:{display:"inline-block"},children:Uf(v.time)}):r.jsx("span",{className:"fut-fee__part-time",children:"—"}),v.kind&&r.jsx("span",{className:"fut-fee__tag is-"+v.kind,children:v.kind==="exit"?h("Exit"):h("Entry")}),v.liq&&r.jsx(Rt.Tooltip,{title:h("The venue closed the position by force: the margin ran out. Such fills carry no Radex fee — only the venue rate."),position:"top",arrow:!0,tag:"span",distance:8,className:"fut-fee__tag is-liq",children:h("Liquidation")}),r.jsx("span",{className:"fut-fee__tag"+(v.crossed?" is-taker":""),children:v.crossed?"Taker":"Maker"}),r.jsx(Rt.Tooltip,{title:v.carried?h("The fee for this fill belongs to the previous trade: it reversed the position."):h("Fee of this fill — part of the {total} above.",{total:pe(i)}),position:"top",arrow:!0,tag:"b",distance:8,children:v.carried?"—":pe(v.fee)})]}),r.jsxs("div",{className:"fut-fee__part-meta",children:[r.jsxs("span",{className:"fut-fee__part-calc",children:[v.sz>0&&r.jsxs(Rt.Tooltip,{title:h("Size of this fill."),position:"top",arrow:!0,tag:"span",distance:8,children:[lt(v.sz),t&&r.jsx("i",{children:zt(t)})]}),v.notional>0&&r.jsx(Rt.Tooltip,{title:h("Volume of this fill in dollars — the fee is counted against it."),position:"top",arrow:!0,tag:"span",distance:8,children:pe(v.notional)}),r.jsx(Rt.Tooltip,{title:v.carried?h("The fee for this fill belongs to the previous trade: it reversed the position."):v.rate!==null?h("Rate of this fill: its fee against its own turnover, {notional}.",{notional:pe(v.notional)}):h("There is no turnover to count the rate against."),position:"top",arrow:!0,tag:"span",distance:8,children:!v.carried&&v.rate!==null?v.rate.toFixed(3)+"%":"—"})]}),v.tid!=null&&r.jsxs("span",{className:"fut-fee__part-id",children:["ID ",String(v.tid)]})]})]}
7,v.tid??b))})]}),r.jsxs("div",{className:"fut-fee__note",children:[c.length>1&&h("A fee is charged on every fill — both on the entry and on the exit.")+" ",h("It is withheld by the venue at execution, so it is already included in the result of the trade.")]})]})})}function Tl({value:s,options:t,onChange:e,ariaLabel:n,className:i=""}){const[o,l]=m.useState(!1),[a,c]=m.useState(0),u=m.useRef(null),d=m.useRef(null),f=Math.max(0,t.findIndex(k=>k.value===s)),g=t[f]??t[0],v=m.useCallback((k=!1)=>{var y;l(!1),k&&((y=d.current)==null||y.focus())},[]),b=m.useCallback(k=>{e(k.value),v(!0)},[e,v]);m.useEffect(()=>{if(!o)return;const k=S=>{var j;(j=u.current)!=null&&j.contains(S.target)||v()},y=()=>v();return window.addEventListener("pointerdown",k),window.addEventListener("scroll",y,!0),()=>{window.removeEventListener("pointerdown",k),window.removeEventListener("scroll",y,!0)}},[o,v]),m.useEffect(()=>{o&&c(f)},[o,f]);const w=k=>{if(k.key==="Escape"){if(!o)return;k.preventDefault(),k.stopPropagation(),v(!0);return}if(!o){(k.key==="Enter"||k.key===" "||k.key==="ArrowDown")&&(k.preventDefault(),l(!0));return}k.key==="ArrowDown"?(k.preventDefault(),c(y=>Math.min(t.length-1,y+1))):k.key==="ArrowUp"?(k.preventDefault(),c(y=>Math.max(0,y-1))):k.key==="Home"?(k.preventDefault(),c(0)):k.key==="End"?(k.preventDefault(),c(t.length-1)):(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),b(t[a]??t[0]))};return r.jsxs("div",{className:"fut-select"+(o?" is-open":"")+(i?" "+i:""),ref:u,children:[r.jsxs("button",{type:"button",ref:d,className:"fut-select__button","aria-haspopup":"listbox","aria-expanded":o,"aria-label":n,onClick:()=>l(k=>!k),onKeyDown:w,children:[r.jsx("span",{children:g==null?void 0:g.label}),r.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M6 9l6 6 6-6",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})]}),o&&r.jsx("div",{className:"fut-select__list",role:"listbox",tabIndex:-1,"aria-label":n,children:t.map((k,y)=>r.jsx("button",{type:"button",role:"option","aria-selected":k.value===s,className:"fut-select__option"+(k.value===s?" is-current":"")+(y===a?" is-active":""),onMouseEnter:()=>c(y),onClick:()=>b(k),children:k.label},String(k.value)))})]})}const Xr=[],H_={};function Ju(s){const t=s.net+(s.open?s.unrealized??0:0),e=(s.entryPx||0)*(s.entrySize||0),n=s.leverage||0,i=n?e/n:e;return{pnl:t,lev:n,pct:s.partial||!i?null:t/i*100,pctBase:n?"margin":"volume"}}const ya=[{id:"fills",path:"",title:"Trades"},{id:"trades",path:"trades",title:"Closed trades"},{id:"funding",path:"funding",title:"Funding"},{id:"deposits",path:"deposits",title:"Deposits"},{id:"withdrawals",path:"withdrawals",title:"Withdrawals"},{id:"transfers",path:"transfers",title:"Deposits & withdrawals"}],K_=[{days:1,label:"24h"},{days:7,label:"7d"},{days:30,label:"30d"},{days:90,label:"90d"}],Ll=100,$_=["pending","sent","confirmed","credited","failed"],El=s=>s?r.jsx(sr,{className:"fut-table__ticker",to:xa(s),title:h("Open chart"),children:zt(s)}):"—",Zr=s=>r.jsx(Rt.Tooltip,{title:Hf(s),position:"top",arrow:!0,tag:"span",children:Uf(s)}),Fl=s=>r.jsx(Rt.Tooltip,{title:s,position:"top",arrow:!0,tag:"span",distance:8,className:"fut-help",style:{display:"inline-flex"},children:"?"});function Y_({accountId:s}){var he;const{showError:t}=Ln(),{pair:e}=hd(),n=ud(),i=((he=ya.find(N=>N.path&&N.path===e))==null?void 0:he.id)??"fills",o=N=>n("/futures/history"+(N.path?"/"+N.path:"")),[l,a]=m.useState(7),[c,u]=m.useState(null),[d,f]=m.useState(!0),[g,v]=m.useState(""),[b,w]=m.useState(""),k=!!g||!!b,[y,S]=m.useState(""),[j,E]=m.useState("all"),[z,F]=m.useState("all"),[A,J]=m.useState("all"),[O,yt]=m.useState(1),[P,G]=m.useState(null),[nt,bt]=m.useState(null);m.useEffect(()=>{yt(1)},[i,l,g,b,y,j,A]),m.useEffect(()=>{var qt;let N=!1;f(!0);const mt=b?Li(b).endOf("day").valueOf():Date.now(),Pt=g?Li(g).startOf("day").valueOf():k?0:mt-l*24*60*60*1e3;return ge.post("/x/futures/history",{miniAppData:(qt=ve())==null?void 0:qt.initData,account_id:s,startTime:Pt,endTime:mt}).then(({data:pt})=>{N||(pt!=null&&pt.err?(t(pt.errText||pt.err),u({fills:[],funding:[],transfers:[],positions:[],leverage:{}})):u({fills:(pt==null?void 0:pt.fills)??[],funding:(pt==null?void 0:pt.funding)??[],transfers:(pt==null?void 0:pt.transfers)??[],positions:(pt==null?void 0:pt.positions)??[],leverage:(pt==null?void 0:pt.leverage)??{}}))}).catch(()=>{N||u({fills:[],funding:[],transfers:[],positions:[],leverage:{}})}).finally(()=>{N||f(!1)}),()=>{N=!0}},[s,l,g,b,k,t]);const $=(c==null?void 0:c.fills)??Xr,ht=(c==null?void 0:c.funding)??Xr,tt=(c==null?void 0:c.transfers)??Xr,H=(c==null?void 0:c.positions)??Xr,et=(c==null?void 0:c.leverage)??H_,rt=m.useMemo(()=>V_($,H,et),[$,H,et]),Nt=tt.filter(N=>N.direction==="deposit"),X=tt.filter(N=>N.direction!=="deposit"),st=y.trim().toLowerCase(),Ot=N=>!st||zt(String(N??"")).toLowerCase().includes(st),St=(N,mt)=>N.sort((Pt,qt)=>(mt(qt)??0)-(mt(Pt)??0)),At=St($.filter(N=>Ot(N.coin)&&(j==="all"||(j==="buy"?N.side==="B":N.side!=="B"))&&(z==="all"||(z==="taker"?
7!!N.crossed:!N.crossed))),N=>N.time),Yt=St(ht.filter(N=>{var mt,Pt;return Ot((mt=N.delta)==null?void 0:mt.coin)&&(j==="all"||((parseFloat(((Pt=N.delta)==null?void 0:Pt.usdc)??0)||0)>=0?j==="buy":j==="sell"))}),N=>N.time),Mt=St(rt.filter(N=>Ot(N.coin)&&(j==="all"||(j==="buy"?N.isLong:!N.isLong))),N=>N.closedAt??N.openedAt),Gt=Mt.reduce((N,mt)=>(N.realized+=mt.realized,N.fee+=mt.fee,N.net+=mt.net,mt.open||(N.closed+=1,mt.net>0&&(N.wins+=1)),N),{realized:0,fee:0,net:0,closed:0,wins:0}),jt=N=>A==="all"?N:N.filter(mt=>mt.status===A),Be={fills:At,trades:Mt,funding:Yt,deposits:jt(Nt),withdrawals:jt(X),transfers:jt(tt)}[i]??[],de=Math.max(1,Math.ceil(Be.length/Ll)),ie=Math.min(O,de),ce=N=>N.slice((ie-1)*Ll,ie*Ll),Ne=()=>de<2?null:r.jsxs("div",{className:"fut-history__pager",children:[r.jsx("button",{type:"button",disabled:ie<=1,onClick:()=>yt(ie-1),children:"←"}),r.jsxs("span",{children:[h("Page")," ",ie," / ",de,r.jsxs("i",{children:[Be.length," ",h("records")]})]}),r.jsx("button",{type:"button",disabled:ie>=de,onClick:()=>yt(ie+1),children:"→"})]}),se={pending:{label:"Pending",tone:"is-muted"},sent:{label:"On the way",tone:""},confirmed:{label:"Confirmed",tone:"is-up"},credited:{label:"Credited",tone:"is-up"},failed:{label:"Failed",tone:"is-down"}},We={arbitrum:"https://arbiscan.io/tx/"},Re=(N,mt)=>N>0?h("Nothing matches the filters"):mt,ze=(N,mt,Pt,qt)=>N.length?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{className:"fut-table__time",children:h("Time")}),Pt&&r.jsx("span",{children:h("Type")}
7),r.jsx("span",{className:"fut-table__num",children:h("Amount")}),r.jsx("span",{className:"fut-table__num",children:h("Fee")}),r.jsx("span",{className:"fut-table__num",children:h("You receive")}),r.jsx("span",{children:h("Status")})]}),N.map(pt=>{const te=pt.direction==="deposit",Tt=se[pt.status]??{label:pt.status,tone:"is-muted"},Ht=Math.max(0,(pt.amount??0)-(pt.received??0)),xt=pt.tx_hash&&We[pt.chain]?We[pt.chain]+pt.tx_hash:null;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{className:"fut-table__time",children:Zr(pt.time)}),Pt&&r.jsx("span",{"data-label":h("Type"),className:te?"is-up":"is-down",children:te?h("Account deposit"):h("Account withdrawal")}),r.jsx("span",{className:"fut-table__num","data-label":h("Amount"),children:pe(pt.amount)}),r.jsx("span",{"data-label":h("Fee"),className:"fut-table__num is-muted",title:pt.exchange_fee?h("Exchange withdrawal fee")+": "+pt.exchange_fee+" USDC":"",children:Ht?pe(Ht):"—"}),r.jsx("span",{className:"fut-table__num","data-label":h("You receive"),children:pe(pt.received)}),r.jsxs("span",{"data-label":h("Status"),className:Tt.tone,title:pt.error||"",children:[h(Tt.label),xt&&r.jsx("a",{className:"fut-table__tx",href:xt,target:"_blank",rel:"noreferrer noopener",title:h("Open transaction"),children:"↗"})]})]},pt.id)})]}),Ne()]}):r.jsx("div",{className:"fut-panel__empty",children:Re(qt,mt)});return r.jsxs("div",{className:"fut-history",children:[r.jsx("div",{className:"fut-history__bar",children:r.jsx("div",{className:"fut-history__tabs",children:ya.map(N=>r.jsx("button",{type:"button",className:i===N.id?"is-active":"",onClick:()=>o(N),children:h(N.title)},N.id))})}),r.jsxs("div",{className:"fut-history__filters",children:[r.jsxs("div",{className:"fut-history__what",children:[(i==="fills"||i==="funding"||i==="trades")&&r.jsxs(r.Fragment,{children:[r.jsxs("label",{className:"fut-history__search",children:[r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"11",cy:"11",r:"7",stroke:"currentColor",strokeWidth:"2"}),r.jsx("path",{d:"M20 20l-3.5-3.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),r.jsx("input",{type:"search",value:y,onChange:N=>S(N.target.value),placeholder:h("Ticker"),"aria-label":h("Ticker")}),y&&r.jsx("button",{type:"button",className:"fut-history__searchclear",onMouseDown:N=>N.preventDefault(),onClick:()=>S(""),title:h("Reset"),"aria-label":h("Reset"),children:"✕"})]}),r.jsx(Tl,{className:j!=="all"?"is-set":"",value:j,onChange:E,ariaLabel:h("Side"),options:[{value:"all",label:h("Side")+": "+h("All")},{value:"buy",label:i==="funding"?h("Received"):i==="trades"?h("Long"):h("Buy")},{value:"sell",label:i==="funding"?h("Paid"):i==="trades"?h("Short"):h("Sell")}]}),i==="fills"&&r.jsx(Tl,{className:z!=="all"?"is-set":"",value:z,onChange:F,ariaLabel:h("Type"),options:[{value:"all",label:h("Type")+": "+h("All")},{value:"maker",label:"Maker"},{value:"taker",label:"Taker"}]})]}),(i==="deposits"||i==="withdrawals"||i==="transfers")&&r.jsx(Tl,{className:A!=="all"?"is-set":"",value:A,onChange:J,ariaLabel:h("Status"),options:[{value:"all",label:h("Status")+": "+h("All")},...$_.map(N=>({value:N,label:h(se[N].label)}))]})]}),r.jsxs("div",{className:"fut-history__when",children:[r.jsx("div",{className:"fut-history__periods",children:K_.map(N=>r.jsx("button",{type:"button",className:!k&&l===N.days?"is-active":"",onClick:()=>{v(""),w(""),a(N.days)},children:N.label},N.days))}),r.jsxs("div",{className:"fut-history__dates"+(k?" is-active":""),children:[r.jsx("input",{type:"date",value:g,max:b||void 0,onChange:N=>v(N.target.value),onClick:N=>{var mt,Pt;try{(Pt=(mt=N.currentTarget).showPicker)==null||Pt.call(mt)}catch{}},"aria-label":h("From")}),r.jsx("em",{children:"—"}),r.jsx("input",{type:"date",value:b,min:g||void 0,onChange:N=>w(N.target.value),onClick:N=>{var mt,Pt;try{(Pt=(mt=N.currentTarget).showPicker)==null||Pt.call(mt)}catch{}},"aria-label":h("To")}),k&&r.jsx("button",{type:"button",className:"fut-history__clear",onClick:()=>{v(""),w("")},title:h("Reset"),"aria-label":h("Reset"),children:"✕"})]})]})]}),d&&r.jsxs("div",{className:"fut-panel__empty",children:[h("Loading"),"…"]}),!d&&i==="fills"&&(At.length===0?r.jsx("div",{className:"fut-panel__empty",children:Re($.length,h("No trades yet"))}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{className:"fut-table__time",children:h("Time")}),r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Side")}),r.jsx("span",{children:r.jsx(Rt.Tooltip,{title:h("Maker means the order sat in the book and waited; taker means it crossed the spread and took liquidity. The fee rate differs between them."),position:"top",arrow:!0,tag:"span",distance:10,children:h("Type")})}),r.jsx("span",{className:"fut-table__num",children:h("Price")}),r.jsx("span",{className:"fut-table__num",children:h("Size")}),r.jsx("span",{className:"fut-table__num",children:h("Volume, $")}),r.jsx("span",{className:"fut-table__num",children:h("Fee")})]}),ce(At).map(N=>{const mt=!!N.liquidation;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{className:"fut-table__time",children:Zr(N.time)}),r.jsx("span",{"data-label":h("Market"),children:El(N.coin)}),r.jsxs("span",{"data-label":h("Side"),className:N.side==="B"?"is-up":"is-down",children:[N.side==="B"?h("Buy"):h("Sell"),mt&&r.jsx(Rt.Tooltip,{title:h("The venue closed the position by force: the margin ran out. Such fills carry no Radex fee — only the venue rate."),position:"top",arrow:!0,tag:"em",distance:10,className:"fut-table__liq",children:h("Liquidation")})]}),r.jsx("span",{"data-label":h("Type"),className:N.crossed?"":"is-muted",children:N.crossed?"Taker":"Maker"}),r.jsx("span",{className:"fut-table__num","data-label":h("Price"),children:lt(parseFloat(N.px))}),r.jsxs("span",{className:"fut-table__num","data-label":h("Size"),children:[lt(parseFloat(N.sz)),r.jsx("i",{className:"fut-table__unit",children:zt(N.coin)})]}),r.jsx("span",{className:"fut-table__num","data-label":h("Volume, $"),children:pe((parseFloat(N.px??0)||0)*(parseFloat(N.sz??0)||0))}),r.jsx("span",{className:"fut-table__num","data-label":h("Fee"),children:r.jsx("button",{type:"button",className:"fut-table__fee",onClick:()=>G({total:parseFloat(N.fee??0)||0,builder:parseFloat(N.builderFee??0)||0,notional:(parseFloat(N.px??0)||0)*(parseFloat(N.sz??0)||0),coin:N.coin,fills:1,parts:[{tid:N.tid,time:N.time,crossed:!!N.crossed,px:parseFloat(N.px??0)||0,sz:parseFloat(N.sz??0)||0,fee:parseFloat(N.fee??0)||0,kind:/^close/i.test(N.dir??"")?"exit":/^open/i.test(N.dir??"")?"entry":null,liq:mt}]}),children:pe(N.fee??0)})})]},N.tid)})]}),Ne()]})),!d&&i==="trades"&&(Mt.length===0?r.jsx("div",{className:"fut-panel__empty",children:Re(rt.length,h("No closed trades yet"))}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-history__totals",children:[r.jsxs("span",{children:[r.jsxs("em",{children:[h("Realized PnL"),Fl(h("Result of the selected trades at exchange prices: exit minus entry. Fees are NOT subtracted here — they are taken into account in «Net result»."))]}),r.jsx("b",{className:Gt.realized>=0?"is-up":"is-down",children:$e(Gt.realized)})]}),r.jsxs("span",{children:[r.jsxs("em",{children:[h("Net result"),Fl(h("The same result with the fees subtracted: what the selected trades actually left you with. The unrealized result of trades that are still open is not included."))]}),r.jsx("b",{className:Gt.net>=0?"is-up":"is-down",children:$e(Gt.net)})]}),r.jsxs("span",{children:[r.jsxs("em",{children:[h("Win rate"),Fl(h("Share of closed trades that ended in profit AFTER fees. Next to it — how many exactly: profitable out of all closed ones. Trades that are still open are not counted."))]}),r.jsxs("b",{children:[Gt.closed?Math.round(Gt.wins/Gt.closed*100)+"%":"—",r.jsxs("i",{children:[Gt.wins," / ",Gt.closed]})]})]})]}),r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{className:"fut-table__time",children:h("Closed")}),r.jsx("span",{children:h("Market")}),r.jsx("span",{children:h("Side")}),r.jsx("span",{className:"fut-table__num",children:h("Size")}),r.jsx("span",{className:"fut-table__num",children:h("Volume, $")}),r.jsx("span",{className:"fut-table__num",children:h("Bought at")}),r.jsx("span",{className:"fut-table__num",children:h("Sold at")}),r.jsx("span",{className:"fut-table__num",children:r.jsx(Rt.Tooltip,{title:h("Result of the trade at exchange prices: exit minus entry. Fees are not included — they are in the next column."),position:"top",arrow:!0,tag:"span",distance:10,children:h("Realized PnL")})}),r.jsx("span",{className:"fut-table__num",children:r.jsx(Rt.Tooltip,{title:h("Shown only for a trade that is still open: what it is 
7worth at the current price. A dash means the trade is already closed and nothing is left to revalue."),position:"top",arrow:!0,tag:"span",distance:10,children:h("Unrealized PnL")})}),r.jsx("span",{className:"fut-table__num",children:h("Fees")}),r.jsx("span",{className:"fut-table__num",children:h("Net result")}),r.jsx("span",{className:"fut-table__num",children:r.jsx(Rt.Tooltip,{title:h("Net result in percent. Counted from the margin when the leverage of the trade is known, otherwise from the entry volume — each row says which in its own tooltip."),position:"top",arrow:!0,tag:"span",distance:10,children:h("PnL, %")})})]}),ce(Mt).map(N=>r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{className:"fut-table__time",children:N.open?r.jsx("em",{className:"fut-history__live",children:h("Still open")}):Zr(N.closedAt)}),r.jsx("span",{"data-label":h("Market"),children:El(N.coin)}),r.jsxs("span",{"data-label":h("Side"),className:N.isLong?"is-up":"is-down",children:[N.isLong?h("Long"):h("Short"),N.liquidated&&r.jsx(Rt.Tooltip,{title:h("The venue closed the position by force: the margin ran out. Such fills carry no Radex fee — only the venue rate."),position:"top",arrow:!0,tag:"em",distance:10,className:"fut-table__liq",children:h("Liquidation")})]}),r.jsxs("span",{className:"fut-table__num","data-label":h("Size"),children:[lt(N.entrySize),r.jsx("i",{className:"fut-table__unit",children:zt(N.coin)})]}),r.jsx("span",{className:"fut-table__num","data-label":h("Volume, $"),children:pe(N.entryNotional)}),r.jsx("span",{className:"fut-table__num","data-label":h("Bought at"),children:lt(N.entryPx)}),r.jsx("span",{className:"fut-table__num","data-label":h("Sold at"),children:N.exitPx?lt(N.exitPx):"—"}),r.jsx("span",{"data-label":h("Realized PnL"),className:"fut-table__num "+(N.realized===0?"is-muted":N.realized>0?"is-up":"is-down"),children:N.realized===0?"—":$e(N.realized)}),r.jsx("span",{"data-label":h("Unrealized PnL"),className:"fut-table__num "+(N.open?(N.unrealized??0)>=0?"is-up":"is-down":"is-muted"),children:N.open?$e(N.unrealized??0):"—"}),r.jsx("span",{className:"fut-table__num","data-label":h("Fees"),children:r.jsx("button",{type:"button",className:"fut-table__fee",onClick:()=>G({total:N.fee,builder:N.builder,notional:N.notional,volume:N.entryNotional,coin:N.coin,fills:N.fills,parts:N.parts}),children:pe(N.fee)})}),r.jsxs("span",{"data-label":h("Net result"),className:"fut-table__num "+(N.net>=0?"is-up":"is-down"),children:[$e(N.net),r.jsx(Rt.Tooltip,{position:"top",arrow:!0,distance:8,tag:"span",title:h("Share PnL card"),children:r.jsx("button",{type:"button",className:"fut-share","aria-label":h("Share PnL card"),onClick:()=>{const{pnl:mt,pct:Pt,pctBase:qt,lev:pt}=Ju(N);bt({coin:N.coin,isLong:N.isLong,leverage:pt,entryPx:N.entryPx,exitPx:N.exitPx,exitLabel:h("Exit price"),size:N.entrySize,pnlUsd:mt,pnlPct:Pt,pctBase:qt,closedAt:N.closedAt??N.openedAt})},children:r.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:r.jsx("path",{d:"M14 4h6v6M20 4l-9 9M18 14v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})})]}),(()=>{const{pct:mt,pctBase:Pt,lev:qt}=Ju(N);return mt===null?r.jsx("span",{className:"fut-table__num is-muted","data-label":h("PnL, %"),children:r.jsx(Rt.Tooltip,{title:h("The trade was opened before the selected period, so its entry is not fully known — there is nothing to count a percentage from."),position:"top",arrow:!0,tag:"span",distance:10,children:"—"})}):r.jsx("span",{"data-label":h("PnL, %"),className:"fut-table__num "+(mt>=0?"is-up":"is-down"),children:r.jsx(Rt.Tooltip,{title:Pt==="margin"?h("Share of the margin for this trade: its volume divided by the {lev}× leverage. This is the same number the position showed while it was open.",{lev:qt}):h("Share of the entry volume: the leverage of this trade is unknown, so there is nothing to count the margin from."),position:"top",arrow:!0,tag:"span",distance:10,children:(mt>=0?"+":"")+mt.toFixed(2)+"%"})})})()]},N.coin+"_"+N.openedAt))]}),Ne()]})),!d&&i==="funding"&&(Yt.length===0?r.jsx("div",{className:"fut-panel__empty",children:Re(ht.length,h("No funding payments"))}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-table",children:[r.jsxs("div",{className:"fut-table__head",children:[r.jsx("span",{className:"fut-table__time",children:h("Time")}),r.jsx("span",{children:h("Market")}),r.jsx("span",{className:"fut-table__num",children:h("Rate")}),r.jsx("span",{className:"fut-table__num",children:h("Payment")})]}),ce(Yt).map((N,mt)=>{var pt,te,Tt;const Pt=parseFloat(((pt=N.delta)==null?void 0:pt.usdc)??0)||0,qt=parseFloat(((te=N.delta)==null?void 0:te.fundingRate)??0)*100;return r.jsxs("div",{className:"fut-table__row",children:[r.jsx("span",{className:"fut-table__time",children:Zr(N.time)}),r.jsx("span",{"data-label":h("Market"),children:El((Tt=N.delta)==null?void 0:Tt.coin)}),r.jsx("span",{className:"fut-table__num is-muted","data-label":h("Rate"),children:qt?qt.toFixed(4)+"%":"—"}),r.jsx("span",{"data-label":h("Payment"),className:"fut-table__num "+(Pt>=0?"is-up":"is-down"),children:$e(Pt)})]},N.time+"_"+mt)})]}),Ne()]})),P&&r.jsx(U_,{fee:P,coin:P.coin,fills:P.fills,onClose:()=>G(null)}),nt&&r.jsx(Df,{card:nt,onClose:()=>bt(null)}
7),!d&&i==="deposits"&&ze(ce(jt(Nt)),h("No deposits yet"),!1,Nt.length),!d&&i==="withdrawals"&&ze(ce(jt(X)),h("No withdrawals yet"),!1,X.length),!d&&i==="transfers"&&ze(ce(jt(tt)),h("No deposits or withdrawals yet"),!0,tt.length)]})}const Q_=[{key:"name",label:"Market",align:"left"},{key:"mark",label:"Price",align:"right"},{key:"change",label:"24h change",align:"right"},{key:"volume",label:"24h volume",align:"right"},{key:"oi",label:"Open interest",align:"right"},{key:"fund",label:"Funding",align:"right"},{key:"lev",label:"Max leverage",align:"right"}];function td(s){return s?s>=1e9?"$"+(s/1e9).toFixed(2)+"B":s>=1e6?"$"+(s/1e6).toFixed(1)+"M":s>=1e3?"$"+(s/1e3).toFixed(0)+"K":"$"+Math.round(s):"—"}function G_({meta:s,ctxs:t,current:e,ownedCoins:n,onPick:i}){const[o,l]=m.useState(""),[a,c]=m.useState("all"),[u,d]=m.useState({key:"volume",dir:"desc"}),[f,g]=m.useState(()=>Bf()),v=n??new Set,b=(y,S)=>{y.stopPropagation();const j=new Set(f);j.has(S)?j.delete(S):j.add(S),g(j),Wf(j)},w=m.useMemo(()=>{const S=((s==null?void 0:s.universe)??[]).map((E,z)=>{const F=(t==null?void 0:t[z])??null,A=parseFloat((F==null?void 0:F.markPx)??0),J=parseFloat((F==null?void 0:F.prevDayPx)??0),O=parseFloat((F==null?void 0:F.openInterest)??0);return{asset:E,name:E.name,mark:A,change:J?(A-J)/J*100:0,volume:parseFloat((F==null?void 0:F.dayNtlVlm)??0),oi:O*A,fund:parseFloat((F==null?void 0:F.funding)??0)*100,lev:E.maxLeverage??0}}).filter(E=>!E.asset.isDelisted).filter(E=>pa(a,E.asset,null,f,v)).filter(E=>!o||E.name.toLowerCase().includes(o.toLowerCase())),j=u.dir==="asc"?1:-1;return S.sort((E,z)=>u.key==="name"?zt(E.name).localeCompare(zt(z.name))*j:((E[u.key]??0)-(z[u.key]??0))*j)},[s,t,o,a,u,f,v]),k=y=>{d(S=>S.key===y?{key:y,dir:S.dir==="desc"?"asc":"desc"}:{key:y,dir:y==="name"?"asc":"desc"})};return r.jsxs("div",{className:"fut-mkpage",children:[r.jsxs("div",{className:"fut-mkpage__head",children:[r.jsx("input",{className:"fut-mkpage__search",type:"text",value:o,onChange:y=>l(y.target.value),placeholder:h("Search")}),r.jsxs("span",{className:"fut-mkpage__count",children:[w.length," ",h("markets")]})]}),r.jsx("div",{className:"fut-markets__tabs",children:ma.map(y=>r.jsx("button",{type:"button",className:y.key===a?"is-active":"",onClick:()=>c(y.key),children:h(y.label)},y.key))}),r.jsxs("div",{className:"fut-mkpage__scroll",children:[r.jsxs("table",{className:"fut-mktable",children:[r.jsx("thead",{children:r.jsxs("tr",{children:[r.jsx("th",{className:"fut-mktable__star"}),Q_.map(y=>r.jsxs("th",{style:{textAlign:y.align},className:"is-sortable"+(u.key===y.key?" is-sorted":""),onClick:()=>k(y.key),children:[h(y.label),u.key===y.key&&r.jsx("i",{children:u.dir==="desc"?"↓":"↑"})]},y.key))]})}),r.jsx("tbody",{children:w.map(y=>r.jsxs("tr",{className:y.name===e?"is-active":"",onClick:()=>i(y.name),children:[r.jsx("td",{className:"fut-mktable__star",children:r.jsx("button",{type:"button",className:"fut-markets__star"+(f.has(y.name)?" is-on":""),onClick:S=>b(S,y.name),"aria-label":h("Favorites"),children:"★"})}),r.jsx("td",{children:r.jsxs("span",{className:"fut-mktable__market",children:[r.jsx($a,{coin:y.name,size:22}),r.jsx("b",{children:zt(y.name)}),v.has(y.name)&&r.jsx(Rt.Tooltip,{title:h("You have an open position on this market"),position:"top",arrow:!0,tag:"span",children:r.jsx("em",{className:"fut-markets__owned"})})]})}),r.jsx("td",{style:{textAlign:"right"},children:y.mark?be(y.mark):"—"}),r.jsxs("td",{style:{textAlign:"right"},className:y.change>=0?"is-up":"is-down",children:[y.change>=0?"+":"",y.change.toFixed(2),"%"]}),r.jsx("td",{style:{textAlign:"right"},children:td(y.volume)}),r.jsx("td",{style:{textAlign:"right"},children:td(y.oi)}),r.jsxs("td",{style:{textAlign:"right"},className:y.fund>0?"is-down":y.fund<0?"is-up":"",children:[y.fund.toFixed(4),"%"]}),r.jsxs("td",{style:{textAlign:"right"},children:[y.lev,"×"]})]},y.name))})]}),w.length===0&&r.jsx("div",{className:"fut-panel__empty",children:h("Nothing found")})]})]})}function Jr(s){const t=Math.abs(s);return t?t>=1e9?(s/1e9).toFixed(2)+"B":t>=1e6?(s/1e6).toFixed(2)+"M":t>=1e3?(s/1e3).toFixed(1)+"K":lt(s):"0"}function X_({coin:s,asset:t,ctx:e}){if(!e&&!t)return null;const n=zt(s),i=parseFloat((e==null?void 0:e.markPx)??0)||0,o=parseFloat((e==null?void 0:e.oraclePx)??0)||0,l=parseFloat((e==null?void 0:e.openInterest)??0)||0,a=l*i,c=parseFloat((e==null?void 0:e.dayNtlVlm)??0)||0,u=parseFloat((e==null?void 0:e.dayBaseVlm)??0)||0,d=parseFloat((e==null?void 0:e.funding)??0)*100,f=[{key:"kind",label:h("Contract type"),value:h("Perpetual")},{key:"oracle",label:h("Index price"),value:o?lt(o):"—"},{key:"mark",label:h("Mark price"),value:i?lt(i):"—"},{key:"oi",label:h("Open interest"),value:l?"$"+Jr(a):"—",extra:l?Jr(l)+" "+n:null},{key:"turnover",label:h("24h turnover"),value:c?"$"+Jr(c):"—"},{key:"volume",label:h("24h volume"),value:u?Jr(u)+" "+n:"—"},{key:"funding",label:h("Funding")+" / 1h",value:(e==null?void 0:e.funding)!==void 0?d.toFixed(4)+"%":"—",tone:d>0?"down":d<0?"up":""},{key:"lev",label:h("Max leverage"),value:t!=null&&t.maxLeverage?t.maxLeverage+"×":"—"},{key:"size",label:h("Contract size"),value:"1 "+n},{key:"settle",label:h("Settled in"),value:"USDC"}];return r.jsxs("div",{className:"fut-contract",children:[r.jsxs("div",{className:"fut-contract__head",children:[h("Contract details")," · ",n]}),r.jsx("div",{className:"fut-contract__list",children:f.map(g=>r.jsxs("div",{className:"fut-contract__row",children:[r.jsx("span",{children:g.label}),r.jsxs("b",{className:g.tone?"is-"+g.tone:"",children:[g.value,g.extra&&r.jsx("i",{children:g.extra})]})]},g.key))})]})}function ed({coin:s,asset:t,ctx:e,position:n,state:i,equity:o=0,leverage:l=10,isCross:a=!0,onApply:c,onClose:u}){Ps(u);const d=zt(s),f=parseFloat((e==null?void 0:e.markPx)??0)||0,g=(t==null?void 0:t.maxLeverage)??20,v=parseFloat((n==null?void 0:n.szi)??0)||0,[b,w]=m.useState(v<0?"sell":"buy"),[k,y]=m.useState(l||10),[S,j]=m.useState(String(be(parseFloat((n==null?void 0:n.entryPx)??0)||f||0))),[E,z]=m.useState(""),[F,A]=m.useState(""),[J,O]=m.useState(v?String(Math.abs(v)):""),[yt,P]=m.useState("coin"),[G,nt]=m.useState(""),bt=b==="buy",$=parseFloat(S)||0,ht=parseFloat(E)||0,tt=parseFloat(F)||0,H=m.useMemo(()=>{const Mt=parseFloat(J)||0;return Mt?yt==="usd"?$?Mt/$:0:Mt:0},[J,yt,$]),et=m.useMemo(()=>Ah({entryPx:$,exitPx:ht,size:H,leverage:k,isLong:bt}),[$,ht,H,k,bt]),rt=m.useMemo(()=>tt?Ah({entryPx:$,exitPx:tt,size:H,leverage:k,isLong:bt}):null,[$,tt,H,k,bt]),Nt=m.useMemo(()=>Kd({entryPx:$,size:H,leverage:k,maxLeverage:g,isLong:bt,isCross:a,equity:o,usedMaintenance:parseFloat((i==null?void 0:i.crossMaintenanceMarginUsed)??0)||0}),[$,H,k,g,bt,a,o,i]),X=rt&&rt.net<0&&et.net>0?et.net/Math.abs(rt.net):null,st=Mt=>{nt(Mt);const Gt=parseFloat(Mt.replace(",","."));if(!Number.isFinite(Gt)||!$||!H)return;const jt=C0({entryPx:$,size:H,isLong:bt,target:Gt});z(jt?String(be(jt)):"")},Ot=Mt=>{z(Mt),nt("")},St=()=>{var Gt;if(!v)return;w(v>0?"buy":"sell"),O(String(Math.abs(v))),P("coin"),j(String(be(parseFloat(n.entryPx)||0)));const Mt=parseInt((Gt=n==null?void 0:n.leverage)==null?void 0:Gt.value,10);Mt&&y(Math.min(Mt,g))},At=()=>{c&&(c({side:b,leverage:k,price:$||null,size:H||null}),u&&u())},Yt=[{key:"margin",label:h("Margin required"),value:et.margin?pe(et.margin):"—"},{key:"gross",label:h("PnL before fees"),value:et.gross?$e(et.gross):"—",tone:et.gross>0?"up":et.gross<0?"down":""},{key:"fees",label:h("Fees")+" ("+h("entry and exit")+")",value:et.fees?"−"+pe(et.fees):"—"},{key:"net",label:h("Net result"),value:et.net?$e(et.net):"—",tone:et.net>0?"up":et.net<0?"down":"",big:!0},{key:"roi",label:"ROI",value:et.roi?(et.roi>=0?"+":"")+et.roi.toFixed(2)+"%":"—",tone:et.roi>0?"up":et.roi<0?"down":""},{key:"change",label:h("Price change"),value:et.changePct?(et.changePct>=0?"+":"")+et.changePct.toFixed(2)+"%":"—"},{key:"liq",label:h("Liquidation price"),value:Nt?lt(Nt):"—",tone:"liq"}];return rt&&Yt.push({key:"loss",label:h("Loss at stop"),value:$e(rt.net),tone:"down"}),X&&Yt.push({key:"rr",label:h("Risk / reward"),value:"1 : "+X.toFixed(2),tone:X>=2?"up":X<1?"down":""}),r.jsx("div",{className:"fut-modal",onClick:u,children:r.jsxs("div",{className:"fut-modal__box fut-calc",onClick:Mt=>Mt.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsxs("b",{children:[h("Calculator")," · ",d]}),r.jsx("button",{type:"button",onClick:u,children:"✕"})]}),r.jsxs("div",{className:"fut-calc__body",children:[r.jsxs("div",{className:"fut-calc__form",children:[r.jsxs("div",{className:"fut-form__sides",children:[r.jsx("button",{type:"button",className:"fut-form__side fut-form__side--buy"+(bt?" is-active":""),onClick:()=>w("buy"),children:h("Long")}),r.jsx("button",{type:"button",className:"fut-form__side fut-form__side--sell"+(bt?"":" is-active"),onClick:()=>w("sell"),children:h("Short")})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsxs("span",{className:"fut-calc__label",children:[h("Leverage"),r.jsxs("em",{children:[h("Max")," ",g,"×"]})]}),r.jsxs("div",{className:"fut-calc__input",children:[r.jsx("input",{type:"text",inputMode:"numeric",value:k,onChange:Mt=>{const Gt=parseInt(Mt.target.value.replace(/\D/g,""),10);y(Number.isFinite(Gt)?Math.min(Gt,g):"")}}),r.jsx("span",{children:"×"})]})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsxs("span",{className:"fut-calc__label",children:[h("Entry price"),f>0&&r.jsx("button",{type:"button",className:"fut-calc__take",onClick:()=>j(String(be(f))),children:h("Market")})]}),r.jsx("div",{className:"fut-calc__input",children:r.jsx("input",{type:"text",inputMode:"decimal",value:S,onChange:Mt=>j(Mt.target.value.replace(",","."))})})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsxs("span",{className:"fut-calc__label",children:[h("Size"),r.jsxs("span",{className:"fut-calc__units",children:[r.jsx("button",{type:"button",className:yt==="coin"?"is-active":"",onClick:()=>P("coin"),children:d}),r.jsx("button",{type:"button",className:yt==="usd"?"is-active":"",onClick:()=>P("usd"),children:"USDC"})]})]}),r.jsx("div",{className:"fut-calc__input",children:r.jsx("input",{type:"text",inputMode:"decimal",value:J,onChange:Mt=>O(Mt.target.value.replace(",","."))})})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsx("span",{className:"fut-calc__label",children:h("Exit price")}),r.jsx("div",{className:"fut-calc__input",children:r.jsx("input",{type:"text",inputMode:"decimal",value:E,onChange:Mt=>Ot(Mt.target.value.replace(",","."))})})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsxs("span",{className:"fut-calc__label",children:[h("Or target profit"),r.jsx("em",{children:"USDC"})]}),r.jsx("div",{className:"fut-calc__input",children:r.jsx("input",{type:"text",inputMode:"decimal",value:G,placeholder:h("Gives the exit price"),onChange:Mt=>st(Mt.target.value.replace(",","."))})})]}),r.jsxs("label",{className:"fut-calc__field",children:[r.jsxs("span",{className:"fut-calc__label",children:[h("Stop price"),r.jsx("em",{children:h("optional")})]}),r.jsx("div",{className:"fut-calc__input",children:r.jsx("input",{type:"text",inputMode:"decimal",value:F,onChange:Mt=>A(Mt.target.value.replace(",","."))})})]}),r.jsxs("div",{className:"fut-calc__actions",children:[!!v&&r.jsx("button",{type:"button",onClick:St,children:h("From position")}),c&&r.jsx("button",{type:"button",className:"is-primary",disabled:!$||!H,onClick:At,children:h("Use in order")})]})]}),r.jsxs("div",{className:"fut-calc__result",children:[r.jsx("div",{className:"fut-calc__result-head",children:h("Result")}),Yt.map(Mt=>r.jsxs("div",{className:"fut-calc__result-row"+(Mt.big?" is-big":""),children:[r.jsx("span",{children:Mt.label}),r.jsx("b",{className:Mt.tone?"is-"+Mt.tone:"",children:Mt.value})]},Mt.key)),r.jsx("div",{className:"fut-calc__note",children:h("Fees are counted on both sides at the taker rate of {fee}%. A limit order that adds liquidity costs less.",{fee:ri.toFixed(3)})})]})]})]})})}const to=[{key:"confirm",title:"Confirmations",options:[{key:"marketConfirm",title:"Confirm market orders",hint:"A market order fills instantly at whatever price is in the book."},{key:"orderMoveConfirm",title:"Confirm moving a limit order",hint:"Moving an order on the chart cancels it and places a new one at the new price."},{key:"tpslConfirm",title:"Confirm take profit and stop loss moves",hint:"After dragging the line, a window opens where the price can be corrected by hand."}]},{key:"chart",title:"Chart",options:[{key:"priceLines",title:"Show position and order lines on the chart",hint:"Entry, liquidation, take profit, stop loss and pending orders."},{key:"volume",title:"Show volume under the candles",hint:"The histogram takes the lower part of the chart."},{key:"tradeMarks",title:"Show my trades on the chart",hint:"Circles B and S on the candles where your buys and sells were filled."}]},{key:"notify",title:"Notifications",notify:!0,options:[{key:"fillNotify",title:"Notify about my fills",hint:"Pop-up messages in the browser: side, size and price of every fill. Visible only while the terminal is open in a tab."}]},{key:"other",title:"Other",options:[{key:"hideAmounts",title:"Hide amounts",hint:"Balances and PnL are replaced with dots. Prices and sizes stay visible."}]}
7,{key:"defaults",title:"Defaults",defaults:!0}],Z_=[0,1,2,3,5,10,20,25,50];function sd({onClose:s,accountId:t=0,tgLinked:e=!1,tgTpsl:n=!1,onTgChange:i=null,tgFills:o=!1,onTgFillsChange:l=null}){var J;const[a,c]=m.useState(mn),[u,d]=m.useState(!!n),[f,g]=m.useState(!!o),[v,b]=m.useState(""),[w,k]=m.useState("");m.useEffect(()=>{d(!!n)},[n]),m.useEffect(()=>{g(!!o)},[o]);const y={tpsl:{field:"tg_tpsl",answer:"tgTpsl",get:()=>u,set:d,notify:i},fills:{field:"tg_fills",answer:"tgFills",get:()=>f,set:g,notify:l}},S=async O=>{var G;if(v)return;const yt=y[O],P=!yt.get();yt.set(P),b(O),k("");try{const{data:nt}=await ge.post("/x/futures/notify",{miniAppData:(G=ve())==null?void 0:G.initData,account_id:t,[yt.field]:P?1:0});nt!=null&&nt.err?(yt.set(!P),k(nt.errText||nt.err)):(d(!!(nt!=null&&nt.tgTpsl)),g(!!(nt!=null&&nt.tgFills)),i&&i(!!(nt!=null&&nt.tgTpsl)),l&&l(!!(nt!=null&&nt.tgFills)))}catch{yt.set(!P),k(h("Network error"))}finally{b("")}},[j,E]=m.useState(to[0].key),z=to.find(O=>O.key===j)??to[0];Ps(s);const F=(O,yt)=>{const P={...a,[O]:yt};c(P),pn(P)},A=O=>F(O,!a[O]);return r.jsx("div",{className:"fut-modal",onClick:s,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--settings",onClick:O=>O.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head",children:[r.jsx("b",{children:h("Futures settings")}),r.jsx("button",{type:"button",onClick:s,children:"✕"})]}),r.jsx("div",{className:"fut-settings__tabs",children:to.map(O=>r.jsx("button",{type:"button",className:O.key===j?"is-active":"",onClick:()=>E(O.key),children:h(O.title)},O.key))}),r.jsxs("div",{className:"fut-settings",children:[z.notify&&r.jsx("div",{className:"fut-settings__group",children:h("In the browser")}),(J=z.options)==null?void 0:J.map(O=>r.jsxs("label",{className:"fut-settings__row",children:[r.jsx("input",{type:"checkbox",checked:!!a[O.key],onChange:()=>A(O.key)}),r.jsxs("span",{children:[r.jsx("b",{children:h(O.title)}),r.jsx("i",{children:h(O.hint)})]})]},O.key)),z.notify&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fut-settings__group",children:h("In Telegram")}),r.jsxs("label",{className:"fut-settings__row"+(e?"":" is-off"),children:[r.jsx("input",{type:"checkbox",checked:e&&u,disabled:!e||!!v,onChange:()=>S("tpsl")}),r.jsxs("span",{children:[r.jsx("b",{children:h("Take profit and stop loss alerts")}),r.jsx("i",{children:e?f?h("Already covered by the setting below. Stays as you leave it: turn that one off and this takes over again."):h("The bot writes when your protection fills — even with the terminal closed. Set per futures account."):h("Not available for this account: alerts are sent only to those who sign in to Radex through the Telegram bot or Telegram login.")})]})]}),r.jsxs("label",{className:"fut-settings__row"+(e?"":" is-off"),children:[r.jsx("input",{type:"checkbox",checked:e&&f,disabled:!e||!!v,onChange:()=>S("fills")}),r.jsxs("span",{children:[r.jsx("b",{children:h("All order fills")}),r.jsx("i",{children:e?h("The bot writes about every fill: market, limit, scale and TWAP orders too. Includes protection, so one fill is still one message."):h("Not available for this account: alerts are sent only to those who sign in to Radex through the Telegram bot or Telegram login.")})]})]}),w&&r.jsx("div",{className:"fut-form__warn",children:w})]}),z.defaults&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-settings__pick",children:[r.jsx("span",{children:h("Leverage")}),r.jsx("div",{className:"fut-settings__choice",children:Z_.map(O=>r.jsx("button",{type:"button",className:a.defaultLeverage===O?"is-active":"",onClick:()=>F("defaultLeverage",O),children:O?O+"×":h("Not set")},O))})]}),r.jsxs("div",{className:"fut-settings__pick",children:[r.jsx("span",{children:h("Margin mode")}),r.jsx("div",{className:"fut-settings__choice",children:[["","Not set"],["cross","Cross"],["isolated","Isolated"]].map(([O,yt])=>r.jsx("button",{type:"button",className:a.defaultMargin===O?"is-active":"",onClick:()=>F("defaultMargin",O),children:h(yt)},O||"none"))})]}),r.jsx("p",{className:"fut-settings__note",children:h("Applied when you open an instrument you have no position in: leverage cannot be changed under an open position.")})]})]})]})})}const Kf=[{key:"direction",icon:"compass",needs:!1,title:()=>h("Where is this market heading?"),hint:()=>h("Bias, scenarios and what would change them")},{key:"buy",icon:"long",needs:!1,title:()=>h("I am thinking of buying"),hint:()=>h("Is long the right side, and at what price")},{key:"sell",icon:"short",needs:!1,title:()=>h("I am thinking of selling"),hint:()=>h("Is short the right side, and what it costs to hold")},{key:"entry",icon:"target",needs:!1,title:()=>h("Where do I enter?"),hint:()=>h("The level worth bidding and how long it lasts")},{key:"tpsl",icon:"shield",needs:!1,title:()=>h("Pick take profit and stop"),hint:()=>h("Levels from structure and volatility, not round numbers")},{key:"risk",icon:"gauge",needs:"any",title:()=>h("Check my risk"),hint:()=>h("Leverage, size and distance to liquidation")},{key:"position",icon:"position",needs:"coin",title:()=>h("Review my position here"),hint:()=>h("Hold, add, trim or move the stop")},{key:"close",icon:"exit",needs:"coin",title:()=>h("Should I close now?"),hint:()=>h("Take it, cut it, or sit on it")},{key:"portfolio",icon:"portfolio",needs:"any",title:()=>h("Review all my positions"),hint:()=>h("Concentration, margin load and the weak link")}],$f=[{key:"1h",title:()=>h("1 hour")},{key:"4h",title:()=>h("4 hours")},{key:"1d",title:()=>h("1 day")},{key:"1w",title:()=>h("1 week")}
7,{key:"1M",title:()=>h("1 month")},{key:"3M",title:()=>h("3 months")},{key:"6M",title:()=>h("6 months")},{key:"1y",title:()=>h("1 year")},{key:"2y",title:()=>h("2 years")},{key:"3y",title:()=>h("3 years")},{key:"4y",title:()=>h("4 years")},{key:"5y",title:()=>h("5 years")}];function J_(s,{hasCoinPosition:t,hasAnyPosition:e}){return s.needs==="coin"?!!t:s.needs==="any"?!!e:!0}function Mn({name:s,size:t=18}){const e={width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.7,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0};switch(s){case"compass":return r.jsxs("svg",{...e,children:[r.jsx("circle",{cx:"12",cy:"12",r:"9"}),r.jsx("path",{d:"m15.5 8.5-2 5-5 2 2-5z"})]});case"long":case"chartUp":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M4 17 10 11l3.5 3.5L20 8"}),r.jsx("path",{d:"M15 8h5v5"})]});case"short":case"chartDown":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M4 8l6 6 3.5-3.5L20 17"}),r.jsx("path",{d:"M15 17h5v-5"})]});case"chartFlat":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M4 12h16"}),r.jsx("path",{d:"M9 8.5 12 12l-3 3.5"})]});case"target":return r.jsxs("svg",{...e,children:[r.jsx("circle",{cx:"12",cy:"12",r:"8"}),r.jsx("circle",{cx:"12",cy:"12",r:"3.5"}),r.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"})]});case"shield":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M12 3l7 3v5.5c0 4.2-2.9 7.6-7 9.5-4.1-1.9-7-5.3-7-9.5V6z"}),r.jsx("path",{d:"m9 12 2 2 4-4"})]});case"gauge":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M4 18a8 8 0 1 1 16 0"}),r.jsx("path",{d:"m12 18 4.5-6"}),r.jsx("circle",{cx:"12",cy:"18",r:"1.4"})]});case"position":return r.jsx("svg",{...e,children:r.jsx("path",{d:"M4 20V9M10 20V4M16 20v-7M22 20H2"})});case"exit":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M14 4h4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-4"}),r.jsx("path",{d:"M10 16 6 12l4-4"}),r.jsx("path",{d:"M6 12h10"})]});case"portfolio":return r.jsxs("svg",{...e,children:[r.jsx("rect",{x:"3",y:"4",width:"8",height:"7",rx:"1.5"}),r.jsx("rect",{x:"13",y:"4",width:"8",height:"4",rx:"1.5"}),r.jsx("rect",{x:"3",y:"14",width:"8",height:"6",rx:"1.5"}),r.jsx("rect",{x:"13",y:"11",width:"8",height:"9",rx:"1.5"})]});case"history":return r.jsxs("svg",{...e,children:[r.jsx("circle",{cx:"12",cy:"12",r:"8"}),r.jsx("path",{d:"M12 7.5V12l3.2 1.9"})]});case"newChat":return r.jsxs("svg",{...e,children:[r.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4.5"}),r.jsx("path",{d:"M12 8.5v7M8.5 12h7"})]});case"insert":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M4 12h10"}),r.jsx("path",{d:"M10.5 8.5 14 12l-3.5 3.5"}),r.jsx("path",{d:"M18 5.5v13"})]});case"close":return r.jsx("svg",{...e,children:r.jsx("path",{d:"M6.5 6.5l11 11M17.5 6.5l-11 11"})});case"spark":return r.jsxs("svg",{...e,children:[r.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),r.jsx("path",{d:"M18.5 15.5l.7 1.9 1.8.6-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.6z"})]});default:return null}}function tk({text:s}){if(!s||typeof s!="string")return null;const t=[];let e=null;const n=()=>{e&&(t.push(e.ordered?r.jsx("ol",{children:e.items.map((i,o)=>r.jsx("li",{children:eo(i)},o))},"l"+t.length):r.jsx("ul",{children:e.items.map((i,o)=>r.jsx("li",{children:eo(i)},o))},"l"+t.length)),e=null)};for(const i of s.split(`
8`)){const o=i.trimEnd();if(!o.trim()){n();continue}const l=o.match(/^\s*[-*•]\s+(.*)$/),a=o.match(/^\s*\d+[.)]\s+(.*)$/),c=o.match(/^#{1,6}\s+(.*)$/);if(c){n(),t.push(r.jsx("h4",{children:eo(c[1])},"h"+t.length));continue}if(l||a){const u=!!a;(!e||e.ordered!==u)&&(n(),e={ordered:u,items:[]}),e.items.push((l||a)[1]);continue}n(),t.push(r.jsx("p",{children:eo(o)},"p"+t.length))}return n(),r.jsx("div",{className:"fut-ai__md",children:t})}function eo(s){const t=[],e=/(\*\*[^*]+\*\*|`[^`]+`|\*[^*\s][^*]*\*)/g;let n=0,i;for(;(i=e.exec(s))!==null;){i.index>n&&t.push(s.slice(n,i.index));const o=i[0];o.startsWith("**")?t.push(r.jsx("b",{children:o.slice(2,-2)},i.index)):o.startsWith("`")?t.push(r.jsx("code",{children:o.slice(1,-1)},i.index)):t.push(r.jsx("i",{children:o.slice(1,-1)},i.index)),n=i.index+o.length}return n<s.length&&t.push(s.slice(n)),t}function ek({analysis:s,context:t,coin:e,szDecimals:n=0,onApply:i,onApplyTpSl:o,onPickPrice:l}){var b,w,k,y,S,j,E,z;if(!s)return null;if(s.on_topic===!1)return r.jsxs("div",{className:"fut-ai__answer fut-ai__answer--off",children:[r.jsx("div",{className:"fut-ai__off-icon",children:"?"}),r.jsx("div",{children:s.refusal||h("Ask about your positions or one of the futures markets.")})]});const a=s.trade_plan||{},c=s.market_view||{},u=F=>F==null?"—":be(F,Math.max(6,2+n)),d=Array.isArray(a.entries)?a.entries:[],f=Array.isArray(a.take_profits)?a.take_profits:[],g=a.stop_loss||{},v=(()=>
8{if(!d.length)return null;const F=d.reduce((A,J)=>A+(Number(J.share_pct)||0),0);return F?d.reduce((A,J)=>A+(Number(J.price)||0)*(Number(J.share_pct)||0),0)/F:Number(d[0].price)||null})();return r.jsxs("div",{className:"fut-ai__answer",children:[r.jsxs("div",{className:"fut-ai__verdict is-"+(s.verdict||"none"),children:[r.jsx("div",{className:"fut-ai__verdict-tag",children:sk(s.verdict)}),r.jsxs("div",{className:"fut-ai__verdict-body",children:[r.jsx("b",{children:s.headline}),r.jsxs("div",{className:"fut-ai__conf",children:[r.jsx("span",{children:h("Confidence")}),r.jsx("i",{children:r.jsx("b",{style:{width:Math.max(2,s.confidence||0)+"%"}})}),r.jsxs("em",{children:[s.confidence,"%"]})]})]})]}),s.summary&&r.jsx("p",{className:"fut-ai__summary",children:s.summary}),s.answer_markdown&&r.jsx(tk,{text:s.answer_markdown}),(c.trend_short||c.momentum)&&r.jsxs("div",{className:"fut-ai__view",children:[r.jsx(so,{label:h("Short-term"),value:nd(c.trend_short),tone:id(c.trend_short)}),r.jsx(so,{label:h("Medium-term"),value:nd(c.trend_medium),tone:id(c.trend_medium)}),c.momentum&&r.jsx(so,{label:h("Momentum"),value:c.momentum}),c.volatility&&r.jsx(so,{label:h("Volatility"),value:c.volatility})]}),c.note&&r.jsx("div",{className:"fut-ai__note",children:c.note}),a.applicable&&r.jsxs("div",{className:"fut-ai__plan",children:[r.jsxs("div",{className:"fut-ai__block-head",children:[r.jsx("b",{children:d.length?h("Trade plan"):h("Levels for this position")}),a.side!=="none"&&r.jsxs("span",{className:"fut-ai__side is-"+a.side,children:[a.side==="long"?h("Long"):h("Short"),a.order_type&&a.order_type!=="none"?" · "+(a.order_type==="limit"?h("limit"):h("market")):""]})]}),r.jsxs("div",{className:"fut-ai__ladder",children:[f.slice().reverse().map((F,A)=>r.jsx(Al,{kind:"tp",title:h("Take profit")+(f.length>1?" "+(f.length-A):""),price:u(F.price),share:F.share_pct,note:F.note,onPick:l&&F.price?()=>l(F.price):null},"tp"+A)),d.map((F,A)=>r.jsx(Al,{kind:"entry",title:h("Entry")+(d.length>1?" "+(A+1):""),price:u(F.price),share:F.share_pct,note:F.note,onPick:l&&F.price?()=>l(F.price):null},"en"+A)),g.price!==null&&g.price!==void 0&&r.jsx(Al,{kind:"stop",title:h("Stop loss"),price:u(g.price),share:null,note:g.note,extra:g.distance_pct!==null&&g.distance_pct!==void 0?lt(Math.abs(g.distance_pct),3)+"%":null,onPick:l?()=>l(g.price):null})]}),r.jsxs("div",{className:"fut-ai__metrics",children:[a.risk_reward!=null&&r.jsx($i,{label:h("Risk / reward"),value:"1 : "+lt(a.risk_reward,3)}),((b=a.leverage)==null?void 0:b.suggested)!=null&&r.jsx($i,{label:h("Leverage"),value:lt(a.leverage.suggested,3)+"×",hint:a.leverage.max_safe!=null?h("Safe ceiling for this stop")+": "+lt(a.leverage.max_safe,3)+"×":a.leverage.note}),((w=a.size)==null?void 0:w.margin_usd)!=null&&r.jsx($i,{label:h("Margin"),value:pe(a.size.margin_usd),hint:a.size.note}),((k=a.size)==null?void 0:k.risk_usd)!=null&&r.jsx($i,{label:h("Risk if stopped"),value:$e(-Math.abs(a.size.risk_usd)),tone:"down"}),a.expected_move_pct!=null&&r.jsx($i,{label:h("Expected move"),value:(a.expected_move_pct>0?"+":"")+lt(a.expected_move_pct,3)+"%",tone:a.expected_move_pct>=0?"up":"down"})]}),a.valid_for&&r.jsxs("div",{className:"fut-ai__valid",children:[h("Valid for"),": ",a.valid_for]}),(i||o)&&r.jsxs("div",{className:"fut-ai__actions",children:[i&&v!=null&&a.side!=="none"&&r.jsx("button",{type:"button",className:"is-primary",onClick:()=>{var F;return i({side:a.side==="short"?"sell":"buy",price:v,leverage:((F=a.leverage)==null?void 0:F.suggested)||null,takeProfit:f.length?f[0].price:null,stopLoss:g.price??null})},children:h("Fill the order form")}),o&&(g.price!=null||f.length>0)&&r.jsx("button",{type:"button",onClick:()=>o({takeProfit:f.length?f[0].price:null,stopLoss:g.price??null}),children:h("Use these TP / SL")})]})]}),((y=s.scenarios)==null?void 0:y.length)>0&&r.jsxs("div",{className:"fut-ai__section",children:[r.jsx("div",{className:"fut-ai__block-head",children:r.jsx("b",{children:h("Scenarios")})}),s.scenarios.map((F,A)=>r.jsxs("div",{className:"fut-ai__scenario",children:[r.jsxs("div",{className:"fut-ai__scenario-head",children:[r.jsx("span",{children:F.name}),r.jsxs("em",{children:[F.probability,"%"]})]}),r.jsx("i",{className:"fut-ai__scenario-bar",children:r.jsx("b",{style:{width:(F.probability||0)+"%"}})}),r.jsx("p",{children:F.description}),r.jsxs("div",{className:"fut-ai__scenario-meta",children:[F.trigger&&r.jsxs("span",{children:[h("Trigger"),": ",F.trigger]}),F.target!=null&&r.jsxs("span",{children:[h("Target"),": ",u(F.target)]}),F.invalidation!=null&&r.jsxs("span",{children:[h("Invalid below/above"),": ",u(F.invalidation)]})]})]},A))]}),((S=s.levels)==null?void 0:S.length)>0&&r.jsxs("div",{className:"fut-ai__section",children:[r.jsx("div",{className:"fut-ai__block-head",children:r.jsx("b",{children:h("Levels to wat
8ch")})}),r.jsx("div",{className:"fut-ai__levels",children:s.levels.map((F,A)=>r.jsxs("div",{className:"fut-ai__level is-"+F.kind,children:[r.jsx("i",{className:"fut-ai__level-icon",children:r.jsx(Mn,{name:nk(F.kind),size:15})}),r.jsxs("div",{className:"fut-ai__level-main",children:[r.jsx("b",{className:"fut-ai__level-price",children:u(F.price)}),r.jsx("span",{className:"fut-ai__level-kind",children:ik(F.kind)})]}),l&&F.price!=null&&r.jsx("span",{className:"fut-ai__level-act",children:r.jsx(Rt.Tooltip,{title:h("Put this price into the order form"),position:"top",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-ai__level-use",onClick:()=>l(F.price),"aria-label":h("Put this price into the order form"),children:r.jsx(Mn,{name:"insert",size:14})})})}),r.jsx("em",{className:"fut-ai__level-note",children:F.note})]},A))})]}),((j=s.signals)==null?void 0:j.length)>0&&r.jsxs("div",{className:"fut-ai__section",children:[r.jsx("div",{className:"fut-ai__block-head",children:r.jsx("b",{children:h("What it is built on")})}),r.jsx("div",{className:"fut-ai__signals",children:s.signals.map((F,A)=>r.jsxs("div",{className:"fut-ai__signal is-"+F.reading,children:[r.jsx("b",{children:F.name}),r.jsx("span",{children:F.value})]},A))})]}),((E=s.position_review)==null?void 0:E.length)>0&&r.jsxs("div",{className:"fut-ai__section",children:[r.jsx("div",{className:"fut-ai__block-head",children:r.jsx("b",{children:h("Your positions")})}),r.jsx("div",{className:"fut-ai__positions",children:s.position_review.map((F,A)=>r.jsxs("div",{className:"fut-ai__position is-"+F.assessment,children:[r.jsxs("div",{className:"fut-ai__position-head",children:[r.jsx("b",{children:zt(F.coin)}),r.jsx("span",{className:"fut-ai__side is-"+F.side,children:F.side==="long"?h("Long"):h("Short")}),r.jsx("em",{children:rk(F.action)})]}),r.jsx("p",{children:F.note})]},A))})]}),((z=s.risks)==null?void 0:z.length)>0&&r.jsxs("div",{className:"fut-ai__section",children:[r.jsx("div",{className:"fut-ai__block-head",children:r.jsx("b",{children:h("What c
8ould go wrong")})}),r.jsx("ul",{className:"fut-ai__risks",children:s.risks.map((F,A)=>r.jsx("li",{children:F},A))})]}),s.costs&&(s.costs.note||s.costs.round_trip_fee_pct!=null)&&r.jsxs("div",{className:"fut-ai__costs",children:[s.costs.round_trip_fee_pct!=null&&r.jsxs("span",{children:[h("Round trip fee"),": ",lt(s.costs.round_trip_fee_pct,3),"%"]}),s.costs.funding_over_horizon_pct!=null&&r.jsxs("span",{children:[h("Funding over the horizon"),":"," ",s.costs.funding_over_horizon_pct>0?"+":"",lt(s.costs.funding_over_horizon_pct,3),"%"]}),s.costs.note&&r.jsx("span",{children:s.costs.note})]}),t&&r.jsxs("div",{className:"fut-ai__meta",children:[r.jsxs("span",{children:[zt(t.coin||e)," @ ",u(t.markPx)]}),r.jsx("span",{children:t.asOf})]}),r.jsx("div",{className:"fut-ai__disclaimer",children:h("Analysis, not investment advice. The decision and the risk are yours.")})]})}function Al({kind:s,title:t,price:e,share:n,note:i,extra:o,onPick:l}){return r.jsxs("div",{className:"fut-ai__plan-row is-"+s,children:[r.jsx("i",{className:"fut-ai__plan-dot"}),r.jsxs("div",{className:"fut-ai__plan-main",children:[r.jsxs("span",{className:"fut-ai__plan-title",children:[t,n?r.jsxs("em",{children:[n,"%"]}):null]}),i&&r.jsx("span",{className:"fut-ai__plan-note",children:i})]}),r.jsxs("button",{type:"button",className:"fut-ai__plan-price",onClick:l||void 0,disabled:!l,children:[e,o&&r.jsx("em",{children:o})]})]})}function so({label:s,value:t,tone:e}){return t?r.jsxs("div",{className:"fut-ai__chip"+(e?" is-"+e:""),children:[r.jsx("span",{children:s}),r.jsx("b",{children:t})]}):null}function $i({label:s,value:t,hint:e,tone:n}){const i=r.jsxs("div",{className:"fut-ai__metric"+(n?" is-"+n:""),children:[r.jsx("span",{children:s}),r.jsx("b",{children:t})]});return e?r.jsx(Rt.Tooltip,{title:e,position:"top",arrow:!0,tag:"span",distance:10,children:i}):i}function sk(s){return{long:h("Buy"),short:h("Sell"),wait:h("Wait"),hold:h("Hold"),reduce:h("Trim"),close:h("Close"),none:h("Answer")}[s]||h("Answer")}function nd(s){return{up:h("Up"),down:h("Down"),flat:h("Flat")}[s]||null}function id(s){return s==="up"?"up":s==="down"?"down":null}function nk(s){return s==="support"||s==="target"?"chartUp":s==="resistance"||s==="stop"||s==="liquidation"?"chartDown":"chartFlat"}function ik(s){return{support:h("Support"),resistance:h("Resistance"),entry:h("Entry"),stop:h("Stop level"),target:h("Target"),liquidation:h("Liquidation"),poc:h("Volume peak")}[s]||s}function rk(s){return{hold:h("Hold"),add:h("Add"),reduce:h("Trim"),close:h("Close"),move_stop:h("Move the stop")}[s]||s}const Yf="futures_ai_chats",ok=15;function Lo(){try{const s=localStorage.getItem(Yf);if(!s)return[];const t=JSON.parse(s);return Array.isArray(t)?t:[]}catch{return[]}}function Qf(s){let t=s.slice(0,ok);for(let e=0;e<3;e++)try{return localStorage.setItem(Yf,JSON.stringify(t)),!0}catch{if(t.length<=1)return!1;t=t.slice(0,Math.ceil(t.length/2))}return!1}function Rl(s){return Lo().filter(t=>t&&Array.isArray(t.messages)&&t.messages.length).filter(t=>(t.accountId??0)===(s??0)).sort((t,e)=>(e.updatedAt??0)-(t.updatedAt??0))}function Gf(s){return Lo().find(t=>t.id===s)??null}function lk({id:s,accountId:t,coin:e,messages:n}){var l;if(!s||!Array.isArray(n)||!n.length)return;const i=Lo().filter(a=>a&&a.id!==s),o=n.find(a=>a.role==="user");i.unshift({id:s,accountId:t??0,coin:e,title:((o==null?void 0:o.text)??"").slice(0,120),createdAt:((l=Gf(s))==null?void 0:l.createdAt)??Date.now(),updatedAt:Date.now(),messages:n.slice(-24)}),Qf(i.sort((a,c)=>(c.updatedAt??0)-(a.updatedAt??0)))}function ak(s){Qf(Lo().filter(t=>t&&t.id!==s))}function ck(){return"c"+Date.now().toString(36)}function hk({coin:s,asset:t,accountId:e,markPx:n,coinPosition:i=null,positionsCount:o=0,hidden:l=!1,onApply:a,onApplyTpSl:c,onPickPrice:u,onDeposit:d,onSignIn:f,onClose:g}){Ps(l?void 0:g);const[v,b]=m.useState(null),[w,k]=m.useState(()=>localStorage.getItem("futures_ai_horizon")||"1d"),[y,S]=m.useState([]),[j,E]=m.useState(""),[z,F]=m.useState(null),[A,J]=m.useState([]),[O,yt]=m.useState("chat"),[P,G]=m.useState(!1),[nt,bt]=m.useState(null),[$,ht]=m.useState(null),[tt,H]=m.useState(null),[et,rt]=m.useState(!0),[Nt,X]=m.useState(null),[st,Ot]=m.useState(null),St=m.useRef(null),At=m.useRef(null),Yt=m.useRef(null),Mt=m.useRef(0),Gt=m.useRef({cancelled:!1});m.useEffect(()=>{const N=Gt.current;return()=>{N.cancelled=!0}},[]);const jt=zt(s);m.useEffect(()=>{const N=Rl(e);J(N);const mt=N.find(Pt=>Pt.coin===s);mt&&(F(mt.id),S(mt.messages??[]),Mt.current=(mt.messages??[]).reduce((Pt,qt)=>Math.max(Pt,qt.id??0),0))},[e,s]);const Be=!!i,de=o>0;m.useEffect(()=>{var mt;let N=!1;return ge.post("/x/futures/ai/status",{miniAppData:(mt=ve())==null?void 0:mt.initData,account_id:e}).then(({data:Pt})=>{N||!Pt||Pt.err||(H(Pt.quota||null),rt(Pt.available!==!1),X(Pt.access||null),Ot(Pt.avgMs??null))}).catch(()=>{}),()=>{N=!0}},[e]),m.useEffect(()=>{!z||!y.length||(lk({id:z,accountId:e,coin:s,messages:y}),J(Rl(e)))},[z,y,e,s]),m.useEffect(()=>{const N=St.current;if(!N)return;const mt=y[y.length-1],Pt=Yt.current;if((mt==null?void 0:mt.role)==="assistant"&&Pt){N.scrollTop+=Pt.getBoundingClientRect().top-N.getBoundingClientRect().top-10;return}N.scrollTop=N.scrollHeight},[y,P]);const ie=m.useCallback(async({intentKey:N,text:mt})=>{var te;if(P)return;ht(null),G(!0),bt(null),yt("chat"),z||F(ck());
8const Pt={id:++Mt.current,role:"user",intent:N,horizon:w,text:mt||mk(N)};S(Tt=>[...Tt,Pt]);const qt=y.slice(-6).map(Tt=>{var Ht,xt;return{role:Tt.role,content:Tt.role==="user"?Tt.text:[(Ht=Tt.analysis)==null?void 0:Ht.headline,(xt=Tt.analysis)==null?void 0:xt.summary].filter(Boolean).join(" ")}}).filter(Tt=>Tt.content),pt=Tt=>{ht(Tt),S(Ht=>Ht.filter(xt=>xt.id!==Pt.id))};try{const{data:Tt}=await ge.post("/x/futures/ai",{miniAppData:(te=ve())==null?void 0:te.initData,account_id:e,coin:s,intent:N,horizon:w,question:mt||"",lang:fd(),history:qt});if(Tt!=null&&Tt.quota&&H(Tt.quota),Tt!=null&&Tt.access&&X(Tt.access),Tt!=null&&Tt.avgMs&&Ot(Tt.avgMs),Tt!=null&&Tt.err||!(Tt!=null&&Tt.id)){pt((Tt==null?void 0:Tt.errText)||(Tt==null?void 0:Tt.err)||h("Could not get the analysis. Please try again.")),G(!1);return}bt({position:Tt.position??0});const Ht=await dk(Tt.id,Gt,xt=>bt({position:xt}));Ht!=null&&Ht.err?pt(Ht.errText||Ht.err):Ht?(Ht.quota&&H(Ht.quota),S(xt=>[...xt,{id:++Mt.current,role:"assistant",analysis:Ht.analysis,context:Ht.context}])):S(xt=>xt.filter(Bt=>Bt.id!==Pt.id))}catch{pt(h("Network error. Please try again."))}finally{G(!1),bt(null)}},[e,z,s,w,P,y]),ce=m.useCallback(N=>{if(b(N),N==="custom"){setTimeout(()=>{var mt;return(mt=At.current)==null?void 0:mt.focus()},50);return}ie({intentKey:N,text:""})},[ie]),Ne=m.useCallback(()=>{const N=j.trim();!N||P||(E(""),At.current&&(At.current.style.height="auto"),ie({intentKey:"custom",text:N}))},[ie,P,j]),se=m.useCallback(N=>{k(N),localStorage.setItem("futures_ai_horizon",N)},[]),We=m.useCallback(()=>{S([]),F(null),b(null),ht(null),yt("chat")},[]),Re=m.useCallback(N=>{const mt=Gf(N);mt&&(F(mt.id),S(mt.messages??[]),yt("chat"),Mt.current=(mt.messages??[]).reduce((Pt,qt)=>Math.max(Pt,qt.id??0),0))},[]),ze=m.useCallback(N=>{ak(N),J(Rl(e)),F(mt=>mt!==N?mt:(S([]),null))},[e]),he=y.length>0||P;return r.jsx("div",{className:"fut-modal fut-modal--ai"+(l?" is-hidden":""),onClick:l?void 0:g,"aria-hidden":l||void 0,children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--ai",onClick:N=>N.stopPropagation(),children:[r.jsxs("div",{className:"fut-modal__head fut-ai__head",children:[r.jsxs("b",{children:[r.jsx("span",{className:"fut-ai__logo",children:r.jsx(Mn,{name:"spark",size:16})}),h("AI analyst"),r.jsx("em",{children:jt})]}),r.jsxs("div",{className:"fut-ai__head-right",children:[A.length>0&&Nt==="OK"&&r.jsx(Rt.Tooltip,{title:h("Saved chats"),position:"bottom",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-ai__act"+(O==="list"?" is-active":""),onClick:()=>yt(N=>N==="list"?"chat":"list"),"aria-label":h("Saved chats"),children:r.jsx(Mn,{name:"history",size:16})})}),he&&r.jsx(Rt.Tooltip,{title:h("New question"),position:"bottom",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-ai__act",onClick:We,disabled:P,"aria-label":h("New question"),children:r.jsx(Mn,{name:"newChat",size:16})})}),r.jsx("button",{type:"button",className:"fut-ai__act fut-ai__act--close",onClick:g,"aria-label":h("Close"),children:r.jsx(Mn,{name:"close",size:16})})]})]}),Nt==="OK"&&r.jsxs("div",{className:"fut-ai__horizon",children:[r.jsx("div",{className:"fut-ai__horizon-head",children:r.jsx("span",{className:"fut-ai__horizon-label",children:h("What is your time frame for this trade?")})}),r.jsx("div",{className:"fut-ai__horizon-list",children:$f.map(N=>r.jsx("button",{type:"button",className:"fut-ai__hz"+(w===N.key?" is-active":""),onClick:()=>se(N.key),disabled:P,children:N.title()},N.key))})]}),r.jsxs("div",{className:"fut-ai__body",ref:St,children:[O==="list"&&r.jsxs("div",{className:"fut-ai__chats",children:[r.jsx("div",{className:"fut-ai__chats-head",children:h("Saved in this browser. Cleared with site data.")}),A.map(N=>r.jsxs("div",{className:"fut-ai__chat"+(N.id===z?" is-current":""),children:[r.jsxs("button",{type:"button",className:"fut-ai__chat-open",onClick:()=>Re(N.id),children:[r.jsxs("span",{className:"fut-ai__chat-top",children:[r.jsx("b",{children:zt(N.coin)}),r.jsx("em",{children:fk(N.updatedAt)})]}),r.jsx("span",{className:"fut-ai__chat-title",children:N.title})]}),r.jsx("button",{type:"button",className:"fut-ai__chat-drop",onClick:()=>ze(N.id),"aria-label":h("Delete"),title:h("Delete"),children:"✕"})]},N.id))]}),O==="chat"&&!he&&Nt&&Nt!=="OK"&&r.jsxs("div",{className:"fut-ai__gate",children:[r.jsx("div",{className:"fut-ai__gate-icon",children:r.jsx(Mn,{name:"spark",size:22})}),r.jsx("b",{children:Nt==="NO_AUTH"?h("Sign in to use the assistant"):Nt==="NOT_ONBOARDED"?h("Open a futures account to use the assistant"):h("Fund your futures account to use the assistant")}),r.jsx("p",{children:h("Half of the analysis is about you: your positions, margin, leverage and fee tier. Without an account there is nothing to read them from.")}),Nt==="NO_AUTH"?f&&r.jsx("button",{type:"button",className:"fut-ai__gate-btn",onClick:()=>{f(),g&&g()},children:h("Sign in")}):d&&r.jsx("button",{type:"button",className:"fut-ai__gate-btn",onClick:()=>{d(),g&&g()},children:Nt==="NOT_ONBOARDED"?h("Open an account"):h("Deposit USDC")})]}),O==="chat"&&!he&&Nt==="OK"&&r.jsxs("div",{className:"fut-ai__intro",children:[r.jsxs("p",{children:[h("Pick what you want to know about")," ",r.jsx("b",{children:jt}),"."," ",h("Your open positions, margin and fee tier are taken into account.")]}),r.jsx("div",{className:"fut-ai__intents",children:Kf.map(N=>{const mt=J_(N,{hasCoinPosition:Be,hasAnyPosition:de});return r.jsxs("button",{type:"button",className:"fut-ai__intent"+(mt?"":" is-off"),onClick:()=>mt&&ce(N.key),disabled:!mt||P||!et,title:mt?"":h("You have no open position for this yet"),children:[r.jsx("span",{className:"fut-ai__intent-icon",children:r.jsx(Mn,{name:N.icon})}),r.jsxs("span",{className:"fut-ai__intent-text",children:[r.jsx("b",{children:N.title()}),r.jsx("em",{children:N.hint()})]})]},N.key)})}),r.jsx("button",{type:"button",className:"fut-ai__own",onClick:()=>ce("custom"),disabled:P||!et,children:h("…or ask your own question")})]}),O==="chat"&&y.map(N=>{var mt;return N.role==="user"?r.jsxs("div",{className:"fut-ai__ask",children:[r.jsx("span",{children:N.text}),r.jsx("em",{children:pk(N.horizon)})]},N.id):r.jsx("div",{ref:N.id===((mt=y[y.length-1])==null?void 0:mt.id)?Yt:null,children:r.jsx(ek,{analysis:N.analysis,context:N.context,coin:s,szDecimals:(t==null?void 0:t.szDecimals)??0,onApply:a,onApplyTpSl:c,onPickPrice:u})},N.id)}),O==="chat"&&!he&&!Nt&&r.jsx("div",{className:"fut-ai__thinking",children:r.jsxs("div",{className:"fut-ai__thinking-line",children:[r.jsx("i",{}),r.jsx("i",{}),r.jsx("i",{})]})}),O==="chat"&&P&&r.jsx(uk,{queued:nt,avgMs:st}),O==="chat"&&$&&r.jsx("div",{className:"fut-ai__error",children:$})]}),O==="chat"&&Nt==="OK"&&(he||v==="custom")&&r.jsxs("div",{className:"fut-ai__composer",children:[r.jsx("textarea",{ref:At,rows:1,value:j,placeholder:h("Ask about {coin} or your positions…",{coin:jt}),onChange:N=>{E(N.target.value),N.target.style.height="auto",N.target.style.height=Math.min(120,N.target.scrollHeight)+"px"},onKeyDown:N=>
8{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),Ne())},disabled:P||!et}),r.jsx("button",{type:"button",className:"fut-ai__send",onClick:Ne,disabled:P||!j.trim()||!et,children:h("Ask")})]}),r.jsx("div",{className:"fut-ai__foot",children:et?tt&&r.jsxs("span",{children:[h("Requests left today"),": ",tt.day_left]}):r.jsx("span",{children:h("The assistant is temporarily unavailable.")})})]})})}function uk({queued:s=null,avgMs:t=null}){const e=m.useMemo(()=>[h("Pulling candles from the exchange"),h("Computing indicators and levels"),h("Reading your positions and margin"),h("Comparing the short-term picture with the bigger one"),h("Putting the answer together")],[]),[n,i]=m.useState(0);m.useEffect(()=>{const a=Date.now(),c=setInterval(()=>i(Math.floor((Date.now()-a)/1e3)),1e3);return()=>clearInterval(c)},[]);const o=e[Math.min(Math.floor(n/4),e.length-1)],l=s&&s.position>0;return r.jsxs("div",{className:"fut-ai__thinking",children:[r.jsxs("div",{className:"fut-ai__thinking-line",children:[r.jsx("i",{}),r.jsx("i",{}),r.jsx("i",{}),r.jsx("span",{children:l?h("In queue: {n} ahead of you",{n:s.position}):o+"…"}),r.jsx("b",{children:rd(n)})]}),r.jsx("div",{className:"fut-ai__thinking-note",children:t?h("Usually takes about {time}",{time:rd(Math.round(t/1e3))}):h("A full analysis usually takes 1 to 3 minutes.")})]})}function rd(s){const t=Math.max(0,Math.round(s));if(t<60)return t+" "+h("sec");const e=Math.floor(t/60),n=t%60;return e+" "+h("min")+(n?" "+n+" "+h("sec"):"")}async function dk(s,t,e){var o;const n=Date.now(),i=720*1e3;for(;!t.current.cancelled;){if(await new Promise(a=>setTimeout(a,2e3)),t.current.cancelled)return null;let l;try{({data:l}=await ge.post("/x/futures/ai/result",{miniAppData:(o=ve())==null?void 0:o.initData,id:s}))}catch{if(Date.now()-n>i)return{err:"TIMEOUT",errText:h("Network error. Please try again.")};continue}if((l==null?void 0:l.status)==="queued"||(l==null?void 0:l.status)==="running"){if(e(l.position??0),Date.now()-n>i)return{err:"TIMEOUT",errText:h("The assistant is busy. Please try again in a minute.")};continue}return l}return null}function fk(s){if(!s)return"";const t=Math.round((Date.now()-s)/6e4);return t<1?h("just now"):t<60?t+" "+h("min"):t<1440?Math.round(t/60)+" "+h("h"):Math.round(t/1440)+" "+h("d")}function mk(s){const t=Kf.find(e=>e.key===s);return t?t.title():h("Question")}function pk(s){const t=$f.find(e=>e.key===s);return t?t.title():s}function gk({funded:s=!1,onboarding:t=!1,waitingDeposit:e=!1,walletAddr:n=null,compact:i=!1,onEnable:o,onDeposit:l}){return r.jsxs("div",{className:"fut-onboard"+(i?" fut-onboard--compact":""),children:[r.jsx("h2",{children:h("Perpetual futures")}),r.jsx("p",{children:h("Trade perpetuals with leverage directly from your Radex wallet.")}),r.jsx("div",{className:"fut-onboard__risk",children:h("Leveraged trading carries a high risk of losing your entire deposit. A price move against your position can trigger liquidation.")}),r.jsx("ul",{className:"fut-onboard__steps",children:r.jsx("li",{children:h("Deposits and withdrawals are made in USDC on Arbitrum")})}),s?r.jsx("button",{type:"button",className:"fut-onboard__btn",disabled:t,onClick:o,children:t?h("Enabling")+"…":h("Enable futures")}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut-onboard__howto",children:[r.jsx("b",{className:"fut-onboard__howto-title",children:h("How to fund your futures account")}),r.jsxs("ol",{children:[r.jsxs("li",{children:[r.jsx("b",{children:h("Send USDC on the Arbitrum network only")}),r.jsx("span",{children:h("The exchange accepts nothing else. USDC sent on another network will not arrive and cannot be returned.")}),n&&r.jsxs("button",{type:"button",className:"fut-transfer__addr",onClick:()=>Pl(n),title:h("Copy"),children:[r.jsx("span",{children:h("Top up this wallet (Arbitrum)")}),r.jsx("b",{children:n})]})]}),r.jsxs("li",{children:[r.jsx("b",{children:h("Keep 3 to 10 USD worth of ETH on the same wallet")}),r.jsx("span",{children:h("Arbitrum charges the network fee in ETH, so USDC alone is not enough to send the deposit. That amount covers many transactions.")}),r.jsxs("div",{className:"fut-onboard__howto-links",children:[r.jsx(sr,{to:"/bridge",children:h("Cross-Chain Swap")}),r.jsx(sr,{to:"/swap",children:h("Swap")})]})]}),r.jsxs("li",{children:[r.jsx("b",{children:h("Fund the account you are opening futures from")}),r.jsx("span",{children:h("Each Radex account has its own wallet and its own separate futures account. Funds sent to another account will not appear here.")})]})]}),r.jsxs("div",{className:"fut-onboard__howto-min",children:[h("Minimum deposit is")," ",ho," USDC."]})]}),r.jsx("div",{className:"fut-onboard__note",children:e?h("Waiting for the deposit to be credited. This usually takes about a minute."):
8h("Step 1 of 2. The exchange requires a deposit before the account can be set up.")}),r.jsx("button",{type:"button",className:"fut-onboard__btn",disabled:e,onClick:l,children:e?h("Waiting")+"…":h("Deposit USDC")})]})]})}function vk({kind:s="auth",onAction:t}){const e=s==="auth";return r.jsxs("div",{className:"fut-gate",children:[r.jsx("div",{className:"fut-gate__icon",children:e?r.jsx(xk,{}):r.jsx(Mn,{name:"position",size:22})}),r.jsx("b",{children:e?h("Sign in required"):h("A futures account is required")}),r.jsx("p",{children:e?h("This section shows your own positions, trades and money. There is nothing to show until you sign in."):h("You do not have a futures account yet. Open it and make the first deposit — your positions and trades will appear here.")}),t&&r.jsx("button",{type:"button",className:"fut-gate__btn",onClick:t,children:e?h("Sign in"):h("Open an account")})]})}function xk(){return r.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[r.jsx("rect",{x:"4",y:"10",width:"16",height:"10",rx:"2"}),r.jsx("path",{d:"M8 10V7a4 4 0 0 1 8 0v3"}),r.jsx("circle",{cx:"12",cy:"15",r:"1.2",fill:"currentColor",stroke:"none"})]})}function yk({compact:s=!1}){return r.jsxs(sr,{to:"/",className:"fut-header__wallet"+(s?" fut-header__wallet--icon":""),"aria-label":h("Wallet"),title:s?h("Wallet"):void 0,children:[r.jsxs("svg",{width:s?17:15,height:s?17:15,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M3 8.5A2.5 2.5 0 0 1 5.5 6H18a2 2 0 0 1 2 2v1M3 8.5V17a2 2 0 0 0 2 2h13a2 2 0 0 0 2-2v-2M3 8.5c0 .83.67 1.5 1.5 1.5H20",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("circle",{cx:"16.5",cy:"13",r:"1.2",fill:"currentColor"})]}),!s&&r.jsx("span",{children:h("Wallet")})]})}const bk="https://radex.global/";function wk({inline:s=!1}){const[t,e]=m.useState(!1);return r.jsxs("div",{className:"fut-logo"+(s?" fut-logo--inline":""),children:[r.jsx("a",{href:bk,className:"fut-logo__link","aria-label":"Radex",children:r.jsx("img",{src:"/images/logo_yellow.svg",alt:"Radex"})}),r.jsx(Rt.Tooltip,{title:h("Futures are in beta — click to find out what that means and where to write."),position:"bottom",arrow:!0,tag:"span",distance:10,style:{display:"inline-flex",alignItems:"center"},children:r.jsx("button",{type:"button",className:"fut-logo__beta",onClick:()=>e(!0),children:"Beta"})}),t&&r.jsx(wm,{onClose:()=>e(!1)})]})}function _k(){const[s,t]=m.useState(typeof window<"u"?window.innerWidth<768:!1);return m.useEffect(()=>{const e=window.matchMedia("(max-width: 767px)"),n=i=>t(i.matches);return t(e.matches),e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]),s}function Nk(){return r.jsx(_0,{children:r.jsx(kk,{})})}function kk(){const{showError:s}=Ln();Fc(h("Futures"));const{view:t,pair:e}=hd(),{pathname:n}=cd(),i=["portfolio","history","markets"].includes(t)?t:"trade",o=i==="trade"?e??t??null:null,l=e?t:va,a=ud(),c=_k(),[u,d]=m.useState(!0),[f,g]=m.useState(null),[v,b]=m.useState(!1),[w,k]=m.useState(!1),[y,S]=m.useState(!1),[j,E]=m.useState(!1),[z,F]=m.useState(null),[A,J]=m.useState(null),[O,yt]=m.useState([]),[P,G]=m.useState([]),nt=m.useRef(null),[bt,$]=m.useState([]),ht=m.useRef(null),[tt,H]=m.useState({}),[et,rt]=m.useState(null),[Nt,X]=m.useState(null),st=m.useCallback(V=>{X(ut=>({coin:V,n:((ut==null?void 0:ut.n)??0)+1}))},[]),[Ot,St]=m.useState(!1),[At,Yt]=m.useState(!1),[Mt,Gt]=m.useState(!1),[jt,Be]=m.useState(localStorage.getItem("futures_coin")||"BTC"),de=m.useMemo(()=>{const V=h("Futures");if(i==="portfolio")return h("Portfolio")+" · "+V;if(i==="markets")return h("Markets")+" · "+V;if(i==="history"){const ut=ya.find(Ct=>Ct.path===(e??""));return(ut?h(ut.title)+" · ":"")+h("History")+" · "+V}return(jt?zt(jt)+" · ":"")+V},[i,e,jt]);Fc(de);const[ie,ce]=m.useState(!1),[Ne,se]=m.useState(!1),[We,Re]=m.useState(!1),[ze,he]=m.useState(!1),[N,mt]=m.useState(!1),[Pt,qt]=m.useState(!1),pt=ur(),[te,Tt]=m.useState(pt.marketHeight||0),Ht=m.useRef(null),xt=m.useRef(null);m.useEffect(()=>{Tt(pt.marketHeight||0)},[pt.marketHeight]);const Bt=V=>{var Ct,ne;const ut=Ht.current;ut&&(V.preventDefault(),(ne=(Ct=V.currentTarget).setPointerCapture)==null||ne.call(Ct,V.pointerId),xt.current={y:V.clientY,from:ut.getBoundingClientRect().height})},re=V=>{const ut=xt.current;if(!ut)return;const Ct=Math.max(360,window.innerHeight-260);Tt(Math.round(Math.min(Ct,Math.max(320,ut.from+(V.clientY-ut.y)))))},Vt=V=>{var ut,Ct;xt.current&&(xt.current=null,(Ct=(ut=V.currentTarget).releasePointerCapture)==null||Ct.call(ut,V.pointerId),pn({...nr(),marketHeight:te}))},Ee=()=>{Tt(0),pn({...nr(),marketHeight:0})},[qe,we]=m.useState(!1),[ye,fe]=m.useState("positions"),[De,nn]=m.useState(null);m.useLayoutEffect(()=>{if(!De)return;const V=()=>{document.documentElement.style.setProperty("--fut-topbar-h",Math.round(De.getBoundingClientRect().height)+"px")};V();const ut=new ResizeObserver(V);return ut.observe(De),()=>{ut.disconnect(),document.documentElement.style.removeProperty("--fut-topbar-h")}},[De]);const Ws=c&&i==="trade"&&ye==="chart";m.useEffect(()=>{if(!Ws)return;const V=document.documentElement,ut=document.body,Ct={rootOverflow:V.style.overflow,bodyOverflow:ut.style.overflow,overscroll:ut.style.overscrollBehavior};return V.style.overflow="hidden",ut.style.overflow="hidden",ut.style.overscrollBehavior="none",()=>{V.style.overflow=Ct.rootOverflow,ut.style.overflow=Ct.bodyOverflow,ut.style.overscrollBehavior=Ct.overscroll}},[Ws]);const[ws,zs]=m.useState("book"),[gs,Jt]=m.useState(null),[Ls,Ds]=m.useState(!1),[qs,vn]=m.useState(null),ms=m.useCallback(V=>{vn(ut=>({...V,seq:((ut==null?void 0:ut.seq)??0)+1})),fe("trade")},[]),Oe=m.useCallback(V=>{Jt(ut=>({price:V,seq:((ut==null?void 0:ut.seq)??0)+1})),fe("trade")},[]),Xt=m.useMemo(()=>parseInt(localStorage.getItem("account_id"),10)||0,[]),as=m.useMemo(()=>ar(jt),[jt]),le=m.useCallback(V=>{V&&(Be(V),a(xa(V,l)))},[a,l]),cs=m.useCallback(V=>{le(V),fe("trade")},[le]);m.useEffect(()=>{var Ct;if(i!=="trade"||!((Ct=A==null?void 0:A.universe)!=null&&Ct.length))return;const V=o?j0(o,A.universe):null,ut=xa(V??jt,l);V&&V!==jt&&Be(V),n!==ut&&a(ut,{replace:!0})},[i,o,l,n,jt,A,a]);const T=m.useMemo(()=>tt[as]??null,[tt,as]),Z=m.useMemo(()=>tt[""]??null,[tt]),Q=m.useMemo(()=>Object.values(tt).flatMap(V=>(V==null?void 0:V.assetPositions)??[]).map(V=>V==null?void 0:V.position).filter(V=>V&&parseFloat(V.szi)!==0),[tt]),vt=m.useCallback(async(V=!1,ut=!1)=>{var Ct,ne;V||d(!0),ut||(nt.current=null,(Ct=ht.current)==null||Ct.call(ht));try{const{data:Zt}=await ge.post("/x/futures",{miniAppData:(ne=ve())==null?void 0:ne.initData,account_id:Xt,orders_version:nt.current});if(Zt!=null&&Zt.err){s(Zt.errText||Zt.err),d(!1);return}Zt.meta&&(J(Zt.meta[0]??null),yt(Zt.meta[1]??[])),g(Zt.auth!==!1),b(!!Zt.onboarded),S(!!Zt.funded),Zt.wsUrl&&p0(Zt.wsUrl,Zt.wsToken??null),Zt.onboarded&&(H(Zt.states??(Zt.state?{"":Zt.state}:{})),Zt.vip&&rt(Zt.vip),Zt.openOrders!==void 0&&G(Zt.openOrders??[]),nt.current=Zt.ordersVersion??null,Zt.twaps!==void 0&&$(Zt.twaps??[]),St(!!Zt.tgLinked),Yt(!!Zt.tgTpsl),Gt(!!Zt.tgFills))}catch{s(h("Network error"))}finally{d(!1)}},[Xt,s]);m.useEffect(()=>{vt()},[vt]);const wt=m.useCallback(async()=>{var V;try{const{data:ut}=await ge.post("/x/futures/twaps",{miniAppData:(V=ve())==null?void 0:V.initData,account_id:Xt});ut!=null&&ut.err||$(ut.twaps??[])}catch{}},[Xt]);m.useEffect(()=>{ht.current=wt},[wt]),m.useEffect(()=>{v&&wt()},[v,wt]),m.useEffect(()=>{if(!v||bt.length===0)return;const V=setInterval(wt,6e4);return()=>clearInterval(V)},[v,bt.length,wt]),m.useEffect(()=>{var ut;if(!f||u||v||y||z)return;let V=!1;return ge.post("/x/futures/wallet",{miniAppData:(ut=ve())==null?void 0:ut.initData,account_id:Xt}).then(({data:Ct})=>
8{!V&&!(Ct!=null&&Ct.err)&&(Ct!=null&&Ct.address)&&F(Ct.address)}).catch(()=>{}),()=>{V=!0}},[f,u,v,y,z,Xt]);const It=m.useCallback(()=>{a("/login",{state:{from:n}})},[a,n]),ot=m.useCallback(V=>()=>{if(f===!1){It();return}if(!v){qt(!0);return}V()},[f,v,It]);m.useEffect(()=>{localStorage.setItem("futures_coin",jt)},[jt]),m.useEffect(()=>{if(!j||y){y&&E(!1);return}let V=0;const ut=setInterval(()=>{if(V++,V>30){E(!1),clearInterval(ut);return}vt(!0,!0)},1e4);return()=>clearInterval(ut)},[j,y,vt]);const Dt=m.useRef(null),Qt=m.useRef(Date.now()),Et=m.useRef(new Set),Wt=m.useCallback(()=>{Dt.current&&clearTimeout(Dt.current),Dt.current=setTimeout(()=>vt(!0,!0),700)},[vt]),_e=m.useCallback(V=>{if(Wt(),!pt.fillNotify||V!=null&&V.isSnapshot)return;const ut=Array.isArray(V)?V:(V==null?void 0:V.fills)??[V];for(const Ct of ut){if(!(Ct!=null&&Ct.coin)||!(Ct!=null&&Ct.sz)||Number(Ct.time)<Qt.current)continue;const ne=String(Ct.tid??Ct.time+":"+Ct.coin+":"+Ct.px+":"+Ct.sz);Et.current.has(ne)||(Et.current.add(ne),Et.current.size>500&&(Et.current=new Set([ne])),ys((Ct.side==="B"?h("Buy"):h("Sell"))+" "+zt(Ct.coin)+" "+lt(parseFloat(Ct.sz))+" @ "+lt(parseFloat(Ct.px))))}},[Wt,pt.fillNotify]);sn("user",{sub:"fills"},_e,v);const Ue=m.useRef([]);m.useEffect(()=>{Ue.current=P},[P]);const ue=m.useRef(null),Xe=m.useCallback(()=>vt(!0),[vt]),rn=m.useCallback(V=>{var ks;const ut=Array.isArray(V)?V:[];if(ut.length===0)return;const Ct=new Set(Ue.current.map(ns=>ns.oid)),ne=new Set;let Zt=!1;for(const ns of ut){const is=(ks=ns==null?void 0:ns.order)==null?void 0:ks.oid;is!=null&&(ns.status==="open"?Ct.has(is)||(Zt=!0):ne.add(is))}ne.size>0&&G(ns=>ns.filter(is=>!ne.has(is.oid))),Zt&&!ue.current&&(ue.current=setTimeout(()=>{ue.current=null,Xe()},1500))},[Xe]);sn("user",{sub:"orders"},rn,v),m.useEffect(()=>()=>{ue.current&&clearTimeout(ue.current)},[]),m.useEffect(()=>{if(!v)return;const V=setInterval(()=>vt(!0,!0),3e4);return()=>clearInterval(V)},[v,vt]);const[Os,ts]=m.useState(null);sn("ctx",{coin:jt},ts,!!jt),m.useEffect(()=>{ts(null)},[jt]);const Ve=To(m.useMemo(()=>
8[...Nv(T),jt].filter(Boolean),[T,jt]));m.useEffect(()=>()=>{Dt.current&&clearTimeout(Dt.current)},[]);const ae=m.useMemo(()=>{var V;return((V=A==null?void 0:A.universe)==null?void 0:V.find(ut=>ut.name===jt))??null},[A,jt]),ke=m.useMemo(()=>px(jt,ae,et),[jt,ae,et]),xe=m.useMemo(()=>((T==null?void 0:T.assetPositions)??[]).map(ut=>ut==null?void 0:ut.position).find(ut=>ut&&ut.coin===jt&&parseFloat(ut.szi)!==0)??null,[T,jt]),ps=m.useMemo(()=>(P??[]).filter(V=>V.coin===jt),[P,jt]),es=m.useMemo(()=>{const V=new Set;for(const ut of Object.values(tt))for(const Ct of(ut==null?void 0:ut.assetPositions)??[]){const ne=Ct==null?void 0:Ct.position;ne&&parseFloat(ne.szi)!==0&&V.add(ne.coin)}for(const ut of P??[])ut!=null&&ut.coin&&V.add(ut.coin);return V},[tt,P]),Me=m.useMemo(()=>{var ut;if(Os)return Os;const V=((ut=A==null?void 0:A.universe)==null?void 0:ut.findIndex(Ct=>Ct.name===jt))??-1;return V>=0?O[V]:null},[Os,A,O,jt]),Qe=Ve[jt]||parseFloat((Me==null?void 0:Me.markPx)??0),Pe=parseFloat((Me==null?void 0:Me.prevDayPx)??0),Ie=Pe?(Qe-Pe)/Pe*100:0,ss=m.useMemo(()=>{var Ct,ne;const V=parseFloat(((Ct=T==null?void 0:T.marginSummary)==null?void 0:Ct.accountValue)??0);if(!V||!((ne=T==null?void 0:T.assetPositions)!=null&&ne.length))return V;let ut=0;for(const Zt of T.assetPositions){const ks=Zt==null?void 0:Zt.position;if(!ks)continue;const ns=parseFloat(ks.szi),is=parseFloat(ks.entryPx),Bn=parseFloat(Ve[ks.coin]??0)||0;!ns||!is||!Bn||(ut+=ns*(Bn-is)-parseFloat(ks.unrealizedPnl??0))}return V+ut},[T,Ve]),En=async()=>{var V;if(!w){k(!0);try{const{data:ut}=await ge.post("/x/futures/onboard",{miniAppData:(V=ve())==null?void 0:V.initData,account_id:Xt});ut!=null&&ut.err?s(ut.errText||ut.err):(ys(h("Futures enabled")),await vt())}catch{s(h("Network error"))}finally{k(!1)}}};if(u)return r.jsx(vm,{});const hs=(V=!1)=>r.jsx(gk,{funded:y,onboarding:w,waitingDeposit:j,walletAddr:z,compact:V,onEnable:En,onDeposit:()=>se("deposit")}),vs=f===null?null:f===!1?"auth":v?null:"account",me=r.jsx(vk,{kind:vs==="auth"?"auth":"account",onAction:vs==="auth"?It:()=>qt(!0)}),us=r.jsxs(r.Fragment,{children:[i==="portfolio"&&(vs?me:r.jsx(z_,{accountId:Xt,onPickCoin:le,state:T,states:tt,allPositions:Q,openOrders:P,mids:Ve,universe:A==null?void 0:A.universe,vip:et,currentDex:as,onChanged:()=>vt(!0),onDeposit:()=>se("deposit"),onWithdraw:()=>se("withdraw")})),i==="history"&&(vs?me:r.jsx(Y_,{accountId:Xt})),i==="markets"&&r.jsx(G_,{meta:A,ctxs:O,current:jt,ownedCoins:es,onPick:cs})]}),He=r.jsxs("div",{className:"fut-topbar",ref:nn,children:[r.jsxs("div",{className:"fut-header",children:[r.jsx(wk,{inline:!0}),r.jsx(P_,{compact:c,authed:f!==!1}),r.jsx("div",{className:"fut-header__spacer"}),c&&r.jsx(sr,{to:"/futures/docs",className:"fut-header__docs","aria-label":h("Documentation"),title:h("Documentation"),children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M5 4.5A1.5 1.5 0 0 1 6.5 3H16l3 3v13.5a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 5 19.5z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),r.jsx("path",{d:"M15 3v3.5H19",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),r.jsx("path",{d:"M8.5 12h7M8.5 15.5h7M8.5 8.5h3",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}),f!==!1&&r.jsx(Rt.Tooltip,{title:h("Futures settings"),position:"bottom",arrow:!0,tag:"span",distance:10,children:r.jsx("button",{type:"button",className:"fut-header__gear",onClick:()=>Re(!0),"aria-label":h("Futures settings"),children:r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("circle",{cx:"12",cy:"12",r:"3",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("path",{d:"M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 9 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4.6 9a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.
86 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),r.jsx(yk,{compact:c})]}),i==="trade"&&r.jsxs("div",{className:"fut-marketline",children:[r.jsxs("button",{type:"button",className:"fut-marketline__pick",onClick:()=>ce(!0),children:[r.jsx($a,{coin:jt,size:22}),r.jsx("span",{className:"fut-marketline__coin",children:zt(jt)}),r.jsx("span",{className:"fut-marketline__quote",children:"USD"}),r.jsx("i",{className:"fut-marketline__caret"})]}),r.jsxs("div",{className:"fut-marketline__price",children:[r.jsx("b",{className:Ie>=0?"is-up":"is-down",children:Qe?_m(Qe,(ae==null?void 0:ae.szDecimals)??0):"—"}),r.jsxs("span",{className:Ie>=0?"is-up":"is-down",children:[Ie>=0?"▲":"▼"," ",Math.abs(Ie).toFixed(2),"%"]})]}),r.jsx(F_,{ctx:Me,asset:ae,compactView:c}),r.jsx(Rt.Tooltip,{title:h("Ask the AI analyst about this market"),position:"bottom",arrow:!0,tag:"span",distance:10,children:r.jsxs("button",{type:"button",className:"fut-marketline__ai",onClick:()=>{mt(!0),he(!0)},"aria-label":h("AI analyst"),children:[r.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[r.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"}),r.jsx("path",{d:"M18.5 15.5l.7 1.9 1.8.6-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.6z",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})]}),r.jsx("span",{children:"AI"})]})})]})]}),oe=Pt&&r.jsx("div",{className:"fut-modal fut-modal--start",onClick:()=>qt(!1),children:r.jsxs("div",{className:"fut-modal__box fut-modal__box--start",onClick:V=>V.stopPropagation(),children:[r.jsx("div",{className:"fut-modal__head fut-modal__head--bare",children:r.jsx("button",{type:"button",onClick:()=>qt(!1),"aria-label":h("Close"),children:"✕"})}),hs(!0)]})}),_s=N&&r.jsx(hk,{hidden:!ze,coin:jt,asset:ae,accountId:Xt,markPx:Qe,coinPosition:xe,positionsCount:Q.length,onApply:V=>{ms(V),he(!1)},onApplyTpSl:V=>{ms(V),he(!1)},onPickPrice:V=>{Oe(V),he(!1)},onDeposit:ot(()=>se("deposit")),onSignIn:It,onClose:()=>he(!1)});return c?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut fut--mobile"+(Ws?" fut--chartfull":""),children:[He,i!=="trade"&&r.jsx("div",{className:"fut__section",children:us}),i==="trade"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fut__mobtabs",children:["positions","trade","chart","book","tape"].map(V=>r.jsxs("button",{type:"button",className:V===ye?"is-active":"",onClick:()=>fe(V),children:[V==="trade"&&h("Trade"),V==="chart"&&h("Chart"),V==="book"&&h("Book"),V==="tape"&&h("Tape"),V==="positions"&&h("Positions")]},V))}),ye==="chart"&&r.jsx("div",{className:"fut__chartfull",children:r.jsx(Mu,{coin:jt,compact:!0,fill:!0,height:360,position:xe,orders:ps,accountId:Xt,markPx:Qe,feePct:ke,szDecimals:(ae==null?void 0:ae.szDecimals)??0,onClosePosition:()=>st(jt),onChanged:()=>vt(!0)})}),ye==="book"&&r.jsx(Nu,{coin:jt,rows:10,compact:!0,onPickPrice:Oe}),ye==="tape"&&r.jsx(Qu,{coin:jt,rows:24,compactView:!0}),ye==="trade"&&r.jsx(Du,{coin:jt,isMobile:c,pickedPrice:gs,vip:et,preset:qs,asset:ae,ctx:Me,accountId:Xt,state:T,equity:ss,onDeposit:ot(()=>se("deposit")),onWithdraw:ot(()=>se("withdraw")),onMove:ot(()=>we(!0)),onCalculator:()=>Ds(!0),onDone:()=>vt(!0),authed:f!==!1,onboarded:v,onNeedAuth:It,onNeedAccount:()=>qt(!0)}),ye==="positions"&&r.jsx(fa,{vip:et,universe:A==null?void 0:A.universe,accountId:Xt,positions:Q,openOrders:P,twaps:bt,onChanged:()=>vt(!0),onboarded:v,coin:jt,onPickCoin:le,closeRequest:Nt,compact:!0})]})]}),ie&&r.jsx(Uu,{meta:A,ctxs:O,current:jt,ownedCoins:es,onPick:V=>{le(V),ce(!1)},onClose:()=>ce(!1)}),Ne&&r.jsx($u,{accountId:Xt,state:Z,states:tt,initialMode:Ne,onClose:()=>se(!1),onDone:()=>{se(!1),vt(!0)}}),qe&&r.jsx(ga,{accountId:Xt,currentDex:as,onClose:()=>we(!1),onDone:()=>vt(!0)}),Ls&&r.jsx(ed,{coin:jt,asset:ae,ctx:Me,position:xe,state:T,equity:ss,onApply:ms,onClose:()=>Ds(!1)}),We&&r.jsx(sd,{accountId:Xt,tgLinked:Ot,tgTpsl:At,tgFills:Mt,onTgChange:Yt,onTgFillsChange:Gt,onClose:()=>Re(!1)}),_s,oe]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"fut",children:[He,i!=="trade"&&r.jsx("div",{className:"fut__section",children:us}),i==="trade"&&r.jsxs("div",{className:"fut__body",children:[r.jsxs("div",{className:"fut__left",children:[r.jsxs("div",{className:"fut__market",ref:Ht,style:te?{height:te+"px"}:void 0,children:[r.jsx("div",{className:"fut__chart",children:r.jsx(Mu,{coin:jt,fill:!0,height:400,position:xe,orders:ps,accountId:Xt,markPx:Qe,feePct:ke,szDecimals:(ae==null?void 0:ae.szDecimals)??0,onClosePosition:()=>st(jt),onChanged:()=>vt(!0)})}),r.jsxs("div",{className:"fut__book",children:[r.jsxs("div",{className:"fut-side__tabs",children:[r.jsx("button",{type:"button",className:ws==="book"?"is-active":"",onClick:()=>zs("book"),children:h("Order book")}),r.jsx("button",{type:"button",className:ws==="tape"?"is-active":"",onClick:()=>zs("tape"),children:h("Trades")})]}),r.jsx("div",{className:"fut-side__pane"+(ws==="book"?"":" is-hidden"),children:r.jsx(Nu,{coin:jt,rows:10,fill:!0,onPickPrice:Oe})}),r.jsx("div",{className:"fut-side__pane"+(ws==="tape"?"":" is-hidden"),children:r.jsx(Qu,{coin:jt,rows:22,fill:!0})})]})]}),r.jsx("div",{className:"fut__resizer",role:"separator","aria-orientation":"horizontal",title:h("Drag to resize"),onPointerDown:Bt,onPointerMove:re,onPointerUp:Vt,onPointerCancel:Vt,onDoubleClick:Ee,children:r.jsx("i",{})}),r.jsx(fa,{vip:et,universe:A==null?void 0:A.universe,accountId:Xt,positions:Q,openOrders:P,twaps:bt,onChanged:()=>vt(!0),onboarded:v,coin:jt,onPickCoin:le,closeRequest:Nt})]}),r.jsxs("div",{className:"fut__form",children:[r.jsx(Du,{coin:jt,isMobile:c,pickedPrice:gs,vip:et,preset:q
8s,asset:ae,ctx:Me,accountId:Xt,state:T,equity:ss,onDeposit:ot(()=>se("deposit")),onWithdraw:ot(()=>se("withdraw")),onMove:ot(()=>we(!0)),onCalculator:()=>Ds(!0),onDone:()=>vt(!0),authed:f!==!1,onboarded:v,onNeedAuth:It,onNeedAccount:()=>qt(!0)}),r.jsx(X_,{coin:jt,asset:ae,ctx:Me})]})]})]}),ie&&r.jsx(Uu,{meta:A,ctxs:O,current:jt,ownedCoins:es,onPick:V=>{le(V),ce(!1)},onClose:()=>ce(!1)}),Ne&&r.jsx($u,{accountId:Xt,state:Z,states:tt,initialMode:Ne,onClose:()=>se(!1),onDone:()=>{se(!1),vt(!0)}}),qe&&r.jsx(ga,{accountId:Xt,currentDex:as,onClose:()=>we(!1),onDone:()=>vt(!0)}),Ls&&r.jsx(ed,{coin:jt,asset:ae,ctx:Me,position:xe,state:T,equity:ss,onApply:ms,onClose:()=>Ds(!1)}),We&&r.jsx(sd,{onClose:()=>Re(!1)}),_s,oe]})}export{Nk as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.