1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4565],{56937:(e,t,i)=>{function r(e){let t=e.description?.split("/")[0]?.trim();return t?t.replace(/\s+Perpetual$/i,""):e.ticker.replace(/[-_/]?(USDT|USDC|USD1|USDS|BUSD|USD|EUR|PERP)$/i,"")||e.ticker}function l(e){let t=e.trim().toUpperCase();return t?`https://crypto-icons.ledger.com/${encodeURIComponent(t)}.png`:void 0}i.d(t,{F:()=>l,b:()=>r})},94565:(e,t,i)=>{i.r(t),i.d(t,{HyperliquidProvider:()=>p});var r=i(56937),l={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h",D:"1d",W:"1w",M:"1M"},s={"1m":"1","3m":"3","5m":"5","15m":"15","30m":"30","45m":"45","1h":"60","2h":"120","3h":"180","4h":"240","6h":"360","8h":"480","12h":"720","1d":"D","1w":"W","1mo":"M","1D":"D","1W":"W","4H":"240",D:"D",W:"W",M:"M"},n=[1,3,5,15,30,60,120,240,480,720],a={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",60:"1h",120:"2h",240:"4h",480:"8h",720:"12h"},o=["1","3","5","15","30","45","60","120","180","240","360","480","720","D","W","M"],u={D:864e5,W:6048e5,M:2592e6};function m(e){return s[e]??s[e.toLowerCase()]??e}function c(e){let t=e.trim();return t.includes("/")?t:t.toUpperCase()}function h(e){return{time:Number(e.t),open:Number(e.o),high:Number(e.h),low:Number(e.l),close:Number(e.c),volume:Number(e.v)}}var p=class{constructor(){this.metaPromise=null,this.spotMetaPromise=null,this.symbolsPromise=null}info(){return{name:"hyperliquid",displayName:"Hyperliquid",requiresApiKey:!1,supportedTimeframes:o,capabilities:{enumerate:!0,stream:!0,symbolInfo:!0}}}async getBars(e,t,i){try{let s=c(e),o=m(t),p=l[o];if(p){var r=(await this.fetchCandles(s,p,function(e){if(u[e])return u[e];let t=parseInt(e,10);return Number.isFinite(t)&&t>0?6e4*t:36e5}(o),i)).map(h);let e=new Map;for(let t of r)e.set(t.time,t);return[...e.values()].sort((e,t)=>e.time-t.time)}let d=/^\d+$/.test(o)?parseInt(o,10):null,f=null!=d?n.filter(e=>e<d&&d%e==0).sort((e,t)=>t-e)[0]??null:null;if(null==d||null==f)return console.warn(`[vela] Hyperliquid: timeframe "${t}" is not supported and cannot be aggregated.`),[];let y=d/f,w={...i,limit:null!=i.limit?i.limit*y+y:void 0},b=(await this.fetchCandles(s,a[f],6e4*f,w)).map(h),S=function(e,t){let i=new Map;for(let r of e){let e=Math.floor(r.time/t)*t,l=i.get(e);l?(l.high=Math.max(l.high,r.high),l.low=Math.min(l.low,r.low),l.close=r.close,l.volume=(l.volume??0)+(r.volume??0)):i.set(e,{time:e,open:r.open,high:r.high,low:r.low,close:r.close,volume:r.volume??0})}return[...i.values()].sort((e,t)=>e.time-t.time)}(b,6e4*d);return null!=i.limit&&S.length>i.limit?S.slice(-i.limit):S}catch(i){return console.warn(`[vela] Hyperliquid: failed to fetch ${e} ${t} \u2014 ${i instanceof Error?i.message:String(i)}`),[]}}async getSymbolInfo(e){let t=c(e),i=await this.fetchMeta().catch(()=>null),r=i?.universe?.find(e=>e.name===t);if(r)return d(e,t,"USD","futures",`${t} / USD Perpetual`,f(Math.max(0,6-(r.szDecimals??2))));if(t.includes("/")){let i=await this.fetchSpotMeta().catch(()=>null),r=i?.universe?.find(e=>e.name===t),l=r&&i?.tokens?i.tokens[r.tokens?.[0]??-1]:void 0,[s=t,n="USDC"]=t.split("/");return d(e,s,n,"crypto",`${s} / ${n}`,f(Math.max(0,8-(l?.szDecimals??2))))}}listSymbols(){return this.symbolsPromise||(this.symbolsPromise=Promise.all([this.listPerps().catch(()=>[]),this.listSpot().catch(()=>[])]).then(([e,t])=>[...e,...t])),this.symbolsPromise}resolveSymbolIcon(e){return(0,r.F)((0,r.b)(e))}subscribe(e,t,i){let r=c(e),s=l[m(t)];return s&&"undefined"!=typeof WebSocket?this.streamCandles(e,t,r,s,i):this.pollBars(e,t,i)}async listPerps(){return((await this.fetchMeta()).universe??[]).filter(e=>!e.isDelisted).map(e=>({ticker:e.name,description:`${e.name} / USD Perpetual`,type:"futures"}))}async listSpot(){let e=await this.fetchSpotMeta(),t=e.tokens??[],i=e=>null!=e?t[e]?.name??null:null;return(e.universe??[]).map(e=>{let t=i(e.tokens?.[0]),r=i(e.tokens?.[1]),l=t&&r?`${t} / ${r}`:e.name;return{ticker:e.name,description:l,type:"crypto"}})}async fetchCandles(e,t,i,r){let l=r.to??Date.now(),s=null!=r.from?r.from:l-((r.limit??500)+2)*i,n=await this.candleSnapshot(e,t,s,l);return null==r.from&&null!=r.limit&&n.length>r.limit?n.slice(-r.limit):n}async candleSnapshot(e,t,i,r){let l=await this.post({type:"candleSnapshot",req:{coin:e,interval:t,startTime:Math.floor(i),endTime:Math.floor(r)}});return Array.isArray(l)?l:[]}streamCandles(e,t,i,r,l){let s=!1,n=null,a=null,o=null,u=null,m=null,c=()=>{u&&(clearTimeout(u),u=null)},p=()=>{a&&(clearInterval(a),a=null)},d=()=>
1{if(!s&&!m){c(),p(),o&&(clearTimeout(o),o=null);try{n?.close()}catch{}n=null,console.warn(`[vela] Hyperliquid: ${e} ${t} stream delivered no data; falling back to polling.`),m=this.pollBars(e,t,l)}},f=()=>{s||m||(n=new WebSocket("wss://api.hyperliquid.xyz/ws"),u=setTimeout(d,15e3),n.onopen=()=>{try{n?.send(JSON.stringify({method:"subscribe",subscription:{type:"candle",coin:i,interval:r}}))}catch{}a=setInterval(()=>{try{n?.send(JSON.stringify({method:"ping"}))}catch{}},3e4)},n.onmessage=e=>{if(!s&&!m)try{let t=JSON.parse("string"==typeof e.data?e.data:"");"candle"===t.channel&&t.data&&t.data.s===i&&(c(),l(h(t.data)))}catch{}},n.onclose=()=>{p(),s||m||(o=setTimeout(f,2e3))},n.onerror=()=>{try{n?.close()}catch{}})};return f(),()=>{s=!0,c(),p(),o&&clearTimeout(o),m?.();try{n?.close()}catch{}}}pollBars(e,t,i){let r=!1,l=null,s=async()=>{if(!r){try{for(let r of(await this.getBars(e,t,{limit:2})))i(r)}catch{}r||(l=setTimeout(()=>void s(),3e3))}};return l=setTimeout(()=>void s(),3e3),()=>{r=!0,l&&clearTimeout(l)}}fetchMeta(){return this.metaPromise??(this.metaPromise=this.post({type:"meta"}).then(e=>e))}fetchSpotMeta(){return this.spotMetaPromise??(this.spotMetaPromise=this.post({type:"spotMeta"}).then(e=>e))}async post(e){let t=await fetch("https://api.hyperliquid.xyz/info",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`Hyperliquid HTTP ${t.status}`);return t.json()}};function d(e,t,i,r,l,s){return{ticker:e,tickerid:`HYPERLIQUID:${e}`,prefix:"HYPERLIQUID",description:l,type:r,basecurrency:t,currency:i,mintick:s,pricescale:Math.round(1/s),timezone:"Etc/UTC",session:"24x7"}}function f(e){return Math.pow(10,-e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.