@tony01/astroneum 0.4.1-beta.2 → 0.4.1-beta.25

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +281 -237
  2. package/LICENSE +21 -21
  3. package/README.md +250 -198
  4. package/dist/{Indicator-BBI3L_lx.d.ts → Indicator-BQQcVGGT.d.ts} +51 -227
  5. package/dist/astroneum.css +1 -1
  6. package/dist/chunk-47YGQEL5.js +399 -0
  7. package/dist/chunk-67XM5LOK.js +2 -0
  8. package/dist/{chunk-2YYGUSVX.js → chunk-DFJMDDL5.js} +1 -1
  9. package/dist/chunk-EFAS6F4C.js +59 -0
  10. package/dist/chunk-EHZN52CY.js +2 -0
  11. package/dist/chunk-HKLWNPMP.js +35 -0
  12. package/dist/chunk-ONPPQW65.js +2 -0
  13. package/dist/chunk-SCTHEM27.js +3 -0
  14. package/dist/chunk-UQXYMB6X.js +2 -0
  15. package/dist/chunk-WSIR5T2M.js +3 -0
  16. package/dist/entries/alerts.d.ts +36 -10
  17. package/dist/entries/alerts.js +1 -1
  18. package/dist/entries/datafeeds/crypto.d.ts +5 -1
  19. package/dist/entries/datafeeds/crypto.js +1 -1
  20. package/dist/entries/datafeeds/polygon.d.ts +3 -1
  21. package/dist/entries/datafeeds/polygon.js +1 -1
  22. package/dist/entries/headless.d.ts +78 -0
  23. package/dist/entries/headless.js +2 -0
  24. package/dist/entries/multichart.d.ts +12 -1
  25. package/dist/entries/multichart.js +1 -1
  26. package/dist/entries/replay.d.ts +3 -1
  27. package/dist/entries/script.d.ts +2 -68
  28. package/dist/entries/script.js +1 -1
  29. package/dist/entries/watchlist.d.ts +32 -2
  30. package/dist/entries/watchlist.js +1 -1
  31. package/dist/entries/workspace.d.ts +61 -0
  32. package/dist/entries/workspace.js +2 -0
  33. package/dist/index-BiXdqLA4.d.ts +45 -0
  34. package/dist/index-_JgHTy8X.d.ts +19 -0
  35. package/dist/index.d.ts +188 -27
  36. package/dist/index.js +1 -1
  37. package/dist/script-BU9StbN-.d.ts +120 -0
  38. package/dist/types-W6SIYQ9m.d.ts +232 -0
  39. package/dist/types-yETgeYsE.d.ts +28 -0
  40. package/dist/zh-CN-NDTUDZGZ.js +3 -0
  41. package/package.json +157 -147
  42. package/dist/chunk-4YOLQ5DC.js +0 -2
  43. package/dist/chunk-I4YQBP2M.js +0 -3
  44. package/dist/chunk-OOMZRONH.js +0 -35
  45. package/dist/chunk-PV2GAINM.js +0 -2
  46. package/dist/chunk-YW3STIPY.js +0 -653
  47. package/dist/zh-CN-Y2C6RSOI.js +0 -3
  48. package/docs/STRUCTURE.md +0 -231
  49. package/docs/TODO-DESIGN.md +0 -261
  50. package/docs/TODO.md +0 -222
  51. package/docs/api.md +0 -528
  52. package/docs/datafeed-guide.md +0 -311
  53. package/docs/design-astroneum.md +0 -479
  54. package/docs/plugin-development.md +0 -565
  55. package/docs/tv-functions-skill.md +0 -706
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ function y(n){try{let e=new URL(n);if(e.protocol!=="http:"&&e.protocol!=="https:")return !1;let t=e.hostname.toLowerCase().replace(/^\[|\]$/g,"");return !(t==="localhost"||t==="127.0.0.1"||t==="::1"||/^(10\.|172\.(1[6-9]|2\d|3[01])\.|192\.168\.|169\.254\.|127\.)/.test(t)||t.endsWith(".local")||t.endsWith(".internal"))}catch{return false}}var m="astroneum-alerts";function A(n){if(Array.isArray(n.conditions))return n;let e=n.condition,t=n.price;return e&&typeof t=="number"&&(n.conditions=[{id:`cond_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,source:{type:"price"},operator:e,value:t}]),n}function v(){try{let n=localStorage.getItem(m);if(!n)return [];let e=JSON.parse(n);return Array.isArray(e)?e.filter(t=>{if(t===null||typeof t!="object")return !1;let i=t,s=Array.isArray(i.conditions)&&i.conditions.length>0,r=typeof i.condition=="string"&&typeof i.price=="number";return typeof i.id=="string"&&typeof i.symbol=="string"&&typeof i.status=="string"&&typeof i.createdAt=="string"&&(s||r)}).map(t=>A(t)):[]}catch{return []}}function d(n){try{localStorage.setItem(m,JSON.stringify(n));}catch{}}var _={Thin:880,Classic:660,Alert:1e3,Bell:523,Chime:784};function S(n="Thin",e="once"){try{let t=new AudioContext,i=_[n]??880,s=()=>{let r=t.createOscillator(),o=t.createGain();r.connect(o),o.connect(t.destination),r.frequency.value=i,o.gain.setValueAtTime(.3,t.currentTime),o.gain.exponentialRampToValueAtTime(.001,t.currentTime+.4),r.start(t.currentTime),r.stop(t.currentTime+.4),r.onended=()=>{e!=="repeating"&&t.close();};};if(s(),e==="repeating"){let r=setInterval(s,600);setTimeout(()=>{clearInterval(r),t.close();},5e3);}}catch{}}var l=null;function w(){return l&&document.body.contains(l)||(l=document.createElement("div"),l.id="astroneum-alert-toast-container",l.style.cssText="position:fixed;top:16px;right:16px;z-index:10000;display:flex;flex-direction:column;gap:8px;pointer-events:none",document.body.appendChild(l)),l}function x(n,e){try{let t=w(),i=document.createElement("div");i.style.cssText="pointer-events:auto;min-width:280px;max-width:400px;padding:12px 16px;border-radius:8px;background:#1d2026;border:1px solid #2962ff;color:#d1d4dc;font-family:-apple-system,sans-serif;font-size:14px;box-shadow:0 4px 16px rgba(0,0,0,0.4);cursor:pointer;transition:opacity 0.3s;animation:toast-in 0.2s ease-out";let s=document.createElement("div");s.textContent=n,s.style.cssText="font-weight:600;margin-bottom:4px;color:#2962ff";let r=document.createElement("div");r.textContent=e,r.style.cssText="color:#8a8f9c;font-size:13px",i.appendChild(s),i.appendChild(r),i.onclick=()=>{i.style.opacity="0",setTimeout(()=>i.remove(),300);},t.appendChild(i),setTimeout(()=>{i.parentNode&&(i.style.opacity="0",setTimeout(()=>i.remove(),300));},8e3);}catch{}}function k(n){if(!n||n.preset==="24/7")return true;let e=new Date,t=e.getDay(),i=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),r=`${i}:${s}`;if(n.preset==="weekdays")return t>=1&&t<=5;if(n.preset==="working_hours")return t>=1&&t<=5&&r>="09:00"&&r<="18:00";if(n.preset==="custom"){if(!(n.days??[0,1,2,3,4,5,6]).includes(t))return false;let a=n.from??"00:00",c=n.to??"23:59";return a<=c?r>=a&&r<=c:r>=a||r<=c}return true}async function h(n,e,t,i){try{await fetch("/astroneum/api/alerts/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:n,subject:e,body:t,isPlainText:i})});}catch{}}async function T(n,e,t,i){try{i({webhookStatus:"pending",webhookStatusAt:new Date().toISOString()});let r=await(await fetch("/astroneum/api/alerts/webhook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({webhookUrl:n,message:e,payload:t})})).json();i({webhookStatus:r?.ok?"delivered":"failed",webhookStatusAt:new Date().toISOString(),webhookHttpStatus:typeof r?.status=="number"?r.status:void 0});}catch{i({webhookStatus:"failed",webhookStatusAt:new Date().toISOString()});}}function C(n,e,t){if(n.type==="price")return e;if(t)return t(n)}function E(n,e,t){switch(n.operator){case "above":return e>=n.value;case "below":return e<=n.value;case "crosses_above":return t!==void 0&&t<n.value&&e>=n.value;case "crosses_below":return t!==void 0&&t>n.value&&e<=n.value;case "crosses":return t!==void 0&&(t<n.value&&e>=n.value||t>n.value&&e<=n.value);case "is_between":if(n.secondValue===void 0)return false;let i=Math.min(n.value,n.secondValue),s=Math.max(n.value,n.secondValue);return e>=i&&e<=s;default:return false}}var p=class n{static _instance=null;_alerts;_lastValues=new Map;_listeners=[];_changeListeners=[];_savePending=false;constructor(){this._alerts=v();}static getInstance(){return n._instance||(n._instance=new n),n._instance}_notifyChange(){for(let e of this._changeListeners)try{e([...this._alerts]);}catch{}}add(e){let t={...e,conditions:e.conditions??[{id:`cond_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,source:{type:"price"},operator:e.condition,value:e.price}],id:`alert_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,status:"active",createdAt:new Date().toISOString(),frequency:e.frequency??"once",soundEnabled:e.soundEnabled??true,notificationEnabled:e.notificationEnabled??false};return this._alerts.push(t),d(this._alerts),this._notifyChange(),t.id}update(e,t){let i=this._alerts.findIndex(s=>s.id===e);return i===-1?false:(this._alerts[i]={...this._alerts[i],...t},d(this._alerts),this._notifyChange(),true)}delete(e){let t=this._alerts.length;return this._alerts=this._alerts.filter(i=>i.id!==e),this._alerts.length!==t?(d(this._alerts),this._notifyChange(),true):false}dismiss(e){return this.update(e,{status:"dismissed"})}reactivate(e){return this.update(e,{status:"active",triggeredAt:void 0})}togglePause(e){let t=this._alerts.find(i=>i.id===e);return t?this.update(e,{status:t.status==="paused"?"active":"paused"}):false}clear(e){this._alerts=e?this._alerts.filter(t=>t.symbol!==e):[],d(this._alerts),this._notifyChange();}getAll(){return this._alerts}getActive(){return this._alerts.filter(e=>e.status==="active")}getForSymbol(e){return this._alerts.filter(t=>t.symbol===e)}getActiveForSymbol(e){return this._alerts.filter(t=>t.symbol===e&&t.status==="active")}getHistory(){return this._alerts.filter(e=>e.status!=="active"&&e.status!=="paused")}getById(e){return this._alerts.find(t=>t.id===e)}check(e){let{symbol:t,price:i,timestamp:s,indicatorResolver:r}=e;for(let o of this._alerts){if(o.symbol!==t||o.status!=="active")continue;if(o.expiration&&new Date(o.expiration).getTime()<s){o.status="expired";continue}let a=true;for(let u of o.conditions){let g=u.source.type==="price"?`${t}:price`:`${t}:ind:${u.source.name}:${u.source.plot}`,b=this._lastValues.get(g),f=C(u.source,i,r);if(f===void 0){a=false;break}if(this._lastValues.set(g,f),!E(u,f,b)){a=false;break}}if(!a)continue;let c=new Date(s).toISOString();o.triggeredAt=c,o.frequency==="once"&&(o.status="triggered"),this._fire(o,i);}this._schedulePersist(),this._notifyChange();}_schedulePersist(){this._savePending||(this._savePending=true,setTimeout(()=>{this._savePending=false,d(this._alerts);},1e3));}_fire(e,t){let i=k(e.notificationSchedule),s=e.messageTemplate??e.note??`${e.symbol} ${e.conditions.map(o=>`${o.operator} ${o.value}`).join(" AND ")}`,r=`${e.symbol} alert triggered \u2014 current: ${t}`;if(e.soundEnabled&&i&&S(e.soundTitle??"Thin",e.soundDuration??"once"),e.notificationEnabled&&i&&"Notification"in window&&(Notification.permission==="granted"?new Notification(`Alert: ${s}`,{body:`Current price: ${t}`,icon:"/favicon.ico"}):Notification.permission!=="denied"&&Notification.requestPermission().then(o=>{o==="granted"&&new Notification(`Alert: ${s}`,{body:`Current price: ${t}`});})),e.toastEnabled&&i&&x(`Alert: ${s}`,r),e.webhookUrl&&y(e.webhookUrl)&&i){let o=e.messageTemplate??r,a={id:e.id,symbol:e.symbol,conditions:e.conditions,price:e.price,triggeredPrice:t,triggeredAt:e.triggeredAt,note:e.note,message:o};T(e.webhookUrl,o,a,c=>{this.update(e.id,c);});}e.emailEnabled&&i&&h("",`Alert: ${s}`,r,false),e.plainTextEnabled&&e.plainTextEmail&&i&&h(e.plainTextEmail,`Alert: ${s}`,r,true);for(let o of this._listeners)try{o(e,t);}catch{}}onTriggered(e){return this._listeners.push(e),()=>{this._listeners=this._listeners.filter(t=>t!==e);}}onChange(e){return this._changeListeners.push(e),e([...this._alerts]),()=>{this._changeListeners=this._changeListeners.filter(t=>t!==e);}}async requestNotificationPermission(){return "Notification"in window?Notification.permission!=="default"?Notification.permission:Notification.requestPermission():"denied"}},$=p;export{$ as a};
@@ -1,3 +1,3 @@
1
1
  'use client';
2
- import {e}from'./chunk-YFPXTHZX.js';import {a as a$1}from'./chunk-SDXH2WAI.js';function p(c){return c.ev==="status"}var a=class{#e;constructor(e){this.#e=e;}_prevSymbolMarket;_ws;_reconnectDelay=1e3;_reconnectTimer;_currentSymbol;_currentCallback;_prevTickTimestamp=0;_prevTickOpen=NaN;_prevTickHigh=NaN;_prevTickLow=NaN;_prevTickClose=NaN;_isDeltaTick(e){return e.timestamp!==this._prevTickTimestamp?true:e.open!==this._prevTickOpen||e.high!==this._prevTickHigh||e.low!==this._prevTickLow||e.close!==this._prevTickClose}_updateDeltaRef(e){this._prevTickTimestamp=e.timestamp,this._prevTickOpen=e.open,this._prevTickHigh=e.high,this._prevTickLow=e.low,this._prevTickClose=e.close;}_mergeTick=e(e=>{this._animator.feed(e);});_animator=new a$1(e=>{this._currentCallback?.(e);});async searchSymbols(e){let s=new URL("https://api.polygon.io/v3/reference/tickers");s.searchParams.set("active","true"),s.searchParams.set("search",e??"");let r=await fetch(s.toString(),{headers:{Authorization:`Bearer ${this.#e}`}});if(!r.ok)throw new Error(`[DefaultDatafeed] searchSymbols failed: ${r.status}`);return ((await r.json()).results??[]).map(t=>({ticker:t.ticker,name:t.name,shortName:t.ticker,market:t.market,exchange:t.primary_exchange,priceCurrency:t.currency_name,type:t.type}))}async getHistoryData(e,s,r,i){let t=new URL(`https://api.polygon.io/v2/aggs/ticker/${e.ticker}/range/${s.multiplier}/${s.timespan}/${r}/${i}`),n=await fetch(t.toString(),{headers:{Authorization:`Bearer ${this.#e}`}});if(!n.ok)throw new Error(`[DefaultDatafeed] getHistoryData failed: ${n.status}`);return ((await n.json()).results??[]).map(o=>({timestamp:o.t,open:o.o,high:o.h,low:o.l,close:o.c,volume:o.v,turnover:o.vw}))}subscribe(e,s,r){let i=e.market;i&&(this._currentSymbol=e,this._currentCallback=r,this._prevSymbolMarket!==i?(this._teardownWS(),this._setupWS(i)):this._ws?.send(JSON.stringify({action:"subscribe",params:`T.${e.ticker}`})),this._prevSymbolMarket=i);}_setupWS(e){this._ws=new WebSocket(`wss://delayed.polygon.io/${e}`),this._ws.onopen=()=>{this._reconnectDelay=1e3,this._ws?.send(JSON.stringify({action:"auth",params:this.#e}));},this._ws.onmessage=s=>{let r=JSON.parse(s.data);if(!Array.isArray(r))return;let i=r;for(let t of i)if(p(t))t.status==="auth_success"&&this._currentSymbol&&this._ws?.send(JSON.stringify({action:"subscribe",params:`T.${this._currentSymbol.ticker}`}));else {let n={timestamp:t.s,open:t.o,high:t.h,low:t.l,close:t.c,volume:t.v,turnover:t.vw};if(!this._isDeltaTick(n))continue;this._updateDeltaRef(n),this._mergeTick(n);}},this._ws.onclose=()=>{this._scheduleReconnect();},this._ws.onerror=()=>{this._ws?.close();};}_scheduleReconnect(){if(!this._currentSymbol||!this._prevSymbolMarket)return;let e=this._reconnectDelay;this._reconnectDelay=Math.min(this._reconnectDelay*2,3e4),this._reconnectTimer=setTimeout(()=>{this._setupWS(this._prevSymbolMarket);},e);}_teardownWS(){this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._animator.cancel(),this._ws?.close(),this._ws=void 0;}unsubscribe(e,s){this._ws?.send(JSON.stringify({action:"unsubscribe",params:`T.${e.ticker}`}));}};
2
+ import {a as a$1}from'./chunk-SDXH2WAI.js';import {e}from'./chunk-YFPXTHZX.js';function p(c){return c.ev==="status"}var a=class{#e;constructor(e){this.#e=e;}_prevSymbolMarket;_ws;_reconnectDelay=1e3;_reconnectTimer;_currentSymbol;_currentCallback;_prevTickTimestamp=0;_prevTickOpen=NaN;_prevTickHigh=NaN;_prevTickLow=NaN;_prevTickClose=NaN;_isDeltaTick(e){return e.timestamp!==this._prevTickTimestamp?true:e.open!==this._prevTickOpen||e.high!==this._prevTickHigh||e.low!==this._prevTickLow||e.close!==this._prevTickClose}_updateDeltaRef(e){this._prevTickTimestamp=e.timestamp,this._prevTickOpen=e.open,this._prevTickHigh=e.high,this._prevTickLow=e.low,this._prevTickClose=e.close;}_mergeTick=e(e=>{this._animator.feed(e);});_animator=new a$1(e=>{this._currentCallback?.(e);});async searchSymbols(e){let s=new URL("https://api.polygon.io/v3/reference/tickers");s.searchParams.set("active","true"),s.searchParams.set("search",e??"");let r=await fetch(s.toString(),{headers:{Authorization:`Bearer ${this.#e}`}});if(!r.ok)throw new Error(`[DefaultDatafeed] searchSymbols failed: ${r.status}`);return ((await r.json()).results??[]).map(t=>({ticker:t.ticker,name:t.name,shortName:t.ticker,market:t.market,exchange:t.primary_exchange,priceCurrency:t.currency_name,type:t.type}))}async getHistoryData(e,s,r,i){let t=new URL(`https://api.polygon.io/v2/aggs/ticker/${e.ticker}/range/${s.multiplier}/${s.timespan}/${r}/${i}`),n=await fetch(t.toString(),{headers:{Authorization:`Bearer ${this.#e}`}});if(!n.ok)throw new Error(`[DefaultDatafeed] getHistoryData failed: ${n.status}`);return ((await n.json()).results??[]).map(o=>({timestamp:o.t,open:o.o,high:o.h,low:o.l,close:o.c,volume:o.v,turnover:o.vw}))}subscribe(e,s,r){let i=e.market;i&&(this._currentSymbol=e,this._currentCallback=r,this._prevSymbolMarket!==i?(this._teardownWS(),this._setupWS(i)):this._ws?.send(JSON.stringify({action:"subscribe",params:`T.${e.ticker}`})),this._prevSymbolMarket=i);}_setupWS(e){this._ws=new WebSocket(`wss://delayed.polygon.io/${e}`),this._ws.onopen=()=>{this._reconnectDelay=1e3,this._ws?.send(JSON.stringify({action:"auth",params:this.#e}));},this._ws.onmessage=s=>{let r=JSON.parse(s.data);if(!Array.isArray(r))return;let i=r;for(let t of i)if(p(t))t.status==="auth_success"&&this._currentSymbol&&this._ws?.send(JSON.stringify({action:"subscribe",params:`T.${this._currentSymbol.ticker}`}));else {let n={timestamp:t.s,open:t.o,high:t.h,low:t.l,close:t.c,volume:t.v,turnover:t.vw};if(!this._isDeltaTick(n))continue;this._updateDeltaRef(n),this._mergeTick(n);}},this._ws.onclose=()=>{this._scheduleReconnect();},this._ws.onerror=()=>{this._ws?.close();};}_scheduleReconnect(){if(!this._currentSymbol||!this._prevSymbolMarket)return;let e=this._reconnectDelay;this._reconnectDelay=Math.min(this._reconnectDelay*2,3e4),this._reconnectTimer=setTimeout(()=>{this._setupWS(this._prevSymbolMarket);},e);}_teardownWS(){this._reconnectTimer!==void 0&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=void 0),this._animator.cancel(),this._ws?.close(),this._ws=void 0;}unsubscribe(e,s){this._ws?.send(JSON.stringify({action:"unsubscribe",params:`T.${e.ticker}`}));}};
3
3
  export{a};
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+ import {b}from'./chunk-47YGQEL5.js';var C={initialCapital:1e4,commissionPercent:.1,slippagePercent:0,positionSizePercent:100,currency:"USD"};function x(e,r,s,t){return e*(1+(r==="long"===s?1:-1)*(t/100))}function E(e,r,s,t){let o=e.filter(u=>u.grossProfit>0).reduce((u,f)=>u+f.grossProfit,0),n=e.filter(u=>u.grossProfit<0).reduce((u,f)=>u+f.grossProfit,0),a=e.reduce((u,f)=>u+f.netProfit,0),m=e.filter(u=>u.netProfit>0).length,c=s.reduce((u,f)=>Math.min(u,f.equity-r),0),i=s.reduce((u,f)=>Math.min(u,f.drawdownPercent),0),p=t[0]?.close??0,g=t.at(-1)?.close??p;return {netProfit:a,netProfitPercent:r===0?0:a/r*100,grossProfit:o,grossLoss:n,profitFactor:n===0?o>0?null:0:o/Math.abs(n),totalTrades:e.length,percentProfitable:e.length===0?0:m/e.length*100,maxDrawdown:c,maxDrawdownPercent:i,buyAndHoldPercent:p===0?0:(g-p)/p*100}}function w(e,r,s={}){let t={...C,...s},o=new Map;for(let g of r)if(g.index>=0&&g.index<e.length){let u=o.get(g.index)??[];u.push(g),o.set(g.index,u);}let n=[],a=[],m=t.initialCapital,c=m,i=null,p=g=>{if(!i)return;let u=e[g],f=x(u.close,i.side,false,t.slippagePercent),y=(f-i.entryPrice)*i.quantity*(i.side==="long"?1:-1),l=Math.abs(f*i.quantity)*(t.commissionPercent/100),d=i.entryCommission+l,b=y-d;m+=b,n.push({id:`trade-${n.length+1}`,side:i.side,entryTime:Number(e[i.entryIndex].timestamp),entryPrice:i.entryPrice,exitTime:Number(u.timestamp),exitPrice:f,quantity:i.quantity,grossProfit:y,commission:d,netProfit:b,barsHeld:g-i.entryIndex}),i=null;};return e.forEach((g,u)=>{for(let l of o.get(u)??[])if(l.action==="exit"&&p(u),l.action==="enter"&&l.side){i&&p(u);let d=x(g.close,l.side,true,t.slippagePercent),b=m*(t.positionSizePercent/100),T=d===0?0:b/d;i={side:l.side,entryIndex:u,entryPrice:d,quantity:T,entryCommission:Math.abs(b)*(t.commissionPercent/100)};}let f=i?(g.close-i.entryPrice)*i.quantity*(i.side==="long"?1:-1)-i.entryCommission:0,y=m+f;c=Math.max(c,y),a.push({timestamp:Number(g.timestamp),equity:y,drawdownPercent:c===0?0:(y-c)/c*100});}),i&&e.length>0&&p(e.length-1),{mode:"runtime",config:t,trades:n,equity:a,bars:e,metrics:E(n,t.initialCapital,a,e)}}function S(e,r){let s=0;return e.map((t,o)=>(s+=isFinite(t)?t:0,o>=r&&(s-=isFinite(e[o-r])?e[o-r]:0),o<r-1?NaN:s/r))}function h(e,r){let s=2/(r+1),t=[],o=NaN;return e.forEach((n,a)=>{if(!isFinite(n)){t.push(NaN);return}if(!isFinite(o)){o=n,t.push(n);return}o=n*s+o*(1-s),t.push(o);}),t}function F(e,r){let s=1/r,t=[],o=NaN;return e.forEach(n=>{if(!isFinite(n)){t.push(NaN);return}o=isFinite(o)?n*s+o*(1-s):n,t.push(o);}),t}function B(e,r){return e.map((s,t)=>{if(t<r-1)return NaN;let o=0,n=0;for(let a=0;a<r;a++){let m=r-a;o+=m,n+=(e[t-a]??NaN)*m;}return n/o})}function I(e,r){let s=0,t=0;return e.map((o,n)=>{if(n===0)return NaN;let a=o-e[n-1];if(s+=a>0?a:0,t+=a<0?-a:0,n<r)return NaN;if(n>r){let i=e[n-1]-e[n-2];s-=i>0?i:0,t-=i<0?-i:0;}let m=s/r,c=t/r;return c===0?100:100-100/(1+m/c)})}function A(e,r){return e.map((s,t)=>{let o=e.slice(Math.max(0,t-r+1),t+1);return Math.max(...o.filter(isFinite))})}function q(e,r){return e.map((s,t)=>{let o=e.slice(Math.max(0,t-r+1),t+1);return Math.min(...o.filter(isFinite))})}function N(e,r){let s=S(e,r);return e.map((t,o)=>{if(o<r-1)return NaN;let n=0;for(let a=0;a<r;a++)n+=(e[o-a]-s[o])**2;return Math.sqrt(n/r)})}function M(e,r){return e.map((s,t)=>t>0&&(e[t-1]<=r[t-1]&&s>r[t]||e[t-1]>=r[t-1]&&s<r[t]))}function D(e,r){return e.map((s,t)=>t>0&&e[t-1]<r[t-1]&&s>r[t])}function O(e,r){return e.map((s,t)=>t>0&&e[t-1]>r[t-1]&&s<r[t])}var v={sma:S,ema:h,rma:F,wma:B,rsi:I,highest:A,lowest:q,stdev:N,cross:M,crossover:D,crossunder:O,bbands(e,r,s=2){let t=S(e,r),o=N(e,r);return {upper:t.map((n,a)=>n+s*o[a]),middle:t,lower:t.map((n,a)=>n-s*o[a])}},macd(e,r=12,s=26,t=9){let o=h(e,r),n=h(e,s),a=o.map((c,i)=>c-n[i]),m=h(a.map(c=>isFinite(c)?c:0),t);return {macd:a,signal:m,histogram:a.map((c,i)=>c-m[i])}}},k=["window","document","location","fetch","XMLHttpRequest","WebSocket","Function","setTimeout","setInterval","importScripts","require","process","__dirname","__filename","global","globalThis"];function R(e){return `
3
+ "use strict";
4
+ ${k.map(s=>`const ${s} = undefined;`).join(" ")}
5
+
6
+ // Freeze Object/Array prototypes to prevent prototype-pollution attacks
7
+ // (adding properties that bleed across script invocations).
8
+ // Note: this does NOT block constructor-chain escapes such as
9
+ // (0).constructor.constructor('return globalThis')()
10
+ // because Number.prototype and Function.prototype are not frozen
11
+ // (Function.prototype must stay live for the factory itself).
12
+ Object.freeze(Object.prototype);
13
+ Object.freeze(Array.prototype);
14
+
15
+ // eval cannot be redeclared in strict mode (SyntaxError),
16
+ // but freezing Object.prototype blocks the indirect-eval
17
+ // bypass via this.constructor.constructor('return eval')().
18
+
19
+ let _name = 'Script';
20
+ let _shortName = 'Script';
21
+ let _overlay = false;
22
+ let _precision = 4;
23
+ const _figures = [];
24
+ const _inputs = {};
25
+ let _rows = null;
26
+
27
+ function study(name, opts) {
28
+ _name = name;
29
+ _shortName = (opts && opts.shortName) ? opts.shortName : name;
30
+ _overlay = (opts && opts.overlay) === true;
31
+ _precision = (opts && opts.precision != null) ? opts.precision : 4;
32
+ }
33
+
34
+ function input(title, defaultVal, opts) {
35
+ // Validate opts to prevent unexpected values from polluting the script context
36
+ _inputs[title] = defaultVal;
37
+ return defaultVal;
38
+ }
39
+
40
+ function plot(values, opts) {
41
+ const key = 'plot' + (_figures.length + 1);
42
+ _figures.push({
43
+ key,
44
+ title: (opts && opts.title) ? opts.title + ': ' : key + ': ',
45
+ type: 'line',
46
+ });
47
+ if (!_rows) _rows = values.map(v => ({}));
48
+ values.forEach((v, i) => { if (_rows[i]) _rows[i][key] = (v == null || !isFinite(v)) ? null : v; });
49
+ }
50
+
51
+ function plotLine(values, opts) { plot(values, opts); }
52
+
53
+ const ta = TA;
54
+ const math = Math;
55
+
56
+ ${e}
57
+
58
+ return { name: _name, shortName: _shortName, overlay: _overlay, precision: _precision, figures: _figures, rows: _rows || [] };
59
+ `}var P=class e{static _instance=null;_registry=new Map;constructor(){}static getInstance(){return e._instance||(e._instance=new e),e._instance}compile(r,s){let t=R(r),o;try{o=new Function("open","high","low","close","volume","TA",t);}catch(c){throw new Error(`Script syntax error: ${c.message}`)}let n;try{n=o([],[],[],[],[],v);}catch(c){throw new Error(`Script runtime error during metadata extraction: ${c.message}`)}let a=s??n.name??"Custom",m={name:a,shortName:n.shortName??a,series:n.overlay?"price":"normal",precision:n.precision??4,figures:n.figures,_source:r,calc(c){let i=c.map(l=>l.open),p=c.map(l=>l.high),g=c.map(l=>l.low),u=c.map(l=>l.close),f=c.map(l=>l.volume??0),y;try{y=o(i,p,g,u,f,v);}catch(l){return console.error("[ScriptEngine] runtime error:",l),c.map(()=>({}))}return y.figures.length>0&&(this.figures=[...y.figures]),y.rows}};return this._registry.set(a,m),b(m),m}compileStrategy(r,s="Strategy"){let t=k.map(n=>`const ${n} = undefined;`).join(" "),o;try{o=new Function("open","high","low","close","volume","TA",`"use strict"; ${t} ${r}; return typeof strategySignals === 'function' ? strategySignals({ open, high, low, close, volume, ta: TA }) : null`);}catch(n){throw new Error(`Strategy syntax error: ${n.message}`)}return {name:s,source:r,run:(n,a)=>{let m=o(n.map(i=>i.open),n.map(i=>i.high),n.map(i=>i.low),n.map(i=>i.close),n.map(i=>i.volume??0),v);if(!Array.isArray(m))throw new Error("Strategy must declare strategySignals(context) and return an array of signals");let c=m.filter(i=>{if(i===null||typeof i!="object")return false;let p=i;return typeof p.index=="number"&&(p.action==="enter"||p.action==="exit")&&(p.action!=="enter"||p.side==="long"||p.side==="short")});return w(n,c,a)}}}get(r){return this._registry.get(r)}list(){return [...this._registry.keys()]}remove(r){this._registry.delete(r);}},G=P;export{w as a,G as b};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import {s}from'./chunk-47YGQEL5.js';function T(t,e,r){let n=(t.x-e.x)*Math.cos(r)-(t.y-e.y)*Math.sin(r)+e.x,s=(t.x-e.x)*Math.sin(r)+(t.y-e.y)*Math.cos(r)+e.y;return {x:n,y:s}}function O(t,e){if(t.length>1){let r;return t[0].x===t[1].x&&t[0].y!==t[1].y?t[0].y<t[1].y?r={x:t[0].x,y:e.height}:r={x:t[0].x,y:0}:t[0].x>t[1].x?r={x:0,y:s.getLinearYFromCoordinates(t[0],t[1],{x:0,y:t[0].y})}:r={x:e.width,y:s.getLinearYFromCoordinates(t[0],t[1],{x:e.width,y:t[0].y})},{coordinates:[t[0],r]}}return []}var v="rgba(22, 119, 255, 0.08)";function L(t,e){let r=e.x>t.x?0:1,n=s.getLinearSlopeIntercept(t,e);return n?Math.atan(n[0])+Math.PI*r:e.y>t.y?Math.PI/2:Math.PI/2*3}function D(t,e){let r=Math.abs(t.x-e.x),n=Math.abs(t.y-e.y);return Math.sqrt(r*r+n*n)}function S(t,e,r,n,s,i,a){let o=r.x>e.x?e.x:r.x,l=[],y=[];return t.forEach(x=>{let u=r.y+n*x,p=(i+s*x).toFixed(a);l.push({coordinates:[{x:e.x,y:u},{x:r.x,y:u}]}),y.push({x:o,y:u,text:`${p} (${(x*100).toFixed(1)}%)`,baseline:"bottom"});}),{lines:l,texts:y}}var Ft={name:"arrow",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length>1){let e=L(t[0],t[1]),r=T({x:t[1].x-8,y:t[1].y+4},t[1],e),n=T({x:t[1].x-8,y:t[1].y-4},t[1],e);return [{type:"line",attrs:{coordinates:t}},{type:"line",ignoreEvent:true,attrs:{coordinates:[r,t[1],n]}}]}return []}},X=Ft;var vt={name:"circle",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{circle:{color:v}},createPointFigures:({coordinates:t})=>{if(t.length>1){let e=D(t[0],t[1]);return {type:"circle",attrs:{...t[0],r:e},styles:{style:"stroke_fill"}}}return []}},R=vt;var At={name:"rect",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{polygon:{color:v}},createPointFigures:({coordinates:t})=>t.length>1?[{type:"polygon",attrs:{coordinates:[t[0],{x:t[1].x,y:t[0].y},t[1],{x:t[0].x,y:t[1].y}]},styles:{style:"stroke_fill"}}]:[]},I=At;var Dt={name:"parallelogram",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{polygon:{color:v}},createPointFigures:({coordinates:t})=>{if(t.length===2)return [{type:"line",ignoreEvent:true,attrs:{coordinates:t}}];if(t.length===3){let e={x:t[0].x+(t[2].x-t[1].x),y:t[2].y};return [{type:"polygon",attrs:{coordinates:[t[0],t[1],t[2],e]},styles:{style:"stroke_fill"}}]}return []},performEventPressedMove:({points:t,performPointIndex:e,performPoint:r})=>{e<2&&(t[0].price=r.price,t[1].price=r.price);},performEventMoveForDrawing:({currentStep:t,points:e,performPoint:r})=>{t===2&&(e[0].price=r.price);}},$=Dt;var Pt={name:"triangle",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{polygon:{color:v}},createPointFigures:({coordinates:t})=>[{type:"polygon",attrs:{coordinates:t},styles:{style:"stroke_fill"}}]},k=Pt;var Tt={name:"fibonacciCircle",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length>1){let e=D(t[0],t[1]),r=[.236,.382,.5,.618,.786,1],n=[],s=[];return r.forEach(i=>{let a=e*i;n.push({...t[0],r:a}),s.push({x:t[0].x,y:t[0].y+a+6,text:`${(i*100).toFixed(1)}%`});}),[{type:"circle",attrs:n,styles:{style:"stroke"}},{type:"text",ignoreEvent:true,attrs:s}]}return []}},_=Tt;var Ot={name:"fibonacciSegment",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r})=>{if(t.length<=1)return [{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let n=e.points,s=n[0].value-n[1].value,i=t[0].y-t[1].y,a=r.getSymbol()?.pricePrecision??2,{lines:o,texts:l}=S([1,.786,.618,.5,.382,.236,0],t[0],t[1],i,s,n[1].value,a);return [{type:"line",attrs:o},{type:"text",ignoreEvent:true,attrs:l}]}},V=Ot;var Mt={name:"fibonacciSpiral",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{if(t.length>1){let r=D(t[0],t[1])/Math.sqrt(24),n=L(t[0],t[1]),s=T({x:t[0].x-r,y:t[0].y},t[0],n),i=T({x:t[0].x-r,y:t[0].y-r},t[0],n),a=[{...s,r,startAngle:n,endAngle:n+Math.PI/2},{...i,r:r*2,startAngle:n+Math.PI/2,endAngle:n+Math.PI}],o=t[0].x-r,l=t[0].y-r;for(let y=2;y<9;y++){let x=a[y-2].r+a[y-1].r,u=0;switch(y%4){case 0:{u=n,o-=a[y-2].r;break}case 1:{u=n+Math.PI/2,l-=a[y-2].r;break}case 2:{u=n+Math.PI,o+=a[y-2].r;break}case 3:{u=n+Math.PI/2*3,l+=a[y-2].r;break}}let p=u+Math.PI/2,f=T({x:o,y:l},t[0],n);a.push({...f,r:x,startAngle:u,endAngle:p});}return [{type:"arc",attrs:a},{type:"line",attrs:O(t,e)}]}return []}},W=Mt;var Et={name:"fibonacciSpeedResistanceFan",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{let r=[],n=[],s=[];if(t.length>1){let i=t[1].x>t[0].x?-38:4,a=t[1].y>t[0].y?-2:20,o=t[1].x-t[0].x,l=t[1].y-t[0].y;[1,.75,.618,.5,.382,.25,0].forEach(x=>{let u=t[1].x-o*x,p=t[1].y-l*x;r.push({coordinates:[{x:u,y:t[0].y},{x:u,y:t[1].y}]}),r.push({coordinates:[{x:t[0].x,y:p},{x:t[1].x,y:p}]}),n=n.concat(O([t[0],{x:u,y:t[1].y}],e)),n=n.concat(O([t[0],{x:t[1].x,y:p}],e)),s.unshift({x:t[0].x+i,y:p+10,text:`${x.toFixed(3)}`}),s.unshift({x:u-18,y:t[0].y+a,text:`${x.toFixed(3)}`});});}return [{type:"line",attrs:r},{type:"line",attrs:n},{type:"text",ignoreEvent:true,attrs:s}]}},B=Et;var wt={name:"fibonacciExtension",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r})=>{if(t.length<=2)return [{type:"line",attrs:{coordinates:t},styles:{style:"dashed"}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let n=e.points,s=n[1].value-n[0].value,i=t[1].y-t[0].y,a=r.getSymbol()?.pricePrecision??2,{lines:o,texts:l}=S([0,.236,.382,.5,.618,.786,1],t[1],t[2],i,s,n[2].value,a);return [{type:"line",attrs:{coordinates:t},styles:{style:"dashed"}},{type:"line",attrs:o},{type:"text",ignoreEvent:true,attrs:l}]}},H=wt;var Lt={name:"fibonacciChannel",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<=1)return [{type:"line",attrs:{coordinates:t}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];if(t.length<=2)return [{type:"line",attrs:{coordinates:[t[0],t[1]]}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let e=t[0],r=t[1],n=t[2],s=r.x-e.x,i=r.y-e.y,a=Math.sqrt(s*s+i*i);if(a===0)return [{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let o=-i/a,l=s/a,y=(n.x-e.x)*o+(n.y-e.y)*l,x=o*y,u=l*y,p=[0,.236,.382,.5,.618,.786,1],f=[],m=[];return p.forEach(c=>{let g={x:e.x+x*c,y:e.y+u*c},h={x:r.x+x*c,y:r.y+u*c};f.push({coordinates:[g,h]}),m.push({x:g.x,y:g.y-4,text:`${(c*100).toFixed(1)}%`,baseline:"bottom"});}),[{type:"line",attrs:{coordinates:[r,n]},styles:{style:"dashed"}},{type:"line",attrs:f},{type:"text",ignoreEvent:true,attrs:m}]}},q=Lt;var St={name:"fibonacciWedge",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<=1)return [{type:"line",attrs:{coordinates:t}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];if(t.length<=2)return [{type:"line",attrs:{coordinates:[t[0],t[1]]}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let e=t[0],r=t[1],n=t[2],s=[0,.236,.382,.5,.618,.786,1],i=[],a=[];return s.forEach(o=>{let l={x:e.x+(r.x-e.x)*o,y:e.y+(r.y-e.y)*o},y={x:e.x+(n.x-e.x)*o,y:e.y+(n.y-e.y)*o};i.push({coordinates:[l,y]}),a.push({x:l.x-4,y:l.y,text:`${(o*100).toFixed(1)}%`,baseline:"bottom"});}),i.push({coordinates:[e,r]}),i.push({coordinates:[e,n]}),[{type:"line",attrs:i},{type:"text",ignoreEvent:true,attrs:a}]}},N=St;var Ct={name:"fibonacciTimeZones",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{if(t.length<=1)return [{type:"line",attrs:{coordinates:t}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let r=t[0],s=t[1].x-r.x;if(s===0)return [{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let i=[1,2,3,5,8,13,21,34,55,89],a=[],o=[];return i.forEach(l=>{let y=r.x+s*l;a.push({coordinates:[{x:y,y:0},{x:y,y:e.height}]}),o.push({x:y+2,y:14,text:`${l}`,baseline:"top"});}),a.push({coordinates:[{x:r.x,y:0},{x:r.x,y:e.height}]}),[{type:"line",attrs:a},{type:"text",ignoreEvent:true,attrs:o}]}},Z=Ct;var Yt={name:"fibonacciArcs",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<=1)return [{type:"line",attrs:{coordinates:t}},{type:"arc",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let e=t[0],r=t[1],n=D(e,r);if(n===0)return [{type:"arc",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let s=Math.atan2(r.y-e.y,r.x-e.x),i=[.236,.382,.5,.618,.786,1],a=[],o=[];return i.forEach(l=>{let y=n*l;a.push({x:e.x,y:e.y,r:y,startAngle:s,endAngle:s+Math.PI}),o.push({x:e.x+y*Math.cos(s),y:e.y+y*Math.sin(s),text:`${(l*100).toFixed(1)}%`,baseline:"bottom"});}),[{type:"line",attrs:{coordinates:[e,r]}},{type:"arc",attrs:a},{type:"text",ignoreEvent:true,attrs:o}]}},j=Yt;var Xt={name:"fibonacciFan",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{if(t.length<=1)return [{type:"line",attrs:{coordinates:t}},{type:"line",attrs:[]},{type:"text",ignoreEvent:true,attrs:[]}];let r=t[0],n=t[1],s=n.x-r.x,i=n.y-r.y,a=[0,.382,.5,.618,1,1.618,2.618],o=[],l=[];return a.forEach(y=>{let x={x:r.x+s,y:r.y+i*y},u=O([r,x],e);Array.isArray(u)?o.push(...u):o.push(u),l.push({x:r.x+4,y:r.y+i*y+2,text:`${y.toFixed(3)}`,baseline:"top"});}),[{type:"line",attrs:o},{type:"text",ignoreEvent:true,attrs:l}]}},G=Xt;var Rt={name:"gannBox",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{polygon:{color:v}},createPointFigures:({coordinates:t})=>{if(t.length>1){let e=(t[1].y-t[0].y)/4,r=t[1].x-t[0].x,n=[{coordinates:[t[0],{x:t[1].x,y:t[1].y-e}]},{coordinates:[t[0],{x:t[1].x,y:t[1].y-e*2}]},{coordinates:[{x:t[0].x,y:t[1].y},{x:t[1].x,y:t[0].y+e}]},{coordinates:[{x:t[0].x,y:t[1].y},{x:t[1].x,y:t[0].y+e*2}]},{coordinates:[{...t[0]},{x:t[0].x+r*.236,y:t[1].y}]},{coordinates:[{...t[0]},{x:t[0].x+r*.5,y:t[1].y}]},{coordinates:[{x:t[0].x,y:t[1].y},{x:t[0].x+r*.236,y:t[0].y}]},{coordinates:[{x:t[0].x,y:t[1].y},{x:t[0].x+r*.5,y:t[0].y}]}],s=[{coordinates:[t[0],t[1]]},{coordinates:[{x:t[0].x,y:t[1].y},{x:t[1].x,y:t[0].y}]}];return [{type:"line",attrs:[{coordinates:[t[0],{x:t[1].x,y:t[0].y}]},{coordinates:[{x:t[1].x,y:t[0].y},t[1]]},{coordinates:[t[1],{x:t[0].x,y:t[1].y}]},{coordinates:[{x:t[0].x,y:t[1].y},t[0]]}]},{type:"polygon",ignoreEvent:true,attrs:{coordinates:[t[0],{x:t[1].x,y:t[0].y},t[1],{x:t[0].x,y:t[1].y}]},styles:{style:"fill"}},{type:"line",attrs:n,styles:{style:"dashed"}},{type:"line",attrs:s}]}return []}},U=Rt;var It=[{label:"1x8",ratio:8},{label:"1x4",ratio:4},{label:"1x3",ratio:3},{label:"1x2",ratio:2},{label:"1x1",ratio:1},{label:"2x1",ratio:.5},{label:"3x1",ratio:.3333333333333333},{label:"4x1",ratio:.25},{label:"8x1",ratio:.125}],$t={name:"gannFan",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{if(t.length<2)return [];let[r,n]=t,s=n.x-r.x,i=n.y-r.y;if(Math.abs(s)<1e-6)return [];let a=i/s,o=[],l=[];for(let{label:y,ratio:x}of It){let u=a*x,p=kt(r,u,s>0,e);o.push({coordinates:[r,p]}),l.push({x:p.x,y:p.y,text:y,baseline:"bottom"});}return [{type:"line",attrs:o},{type:"text",ignoreEvent:true,attrs:l}]}};function kt(t,e,r,n){let s=[],i=r?n.width:0,a=t.y+e*(i-t.x);if(a>=0&&a<=n.height&&s.push({x:i,y:a}),Math.abs(e)>1e-6){let o=t.x+(0-t.y)/e;o>=0&&o<=n.width&&(r?o>t.x:o<t.x)&&s.push({x:o,y:0});let l=t.x+(n.height-t.y)/e;l>=0&&l<=n.width&&(r?l>t.x:l<t.x)&&s.push({x:l,y:n.height});}return s.length===0?{x:i,y:a}:s.reduce((o,l)=>{let y=Math.hypot(o.x-t.x,o.y-t.y);return Math.hypot(l.x-t.x,l.y-t.y)>y?l:o})}var z=$t;var _t={name:"pitchfork",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e})=>{if(t.length<2)return [];let[r,n,s]=t;if(t.length===2)return [{type:"line",attrs:{coordinates:[r,n]}}];let i={x:(n.x+s.x)/2,y:(n.y+s.y)/2},a=i.x-r.x,o=i.y-r.y,l=E(r,i,e),y={x:n.x+a*10,y:n.y+o*10},x={x:s.x+a*10,y:s.y+o*10},u=E(n,y,e),p=E(s,x,e),f=J(n,i,.5),m=J(s,i,.5),c={x:f.x+a*10,y:f.y+o*10},g={x:m.x+a*10,y:m.y+o*10},h=E(f,c,e),F=E(m,g,e);return [{type:"line",attrs:l},{type:"line",attrs:u},{type:"line",attrs:p},{type:"line",attrs:[{coordinates:[r,n]},{coordinates:[r,s]}],styles:{style:"dashed"}},{type:"line",attrs:[h,F],styles:{style:"dashed"}}]}};function E(t,e,r){let n=e.x-t.x,s=e.y-t.y;if(Math.abs(n)<1e-6)return {coordinates:[{x:t.x,y:0},{x:t.x,y:r.height}]};let i=s/n,a=t.y-i*t.x,o=a,l=i*r.width+a;return {coordinates:[{x:0,y:o},{x:r.width,y:l}]}}function J(t,e,r){return {x:t.x+(e.x-t.x)*r,y:t.y+(e.y-t.y)*r}}var K=_t;function C(t,e){return {name:t,totalStep:e,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:r})=>{let n=r.map((s,i)=>({...s,text:`(${i})`,baseline:"bottom"}));return [{type:"line",attrs:{coordinates:r}},{type:"text",ignoreEvent:true,attrs:n}]}}}var Q=C("threeWaves",5),tt=C("fiveWaves",7),et=C("eightWaves",10),rt=C("anyWaves",Number.MAX_SAFE_INTEGER);var Vt={name:"abcd",totalStep:5,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{let e=[],r=[],n=["A","B","C","D"],s=t.map((i,a)=>({...i,baseline:"bottom",text:`(${n[a]})`}));return t.length>2&&(e=[t[0],t[2]],t.length>3&&(r=[t[1],t[3]])),[{type:"line",attrs:{coordinates:t}},{type:"line",attrs:[{coordinates:e},{coordinates:r}],styles:{style:"dashed"}},{type:"text",ignoreEvent:true,attrs:s}]}},nt=Vt;var Wt={name:"xabcd",totalStep:6,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,styles:{polygon:{color:v}},createPointFigures:({coordinates:t,overlay:e})=>{let r=[],n=[],s=["X","A","B","C","D"],i=t.map((a,o)=>({...a,baseline:"bottom",text:`(${s[o]})`}));return t.length>2&&(r.push({coordinates:[t[0],t[2]]}),n.push({coordinates:[t[0],t[1],t[2]]}),t.length>3&&(r.push({coordinates:[t[1],t[3]]}),t.length>4&&(r.push({coordinates:[t[2],t[4]]}),n.push({coordinates:[t[2],t[3],t[4]]})))),[{type:"line",attrs:{coordinates:t}},{type:"line",attrs:r,styles:{style:"dashed"}},{type:"polygon",ignoreEvent:true,attrs:n},{type:"text",ignoreEvent:true,attrs:i}]}},st=Wt;var Bt={name:"measure",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<2)return [];let e=t[0],r=t[1],n=t.length>2?t[2]:void 0,s=Math.abs(r.x-e.x),i=Math.abs(r.y-e.y),a=Math.sqrt(s*s+i*i),o=r.x>e.x?r.x+6:r.x-80,l=[{type:"line",attrs:{coordinates:[e,r]}},{type:"text",ignoreEvent:true,attrs:{x:o,y:r.y+4,text:`${a.toFixed(0)}px`,align:"left",baseline:"top"}}];return n&&l.push({type:"line",attrs:{coordinates:[e,n]}}),l}},it=Bt;var Ht={name:"longPosition",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r,chart:n})=>{if(t.length<2)return [];let s=t[0],i=t[1],a=t.length>2?t[2]:void 0,o=n.getSymbol()?.pricePrecision??2,l=[{coordinates:[{x:0,y:s.y},{x:e.width,y:s.y}]},{coordinates:[{x:0,y:i.y},{x:e.width,y:i.y}]}],y=[{x:4,y:s.y,text:`Entry ${(r.points[0]?.value??0).toFixed(o)}`,baseline:"bottom"},{x:4,y:i.y,text:`Stop ${(r.points[1]?.value??0).toFixed(o)}`,baseline:"top"}],x=[{type:"line",attrs:l},{type:"text",ignoreEvent:true,attrs:y}],u=s.y-i.y;if(u>0&&x.push({type:"rect",attrs:{x:0,y:i.y,width:e.width,height:u},styles:{style:"fill",color:"rgba(239, 83, 80, 0.12)"},ignoreEvent:true}),a){l.push({coordinates:[{x:0,y:a.y},{x:e.width,y:a.y}]}),y.push({x:4,y:a.y,text:`Target ${(r.points[2]?.value??0).toFixed(o)}`,baseline:"bottom"});let p=a.y-s.y;p>0&&(x.push({type:"rect",attrs:{x:0,y:s.y,width:e.width,height:p},styles:{style:"fill",color:"rgba(38, 166, 154, 0.12)"},ignoreEvent:true}),u>0&&y.push({x:e.width-80,y:s.y-4,text:`R:R ${(p/u).toFixed(2)}`,baseline:"bottom"}));}return x}},at=Ht;var qt={name:"shortPosition",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r,chart:n})=>{if(t.length<2)return [];let s=t[0],i=t[1],a=t.length>2?t[2]:void 0,o=n.getSymbol()?.pricePrecision??2,l=[{coordinates:[{x:0,y:s.y},{x:e.width,y:s.y}]},{coordinates:[{x:0,y:i.y},{x:e.width,y:i.y}]}],y=[{x:4,y:s.y,text:`Entry ${(r.points[0]?.value??0).toFixed(o)}`,baseline:"bottom"},{x:4,y:i.y,text:`Stop ${(r.points[1]?.value??0).toFixed(o)}`,baseline:"top"}],x=[{type:"line",attrs:l},{type:"text",ignoreEvent:true,attrs:y}],u=i.y-s.y;if(u>0&&x.push({type:"rect",attrs:{x:0,y:s.y,width:e.width,height:u},styles:{style:"fill",color:"rgba(239, 83, 80, 0.12)"},ignoreEvent:true}),a){l.push({coordinates:[{x:0,y:a.y},{x:e.width,y:a.y}]}),y.push({x:4,y:a.y,text:`Target ${(r.points[2]?.value??0).toFixed(o)}`,baseline:"top"});let p=s.y-a.y;p>0&&(x.push({type:"rect",attrs:{x:0,y:a.y,width:e.width,height:p},styles:{style:"fill",color:"rgba(38, 166, 154, 0.12)"},ignoreEvent:true}),u>0&&y.push({x:e.width-80,y:s.y+4,text:`R:R ${(p/u).toFixed(2)}`,baseline:"top"}));}return x}},ot=qt;var Nt={name:"positionForecast",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<2)return [];let e=t[0],r=t[1],n=r.x-e.x,s=r.y-e.y,i={x:r.x+n*.5,y:r.y+s*.5},a=Math.abs(s)*.15+8;return [{type:"line",attrs:{coordinates:[e,r]},styles:{style:"solid"}},{type:"line",attrs:{coordinates:[r,i]},styles:{style:"dashed"}},{type:"polygon",attrs:{coordinates:[r,{x:i.x,y:i.y-a},i,{x:i.x,y:i.y+a}]},styles:{style:"fill",color:"rgba(41, 98, 255, 0.08)"},ignoreEvent:true}]}},lt=Nt;var Zt={name:"barsPattern",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r,xAxis:n,yAxis:s})=>{if(t.length<3||!n||!s)return [];let i=e.points[0]?.dataIndex??0,a=e.points[1]?.dataIndex??i,o=t[2].x,l=r.getDataList(),y=Math.min(i,a),x=Math.max(i,a),u=Math.max(2,Math.abs(n.convertToPixel(1)-n.convertToPixel(0))*.6),p=[],f=[];for(let c=y;c<=x&&c<l.length;c++){let g=l[c];if(!g)continue;let h=o+(c-y)*u,F=s.convertToPixel(g.open),b=s.convertToPixel(g.close),d=s.convertToPixel(g.high),P=s.convertToPixel(g.low);p.push({coordinates:[{x:h,y:d},{x:h,y:P}]});let A=Math.min(F,b),M=Math.max(1,Math.abs(b-F));f.push({x:h-u/2,y:A,width:u,height:M});}let m=[];return p.length&&m.push({type:"line",attrs:p,styles:{color:"rgba(120, 120, 120, 0.6)"}}),f.length&&m.push({type:"rect",attrs:f,styles:{style:"stroke_fill",color:"rgba(120, 120, 120, 0.3)",borderColor:"rgba(120, 120, 120, 0.6)"},ignoreEvent:true}),m}},yt=Zt;var jt={name:"ghostFeed",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r,xAxis:n,yAxis:s})=>{if(t.length<2||!n||!s)return [];let i=e.points[0]?.dataIndex??0,a=t[1].x-t[0].x,o=r.getDataList(),l=Math.max(2,Math.abs(n.convertToPixel(1)-n.convertToPixel(0))*.6),y=Math.min(50,i+1),x=[],u=[];for(let f=0;f<y;f++){let m=i-y+1+f;if(m<0||m>=o.length)continue;let c=o[m];if(!c)continue;let h=n.convertToPixel(m)+a,F=s.convertToPixel(c.open),b=s.convertToPixel(c.close),d=s.convertToPixel(c.high),P=s.convertToPixel(c.low);x.push({coordinates:[{x:h,y:d},{x:h,y:P}]});let A=Math.min(F,b),M=Math.max(1,Math.abs(b-F));u.push({x:h-l/2,y:A,width:l,height:M});}let p=[];return x.length&&p.push({type:"line",attrs:x,styles:{color:"rgba(100, 149, 237, 0.5)"}}),u.length&&p.push({type:"rect",attrs:u,styles:{style:"stroke_fill",color:"rgba(100, 149, 237, 0.2)",borderColor:"rgba(100, 149, 237, 0.5)"},ignoreEvent:true}),p}},ut=jt;var Gt={name:"sector",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t})=>{if(t.length<3)return [];let e=t[0],r=t[1],n=t[2],s=Math.sqrt((r.x-e.x)**2+(r.y-e.y)**2),i=Math.atan2(r.y-e.y,r.x-e.x),a=Math.atan2(n.y-e.y,n.x-e.x);return [{type:"arc",attrs:{x:e.x,y:e.y,r:s,startAngle:i,endAngle:a},styles:{style:"stroke_fill",color:"rgba(41, 98, 255, 0.1)"}},{type:"line",attrs:{coordinates:[e,r]}},{type:"line",attrs:{coordinates:[e,n]}}]}},xt=Gt;var Ut={name:"anchoredVwap",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r,xAxis:n,yAxis:s})=>{if(t.length<1||!n||!s)return [];let i=e.points[0]?.dataIndex??0,a=r.getDataList(),o=a.length-1;if(i>=o)return [];let l=0,y=0,x=[];for(let u=i;u<=o&&u<a.length;u++){let p=a[u];if(!p)continue;let f=(p.high+p.low+p.close)/3,m=p.volume??0;if(l+=f*m,y+=m,y>0){let c=l/y,g=n.convertToPixel(u),h=s.convertToPixel(c);x.push({x:g,y:h});}}return x.length<2?[]:[{type:"line",attrs:{coordinates:x},styles:{style:"solid",color:"#2962ff"}}]}},pt=Ut;var zt={name:"fixedRangeVolumeProfile",totalStep:4,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r,chart:n,xAxis:s,yAxis:i})=>{if(t.length<2||!s||!i)return [];let a=r.points[0]?.dataIndex??0,o=r.points[1]?.dataIndex??a,l=n.getDataList(),y=Math.min(t[0].y,t[1].y),x=Math.max(t[0].y,t[1].y),u=24,p=(x-y)/u,f=new Array(u).fill(0),m=Math.min(a,o),c=Math.max(a,o);for(let b=m;b<=c&&b<l.length;b++){let d=l[b];if(!d)continue;let P=d.volume??0,A=i.convertToPixel(d.high),M=i.convertToPixel(d.low),bt=Math.max(0,Math.floor((A-y)/p)),dt=Math.min(u-1,Math.floor((M-y)/p));for(let Y=bt;Y<=dt;Y++)f[Y]+=P;}let g=Math.max(...f,1),h=e.width*.25,F=[];for(let b=0;b<u;b++){if(f[b]<=0)continue;let d=f[b]/g*h;F.push({x:e.width-d,y:y+b*p,width:d,height:p*.9});}return [{type:"rect",attrs:F,styles:{style:"fill",color:"rgba(41, 98, 255, 0.4)"},ignoreEvent:true}]}},ct=zt;var Jt={name:"anchoredVolumeProfile",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r,chart:n,yAxis:s})=>{if(t.length<1||!s)return [];let i=r.points[0]?.dataIndex??0,a=n.getDataList(),o=30,l=e.top,x=(e.bottom-l)/o,u=new Array(o).fill(0);for(let c=i;c<a.length;c++){let g=a[c];if(!g)continue;let h=g.volume??0,F=s.convertToPixel(g.high),b=s.convertToPixel(g.low),d=Math.max(0,Math.floor((F-l)/x)),P=Math.min(o-1,Math.floor((b-l)/x));for(let A=d;A<=P;A++)u[A]+=h;}let p=Math.max(...u,1),f=e.width*.2,m=[];for(let c=0;c<o;c++){if(u[c]<=0)continue;let g=u[c]/p*f;m.push({x:e.width-g,y:l+c*x,width:g,height:x*.9});}return [{type:"rect",attrs:m,styles:{style:"fill",color:"rgba(41, 98, 255, 0.3)"},ignoreEvent:true}]}},ft=Jt;var Kt={name:"priceRange",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r,chart:n})=>{if(t.length<2)return [];let s=t[0],i=t[1],a=n.getSymbol()?.pricePrecision??2,o=r.points[0]?.value??0,l=r.points[1]?.value??0,y=Math.abs(o-l).toFixed(a),x=o!==0?(Math.abs(o-l)/o*100).toFixed(2):"0.00";return [{type:"line",attrs:[{coordinates:[{x:0,y:s.y},{x:e.width,y:s.y}]},{coordinates:[{x:0,y:i.y},{x:e.width,y:i.y}]},{coordinates:[{x:20,y:s.y},{x:20,y:i.y}]}]},{type:"text",ignoreEvent:true,attrs:[{x:24,y:s.y,text:o.toFixed(a),baseline:"bottom"},{x:24,y:i.y,text:l.toFixed(a),baseline:"top"},{x:24,y:(s.y+i.y)/2,text:`${y} (${x}%)`,baseline:"middle"}]}]}},mt=Kt;var Qt={name:"dateRange",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,bounding:e,overlay:r})=>{if(t.length<2)return [];let n=t[0],s=t[1],i=r.points[0]?.timestamp??0,a=r.points[1]?.timestamp??0,o=y=>{let x=new Date(y);return `${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`},l=Math.abs(Math.round((a-i)/864e5));return [{type:"line",attrs:[{coordinates:[{x:n.x,y:0},{x:n.x,y:e.height}]},{coordinates:[{x:s.x,y:0},{x:s.x,y:e.height}]},{coordinates:[{x:n.x,y:16},{x:s.x,y:16}]}]},{type:"text",ignoreEvent:true,attrs:[{x:n.x+4,y:12,text:o(i),baseline:"bottom"},{x:s.x+4,y:12,text:o(a),baseline:"bottom"},{x:(n.x+s.x)/2,y:28,text:`${l}d`,baseline:"top"}]}]}},gt=Qt;var te={name:"dateAndPriceRange",totalStep:3,needDefaultPointFigure:true,needDefaultXAxisFigure:true,needDefaultYAxisFigure:true,createPointFigures:({coordinates:t,overlay:e,chart:r})=>{if(t.length<2)return [];let n=t[0],s=t[1],i=r.getSymbol()?.pricePrecision??2,a=e.points[0]?.value??0,o=e.points[1]?.value??0,l=e.points[0]?.timestamp??0,y=e.points[1]?.timestamp??0,x=Math.min(n.x,s.x),u=Math.min(n.y,s.y),p=Math.abs(s.x-n.x),f=Math.abs(s.y-n.y),m=g=>{let h=new Date(g);return `${h.getFullYear()}-${String(h.getMonth()+1).padStart(2,"0")}-${String(h.getDate()).padStart(2,"0")}`},c=Math.abs(Math.round((y-l)/864e5));return [{type:"rect",attrs:{x,y:u,width:p,height:f},styles:{style:"stroke_fill",color:"rgba(41, 98, 255, 0.06)",borderColor:"#2962ff"},ignoreEvent:true},{type:"text",ignoreEvent:true,attrs:[{x:x+p+4,y:u,text:Math.max(a,o).toFixed(i),baseline:"bottom"},{x:x+p+4,y:u+f,text:Math.min(a,o).toFixed(i),baseline:"top"},{x,y:u+f+4,text:m(Math.min(l,y)),baseline:"top"},{x:x+p,y:u+f+4,text:m(Math.max(l,y)),baseline:"top"},{x:x+p/2,y:u+f+18,text:`${c}d`,baseline:"top"}]}]}},ht=te;var Sr=[X,R,I,k,$,_,V,W,B,H,q,N,Z,j,G,U,z,K,Q,tt,et,rt,nt,st,it,at,ot,lt,yt,ut,xt,pt,ct,ft,mt,gt,ht];export{Sr as a};