bn-lightweight-charts 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var Lib=function(t,e){"use strict";const i={backgroundColor:"rgb(18,24,38)",hoverBackgroundColor:"#3c434c",clickBackgroundColor:"#50565E",activeBackgroundColor:"rgba(0, 122, 255, 0.7)",mutedBackgroundColor:"rgba(0, 122, 255, 0.3)",borderColor:"#3C434C",color:"#d8d9db",activeColor:"#ececed"};function s(){window.pane={...i},window.containerDiv=document.getElementById("container")||document.createElement("div"),window.setCursor=t=>{t&&(window.cursor=t),document.body.style.cursor=window.cursor},window.cursor="default",window.textBoxFocused=!1}function n(t){let e=document.createElement("template");t=t.trim(),e.innerHTML=t;const i=e.content.firstChild;if(!i)throw new Error("Invalid HTML passed to htmlToElement");return i}class o{handler;div;seriesContainer;ohlcEnabled=!1;percentEnabled=!1;linesEnabled=!1;colorBasedOnCandle=!1;text;candle;_lines=[];_lines_grp={};constructor(t){this.legendHandler=this.legendHandler.bind(this),this.handler=t,this.ohlcEnabled=!1,this.percentEnabled=!1,this.linesEnabled=!1,this.colorBasedOnCandle=!1,this.div=document.createElement("div"),this.div.classList.add("legend"),this.div.style.maxWidth=100*t.scale.width-8+"vw",this.div.style.display="none";const e=document.createElement("div");e.style.display="flex",e.style.flexDirection="row",this.seriesContainer=document.createElement("div"),this.seriesContainer.classList.add("series-container"),this.text=document.createElement("span"),this.text.style.lineHeight="1.8",this.candle=document.createElement("div"),e.appendChild(this.seriesContainer),this.div.appendChild(this.text),this.div.appendChild(this.candle),this.div.appendChild(e),t.div.appendChild(this.div),t.chart.subscribeCrosshairMove(this.legendHandler)}toJSON(){const{_lines:t,handler:e,...i}=this;return i}makeSeriesRow(t,e,i){const s="#FFF";let o=`\n <path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:${s};stroke-opacity:1;stroke-miterlimit:4;" d="M 21.998437 12 C 21.998437 12 18.998437 18 12 18 C 5.001562 18 2.001562 12 2.001562 12 C 2.001562 12 5.001562 6 12 6 C 18.998437 6 21.998437 12 21.998437 12 Z M 21.998437 12 " transform="matrix(0.833333,0,0,0.833333,0,0)"/>\n <path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:${s};stroke-opacity:1;stroke-miterlimit:4;" d="M 15 12 C 15 13.654687 13.654687 15 12 15 C 10.345312 15 9 13.654687 9 12 C 9 10.345312 10.345312 9 12 9 C 13.654687 9 15 10.345312 15 12 Z M 15 12 " transform="matrix(0.833333,0,0,0.833333,0,0)"/>\`\n `,r=`\n <path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:${s};stroke-opacity:1;stroke-miterlimit:4;" d="M 20.001562 9 C 20.001562 9 19.678125 9.665625 18.998437 10.514062 M 12 14.001562 C 10.392187 14.001562 9.046875 13.589062 7.95 12.998437 M 12 14.001562 C 13.607812 14.001562 14.953125 13.589062 16.05 12.998437 M 12 14.001562 L 12 17.498437 M 3.998437 9 C 3.998437 9 4.354687 9.735937 5.104687 10.645312 M 7.95 12.998437 L 5.001562 15.998437 M 7.95 12.998437 C 6.689062 12.328125 5.751562 11.423437 5.104687 10.645312 M 16.05 12.998437 L 18.501562 15.998437 M 16.05 12.998437 C 17.38125 12.290625 18.351562 11.320312 18.998437 10.514062 M 5.104687 10.645312 L 2.001562 12 M 18.998437 10.514062 L 21.998437 12 " transform="matrix(0.833333,0,0,0.833333,0,0)"/>\n `,a=document.createElement("div");a.style.display="flex",a.style.alignItems="center";let l=document.createElement("div"),h=document.createElement("div");h.classList.add("legend-toggle-switch");let d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width","22"),d.setAttribute("height","16");let c=document.createElementNS("http://www.w3.org/2000/svg","g");c.innerHTML=o;let p=!0;h.addEventListener("click",(()=>{p?(p=!1,c.innerHTML=r,e.applyOptions({visible:!1})):(p=!0,e.applyOptions({visible:!0}),c.innerHTML=o)})),d.appendChild(c),h.appendChild(d),a.appendChild(l),a.appendChild(h),this.seriesContainer.appendChild(a);const u=e.options().baseLineColor;this._lines.push({name:t,paneIndex:i,div:l,row:a,toggle:h,series:e,solid:u.startsWith("rgba")?u.replace(/[^,]+(?=\))/,"1"):u}),this._lines.sort(((t,e)=>t.paneIndex-e.paneIndex)),this._lines_grp=this._lines.reduce(((t,e)=>(t[e.paneIndex]||(t[e.paneIndex]=[]),t[e.paneIndex].push(e),t)),{}),this.seriesContainer.innerHTML="";for(const t in this._lines_grp){for(const e of this._lines_grp[t])this.seriesContainer.appendChild(e.row);this.seriesContainer.appendChild(n("<br>"))}}legendItemFormat(t,e){return t.toFixed(e).toString().padStart(8," ")}shorthandFormat(t){const e=Math.abs(t);return e>=1e6?(t/1e6).toFixed(1)+"M":e>=1e3?(t/1e3).toFixed(1)+"K":t.toString().padStart(8," ")}legendHandler(t,e=!1){if(!this.ohlcEnabled&&!this.linesEnabled&&!this.percentEnabled)return;const i=this.handler.series.options();if(!t.time)return this.candle.style.color="transparent",void(this.candle.innerHTML=this.candle.innerHTML.replace(i.upColor,"").replace(i.downColor,""));let s,n=null;if(e){const e=this.handler.chart.timeScale();let i=e.timeToCoordinate(t.time);i&&(n=e.coordinateToLogical(i.valueOf())),n&&(s=this.handler.series.dataByIndex(n.valueOf()))}else s=t.seriesData.get(this.handler.series);this.candle.style.color="";let o='<span style="line-height: 1.8;">';if(s){if(this.ohlcEnabled&&(o+=`O ${this.legendItemFormat(s.open,this.handler.precision)} `,o+=`| H ${this.legendItemFormat(s.high,this.handler.precision)} `,o+=`| L ${this.legendItemFormat(s.low,this.handler.precision)} `,o+=`| C ${this.legendItemFormat(s.close,this.handler.precision)} `),this.handler.volumeSeries){let e;e=n?this.handler.volumeSeries.dataByIndex(n):t.seriesData.get(this.handler.volumeSeries),e&&(o+=this.ohlcEnabled?`| V ${this.shorthandFormat(e.value)}`:"")}if(this.percentEnabled){let t=(s.close-s.open)/s.open*100,e=t>0?i.upColor:i.downColor,n=`${t>=0?"+":""}${t.toFixed(2)} %`;this.colorBasedOnCandle?o+=`| <span style="color: ${e};">${n}</span>`:o+="| "+n}}this.candle.innerHTML=o+"</span>",this._lines.forEach((i=>{if(!this.linesEnabled)return void(i.row.style.display="none");let s,o;if(i.row.style.display="flex",s=e&&n?i.series.dataByIndex(n):t.seriesData.get(i.series),s?.value){if("Histogram"==i.series.seriesType())o=this.shorthandFormat(s.value);else{const t=i.series.options().priceFormat;o=this.legendItemFormat(s.value,t.precision)}i.div.innerHTML=`<span style="color: ${i.solid};">▨</span> ${i.name} : ${o}`}}))}}function r(t){if(void 0===t)throw new Error("Value is undefined");return t}class a{_chart=void 0;_series=void 0;requestUpdate(){this._requestUpdate&&this._requestUpdate()}_requestUpdate;attached({chart:t,series:e,requestUpdate:i}){this._chart=t,this._series=e,this._series.subscribeDataChanged(this._fireDataUpdated),this._requestUpdate=i,this.requestUpdate()}detached(){this._chart=void 0,this._series=void 0,this._requestUpdate=void 0}get chart(){return r(this._chart)}get series(){return r(this._series)}_fireDataUpdated(t){this.dataUpdated&&this.dataUpdated(t)}}const l={lineColor:"#1E80F0",lineStyle:e.LineStyle.Solid,width:4};var h;!function(t){t[t.NONE=0]="NONE",t[t.HOVERING=1]="HOVERING",t[t.DRAGGING=2]="DRAGGING",t[t.DRAGGINGP1=3]="DRAGGINGP1",t[t.DRAGGINGP2=4]="DRAGGINGP2",t[t.DRAGGINGP3=5]="DRAGGINGP3",t[t.DRAGGINGP4=6]="DRAGGINGP4"}(h||(h={}));class d extends a{_paneViews=[];_options;_points=[];_state=h.NONE;_startDragPoint=null;_latestHoverPoint=null;static _mouseIsDown=!1;static hoveredObject=null;static lastHoveredObject=null;_listeners=[];constructor(t){super(),this._options={...l,...t}}updateAllViews(){this._paneViews.forEach((t=>t.update()))}paneViews(){return this._paneViews}applyOptions(t){this._options={...this._options,...t},this.requestUpdate()}updatePoints(...t){for(let e=0;e<this.points.length;e++)null!=t[e]&&(this.points[e]=t[e]);this.requestUpdate()}detach(){this._options.lineColor="transparent",this.requestUpdate(),this.series.detachPrimitive(this);for(const t of this._listeners)document.body.removeEventListener(t.name,t.listener)}get points(){return this._points}_subscribe(t,e){document.body.addEventListener(t,e),this._listeners.push({name:t,listener:e})}_unsubscribe(t,e){document.body.removeEventListener(t,e);const i=this._listeners.find((i=>i.name===t&&i.listener===e));this._listeners.splice(this._listeners.indexOf(i),1)}_handleHoverInteraction(t){if(this._latestHoverPoint=t.point,d._mouseIsDown)this._handleDragInteraction(t);else if(this._mouseIsOverDrawing(t)){if(this._state!=h.NONE)return;this._moveToState(h.HOVERING),d.hoveredObject=d.lastHoveredObject=this}else{if(this._state==h.NONE)return;this._moveToState(h.NONE),d.hoveredObject===this&&(d.hoveredObject=null)}}static _eventToPoint(t,e){if(!e||!t.point||!t.logical)return null;const i=e.coordinateToPrice(t.point.y);return null==i?null:{time:t.time||null,logical:t.logical,price:i.valueOf()}}static _getDiff(t,e){return{logical:t.logical-e.logical,price:t.price-e.price}}_addDiffToPoint(t,e,i){t&&(t.logical=t.logical+e,t.price=t.price+i,t.time=this.series.dataByIndex(t.logical)?.time||null)}_handleMouseDownInteraction=()=>{d._mouseIsDown=!0,this._onMouseDown()};_handleMouseUpInteraction=()=>{d._mouseIsDown=!1,this._moveToState(h.HOVERING)};_handleDragInteraction(t){if(this._state!=h.DRAGGING&&this._state!=h.DRAGGINGP1&&this._state!=h.DRAGGINGP2&&this._state!=h.DRAGGINGP3&&this._state!=h.DRAGGINGP4)return;const e=d._eventToPoint(t,this.series);if(!e)return;this._startDragPoint=this._startDragPoint||e;const i=d._getDiff(e,this._startDragPoint);this._onDrag(i),this.requestUpdate(),this._startDragPoint=e}}class c{_options;constructor(t){this._options=t}}class p extends c{_p1;_p2;_hovered;constructor(t,e,i,s){super(i),this._p1=t,this._p2=e,this._hovered=s}_getScaledCoordinates(t){return null===this._p1.x||null===this._p1.y||null===this._p2.x||null===this._p2.y?null:{x1:Math.round(this._p1.x*t.horizontalPixelRatio),y1:Math.round(this._p1.y*t.verticalPixelRatio),x2:Math.round(this._p2.x*t.horizontalPixelRatio),y2:Math.round(this._p2.y*t.verticalPixelRatio)}}_drawEndCircle(t,e,i){t.context.fillStyle="#000",t.context.beginPath(),t.context.arc(e,i,9,0,2*Math.PI),t.context.stroke(),t.context.fill()}}function u(t,i){const s={[e.LineStyle.Solid]:[],[e.LineStyle.Dotted]:[t.lineWidth,t.lineWidth],[e.LineStyle.Dashed]:[2*t.lineWidth,2*t.lineWidth],[e.LineStyle.LargeDashed]:[6*t.lineWidth,6*t.lineWidth],[e.LineStyle.SparseDotted]:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}class _ extends c{_point={x:null,y:null};constructor(t,e){super(e),this._point=t}draw(t){t.useBitmapCoordinateSpace((t=>{if(null==this._point.y)return;const e=t.context,i=Math.round(this._point.y*t.verticalPixelRatio),s=this._point.x?this._point.x*t.horizontalPixelRatio:0;e.lineWidth=this._options.width,e.strokeStyle=this._options.lineColor,u(e,this._options.lineStyle),e.beginPath(),e.moveTo(s,i),e.lineTo(t.bitmapSize.width,i),e.stroke()}))}}class m{_source;constructor(t){this._source=t}}class v extends m{_p1={x:null,y:null};_p2={x:null,y:null};_source;constructor(t){super(t),this._source=t}update(){if(!this._source.p1||!this._source.p2)return;const t=this._source.series,e=t.priceToCoordinate(this._source.p1.price),i=t.priceToCoordinate(this._source.p2.price),s=this._getX(this._source.p1),n=this._getX(this._source.p2);this._p1={x:s,y:e},this._p2={x:n,y:i}}_getX(t){return this._source.chart.timeScale().logicalToCoordinate(t.logical)}}class g extends m{_source;_point={x:null,y:null};constructor(t){super(t),this._source=t}update(){const t=this._source._point,e=this._source.chart.timeScale(),i=this._source.series;"RayLine"==this._source._type&&(this._point.x=t.time?e.timeToCoordinate(t.time):e.logicalToCoordinate(t.logical)),this._point.y=i.priceToCoordinate(t.price)}renderer(){return new _(this._point,this._source._options)}}class w{_source;_y=null;_price=null;constructor(t){this._source=t}update(){if(!this._source.series||!this._source._point)return;this._y=this._source.series.priceToCoordinate(this._source._point.price);const t=this._source.series.options().priceFormat.precision;this._price=this._source._point.price.toFixed(t).toString()}visible(){return!0}tickVisible(){return!0}coordinate(){return this._y??0}text(){return this._price||""}textColor(){return"white"}backColor(){return this._source._options.lineColor}}class y extends d{_type="HorizontalLine";_paneViews;_point;_callbackName;_priceAxisViews;_startDragPoint=null;constructor(t,e,i=null){super(e),this._point=t,this._point.time=null,this._paneViews=[new g(this)],this._priceAxisViews=[new w(this)],this._callbackName=i}get points(){return[this._point]}updatePoints(...t){for(const e of t)e&&(this._point.price=e.price);this.requestUpdate()}updateAllViews(){this._paneViews.forEach((t=>t.update())),this._priceAxisViews.forEach((t=>t.update()))}priceAxisViews(){return this._priceAxisViews}_moveToState(t){switch(t){case h.NONE:document.body.style.cursor="default",this._unsubscribe("mousedown",this._handleMouseDownInteraction);break;case h.HOVERING:document.body.style.cursor="pointer",this._unsubscribe("mouseup",this._childHandleMouseUpInteraction),this._subscribe("mousedown",this._handleMouseDownInteraction),this.chart.applyOptions({handleScroll:!0});break;case h.DRAGGING:document.body.style.cursor="grabbing",this._subscribe("mouseup",this._childHandleMouseUpInteraction),this.chart.applyOptions({handleScroll:!1})}this._state=t}_onDrag(t){this._addDiffToPoint(this._point,0,t.price),this.requestUpdate()}_mouseIsOverDrawing(t,e=4){if(!t.point)return!1;const i=this.series.priceToCoordinate(this._point.price);return!!i&&Math.abs(i-t.point.y)<e}_onMouseDown(){this._startDragPoint=null;if(this._latestHoverPoint)return this._moveToState(h.DRAGGING)}_childHandleMouseUpInteraction=()=>{this._handleMouseUpInteraction(),this._callbackName&&window.callbackFunction(`${this._callbackName}_~_${this._point.price.toFixed(8)}`)}}class b{_chart;_series;_finishDrawingCallback=null;_drawings=[];_activeDrawing=null;_isDrawing=!1;_drawingType=null;constructor(t,e,i=null){this._chart=t,this._series=e,this._finishDrawingCallback=i,this._chart.subscribeClick(this._clickHandler),this._chart.subscribeCrosshairMove(this._moveHandler)}_clickHandler=t=>this._onClick(t);_moveHandler=t=>this._onMouseMove(t);beginDrawing(t){this._drawingType=t,this._isDrawing=!0}stopDrawing(){this._isDrawing=!1,this._activeDrawing=null}get drawings(){return this._drawings}addNewDrawing(t){this._series.attachPrimitive(t),this._drawings.push(t)}delete(t){if(null==t)return;const e=this._drawings.indexOf(t);-1!=e&&(this._drawings.splice(e,1),t.detach())}clearDrawings(){for(const t of this._drawings)t.detach();this._drawings=[]}repositionOnTime(){for(const t of this.drawings){const e=[];for(const i of t.points){if(!i){e.push(i);continue}const t=i.time?this._chart.timeScale().coordinateToLogical(this._chart.timeScale().timeToCoordinate(i.time)||0):i.logical;e.push({time:i.time,logical:t,price:i.price})}t.updatePoints(...e)}}_onClick(t){if(!this._isDrawing)return;const e=d._eventToPoint(t,this._series);if(e)if(null==this._activeDrawing){if(null==this._drawingType)return;this._activeDrawing=new this._drawingType(e,e),this._series.attachPrimitive(this._activeDrawing),this._drawingType==y&&this._onClick(t)}else{if(this._drawings.push(this._activeDrawing),this.stopDrawing(),!this._finishDrawingCallback)return;this._finishDrawingCallback()}}_onMouseMove(t){if(!t)return;for(const e of this._drawings)e._handleHoverInteraction(t);if(!this._isDrawing||!this._activeDrawing)return;const e=d._eventToPoint(t,this._series);e&&this._activeDrawing.updatePoints(null,e)}}class x extends p{constructor(t,e,i,s){super(t,e,i,s)}draw(t){t.useBitmapCoordinateSpace((t=>{if(null===this._p1.x||null===this._p1.y||null===this._p2.x||null===this._p2.y)return;const e=t.context,i=this._getScaledCoordinates(t);i&&(e.lineWidth=this._options.width,e.strokeStyle=this._options.lineColor,u(e,this._options.lineStyle),e.beginPath(),e.moveTo(i.x1,i.y1),e.lineTo(i.x2,i.y2),e.stroke(),this._hovered&&(this._drawEndCircle(t,i.x1,i.y1),this._drawEndCircle(t,i.x2,i.y2)))}))}}class f extends v{constructor(t){super(t)}renderer(){return new x(this._p1,this._p2,this._source._options,this._source.hovered)}}class C extends d{_paneViews=[];_hovered=!1;constructor(t,e,i){super(),this.points.push(t),this.points.push(e),this._options={...l,...i}}setFirstPoint(t){this.updatePoints(t)}setSecondPoint(t){this.updatePoints(null,t)}get p1(){return this.points[0]}get p2(){return this.points[1]}get hovered(){return this._hovered}}class D extends C{_type="TrendLine";constructor(t,e,i){super(t,e,i),this._paneViews=[new f(this)]}_moveToState(t){switch(t){case h.NONE:document.body.style.cursor="default",this._hovered=!1,this.requestUpdate(),this._unsubscribe("mousedown",this._handleMouseDownInteraction);break;case h.HOVERING:document.body.style.cursor="pointer",this._hovered=!0,this.requestUpdate(),this._subscribe("mousedown",this._handleMouseDownInteraction),this._unsubscribe("mouseup",this._handleMouseDownInteraction),this.chart.applyOptions({handleScroll:!0});break;case h.DRAGGINGP1:case h.DRAGGINGP2:case h.DRAGGING:document.body.style.cursor="grabbing",this._subscribe("mouseup",this._handleMouseUpInteraction),this.chart.applyOptions({handleScroll:!1})}this._state=t}_onDrag(t){this._state!=h.DRAGGING&&this._state!=h.DRAGGINGP1||this._addDiffToPoint(this.p1,t.logical,t.price),this._state!=h.DRAGGING&&this._state!=h.DRAGGINGP2||this._addDiffToPoint(this.p2,t.logical,t.price)}_onMouseDown(){this._startDragPoint=null;const t=this._latestHoverPoint;if(!t)return;const e=this._paneViews[0]._p1,i=this._paneViews[0]._p2;if(!(e.x&&i.x&&e.y&&i.y))return this._moveToState(h.DRAGGING);Math.abs(t.x-e.x)<10&&Math.abs(t.y-e.y)<10?this._moveToState(h.DRAGGINGP1):Math.abs(t.x-i.x)<10&&Math.abs(t.y-i.y)<10?this._moveToState(h.DRAGGINGP2):this._moveToState(h.DRAGGING)}_mouseIsOverDrawing(t,e=4){if(!t.point)return!1;const i=this._paneViews[0]._p1.x,s=this._paneViews[0]._p1.y,n=this._paneViews[0]._p2.x,o=this._paneViews[0]._p2.y;if(!(i&&n&&s&&o))return!1;const r=t.point.x,a=t.point.y;if(r<=Math.min(i,n)-e||r>=Math.max(i,n)+e)return!1;return Math.abs((o-s)*r-(n-i)*a+n*s-o*i)/Math.sqrt((o-s)**2+(n-i)**2)<=e}}class E extends p{constructor(t,e,i,s){super(t,e,i,s)}draw(t){t.useBitmapCoordinateSpace((t=>{const e=t.context,i=this._getScaledCoordinates(t);if(!i)return;e.lineWidth=this._options.width,e.strokeStyle=this._options.lineColor,u(e,this._options.lineStyle),e.fillStyle=this._options.fillColor;const s=Math.min(i.x1,i.x2),n=Math.min(i.y1,i.y2),o=Math.abs(i.x1-i.x2),r=Math.abs(i.y1-i.y2);e.strokeRect(s,n,o,r),e.fillRect(s,n,o,r),this._hovered&&(this._drawEndCircle(t,s,n),this._drawEndCircle(t,s+o,n),this._drawEndCircle(t,s+o,n+r),this._drawEndCircle(t,s,n+r))}))}}class k extends v{constructor(t){super(t)}renderer(){return new E(this._p1,this._p2,this._source._options,this._source.hovered)}}const L={fillEnabled:!0,fillColor:"rgba(255, 255, 255, 0.2)",...l};class S extends C{_type="Box";constructor(t,e,i){super(t,e,i),this._options={...L,...i},this._paneViews=[new k(this)]}_moveToState(t){switch(t){case h.NONE:document.body.style.cursor="default",this._hovered=!1,this._unsubscribe("mousedown",this._handleMouseDownInteraction);break;case h.HOVERING:document.body.style.cursor="pointer",this._hovered=!0,this._unsubscribe("mouseup",this._handleMouseUpInteraction),this._subscribe("mousedown",this._handleMouseDownInteraction),this.chart.applyOptions({handleScroll:!0});break;case h.DRAGGINGP1:case h.DRAGGINGP2:case h.DRAGGINGP3:case h.DRAGGINGP4:case h.DRAGGING:document.body.style.cursor="grabbing",document.body.addEventListener("mouseup",this._handleMouseUpInteraction),this._subscribe("mouseup",this._handleMouseUpInteraction),this.chart.applyOptions({handleScroll:!1})}this._state=t}_onDrag(t){this._state!=h.DRAGGING&&this._state!=h.DRAGGINGP1||this._addDiffToPoint(this.p1,t.logical,t.price),this._state!=h.DRAGGING&&this._state!=h.DRAGGINGP2||this._addDiffToPoint(this.p2,t.logical,t.price),this._state!=h.DRAGGING&&(this._state==h.DRAGGINGP3&&(this._addDiffToPoint(this.p1,t.logical,0),this._addDiffToPoint(this.p2,0,t.price)),this._state==h.DRAGGINGP4&&(this._addDiffToPoint(this.p1,0,t.price),this._addDiffToPoint(this.p2,t.logical,0)))}_onMouseDown(){this._startDragPoint=null;const t=this._latestHoverPoint,e=this._paneViews[0]._p1,i=this._paneViews[0]._p2;if(!(e.x&&i.x&&e.y&&i.y))return this._moveToState(h.DRAGGING);const s=10;Math.abs(t.x-e.x)<s&&Math.abs(t.y-e.y)<s?this._moveToState(h.DRAGGINGP1):Math.abs(t.x-i.x)<s&&Math.abs(t.y-i.y)<s?this._moveToState(h.DRAGGINGP2):Math.abs(t.x-e.x)<s&&Math.abs(t.y-i.y)<s?this._moveToState(h.DRAGGINGP3):Math.abs(t.x-i.x)<s&&Math.abs(t.y-e.y)<s?this._moveToState(h.DRAGGINGP4):this._moveToState(h.DRAGGING)}_mouseIsOverDrawing(t,e=4){if(!t.point)return!1;const i=this._paneViews[0]._p1.x,s=this._paneViews[0]._p1.y,n=this._paneViews[0]._p2.x,o=this._paneViews[0]._p2.y;if(!(i&&n&&s&&o))return!1;const r=t.point.x,a=t.point.y,l=Math.min(i,n),h=Math.min(s,o),d=Math.abs(i-n),c=Math.abs(s-o),p=e/2;return r>l-p&&r<l+d+p&&a>h-p&&a<h+c+p}}class G{colorOption;static colors=["#EBB0B0","#E9CEA1","#E5DF80","#ADEB97","#A3C3EA","#D8BDED","#E15F5D","#E1B45F","#E2D947","#4BE940","#639AE1","#D7A0E8","#E42C2A","#E49D30","#E7D827","#3CFF0A","#3275E4","#B06CE3","#F3000D","#EE9A14","#F1DA13","#2DFC0F","#1562EE","#BB00EF","#B50911","#E3860E","#D2BD11","#48DE0E","#1455B4","#6E009F","#7C1713","#B76B12","#8D7A13","#479C12","#165579","#51007E"];_div;saveDrawings;opacity=0;_opacitySlider;_opacityLabel;rgba;constructor(t,e){this.colorOption=e,this.saveDrawings=t,this._div=document.createElement("div"),this._div.classList.add("color-picker");let i=document.createElement("div");i.style.margin="10px",i.style.display="flex",i.style.flexWrap="wrap",G.colors.forEach((t=>i.appendChild(this.makeColorBox(t))));let s=document.createElement("div");s.style.backgroundColor=window.pane.borderColor,s.style.height="1px",s.style.width="130px";let n=document.createElement("div");n.style.margin="10px";let o=document.createElement("div");o.style.color="lightgray",o.style.fontSize="12px",o.innerText="Opacity",this._opacityLabel=document.createElement("div"),this._opacityLabel.style.color="lightgray",this._opacityLabel.style.fontSize="12px",this._opacitySlider=document.createElement("input"),this._opacitySlider.type="range",this._opacitySlider.value=(100*this.opacity).toString(),this._opacityLabel.innerText=this._opacitySlider.value+"%",this._opacitySlider.oninput=()=>{this._opacityLabel.innerText=this._opacitySlider.value+"%",this.opacity=parseInt(this._opacitySlider.value)/100,this.updateColor()},n.appendChild(o),n.appendChild(this._opacitySlider),n.appendChild(this._opacityLabel),this._div.appendChild(i),this._div.appendChild(s),this._div.appendChild(n),window.containerDiv.appendChild(this._div)}_updateOpacitySlider(){this._opacitySlider.value=(100*this.opacity).toString(),this._opacityLabel.innerText=this._opacitySlider.value+"%"}makeColorBox(t){const e=document.createElement("div");e.style.width="18px",e.style.height="18px",e.style.borderRadius="3px",e.style.margin="3px",e.style.boxSizing="border-box",e.style.backgroundColor=t,e.addEventListener("mouseover",(()=>e.style.border="2px solid lightgray")),e.addEventListener("mouseout",(()=>e.style.border="none"));const i=G.extractRGBA(t);return e.addEventListener("click",(()=>{this.rgba=i,this.updateColor()})),e}static extractRGBA(t){const e=document.createElement("div");e.style.color=t,document.body.appendChild(e);const i=getComputedStyle(e).color;document.body.removeChild(e);const s=i.match(/\d+/g)?.map(Number);if(!s)return[];let n=i.includes("rgba")?parseFloat(i.split(",")[3]):1;return[s[0],s[1],s[2],n]}updateColor(){if(!d.lastHoveredObject||!this.rgba)return;const t=`rgba(${this.rgba[0]}, ${this.rgba[1]}, ${this.rgba[2]}, ${this.opacity})`;d.lastHoveredObject.applyOptions({[this.colorOption]:t}),this.saveDrawings()}openMenu(t){d.lastHoveredObject&&(this.rgba=G.extractRGBA(d.lastHoveredObject._options[this.colorOption]),this.opacity=this.rgba[3],this._updateOpacitySlider(),this._div.style.top=t.top-30+"px",this._div.style.left=t.right+"px",this._div.style.display="flex",setTimeout((()=>document.addEventListener("mousedown",(t=>{this._div.contains(t.target)||this.closeMenu()}))),10))}closeMenu(){document.body.removeEventListener("click",this.closeMenu),this._div.style.display="none"}}class T{static _styles=[{name:"Solid",var:e.LineStyle.Solid},{name:"Dotted",var:e.LineStyle.Dotted},{name:"Dashed",var:e.LineStyle.Dashed},{name:"Large Dashed",var:e.LineStyle.LargeDashed},{name:"Sparse Dotted",var:e.LineStyle.SparseDotted}];_div;_saveDrawings;constructor(t){this._saveDrawings=t,this._div=document.createElement("div"),this._div.classList.add("context-menu"),T._styles.forEach((t=>{this._div.appendChild(this._makeTextBox(t.name,t.var))})),window.containerDiv.appendChild(this._div)}_makeTextBox(t,e){const i=document.createElement("span");return i.classList.add("context-menu-item"),i.innerText=t,i.addEventListener("click",(()=>{d.lastHoveredObject?.applyOptions({lineStyle:e}),this._saveDrawings()})),i}openMenu(t){this._div.style.top=t.top-30+"px",this._div.style.left=t.right+"px",this._div.style.display="block",setTimeout((()=>document.addEventListener("mousedown",(t=>{this._div.contains(t.target)||this.closeMenu()}))),10)}closeMenu(){document.removeEventListener("click",this.closeMenu),this._div.style.display="none"}}function I(t){const e=[];for(const i of t)0==e.length?e.push(i.toUpperCase()):i==i.toUpperCase()?e.push(" "+i):e.push(i);return e.join("")}class M{saveDrawings;drawingTool;div;hoverItem;items=[];constructor(t,e){this.saveDrawings=t,this.drawingTool=e,this._onRightClick=this._onRightClick.bind(this),this.div=document.createElement("div"),this.div.classList.add("context-menu"),document.body.appendChild(this.div),this.hoverItem=null,document.body.addEventListener("contextmenu",this._onRightClick)}_handleClick=t=>this._onClick(t);_onClick(t){t.target&&(this.div.contains(t.target)||(this.div.style.display="none",document.body.removeEventListener("click",this._handleClick)))}_onRightClick(t){if(!d.hoveredObject)return;for(const t of this.items)this.div.removeChild(t);this.items=[];for(const t of Object.keys(d.hoveredObject._options)){let e;if(t.toLowerCase().includes("color"))e=new G(this.saveDrawings,t);else{if("lineStyle"!==t)continue;e=new T(this.saveDrawings)}let i=t=>e.openMenu(t);this.menuItem(I(t),i,(()=>{document.removeEventListener("click",e.closeMenu),e._div.style.display="none"}))}this.separator(),this.menuItem("Delete Drawing",(()=>this.drawingTool.delete(d.lastHoveredObject))),t.preventDefault(),this.div.style.left=t.clientX+"px",this.div.style.top=t.clientY+"px",this.div.style.display="block",document.body.addEventListener("click",this._handleClick)}menuItem(t,e,i=null){const s=document.createElement("span");s.classList.add("context-menu-item"),this.div.appendChild(s);const n=document.createElement("span");if(n.innerText=t,n.style.pointerEvents="none",s.appendChild(n),i){let t=document.createElement("span");t.innerText="►",t.style.fontSize="8px",t.style.pointerEvents="none",s.appendChild(t)}if(s.addEventListener("mouseover",(()=>{this.hoverItem&&this.hoverItem.closeAction&&this.hoverItem.closeAction(),this.hoverItem={elem:n,action:e,closeAction:i}})),i){let t;s.addEventListener("mouseover",(()=>t=setTimeout((()=>e(s.getBoundingClientRect())),100))),s.addEventListener("mouseout",(()=>clearTimeout(t)))}else s.addEventListener("click",(t=>{e(t),this.div.style.display="none"}));this.items.push(s)}separator(){const t=document.createElement("div");t.style.width="90%",t.style.height="1px",t.style.margin="3px 0px",t.style.backgroundColor=window.pane.borderColor,this.div.appendChild(t),this.items.push(t)}}class N extends y{_type="RayLine";constructor(t,e){super({...t},e),this._point.time=t.time}updatePoints(...t){for(const e of t)e&&(this._point=e);this.requestUpdate()}_onDrag(t){this._addDiffToPoint(this._point,t.logical,t.price),this.requestUpdate()}_mouseIsOverDrawing(t,e=4){if(!t.point)return!1;const i=this.series.priceToCoordinate(this._point.price),s=this._point.time?this.chart.timeScale().timeToCoordinate(this._point.time):null;return!(!i||!s)&&(Math.abs(i-t.point.y)<e&&t.point.x>s-e)}}class R extends c{_point={x:null,y:null};constructor(t,e){super(e),this._point=t}draw(t){t.useBitmapCoordinateSpace((t=>{if(null==this._point.x)return;const e=t.context,i=this._point.x*t.horizontalPixelRatio;e.lineWidth=this._options.width,e.strokeStyle=this._options.lineColor,u(e,this._options.lineStyle),e.beginPath(),e.moveTo(i,0),e.lineTo(i,t.bitmapSize.height),e.stroke()}))}}class A extends m{_source;_point={x:null,y:null};constructor(t){super(t),this._source=t}update(){const t=this._source._point,e=this._source.chart.timeScale(),i=this._source.series;this._point.x=t.time?e.timeToCoordinate(t.time):e.logicalToCoordinate(t.logical),this._point.y=i.priceToCoordinate(t.price)}renderer(){return new R(this._point,this._source._options)}}class B{_source;_x=null;constructor(t){this._source=t}update(){if(!this._source.chart||!this._source._point)return;const t=this._source._point,e=this._source.chart.timeScale();this._x=t.time?e.timeToCoordinate(t.time):e.logicalToCoordinate(t.logical)}visible(){return!0}tickVisible(){return!0}coordinate(){return this._x??0}text(){return""}textColor(){return"white"}backColor(){return this._source._options.lineColor}}class P extends d{_type="VerticalLine";_paneViews;_timeAxisViews;_point;_callbackName;_startDragPoint=null;constructor(t,e,i=null){super(e),this._point=t,this._paneViews=[new A(this)],this._callbackName=i,this._timeAxisViews=[new B(this)]}updateAllViews(){this._paneViews.forEach((t=>t.update())),this._timeAxisViews.forEach((t=>t.update()))}timeAxisViews(){return this._timeAxisViews}updatePoints(...t){for(const e of t)e&&(!e.time&&e.logical&&(e.time=this.series.dataByIndex(e.logical)?.time||null),this._point=e);this.requestUpdate()}get points(){return[this._point]}_moveToState(t){switch(t){case h.NONE:document.body.style.cursor="default",this._unsubscribe("mousedown",this._handleMouseDownInteraction);break;case h.HOVERING:document.body.style.cursor="pointer",this._unsubscribe("mouseup",this._childHandleMouseUpInteraction),this._subscribe("mousedown",this._handleMouseDownInteraction),this.chart.applyOptions({handleScroll:!0});break;case h.DRAGGING:document.body.style.cursor="grabbing",this._subscribe("mouseup",this._childHandleMouseUpInteraction),this.chart.applyOptions({handleScroll:!1})}this._state=t}_onDrag(t){this._addDiffToPoint(this._point,t.logical,0),this.requestUpdate()}_mouseIsOverDrawing(t,e=4){if(!t.point)return!1;const i=this.chart.timeScale();let s;return s=this._point.time?i.timeToCoordinate(this._point.time):i.logicalToCoordinate(this._point.logical),!!s&&Math.abs(s-t.point.x)<e}_onMouseDown(){this._startDragPoint=null;if(this._latestHoverPoint)return this._moveToState(h.DRAGGING)}_childHandleMouseUpInteraction=()=>{this._handleMouseUpInteraction(),this._callbackName&&window.callbackFunction(`${this._callbackName}_~_${this._point.price.toFixed(8)}`)}}class O{static TREND_SVG='<rect x="3.84" y="13.67" transform="matrix(0.7071 -0.7071 0.7071 0.7071 -5.9847 14.4482)" width="21.21" height="1.56"/><path d="M23,3.17L20.17,6L23,8.83L25.83,6L23,3.17z M23,7.41L21.59,6L23,4.59L24.41,6L23,7.41z"/><path d="M6,20.17L3.17,23L6,25.83L8.83,23L6,20.17z M6,24.41L4.59,23L6,21.59L7.41,23L6,24.41z"/>';static HORZ_SVG='<rect x="4" y="14" width="9" height="1"/><rect x="16" y="14" width="9" height="1"/><path d="M11.67,14.5l2.83,2.83l2.83-2.83l-2.83-2.83L11.67,14.5z M15.91,14.5l-1.41,1.41l-1.41-1.41l1.41-1.41L15.91,14.5z"/>';static RAY_SVG='<rect x="8" y="14" width="17" height="1"/><path d="M3.67,14.5l2.83,2.83l2.83-2.83L6.5,11.67L3.67,14.5z M7.91,14.5L6.5,15.91L5.09,14.5l1.41-1.41L7.91,14.5z"/>';static BOX_SVG='<rect x="8" y="6" width="12" height="1"/><rect x="9" y="22" width="11" height="1"/><path d="M3.67,6.5L6.5,9.33L9.33,6.5L6.5,3.67L3.67,6.5z M7.91,6.5L6.5,7.91L5.09,6.5L6.5,5.09L7.91,6.5z"/><path d="M19.67,6.5l2.83,2.83l2.83-2.83L22.5,3.67L19.67,6.5z M23.91,6.5L22.5,7.91L21.09,6.5l1.41-1.41L23.91,6.5z"/><path d="M19.67,22.5l2.83,2.83l2.83-2.83l-2.83-2.83L19.67,22.5z M23.91,22.5l-1.41,1.41l-1.41-1.41l1.41-1.41L23.91,22.5z"/><path d="M3.67,22.5l2.83,2.83l2.83-2.83L6.5,19.67L3.67,22.5z M7.91,22.5L6.5,23.91L5.09,22.5l1.41-1.41L7.91,22.5z"/><rect x="22" y="9" width="1" height="11"/><rect x="6" y="9" width="1" height="11"/>';static VERT_SVG=O.RAY_SVG;div;activeIcon=null;buttons=[];_commandFunctions;_handlerID;_drawingTool;constructor(t,e,i,s){this._handlerID=t,this._commandFunctions=s,this._drawingTool=new b(e,i,(()=>this.removeActiveAndSave())),this.div=this._makeToolBox(),new M(this.saveDrawings,this._drawingTool),s.push((t=>{if((t.metaKey||t.ctrlKey)&&"KeyZ"===t.code){const t=this._drawingTool.drawings.pop();return t&&this._drawingTool.delete(t),!0}return!1}))}toJSON(){const{...t}=this;return t}_makeToolBox(){let t=document.createElement("div");t.classList.add("toolbox"),this.buttons.push(this._makeToolBoxElement(D,"KeyT",O.TREND_SVG)),this.buttons.push(this._makeToolBoxElement(y,"KeyH",O.HORZ_SVG)),this.buttons.push(this._makeToolBoxElement(N,"KeyR",O.RAY_SVG)),this.buttons.push(this._makeToolBoxElement(S,"KeyB",O.BOX_SVG)),this.buttons.push(this._makeToolBoxElement(P,"KeyV",O.VERT_SVG,!0));for(const e of this.buttons)t.appendChild(e);return t}_makeToolBoxElement(t,e,i,s=!1){const n=document.createElement("div");n.classList.add("toolbox-button");const o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","29"),o.setAttribute("height","29");const r=document.createElementNS("http://www.w3.org/2000/svg","g");r.innerHTML=i,r.setAttribute("fill",window.pane.color),o.appendChild(r),n.appendChild(o);const a={div:n,group:r,type:t};return n.addEventListener("click",(()=>this._onIconClick(a))),this._commandFunctions.push((t=>this._handlerID===window.handlerInFocus&&(!(!t.altKey||t.code!==e)&&(t.preventDefault(),this._onIconClick(a),!0)))),1==s&&(o.style.transform="rotate(90deg)",o.style.transformBox="fill-box",o.style.transformOrigin="center"),n}_onIconClick(t){this.activeIcon&&(this.activeIcon.div.classList.remove("active-toolbox-button"),window.setCursor("crosshair"),this._drawingTool?.stopDrawing(),this.activeIcon===t)?this.activeIcon=null:(this.activeIcon=t,this.activeIcon.div.classList.add("active-toolbox-button"),window.setCursor("crosshair"),this._drawingTool?.beginDrawing(this.activeIcon.type))}removeActiveAndSave=()=>{window.setCursor("default"),this.activeIcon&&this.activeIcon.div.classList.remove("active-toolbox-button"),this.activeIcon=null,this.saveDrawings()};addNewDrawing(t){this._drawingTool.addNewDrawing(t)}clearDrawings(){this._drawingTool.clearDrawings()}saveDrawings=()=>{const t=[];for(const e of this._drawingTool.drawings)t.push({type:e._type,points:e.points,options:e._options});const e=JSON.stringify(t);window.callbackFunction(`save_drawings${this._handlerID}_~_${e}`)};loadDrawings(t){t.forEach((t=>{switch(t.type){case"Box":this._drawingTool.addNewDrawing(new S(t.points[0],t.points[1],t.options));break;case"TrendLine":this._drawingTool.addNewDrawing(new D(t.points[0],t.points[1],t.options));break;case"HorizontalLine":this._drawingTool.addNewDrawing(new y(t.points[0],t.options));break;case"RayLine":this._drawingTool.addNewDrawing(new N(t.points[0],t.options));break;case"VerticalLine":this._drawingTool.addNewDrawing(new P(t.points[0],t.options))}}))}}class V{makeButton;callbackName;div;isOpen=!1;widget;constructor(t,e,i,s,n,o){this.makeButton=t,this.callbackName=e,this.div=document.createElement("div"),this.div.classList.add("topbar-menu"),this.widget=this.makeButton(s+" ↓",null,n,!0,o),this.updateMenuItems(i),this.widget.elem.addEventListener("click",(()=>{if(this.isOpen=!this.isOpen,!this.isOpen)return void(this.div.style.display="none");let t=this.widget.elem.getBoundingClientRect();this.div.style.display="flex",this.div.style.flexDirection="column";let e=t.x+t.width/2;this.div.style.left=e-this.div.clientWidth/2+"px",this.div.style.top=t.y+t.height+"px"})),document.body.appendChild(this.div)}updateMenuItems(t){this.div.innerHTML="",t.forEach((t=>{let e=this.makeButton(t,null,!1,!1);e.elem.addEventListener("click",(()=>{this._clickHandler(e.elem.innerText)})),e.elem.style.margin="4px 4px",e.elem.style.padding="2px 2px",this.div.appendChild(e.elem)})),this.widget.elem.innerText=t[0]+" ↓"}_clickHandler(t){this.widget.elem.innerText=t+" ↓",window.callbackFunction(`${this.callbackName}_~_${t}`),this.div.style.display="none",this.isOpen=!1}}class H{_handler;_div;left;right;constructor(t){this._handler=t,this._div=document.createElement("div"),this._div.classList.add("topbar");const e=t=>{const e=document.createElement("div");return e.classList.add("topbar-container"),e.style.justifyContent=t,this._div.appendChild(e),e};this.left=e("flex-start"),this.right=e("flex-end")}makeSwitcher(t,e,i,s="left"){const n=document.createElement("div");let o;n.style.margin="4px 12px";const r={elem:n,callbackName:i,intervalElements:t.map((t=>{const i=document.createElement("button");i.classList.add("topbar-button"),i.classList.add("switcher-button"),i.style.margin="0px 2px",i.innerText=t,t==e&&(o=i,i.classList.add("active-switcher-button"));const s=H.getClientWidth(i);return i.style.minWidth=s+1+"px",i.addEventListener("click",(()=>r.onItemClicked(i))),n.appendChild(i),i})),onItemClicked:t=>{t!=o&&(o.classList.remove("active-switcher-button"),t.classList.add("active-switcher-button"),o=t,window.callbackFunction(`${r.callbackName}_~_${t.innerText}`))}};return this.appendWidget(n,s,!0),r}makeTextBoxWidget(t,e="left",i=null){if(i){const s=document.createElement("input");return s.classList.add("topbar-textbox-input"),s.value=t,s.style.width=`${s.value.length+2}ch`,s.addEventListener("focus",(()=>{window.textBoxFocused=!0})),s.addEventListener("input",(t=>{t.preventDefault(),s.style.width=`${s.value.length+2}ch`})),s.addEventListener("keydown",(t=>{"Enter"==t.key&&(t.preventDefault(),s.blur())})),s.addEventListener("blur",(()=>{window.callbackFunction(`${i}_~_${s.value}`),window.textBoxFocused=!1})),this.appendWidget(s,e,!0),s}{const i=document.createElement("div");return i.classList.add("topbar-textbox"),i.innerText=t,this.appendWidget(i,e,!0),i}}makeMenu(t,e,i,s,n){return new V(this.makeButton.bind(this),s,t,e,i,n)}makeButton(t,e,i,s=!0,n="left",o=!1){let r=document.createElement("button");r.classList.add("topbar-button"),r.innerText=t,document.body.appendChild(r),r.style.minWidth=r.clientWidth+1+"px",document.body.removeChild(r);let a={elem:r,callbackName:e};if(e){let t;if(o){let e=!1;t=()=>{e=!e,window.callbackFunction(`${a.callbackName}_~_${e}`),r.style.backgroundColor=e?"var(--active-bg-color)":"",r.style.color=e?"var(--active-color)":""}}else t=()=>window.callbackFunction(`${a.callbackName}_~_${r.innerText}`);r.addEventListener("click",t)}return s&&this.appendWidget(r,n,i),a}makeSeparator(t="left"){const e=document.createElement("div");e.classList.add("topbar-seperator");("left"==t?this.left:this.right).appendChild(e)}appendWidget(t,e,i){const s="left"==e?this.left:this.right;i?("left"==e&&s.appendChild(t),this.makeSeparator(e),"right"==e&&s.appendChild(t)):s.appendChild(t),this._handler.reSize()}static getClientWidth(t){document.body.appendChild(t);const e=t.clientWidth;return document.body.removeChild(t),e}}s();return t.Box=S,t.Handler=class{id;commandFunctions=[];wrapper;div;chart;scale;precision=2;series;volumeSeries;legend;_topBar;toolBox;spinner;_seriesList=[];resize_hdr_height=8;watermark;seriesMarkers;constructor(t,i,s,n,r,a=0){this.reSize=this.reSize.bind(this),this.id=t,this.scale={width:i,height:s},this.wrapper=document.createElement("div"),this.wrapper.classList.add("handler"),this.wrapper.style.float=n,this.div=document.createElement("div"),this.div.style.position="relative",this.wrapper.appendChild(this.div),window.containerDiv.append(this.wrapper);const l=document.createElement("div");let h,d;l.classList.add("resize-handle"),this.wrapper.appendChild(l);const c=t=>{const e=t.clientY-h,i=Math.max(50,d+e);this.wrapper.style.height=`${i}px`,this.chart.resize(this.wrapper.offsetWidth,i-this.resize_hdr_height)},p=()=>{document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",p)};l.addEventListener("mousedown",(t=>{t.preventDefault(),h=t.clientY,d=this.wrapper.getBoundingClientRect().height,document.addEventListener("mousemove",c),document.addEventListener("mouseup",p)})),this.chart=this._createChart(),this.series=this.createCandlestickSeries(a),this.volumeSeries=this.createVolumeSeries(a),this.seriesMarkers=e.createSeriesMarkers(this.series,[]),this.legend=new o(this),document.addEventListener("keydown",(t=>{for(let e=0;e<this.commandFunctions.length&&!this.commandFunctions[e](t);e++);})),window.handlerInFocus=this.id,this.wrapper.addEventListener("mouseover",(()=>window.handlerInFocus=this.id)),this.reSize(),r&&window.addEventListener("resize",(()=>this.reSize()))}reSize(){let t=0!==this.scale.height&&this._topBar?._div.offsetHeight||0;if(this.scale.height>=0)this.chart.resize(window.innerWidth*this.scale.width,window.innerHeight*this.scale.height-t-this.resize_hdr_height),this.wrapper.style.width=100*this.scale.width+"%",this.wrapper.style.height=100*this.scale.height+"%";else{var e=Math.ceil(Math.abs(this.scale.height));this.chart.resize(window.containerDiv.offsetWidth*this.scale.width,e-t-this.resize_hdr_height),this.wrapper.style.width=100*this.scale.width+"%",this.wrapper.style.height=`${e}px`}0===this.scale.height||0===this.scale.width?this.toolBox&&(this.toolBox.div.style.display="none"):this.toolBox&&(this.toolBox.div.style.display="flex")}_createChart(){return e.createChart(this.div,{width:window.containerDiv.offsetWidth*this.scale.width,height:this.scale.height<0?Math.ceil(Math.abs(this.scale.height)):window.innerHeight*this.scale.height,layout:{textColor:window.pane.color,background:{color:"rgb(18,24,38)",type:e.ColorType.Solid},fontSize:12,panes:{separatorColor:"lightgrey",separatorHoverColor:"rgba(255, 0, 0, 0.4)",enableResize:!0}},rightPriceScale:{scaleMargins:{top:.3,bottom:.25}},timeScale:{timeVisible:!0,secondsVisible:!1},crosshair:{mode:e.CrosshairMode.Normal,vertLine:{labelBackgroundColor:"rgb(46, 46, 46)"},horzLine:{labelBackgroundColor:"rgb(55, 55, 55)"}},grid:{vertLines:{color:"#444",style:1},horzLines:{color:"#444",style:1}},handleScroll:{vertTouchDrag:!0}})}createCandlestickSeries(t){const i="rgba(39, 157, 130, 100)",s="rgba(200, 97, 100, 100)",n=this.chart.addSeries(e.CandlestickSeries,{upColor:i,borderUpColor:i,wickUpColor:i,downColor:s,borderDownColor:s,wickDownColor:s},t);return n.priceScale().applyOptions({scaleMargins:{top:.2,bottom:.2}}),n}createVolumeSeries(t){const i=this.chart.addSeries(e.HistogramSeries,{color:"#26a69a",priceFormat:{type:"volume"},priceScaleId:"volume_scale"},t);return i.priceScale().applyOptions({scaleMargins:{top:.8,bottom:0}}),i}createLineSeries(t,i,s=0){const n=this.chart.addSeries(e.LineSeries,{...i},s);return this._seriesList.push(n),this.legend.makeSeriesRow(t,n,s),{name:t,series:n}}createHistogramSeries(t,i,s=0){const n=this.chart.addSeries(e.HistogramSeries,{...i},s);return this._seriesList.push(n),this.legend.makeSeriesRow(t,n,s),{name:t,series:n}}createToolBox(){this.toolBox=new O(this.id,this.chart,this.series,this.commandFunctions),this.div.appendChild(this.toolBox.div)}createTopBar(){return this._topBar=new H(this),this.wrapper.prepend(this._topBar._div),this._topBar}toJSON(){const{chart:t,...e}=this;return e}static syncChartsAll(t,e=!1){t.forEach((e=>{e.chart.subscribeCrosshairMove((i=>{t.forEach((t=>{if(t===e)return;if(!i.time)return void t.chart.clearCrosshairPosition();const s=i.seriesData.get(e.series)||null;t.chart.setCrosshairPosition(0,i.time,t.series),s&&t.legend.legendHandler(s,!0)}))}))})),e||t.forEach((e=>{e.chart.timeScale().subscribeVisibleLogicalRangeChange((i=>{t.forEach((t=>{t!==e&&i&&t.chart.timeScale().setVisibleLogicalRange(i)}))}))}))}static syncCharts(t,e,i=!1){function s(t,e,i){i.time?(t.chart.setCrosshairPosition(0,i.time,t.series),e&&t.legend.legendHandler(e,!0)):t.chart.clearCrosshairPosition()}function n(t,e){return e.time&&e.seriesData.get(t)||null}const o=t.chart.timeScale(),r=e.chart.timeScale();e.chart.subscribeCrosshairMove((i=>{s(t,n(e.series,i),i)})),t.chart.subscribeCrosshairMove((i=>{s(e,n(t.series,i),i)})),i||(t.chart.timeScale().subscribeVisibleLogicalRangeChange((t=>{t&&r.setVisibleLogicalRange(t)})),e.chart.timeScale().subscribeVisibleLogicalRangeChange((t=>{t&&o.setVisibleLogicalRange(t)})))}static makeSearchBox(t){const e=document.createElement("div");e.classList.add("searchbox"),e.style.display="none";const i=document.createElement("div");i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1"><path style="fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke:lightgray;stroke-opacity:1;stroke-miterlimit:4;" d="M 15 15 L 21 21 M 10 17 C 6.132812 17 3 13.867188 3 10 C 3 6.132812 6.132812 3 10 3 C 13.867188 3 17 6.132812 17 10 C 17 13.867188 13.867188 17 10 17 Z M 10 17 "/></svg>';const s=document.createElement("input");return s.type="text",e.appendChild(i),e.appendChild(s),t.div.appendChild(e),t.commandFunctions.push((i=>window.handlerInFocus===t.id&&!window.textBoxFocused&&("none"===e.style.display?!!/^[a-zA-Z0-9]$/.test(i.key)&&(e.style.display="flex",s.focus(),!0):("Enter"===i.key||"Escape"===i.key)&&("Enter"===i.key&&window.callbackFunction(`search${t.id}_~_${s.value}`),e.style.display="none",s.value="",!0)))),s.addEventListener("input",(()=>s.value=s.value.toUpperCase())),{window:e,box:s}}static makeSpinner(t){t.spinner=document.createElement("div"),t.spinner.classList.add("spinner"),t.wrapper.appendChild(t.spinner);let e=0;!function i(){t.spinner&&(e+=10,t.spinner.style.transform=`translate(-50%, -50%) rotate(${e}deg)`,requestAnimationFrame(i))}()}static _styleMap={"--bg-color":"backgroundColor","--hover-bg-color":"hoverBackgroundColor","--click-bg-color":"clickBackgroundColor","--active-bg-color":"activeBackgroundColor","--muted-bg-color":"mutedBackgroundColor","--border-color":"borderColor","--color":"color","--active-color":"activeColor"};static setRootStyles(t){const e=document.documentElement.style;for(const[i,s]of Object.entries(this._styleMap))e.setProperty(i,t[s])}createWatermark(t,i,s){this.watermark?this.watermark.applyOptions({lines:[{text:t,color:s,fontSize:i}]}):this.watermark=e.createTextWatermark(this.chart.panes()[0],{horzAlign:"center",vertAlign:"center",lines:[{text:t,color:s,fontSize:i}]})}},t.HorizontalLine=y,t.Legend=o,t.RayLine=N,t.Table=class{_div;callbackName;borderColor;borderWidth;table;rows={};headings;widths;alignments;footer;header;constructor(t,e,i,s,n,o,r=!1,a,l,h,d,c){this._div=document.createElement("div"),this.callbackName=null,this.borderColor=l,this.borderWidth=h,r?(this._div.style.position="absolute",this._div.style.cursor="move"):(this._div.style.position="relative",this._div.style.float=o),this._div.style.zIndex="2000",this.reSize(t,e),this._div.style.display="flex",this._div.style.flexDirection="column",this._div.style.borderRadius="5px",this._div.style.color="white",this._div.style.fontSize="12px",this._div.style.fontVariantNumeric="tabular-nums",this.table=document.createElement("table"),this.table.style.width="100%",this.table.style.borderCollapse="collapse",this._div.style.overflow="hidden",this.headings=i,this.widths=s.map((t=>100*t+"%")),this.alignments=n;let p=this.table.createTHead().insertRow();for(let t=0;t<this.headings.length;t++){let e=document.createElement("th");e.textContent=this.headings[t],e.style.width=this.widths[t],e.style.letterSpacing="0.03rem",e.style.padding="0.2rem 0px",e.style.fontWeight="500",e.style.textAlign="center",0!==t&&(e.style.borderLeft=h+"px solid "+l),e.style.position="sticky",e.style.top="0",e.style.backgroundColor=c.length>0?c[t]:a,e.style.color=d[t],p.appendChild(e)}let u,_,m=document.createElement("div");if(m.style.overflowY="auto",m.style.overflowX="hidden",m.style.backgroundColor=a,m.appendChild(this.table),this._div.appendChild(m),window.containerDiv.appendChild(this._div),!r)return;let v=t=>{this._div.style.left=t.clientX-u+"px",this._div.style.top=t.clientY-_+"px"},g=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",g)};this._div.addEventListener("mousedown",(t=>{u=t.clientX-this._div.offsetLeft,_=t.clientY-this._div.offsetTop,document.addEventListener("mousemove",v),document.addEventListener("mouseup",g)}))}divToButton(t,e){t.addEventListener("mouseover",(()=>t.style.backgroundColor="rgba(60, 60, 60, 0.6)")),t.addEventListener("mouseout",(()=>t.style.backgroundColor="transparent")),t.addEventListener("mousedown",(()=>t.style.backgroundColor="rgba(60, 60, 60)")),t.addEventListener("click",(()=>window.callbackFunction(e))),t.addEventListener("mouseup",(()=>t.style.backgroundColor="rgba(60, 60, 60, 0.6)"))}newRow(t,e=!1){let i=this.table.insertRow();i.style.cursor="default";for(let s=0;s<this.headings.length;s++){let n=i.insertCell();n.style.width=this.widths[s],n.style.textAlign=this.alignments[s],n.style.border=this.borderWidth+"px solid "+this.borderColor,e&&this.divToButton(n,`${this.callbackName}_~_${t};;;${this.headings[s]}`)}e||this.divToButton(i,`${this.callbackName}_~_${t}`),this.rows[t]=i}deleteRow(t){this.table.deleteRow(this.rows[t].rowIndex),delete this.rows[t]}clearRows(){let t=Object.keys(this.rows).length;for(let e=0;e<t;e++)this.table.deleteRow(-1);this.rows={}}_getCell(t,e){return this.rows[t].cells[this.headings.indexOf(e)]}updateCell(t,e,i){this._getCell(t,e).textContent=i}styleCell(t,e,i,s){this._getCell(t,e).style[i]=s}makeSection(t,e,i,s=!1){let n=document.createElement("div");n.style.display="flex",n.style.width="100%",n.style.padding="3px 0px",n.style.backgroundColor="rgb(30, 30, 30)","footer"===e?this._div.appendChild(n):this._div.prepend(n);const o=[];for(let e=0;e<i;e++){let i=document.createElement("div");n.appendChild(i),i.style.flex="1",i.style.textAlign="center",s&&(this.divToButton(i,`${t}_~_${e}`),i.style.borderRadius="2px"),o.push(i)}"footer"===e?this.footer=o:this.header=o}reSize(t,e){this._div.style.width=t<=1?100*t+"%":t+"px",this._div.style.height=e<=1?100*e+"%":e+"px"}},t.ToolBox=O,t.TopBar=H,t.TrendLine=D,t.VerticalLine=P,t.globalParamInit=s,t.htmlToElement=n,t.paneStyleDefault=i,t.setCursor=t=>{t&&(window.cursor=t),document.body.style.cursor=window.cursor},t}({},LightweightCharts);
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html lang="">
3
+ <head>
4
+ <title>bn_lightweight-charts-python</title>
5
+ <link rel="stylesheet" href="styles.css">
6
+ <script src="./lightweight-charts.js"></script>
7
+ <meta name="viewport" content ="width=device-width, initial-scale=1">
8
+ <meta charset="UTF-8">
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ /*overflow: hidden;*/
14
+ overflow-y: auto;
15
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
16
+ Cantarell, "Helvetica Neue", sans-serif;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div id="container"></div>
22
+ <script src="./bundle.js"></script>
23
+ </body>
24
+ </html>
25
+
@@ -0,0 +1,144 @@
1
+ <!DOCTYPE html>
2
+ <html lang="">
3
+ <head>
4
+ <title>bn_lightweight-charts-python</title>
5
+ <link rel="stylesheet" href="styles.css">
6
+ <script src="./lightweight-charts.js"></script>
7
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
8
+ <meta charset="UTF-8">
9
+ <script src=" https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/js/bootstrap.bundle.min.js "></script>
10
+ <link href=" https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/css/bootstrap.min.css " rel="stylesheet">
11
+
12
+ <style>
13
+ body {
14
+ margin: 0;
15
+ padding: 0;
16
+ /*overflow: hidden;*/
17
+ overflow-y: auto;
18
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
19
+ Cantarell, "Helvetica Neue", sans-serif;
20
+ }
21
+
22
+ .tableview {
23
+ background: darkgrey;
24
+ color: black;
25
+ border-collapse: separate;
26
+ border-spacing: 0;
27
+ /*width: 100%;*/
28
+ border: solid #ccc 1px;
29
+ -moz-border-radius: 6px;
30
+ -webkit-border-radius: 6px;
31
+ border-radius: 6px;
32
+ font-family: 'trebuchet MS' , 'Lucida sans' , Arial;
33
+ font-size: 16px;
34
+ }
35
+
36
+ .tableview > tbody > tr:hover {
37
+ background: #fbf8e9;
38
+ }
39
+
40
+ .tableview > tbody > tr > td, .tableview > thead > tr > th {
41
+ border-left: 1px solid #ccc;
42
+ border-top: 1px solid #ccc;
43
+ padding: 4px;
44
+ text-align: left;
45
+ }
46
+
47
+ .tableview > thead > tr > th, .tableview > thead > tr > td {
48
+ background-color: #dce9f9;
49
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
50
+ background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
51
+ background-image: -moz-linear-gradient(top, #ebf3fc, #dce9f9);
52
+ background-image: -ms-linear-gradient(top, #ebf3fc, #dce9f9);
53
+ background-image: -o-linear-gradient(top, #ebf3fc, #dce9f9);
54
+ background-image: linear-gradient(to bottom, #ebf3fc, #dce9f9);
55
+ -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
56
+ -moz-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
57
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
58
+ border-top: none;
59
+ text-shadow: 0 1px 0 rgba(255,255,255,.5);
60
+ }
61
+
62
+ </style>
63
+ </head>
64
+ <body data-bs-theme="dark">
65
+ <div style="z-index:99999" class="offcanvas offcanvas-start w-10" tabindex="-1" id="offcanvas" data-bs-keyboard="false" data-bs-backdrop="false">
66
+ <div class="offcanvas-header">
67
+ <h6 class="offcanvas-title d-none d-sm-block" id="offcanvas">List of instruments</h6>
68
+ <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
69
+ </div>
70
+ <div class="offcanvas-body px-0">
71
+ <!---->
72
+ <div class="d-flex flex-column align-items-stretch flex-shrink-0 bg-white" style="width: 380px;">
73
+ <div id="slist" class="list-group list-group-flush border-bottom scrollarea">
74
+
75
+ <a href="#" class="list-group-item list-group-item-action active py-2 lh-tight_">
76
+ <div class="d-flex w-100 align-items-center justify-content-between">
77
+ <strong class="mb-1">List of instruments</strong>
78
+ </div>
79
+ </a>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ </div>
84
+
85
+ <button style="width: 40px; height: 40px; z-index: 1000; position: absolute; left: 10px; top: 2px;" class="btn btn-warning float-start" data-bs-toggle="offcanvas" data-bs-target="#offcanvas" role="button">
86
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16">
87
+ <path fill-rule="evenodd" d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5"/>
88
+ </svg>
89
+ </button>
90
+
91
+
92
+ <nav>
93
+ <div style="margin-left:70px;" class="nav nav-tabs" id="nav-tab" role="tablist">
94
+ <button class="nav-link active" id="nav-home-tab" data-bs-toggle="tab" data-bs-target="#nav-chart" type="button" role="tab" aria-controls="nav-chart" aria-selected="true">Chart</button>
95
+ <button class="nav-link" id="nav-trades-tab" data-bs-toggle="tab" data-bs-target="#nav-trades" type="button" role="tab" aria-controls="nav-trades" aria-selected="false">Trades</button>
96
+ <button class="nav-link" id="nav-perf-tab" data-bs-toggle="tab" data-bs-target="#nav-perf" type="button" role="tab" aria-controls="nav-perf" aria-selected="false">Performance</button>
97
+ </div>
98
+ </nav>
99
+ <div class="tab-content" id="nav-tabContent">
100
+ <div class="tab-pane fade show active" id="nav-chart" role="tabpanel" aria-labelledby="nav-chart-tab" tabindex="0">
101
+ <div id="container"></div>
102
+ </div>
103
+ <div class="tab-pane fade" id="nav-trades" role="tabpanel" aria-labelledby="nav-trades-tab" tabindex="1">
104
+ <div style="padding-left: 20px; padding-top: 10px; padding-bottom: 10px;">
105
+ <h6>Trades for [ <span id="trades-title"></span> ] </h6>
106
+ <table id="trades" class="tableview" style="border-collapse: collapse;">
107
+ <thead style="position: sticky; top: 0;">
108
+ <th> Ref </th>
109
+ <th> Position </th>
110
+ <th> TradeId </th>
111
+ <th> Open Date </th>
112
+ <th> Open Price</th>
113
+ <th> Close Date </th>
114
+ <th> Close Price </th>
115
+ <th> Profit </th>
116
+ <th> Profit% </th>
117
+ <th> Comm </th>
118
+ <th> Bars Help </th>
119
+ </thead>
120
+ <tbody>
121
+ </tbody>
122
+ </table>
123
+ </div>
124
+ </div>
125
+ <div class="tab-pane fade" id="nav-perf" role="tabpanel" aria-labelledby="nav-perf-tab" tabindex="2">
126
+ <div style="padding-left: 20px; padding-top: 10px; padding-bottom: 10px;">
127
+ <h6>Performance Report for [ <span id="strategy-title"></span> ] </h6>
128
+ <table id="performance" class="tableview">
129
+ <thead>
130
+ <th> Metric </th>
131
+ <th> Value </th>
132
+ </thead>
133
+ <tbody>
134
+ </tbody>
135
+ </table>
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <script src="./bundle.js"></script>
141
+ </body>
142
+ </html>
143
+
144
+