UNPKG

fejn-kline

Version:

kline chart

90 lines (72 loc) 36.6 kB
"use strict";const fejnNumber=require("fejn-number"),klinecharts=require("klinecharts"),utils=require("./shared/fejn-kline.Byndoykj.cjs"),getStyles=t=>{const e=utils.styles[t]||utils.styles.dark;return{grid:{show:!0,horizontal:{show:!0,size:1,color:e.grid,style:klinecharts.LineType.Dashed,dashedValue:[2,2]},vertical:{show:!0,size:1,color:e.grid,style:klinecharts.LineType.Dashed,dashedValue:[2,2]}},candle:{type:klinecharts.CandleType.CandleSolid,bar:{upColor:e.up,downColor:e.down,noChangeColor:e.up,upBorderColor:e.up,downBorderColor:e.down,noChangeBorderColor:e.up,upWickColor:e.up,downWickColor:e.down,noChangeWickColor:e.up},area:{lineSize:2,lineColor:"#2196F3",value:"close",smooth:!0,backgroundColor:[{offset:0,color:"rgba(33, 150, 243, 0.01)"},{offset:1,color:"rgba(33, 150, 243, 0.2)"}],point:{show:!0,color:"blue",radius:4,rippleColor:"0.3",rippleRadius:8,animation:!0,animationDuration:1e3}},priceMark:{show:!0,high:{show:!0,color:e.price_mark,textOffset:4,textSize:e.text_size,textFamily:e.family,textWeight:"normal"},low:{show:!0,color:e.price_mark,textOffset:4,textSize:e.text_size,textFamily:e.family,textWeight:"normal"},last:{show:!0,upColor:e.up,downColor:e.down,noChangeColor:e.up,line:{show:!0,style:klinecharts.LineType.Dashed,dashedValue:[4,4],size:.4},text:{show:!0,style:klinecharts.PolygonType.Fill,size:e.text_size,paddingLeft:7,paddingTop:3,paddingRight:5,paddingBottom:2,borderStyle:klinecharts.LineType.Solid,borderSize:1,borderColor:"transparent",borderDashedValue:[2,2],color:"#FFFFFF",family:e.family,weight:"normal",borderRadius:2}}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:klinecharts.TooltipShowRule.Always,showType:klinecharts.TooltipShowType.Standard,custom:[],defaultValue:"n/a",rect:{position:"fixed",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,offsetLeft:4,offsetTop:4,offsetRight:4,offsetBottom:4,borderRadius:4,borderSize:1,borderColor:"#f2f3f5",color:"#FEFEFE"},text:{size:11,family:e.family,weight:"normal",color:e.tooltip_color,marginLeft:12,marginTop:12,marginRight:-6,marginBottom:0},icons:[]}},indicator:{ohlc:{upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity},bars:[{style:klinecharts.PolygonType.Fill,borderStyle:klinecharts.LineType.Solid,borderSize:1,borderDashedValue:[2,2],upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity}],lines:[{style:klinecharts.LineType.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#FF9600"},{style:klinecharts.LineType.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#935EBD"},{style:klinecharts.LineType.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#2196F3"},{style:klinecharts.LineType.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#E11D74"},{style:klinecharts.LineType.Solid,smooth:!1,size:.4,dashedValue:[2,2],color:"#01C5C4"}],circles:[{style:klinecharts.PolygonType.Fill,borderStyle:klinecharts.LineType.Solid,borderSize:1,borderDashedValue:[2,2],upColor:e.up_opacity,downColor:e.down_opacity,noChangeColor:e.up_opacity}],lastValueMark:{show:!1,text:{show:!1,style:klinecharts.PolygonType.Fill,color:"#FFFFFF",size:e.text_size,family:e.family,weight:"normal",borderStyle:klinecharts.LineType.Solid,borderSize:1,borderDashedValue:[2,2],paddingLeft:7,paddingTop:3,paddingRight:5,paddingBottom:2,borderRadius:2}},tooltip:{offsetLeft:4,offsetTop:6,offsetRight:4,offsetBottom:6,showRule:klinecharts.TooltipShowRule.Always,showType:klinecharts.TooltipShowType.Standard,showName:!0,showParams:!0,defaultValue:"n/a",text:{size:12,family:e.family,weight:"normal",color:e.tooltip_color,marginTop:12,marginRight:-6,marginBottom:0,marginLeft:12},icons:[]}},xAxis:{show:!0,size:"auto",axisLine:{show:!0,color:e.scales_line,size:1},tickText:{show:!0,color:e.scales_text,family:e.family,weight:"normal",size:e.text_size,marginStart:3,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:e.scales_line}},yAxis:{show:!0,size:"auto",position:klinecharts.YAxisPosition.Right,type:klinecharts.YAxisType.Normal,inside:!1,reverse:!1,axisLine:{show:!0,color:e.scales_line,size:1},tickText:{show:!0,color:e.scales_text,family:e.family,weight:"normal",size:e.text_size,marginStart:3,marginEnd:6},tickLine:{show:!0,size:1,length:3,color:e.scales_line}},separator:{size:1,color:e.scales_line,fill:!0,activeBackgroundColor:"rgba(230, 230, 230, .15)"},crosshair:{show:!0,horizontal:{show:!0,line:{show:!0,style:klinecharts.LineType.Dashed,dashedValue:[6,6],size:1,color:e.cross_line},text:{show:!0,style:klinecharts.PolygonType.Fill,color:e.crosshair,size:e.text_size,family:e.family,weight:"normal",borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2],borderSize:1,borderColor:e.crosshair_bg,borderRadius:2,paddingLeft:7,paddingRight:5,paddingTop:3,paddingBottom:2,backgroundColor:e.crosshair_bg}},vertical:{show:!0,line:{show:!0,style:klinecharts.LineType.Dashed,dashedValue:[6,6],size:1,color:"#888888"},text:{show:!0,style:klinecharts.PolygonType.Fill,color:"#FFFFFF",size:e.text_size,family:e.family,weight:"normal",borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2],borderSize:1,borderColor:e.crosshair_bg,borderRadius:2,paddingLeft:2,paddingRight:2,paddingTop:3,paddingBottom:2,backgroundColor:e.crosshair_bg}}},overlay:{point:{color:"#1677FF",borderColor:"rgba(22, 119, 255, 0.35)",borderSize:1,radius:5,activeColor:"#1677FF",activeBorderColor:"rgba(22, 119, 255, 0.35)",activeBorderSize:3,activeRadius:5},line:{style:klinecharts.LineType.Solid,smooth:!1,color:"#1677FF",size:1,dashedValue:[2,2]},rect:{style:klinecharts.PolygonType.Fill,color:"rgba(22, 119, 255, 0.25)",borderColor:"#1677FF",borderSize:1,borderRadius:0,borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2]},polygon:{style:klinecharts.PolygonType.Fill,color:"#1677FF",borderColor:"#1677FF",borderSize:1,borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2]},circle:{style:klinecharts.PolygonType.Fill,color:"rgba(22, 119, 255, 0.25)",borderColor:"#1677FF",borderSize:1,borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2]},arc:{style:klinecharts.LineType.Solid,color:"#1677FF",size:1,dashedValue:[2,2]},text:{color:"#1677FF",size:12,family:e.family,weight:"normal",borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2],borderSize:0,borderRadius:2,borderColor:"#1677FF",paddingLeft:0,paddingRight:0,paddingTop:0,paddingBottom:0,backgroundColor:"transparent"},rectText:{style:klinecharts.PolygonType.Fill,color:"#FFFFFF",size:12,family:e.family,weight:"normal",borderStyle:klinecharts.LineType.Solid,borderDashedValue:[2,2],borderSize:1,borderRadius:2,borderColor:"#1677FF",paddingLeft:4,paddingRight:4,paddingTop:4,paddingBottom:4,backgroundColor:"#1677FF"}}}},n={o:"O",h:"H",l:"L",c:"C"},c={[utils.Lang["en-US"]]:n,[utils.Lang["vi-VN"]]:n,[utils.Lang["es-ES"]]:n,[utils.Lang["id-ID"]]:n,[utils.Lang["zh-CN"]]:{o:"\u5F00=",h:"\u9AD8=",l:"\u4F4E=",c:"\u6536="},[utils.Lang["zh-TW"]]:{o:"\u958B=",h:"\u9AD8=",l:"\u4F4E=",c:"\u6536="},[utils.Lang["ja-JP"]]:{o:"\u59CB\u5024",h:"\u9AD8\u5024",l:"\u5B89\u5024",c:"\u7D42\u5024"},[utils.Lang["ru-RU"]]:{o:"\u041E\u0422\u041A\u0420",h:"\u041C\u0410\u041A\u0421",l:"\u041C\u0418\u041D",c:"\u0417\u0410\u041A\u0420"},[utils.Lang["tr-TR"]]:{o:"A",h:"Y",l:"D",c:"K"},[utils.Lang["pt-BR"]]:{o:"Abr",h:"M\xE1x.",l:"M\xEDn.",c:"Fch"},[utils.Lang["fr-FR"]]:{o:"O",h:"H",l:"B",c:"C"},[utils.Lang["th-TH"]]:{o:"\u0E40\u0E1B\u0E34\u0E14",h:"\u0E2A\u0E39\u0E07",l:"\u0E15\u0E48\u0E33",c:"\u0E1B\u0E34\u0E14"},[utils.Lang["ko-KR"]]:{o:"\uC2DC",h:"\uACE0",l:"\uC800",c:"\uC885"}};function w(t){const{data:e,pricePrecision:i,locale:p}=t,h=c[utils.Lang[p]],r=fejnNumber.minus(e.close,e.open),_=fejnNumber.times(fejnNumber.div(r,e.open),100),a=fejnNumber.lt(r,0)?t.downColor:t.upColor,l=`${fejnNumber.gt(r,0)?"+":""}${fejnNumber.toFixed(r,i,7)}`,g=`(${fejnNumber.gt(_,0)?"+":""}${fejnNumber.toFixed(_,2,7)}%)`;return[{title:h.o,value:{text:fejnNumber.toFixed(e.open,i),color:a}},{title:h.h,value:{text:fejnNumber.toFixed(e.high,i),color:a}},{title:h.l,value:{text:fejnNumber.toFixed(e.low,i),color:a}},{title:h.c,value:{text:fejnNumber.toFixed(e.close,i),color:a}},{title:"",value:{text:`${l} ${g}`,color:a}}]}function L(t,e){if(typeof t=="string"&&!t.length)throw new Error("Dom id \u4E0D\u80FD\u4E3A\u7A7A");e.styles||(e.styles=getStyles(e?.theme||utils.theme)),e.locale=utils.Lang[e.locale]||utils.lang;const i=klinecharts.init(t,e);if(!i)return null;i.$updateTooltip=()=>{const{candle:h}=i.getStyles();h.tooltip.custom=({current:r},{bar:_})=>{const a={data:r,pricePrecision:i.getPriceVolumePrecision().price,locale:i.getLocale(),upColor:_.upColor,downColor:_.downColor};return w(a)},i.setStyles({candle:h})},i.$setTheme=h=>{const r=getStyles(h);r&&i.setStyles(r)};const p=()=>{const h=new ResizeObserver(()=>{setTimeout(()=>{i.resize()},0)});i.getDom()&&h.observe(i.getDom())};return i.$addDefaultMa=()=>{i.getIndicatorByPaneId("candle_pane","MA")&&i.removeIndicator("candle_pane","MA"),i.createIndicator({name:"MA",calcParams:[10,30,60]},!1,{id:"candle_pane",dragEnabled:!0})},i.$addVol=()=>{i.getIndicatorByPaneId("default_vol","VOL")&&i.removeIndicator("default_vol","VOL"),i.createIndicator({name:"VOL",calcParams:[20],precision:i.getPriceVolumePrecision().volume,figures:[{key:"ma1",title:"",type:"line"},{key:"volume",title:"",type:"bar",baseValue:0,styles({current:h},r,{bars:_}){const{close:a,open:l}=h.kLineData||{close:0,open:0},{upColor:g,downColor:S}=_[0];return{color:fejnNumber.lt(fejnNumber.minus(a,l),0)?S:g}}}]},!1,{id:"default_vol"})},i.$screenshot=()=>{const h=i.getConvertPictureUrl(!0),r=new Image,_=window.open("","_blank");r.src=h,_?.document.write(r.outerHTML),_?.document.close()},i.$setGraph=h=>{const r=i.getStyles();r.candle.type=utils.graphs.simple_map[h]||utils.graphs.simple_map[1],i.setStyles(r)},p(),i.$updateTooltip(),i.setLeftMinVisibleBarCount(2),i.setRightMinVisibleBarCount(2),i.setOffsetRightDistance(42),i.setBarSpace(6.2),i.setPaneOptions({id:"candle_pane",gap:{top:.3}}),e.showMa&&i.$addDefaultMa(),e.showVol&&i.$addVol(),i}function m$1(t,e){const i={...t};for(const p in e)typeof t[p]!="object"||t[p]===null||Array.isArray(t[p])?e[p]!==void 0&&(i[p]=e[p]):i[p]=m$1(t[p],e[p]);return i}const I={width:800,height:500,interval:"1D",timezone:"Etc/UTC",container:"",library_path:"",locale:"en",widgetbar:{details:!1,watchlist:!1,news:!1,datawindow:!1,watchlist_settings:{default_symbols:[]}},overrides:{"mainSeriesProperties.showCountdown":!1},studies_overrides:{},trading_customization:{position:{},order:{}},brokerConfig:{configFlags:{}},fullscreen:!1,autosize:!1,disabled_features:[],enabled_features:[],debug:!1,logo:{},time_frames:[{text:"5y",resolution:"1W"},{text:"1y",resolution:"1W"},{text:"6m",resolution:"120"},{text:"3m",resolution:"60"},{text:"1m",resolution:"30"},{text:"5d",resolution:"5"},{text:"1d",resolution:"1"}],client_id:"0",user_id:"0",charts_storage_api_version:"1.0",favorites:{intervals:[],chartTypes:[],indicators:[],drawingTools:[]}},y=JSON.parse('[{"iso":"ar","dir":"rtl","language":"ar"},{"iso":"pt","dir":"ltr","language":"pt"},{"iso":"ca","dir":"ltr","language":"ca_ES"},{"iso":"cs","dir":"ltr","language":"cs"},{"iso":"de","dir":"ltr","language":"de"},{"iso":"en","dir":"ltr","language":"en"},{"iso":"es","dir":"ltr","language":"es"},{"iso":"fa","dir":"rtl","language":"fa"},{"iso":"fr","dir":"ltr","language":"fr"},{"iso":"he","dir":"rtl","language":"he_IL"},{"iso":"hu","dir":"ltr","language":"hu_HU"},{"iso":"id","dir":"ltr","language":"id_ID"},{"iso":"en","dir":"ltr","language":"en"},{"iso":"it","dir":"ltr","language":"it"},{"iso":"ja","dir":"ltr","language":"ja"},{"iso":"ko","dir":"ltr","language":"ko"},{"iso":"ms","dir":"ltr","language":"ms_MY"},{"iso":"pl","dir":"ltr","language":"pl"},{"iso":"ru","dir":"ltr","language":"ru"},{"iso":"sv","dir":"ltr","language":"sv"},{"iso":"th","dir":"ltr","language":"th"},{"iso":"tr","dir":"ltr","language":"tr"},{"iso":"vi","dir":"ltr","language":"vi"},{"iso":"zh-Hans","dir":"ltr","language":"zh"},{"iso":"zh-Hant","dir":"ltr","language":"zh_TW"},{"iso":"el","dir":"ltr","language":"el"},{"iso":"nl","dir":"ltr","language":"nl_NL"},{"iso":"ro","dir":"ltr","language":"ro"}]');let f$1=!1;function b$1(){return"CL v26.003 (internal id e793d706 @ 2023-10-05T20:27:44.510Z)"}const A=class{constructor(t){var e,i;if(this._id=`tradingview_${(1048576*(1+Math.random())|0).toString(16).substring(1)}`,this._ready=!1,this._readyHandlers=[],this._onWindowResize=this._autoResizeChart.bind(this),!t.datafeed)throw new Error("Datafeed is not defined");!((e=t.overrides)===null||e===void 0)&&e["mainSeriesProperties.priceAxisProperties.lockScale"]&&(console.warn("mainSeriesProperties.priceAxisProperties.lockScale can not be set to true within the widget constructor"),delete t.overrides["mainSeriesProperties.priceAxisProperties.lockScale"]),this._options=m$1(I,t),((i=this._options.theme)!==null&&i!==void 0?i:"light").toLowerCase()==="dark"&&this._options.loading_screen===void 0&&(this._options.loading_screen={backgroundColor:"#131722"}),this._options.debug&&(f$1||(f$1=!0,console.log("Using CL v26.003 (internal id e793d706 @ 2023-10-05T20:27:44.510Z)"))),this._create()}setDebugMode(t){this._innerAPI().setDebugMode(t)}onChartReady(t){this._ready?t.call(this):this._readyHandlers.push(t)}headerReady(){return this._innerWindowLoaded.then(()=>this._innerWindow().headerReady())}onGrayedObjectClicked(t){this._doWhenInnerApiLoaded(e=>{e.onGrayedObjectClicked(t)})}onShortcut(t,e){this._doWhenInnerWindowLoaded(i=>{i.createShortcutAction(t,e)})}subscribe(t,e){this._doWhenInnerApiLoaded(i=>{i.subscribe(t,e)})}unsubscribe(t,e){this._doWhenInnerApiLoaded(i=>{i.unsubscribe(t,e)})}chart(t){return this._innerAPI().chart(t)}getLanguage(){return this._options.locale}setSymbol(t,e,i){this._innerAPI().changeSymbol(t,e,i)}remove(){window.removeEventListener("resize",this._onWindowResize),this._readyHandlers.splice(0,this._readyHandlers.length),delete window[this._id],this._iFrame.parentNode&&this._iFrame.parentNode.removeChild(this._iFrame)}closePopupsAndDialogs(){this._doWhenInnerApiLoaded(t=>{t.closePopupsAndDialogs()})}selectLineTool(t,e){this._innerAPI().selectLineTool(t,e)}selectedLineTool(){return this._innerAPI().selectedLineTool()}save(t){this._innerAPI().saveChart(t)}load(t,e){this._innerAPI().loadChart({json:t,extendedData:e})}getSavedCharts(t){this._innerAPI().getSavedCharts(t)}loadChartFromServer(t){this._innerAPI().loadChartFromServer(t)}saveChartToServer(t,e,i){this._innerAPI().saveChartToServer(t,e,i)}removeChartFromServer(t,e){this._innerAPI().removeChartFromServer(t,e)}onContextMenu(t){this._doWhenInnerApiLoaded(e=>{e.onContextMenu(t)})}createButton(t){return this._innerWindow().createButton(t)}createDropdown(t){return this._innerWindow().createDropdown(t)}showNoticeDialog(t){this._doWhenInnerApiLoaded(e=>{e.showNoticeDialog(t)})}showConfirmDialog(t){this._doWhenInnerApiLoaded(e=>{e.showConfirmDialog(t)})}showLoadChartDialog(){this._innerAPI().showLoadChartDialog()}showSaveAsChartDialog(){this._innerAPI().showSaveAsChartDialog()}symbolInterval(){return this._innerAPI().getSymbolInterval()}mainSeriesPriceFormatter(){return this._innerAPI().mainSeriesPriceFormatter()}getIntervals(){return this._innerAPI().getIntervals()}getStudiesList(){return this._innerAPI().getStudiesList()}getStudyInputs(t){return this._innerAPI().getStudyInputs(t)}getStudyStyles(t){return this._innerAPI().getStudyStyles(t)}addCustomCSSFile(t){this._innerWindow().addCustomCSSFile(t)}applyOverrides(t){this._options=m$1(this._options,{overrides:t}),this._doWhenInnerWindowLoaded(e=>{e.applyOverrides(t)})}applyStudiesOverrides(t){this._doWhenInnerWindowLoaded(e=>{e.applyStudiesOverrides(t)})}watchList(){return this._innerAPI().watchlist()}news(){return this._innerAPI().news()}widgetbar(){return this._innerAPI().widgetbar()}activeChart(){return this._innerAPI().activeChart()}activeChartIndex(){return this._innerAPI().activeChartIndex()}setActiveChart(t){return this._innerAPI().setActiveChart(t)}chartsCount(){return this._innerAPI().chartsCount()}layout(){return this._innerAPI().layout()}setLayout(t){this._innerAPI().setLayout(t)}layoutName(){return this._innerAPI().layoutName()}changeTheme(t,e){return this._innerWindow().changeTheme(t,e)}getTheme(){return this._innerWindow().getTheme()}takeScreenshot(){this._doWhenInnerApiLoaded(t=>{t.takeScreenshot()})}lockAllDrawingTools(){return this._innerAPI().lockAllDrawingTools()}hideAllDrawingTools(){return this._innerAPI().hideAllDrawingTools()}drawOnAllCharts(t){this._innerAPI().drawOnAllCharts(t)}magnetEnabled(){return this._innerAPI().magnetEnabled()}magnetMode(){return this._innerAPI().magnetMode()}undoRedoState(){return this._innerAPI().undoRedoState()}setIntervalLinkingEnabled(t){this._innerAPI().setIntervalLinkingEnabled(t)}setDateRangeLinkingEnabled(t){this._innerAPI().setDateRangeLinkingEnabled(t)}setTimeFrame(t){this._innerAPI().setTimeFrame(t)}symbolSync(){return this._innerAPI().symbolSync()}intervalSync(){return this._innerAPI().intervalSync()}crosshairSync(){return this._innerAPI().crosshairSync()}timeSync(){return this._innerAPI().timeSync()}dateRangeSync(){return this._innerAPI().dateRangeSync()}setFeatureEnabled(t,e){this._innerAPI().setFeatureEnabled(t,e)}getAllFeatures(){return this._innerWindow().getAllFeatures()}clearUndoHistory(){return this._innerAPI().clearUndoHistory()}undo(){return this._innerAPI().undo()}redo(){return this._innerAPI().redo()}startFullscreen(){this._innerAPI().startFullscreen()}exitFullscreen(){this._innerAPI().exitFullscreen()}takeClientScreenshot(t){return this._innerAPI().takeClientScreenshot(t)}navigationButtonsVisibility(){return this._innerWindow().getNavigationButtonsVisibility()}paneButtonsVisibility(){return this._innerWindow().getPaneButtonsVisibility()}dateFormat(){return this._innerWindow().getDateFormat()}timeHoursFormat(){return this._innerWindow().getTimeHoursFormat()}currencyAndUnitVisibility(){return this._innerWindow().getCurrencyAndUnitVisibility()}supportedChartTypes(){return this._innerAPI().supportedChartTypes()}watermark(){return this._innerAPI().watermark()}customSymbolStatus(){return this._innerWindow().customSymbolStatus()}setCSSCustomProperty(t,e){if(t.startsWith("--")===!1)throw new Error("customPropertyName should begin with a double hyphen");this._innerWindow().document.body.style.setProperty(t,e)}getCSSCustomPropertyValue(t){if(t.startsWith("--")===!1)throw new Error("customPropertyName should begin with a double hyphen");const e=this._innerWindow().document.body;return e.style.getPropertyValue(t)||getComputedStyle(e).getPropertyValue(t)}linking(){return this._innerAPI().linking}_innerAPI(){return this._innerWindow().tradingViewApi}_innerWindow(){return this._iFrame.contentWindow}_doWhenInnerWindowLoaded(t){this._ready?t(this._innerWindow()):this._innerWindowLoaded.then(()=>{t(this._innerWindow())})}_doWhenInnerApiLoaded(t){this._doWhenInnerWindowLoaded(e=>{e.doWhenApiIsReady(()=>t(this._innerAPI()))})}_autoResizeChart(){this._options.fullscreen&&(this._iFrame.style.height=window.innerHeight+"px",P&&setTimeout(()=>{this._iFrame.style.height=window.innerHeight+"px"},30))}_create(){var t,e;const i=(e=(t=this._options.enabled_features)===null||t===void 0?void 0:t.includes("iframe_loading_compatibility_mode"))!==null&&e!==void 0&&e,[p,h]=this._render(!i),r=this._options.container,_=typeof r=="string"?document.getElementById(r):r;if(_===null)throw new Error(`There is no such element - #${this._options.container}`);_.innerHTML=p,this._iFrame=_.querySelector(`#${this._id}`);const a=this._iFrame;i&&(a.contentWindow?(a.contentWindow.document.open(),a.contentWindow.document.write(h),a.contentWindow.document.close()):console.warn("Unable to locate contentWindow for the created iframe. Please try disabling the `iframe_loading_compatibility_mode` featureset.")),(this._options.autosize||this._options.fullscreen)&&(a.style.width="100%",this._options.fullscreen||(a.style.height="100%")),window.addEventListener("resize",this._onWindowResize),this._onWindowResize(),this._innerWindowLoaded=new Promise(l=>{const g=()=>{a.removeEventListener("load",g,!1),l()};a.addEventListener("load",g,!1)}),this._innerWindowLoaded.then(()=>{try{this._innerWindow().widgetReady(()=>{this._ready=!0;for(const l of this._readyHandlers)try{l.call(this)}catch(g){console.error(g)}this._innerWindow().initializationFinished()})}catch(l){if(l instanceof Error&&/widgetReady is not a function/.test(l.message))throw new Error(`There was an error when loading the library. Usually this error means the library failed to load its static files. Check that the library files are available at ${window.location.host}/${this._options.library_path||""} or correct the library_path option.`)}})}_render(t){const e=window;if(e[this._id]={datafeed:this._options.datafeed,customFormatters:this._options.custom_formatters||this._options.customFormatters,brokerFactory:this._options.broker_factory||this._options.brokerFactory,overrides:this._options.overrides,studiesOverrides:this._options.studies_overrides,tradingCustomization:this._options.trading_customization,disabledFeatures:this._options.disabled_features,enabledFeatures:this._options.enabled_features,brokerConfig:this._options.broker_config||this._options.brokerConfig,restConfig:this._options.restConfig,favorites:this._options.favorites,logo:this._options.logo,numeric_formatting:this._options.numeric_formatting,rss_news_feed:this._options.rss_news_feed,rss_news_title:this._options.rss_news_title,newsProvider:this._options.news_provider,loadLastChart:this._options.load_last_chart,saveLoadAdapter:this._options.save_load_adapter,loading_screen:this._options.loading_screen,settingsAdapter:this._options.settings_adapter,getCustomIndicators:this._options.custom_indicators_getter,additionalSymbolInfoFields:this._options.additional_symbol_info_fields,headerWidgetButtonsMode:this._options.header_widget_buttons_mode,customTranslateFunction:this._options.custom_translate_function,symbolSearchComplete:this._options.symbol_search_complete,contextMenu:this._options.context_menu,settingsOverrides:this._options.settings_overrides,timeframe:this._options.timeframe,customTimezones:this._options.custom_timezones},this._options.saved_data)e[this._id].chartContent={json:this._options.saved_data},this._options.saved_data_meta_info&&(e[this._id].chartContentExtendedData=this._options.saved_data_meta_info);else if(!this._options.load_last_chart&&!this._options.symbol)throw new Error("Symbol is not defined: either 'symbol' or 'load_last_chart' option must be set");if(this._options.library_path&&!this._options.library_path.endsWith("/")&&console.warn("library_path option should contain a trailing forward slash"),this._options.locale){const r=encodeURIComponent(this._options.locale);y.findIndex(_=>_.language===r)>=0||(console.warn("locale isn't supported. Using default of `en`."),this._options.locale="en")}const i=function(r,_){var a;const l=new URL(`${r||""}`,location.href).href,g=JSON.parse('["bundles/runtime.0809a655c13b333b6a76.js","bundles/__LANG__.5008.e5d7d914577969582fa4.js","bundles/3515.2f722d33cebe31a154b1.css","bundles/9401.4792ed983286dcafa79b.js","bundles/library.847f247511d3f9997d72.js"]'),S=encodeURIComponent(_),F=(a=y.find(v=>v.language===S))!==null&&a!==void 0?a:{iso:"en",dir:"ltr"},z=`lang="${F.iso}" dir="${F.dir}"`;return`<!DOCTYPE html><html ${(T={bundles:` ${function(v,R,E){if(v===void 0)return"";const x=[],k=[];for(const C of v)C.endsWith(".js")?x.push(`<script defer crossorigin="anonymous" src="${C.replace("__LANG__",E)}"><\/script>`):C.endsWith(".css")&&k.push(`<link type="text/css" href="${R?C.replace(/\.css$/i,".rtl.css"):C}" rel="stylesheet"/>`);return[...x,...k].join(` `)}(g,F.dir==="rtl",S)} `,localeLanguage:S,htmlAttrs:z,libraryPath:l}).htmlAttrs}><head><base href="${T.libraryPath}"><meta charset="utf-8"><script>window===window.parent&&(location.href="about:blank")<\/script> ${T.bundles} </head><body class="chart-page unselectable on-widget"><div class="loading-indicator" id="loading-indicator"></div><script>var JSServer={},__initialEnabledFeaturesets=["charting_library"]<\/script><script>(function() { window.urlParams = (function () { var match, pl = /\\+/g, // Regex for replacing addition symbol with a space search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')).replace(/<\\/?[^>]+(>|$)/g, ''); }, query = function() { // We don't use hash on the url because: safari 13 throws an error if you attempt this // on a blob, and safari 14 will strip hash from blob urls. if (frameElement && frameElement.dataset.widgetOptions) { return frameElement.dataset.widgetOptions; } else { throw "Unexpected use of this page"; } }(), result = {}; while (match = search.exec(query)) { result[decode(match[1])] = decode(match[2]); } var additionalSettingsObject = window.parent[result.uid]; var customObjectNames = ['datafeed', 'customFormatters', 'brokerFactory', 'save_load_adapter', 'customTranslateFunction', 'contextMenu']; for (var p in additionalSettingsObject) { if (customObjectNames.indexOf(p) === -1) { result[p] = JSON.stringify(additionalSettingsObject[p]); } } return result; })(); window.locale = urlParams.locale; window.language = urlParams.locale; // a very big attention needed here window.customTranslateFunction = window.parent[urlParams.uid].customTranslateFunction; window.addCustomCSSFile = function(href) { var link = document.createElement('link'); link.setAttribute('type', 'text/css'); link.setAttribute('rel', 'stylesheet'); link.setAttribute('href', href); link.setAttribute('cross-origin', 'anonymous'); window.loadedCustomCss = new Promise((resolve) => { link.onload = resolve; link.onerror = resolve; }); document.body.appendChild(link); }; window.loadedCustomCss = Promise.resolve(); if (!!urlParams.customCSS) { window.addCustomCSSFile(urlParams.customCSS); } var loadingScreenParams = {}; if (typeof urlParams.loading_screen === 'string') { try { loadingScreenParams = JSON.parse(urlParams.loading_screen); } catch(e) {} } var loadingIndicatorElement = document.getElementById('loading-indicator'); if (loadingScreenParams.backgroundColor) { loadingIndicatorElement.style = 'background-color: ' + loadingScreenParams.backgroundColor; } !function(){"use strict";var t,e=new WeakMap;!function(t){t[t.Element=1]="Element",t[t.Document=9]="Document"}(t||(t={}));var n={mini:"xsmall",xsmall:"xsmall",small:"small",medium:"medium",large:"large"};var i,s,o,r,l,c=(void 0===l&&(l=""),i='<div class="tv-spinner '.concat(l,'" role="progressbar"></div>'),o=function(n,i){var s,o;return s=null==i?document.documentElement:i.nodeType===t.Document?i.documentElement:i,e&&(o=e.get(s)),o||((o=s.ownerDocument.createRange()).selectNodeContents(s),e&&e.set(s,o)),o.createContextualFragment(n)}(i,s),null!==(r=o.firstElementChild)&&o.removeChild(r),r),a=function(){function t(t){this._shown=!1,this._el=c.cloneNode(!0),this.setSize(n[t||"large"])}return t.prototype.spin=function(t){return this._el.classList.add("tv-spinner--shown"),void 0===this._container&&(this._container=t,void 0!==t&&t.appendChild(this._el)),this._shown=!0,this},t.prototype.stop=function(t){return t&&void 0!==this._container&&this._container.removeChild(this._el),this._el&&this._el.classList.remove("tv-spinner--shown"),this._shown=!1,this},t.prototype.setStyle=function(t){var e=this;return Object.keys(t).forEach((function(n){var i=t[n];void 0!==i&&e._el.style.setProperty(n,i)})),this},t.prototype.style=function(){return this._el.style},t.prototype.setSize=function(t){var e=void 0!==t?"tv-spinner--size_".concat(t):"";return this._el.className="tv-spinner ".concat(e," ").concat(this._shown?"tv-spinner--shown":""),this},t.prototype.getEl=function(){return this._el},t.prototype.destroy=function(){this.stop(),delete this._el,delete this._container},t}();window.Spinner=a}(); var spinnerColor = (loadingScreenParams.foregroundColor) ? loadingScreenParams.foregroundColor : undefined; var loadingSpinner = new Spinner('large').setStyle({ '--tv-spinner-color': spinnerColor, zIndex: String(2e9), }); loadingSpinner.getEl().classList.add('spinner'); loadingSpinner.spin(loadingIndicatorElement); })();<\/script></body></html>`;var T}(this._options.library_path||"",this._options.locale);let p=new URL("about:blank");if(t){const r=new Blob([i],{type:"text/html"}),_=URL.createObjectURL(r);p=new URL(_)}const h="symbol="+encodeURIComponent(this._options.symbol||"")+"&interval="+encodeURIComponent(this._options.interval)+(this._options.toolbar_bg?"&toolbarbg="+encodeURIComponent(this._options.toolbar_bg.replace("#","")):"")+(this._options.studies_access?"&studiesAccess="+encodeURIComponent(JSON.stringify(this._options.studies_access)):"")+"&widgetbar="+encodeURIComponent(JSON.stringify(this._options.widgetbar))+(this._options.drawings_access?"&drawingsAccess="+encodeURIComponent(JSON.stringify(this._options.drawings_access)):"")+"&timeFrames="+encodeURIComponent(JSON.stringify(this._options.time_frames))+"&locale="+encodeURIComponent(this._options.locale)+"&uid="+encodeURIComponent(this._id)+"&clientId="+encodeURIComponent(String(this._options.client_id))+"&userId="+encodeURIComponent(String(this._options.user_id))+(this._options.charts_storage_url?"&chartsStorageUrl="+encodeURIComponent(this._options.charts_storage_url):"")+(this._options.charts_storage_api_version?"&chartsStorageVer="+encodeURIComponent(this._options.charts_storage_api_version):"")+(this._options.custom_css_url?"&customCSS="+encodeURIComponent(this._options.custom_css_url):"")+(this._options.custom_font_family?"&customFontFamily="+encodeURIComponent(this._options.custom_font_family):"")+(this._options.auto_save_delay?"&autoSaveDelay="+encodeURIComponent(String(this._options.auto_save_delay)):"")+"&debug="+encodeURIComponent(String(this._options.debug))+(this._options.snapshot_url?"&snapshotUrl="+encodeURIComponent(this._options.snapshot_url):"")+(this._options.timezone?"&timezone="+encodeURIComponent(this._options.timezone):"")+(this._options.study_count_limit?"&studyCountLimit="+encodeURIComponent(String(this._options.study_count_limit)):"")+(this._options.symbol_search_request_delay?"&ssreqdelay="+encodeURIComponent(String(this._options.symbol_search_request_delay)):"")+(this._options.compare_symbols?"&compareSymbols="+encodeURIComponent(JSON.stringify(this._options.compare_symbols)):"")+(this._options.theme?"&theme="+encodeURIComponent(String(this._options.theme)):"")+(this._options.header_widget_buttons_mode?"&header_widget_buttons_mode="+encodeURIComponent(String(this._options.header_widget_buttons_mode)):"")+(this._options.time_scale?"&time_scale="+encodeURIComponent(JSON.stringify(this._options.time_scale)):"");return[`<iframe id="${this._id}" name="${this._id}" src="${p.href}" data-widget-options="${h}" ${this._options.autosize||this._options.fullscreen?"":`width="${this._options.width}" height="${this._options.height}"`} title="Financial Chart" frameborder="0" allowTransparency="true" scrolling="no" allowfullscreen style="display:block;opacity:0"> </iframe>`,i]}};typeof window<"u"&&(window.TradingView=window.TradingView||{},window.TradingView.version=b$1);const P=!(typeof window>"u"||!window.navigator||!window.navigator.userAgent)&&window.navigator.userAgent.includes("CriOS"),s={supported_resolutions:utils.intervals,supports_marks:!0,supports_time:!0,supports_timescale_marks:!0,supports_search:!0,reset_cache_timeout:.001},o={onReady:t=>{setTimeout(()=>t(s))},searchSymbols:()=>{},resolveSymbol:(t,e)=>{const i={name:t,full_name:`${t}:Example Exchange`,ticker:t,description:t,exchange:"Example Exchange",listed_exchange:"Example Exchange",type:"crypto",session:"24x7",timezone:"Etc/UTC",format:"price",minmov:1,minmove2:0,pricescale:1e8,has_seconds:!0,has_intraday:!0,has_daily:!0,has_weekly_and_monthly:!0,volume_precision:4,visible_plots_set:"ohlcv"};setTimeout(()=>{e(i)})},getBars:()=>{},subscribeBars:()=>{},unsubscribeBars:()=>{}},u=(t=utils.theme)=>{const e=utils.styles[t];return{volumePaneSize:"medium","scalesProperties.fontSize":10,"scalesProperties.lineColor":e.scales_line,"scalesProperties.textColor":e.scales_text,"scalesProperties.crosshairLabelBgColorLight":e.crosshair_bg,"scalesProperties.crosshairLabelBgColorDark":e.crosshair_bg,"paneProperties.background":e.background,"paneProperties.backgroundType":"solid","paneProperties.vertGridProperties.style":1,"paneProperties.horzGridProperties.style":1,"paneProperties.vertGridProperties.color":e.grid,"paneProperties.horzGridProperties.color":e.grid,"paneProperties.crossHairProperties.color":e.cross_line,"mainSeriesProperties.candleStyle.upColor":e.up,"mainSeriesProperties.candleStyle.downColor":e.down,"mainSeriesProperties.candleStyle.borderUpColor":e.up,"mainSeriesProperties.candleStyle.borderDownColor":e.down,"mainSeriesProperties.candleStyle.wickUpColor":e.up,"mainSeriesProperties.candleStyle.wickDownColor":e.down,"mainSeriesProperties.hollowCandleStyle.upColor":e.up,"mainSeriesProperties.hollowCandleStyle.downColor":e.down,"mainSeriesProperties.hollowCandleStyle.borderUpColor":e.up,"mainSeriesProperties.hollowCandleStyle.borderDownColor":e.down,"mainSeriesProperties.hollowCandleStyle.wickUpColor":e.up,"mainSeriesProperties.hollowCandleStyle.wickDownColor":e.down,"mainSeriesProperties.haStyle.upColor":e.up,"mainSeriesProperties.haStyle.downColor":e.down,"mainSeriesProperties.haStyle.borderUpColor":e.up,"mainSeriesProperties.haStyle.borderDownColor":e.down,"mainSeriesProperties.haStyle.wickUpColor":e.up,"mainSeriesProperties.haStyle.wickDownColor":e.down,"mainSeriesProperties.barStyle.upColor":e.up,"mainSeriesProperties.barStyle.downColor":e.down,"mainSeriesProperties.baselineStyle.topFillColor1":"rgba(21, 187, 122, 0.1)","mainSeriesProperties.baselineStyle.topFillColor2":"rgba(21, 187, 122, 0.1)","mainSeriesProperties.baselineStyle.bottomFillColor1":"rgba(210, 51, 77, 0.1)","mainSeriesProperties.baselineStyle.bottomFillColor2":"rgba(210, 51, 77, 0.1)","mainSeriesProperties.baselineStyle.topLineColor":e.up,"mainSeriesProperties.baselineStyle.bottomLineColor":e.down,"mainSeriesProperties.columnStyle.upColor":e.up,"mainSeriesProperties.columnStyle.downColor":e.down,"mainSeriesProperties.lineStyle.color":e.up,"mainSeriesProperties.lineWithMarkersStyle.color":e.up,"mainSeriesProperties.highLowAvgPrice.highLowPriceLabelsVisible":!0}},{getStore:d,removeStore:f,setStore:m}=utils._;function b(t,e){if(typeof t=="string"&&!t.length)throw new Error("Dom id \u4E0D\u80FD\u4E3A\u7A7A");const i={...e},p=e.storeKey||utils.storeKey;["locale","datafeed","storeKey"].forEach(l=>{delete i[l]});const h=utils.styles[e.theme||utils.theme],r=d(p);if(r&&r.charts?.length){const l=r.charts[0].panes?.[0]?.sources?.[0].state;l&&(l.symbol=e.symbol,l.interval=e.interval)}const _={container:t,locale:utils.TvLang[e.locale]||utils.TvLang[utils.lang],datafeed:Object.assign(o,e.datafeed||{}),autosize:!0,time_frames:[],timezone:"Etc/UTC",theme:utils.theme,custom_css_url:e.custom_css_url||"theme.css",custom_font_family:h.family,overrides:u(e.theme||utils.theme),header_widget_buttons_mode:"compact",enabled_features:["hide_left_toolbar_by_default","move_logo_to_main_pane","chart_crosshair_menu"],disabled_features:["header_symbol_search","header_compare","symbol_search_hot_key","volume_force_overlay","display_market_status","header_widget"],studies_overrides:{"volume.volume.color.0":h.down,"volume.volume.color.1":h.up,"volume.volume ma.color":h.ma},auto_save_delay:.05,settings_adapter:{initialSettings:{...r},setValue(l,g){const S=d(p)||{};["chartproperties","chartproperties.mainSeriesProperties"].includes(l)||(S[l]=g),m(p,S)},removeValue(l){const g=d(p)||{};Object.hasOwn(g,l)&&delete g[l],m(p,g)}},...i};r||(f("tradingview.chartproperties.mainSeriesProperties"),f("tradingview.chartproperties")),r?.layout&&r.charts?.length&&(_.saved_data=r);const a=new A(_);return a.$addDefaultMa=()=>{const l=a.activeChart();[10,30,60].forEach(g=>{l.createStudy("Moving Average",!1,!1,{length:g},{showLabelsOnPriceScale:!1})})},a.onChartReady(()=>{e.showMa&&!r&&a.$addDefaultMa(),a.subscribe("onAutoSaveNeeded",()=>{a.save(l=>{m(p,l)})}),a.subscribe("onScreenshotReady",l=>{window.open(`https://www.tradingview.com/x/${l}/`,"_blank")}),a.subscribe("onPlusClick",l=>{typeof e.onPlusClick=="function"&&e?.onPlusClick(l)})}),a}exports.simpleDispose=klinecharts.dispose,exports.getOverrides=u,exports.simpleInit=L,exports.tvInit=b;