stock-sdk 1.8.2 → 1.8.3
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.
- package/README.md +39 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +426 -594
- package/dist/index.d.ts +426 -594
- package/dist/index.js +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Gn=Object.defineProperty;var Fe=(t,e)=>{for(var n in e)Gn(t,n,{get:e[n],enumerable:!0})};function ae(t){return new TextDecoder("gbk").decode(t)}function le(t){let e=t.split(";").map(i=>i.trim()).filter(Boolean),n=[];for(let i of e){let r=i.indexOf("=");if(r<0)continue;let o=i.slice(0,r).trim();o.startsWith("v_")&&(o=o.slice(2));let s=i.slice(r+1).trim();s.startsWith('"')&&s.endsWith('"')&&(s=s.slice(1,-1));let a=s.split("~");n.push({key:o,fields:a})}return n}function h(t){if(!t||t==="")return 0;let e=parseFloat(t);return Number.isNaN(e)?0:e}function S(t){if(!t||t==="")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function R(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function p(t){return t==null?null:R(String(t))}var ve="https://qt.gtimg.cn",we="https://web.ifzq.gtimg.cn/appstock/app/minute/query",He="https://assets.linkdiary.cn/shares/zh_a_list.json",qe="https://assets.linkdiary.cn/shares/us_list.json",je="https://assets.linkdiary.cn/shares/hk_list.json",Qe="https://assets.linkdiary.cn/shares/fund_list",Bt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var ue="https://push2his.eastmoney.com/api/qt/stock/kline/get",$e="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Ge="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",ze="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Ve="https://17.push2.eastmoney.com/api/qt/clist/get",We="https://91.push2.eastmoney.com/api/qt/stock/get",Xe="https://29.push2.eastmoney.com/api/qt/clist/get",Ye="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",Ze="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Je="https://79.push2.eastmoney.com/api/qt/clist/get",et="https://91.push2.eastmoney.com/api/qt/stock/get",tt="https://29.push2.eastmoney.com/api/qt/clist/get",nt="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",rt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",B="https://datacenter-web.eastmoney.com/api/data/v1/get",V="https://push2his.eastmoney.com/api/qt/stock/kline/get",ot="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",W="58b2fa8f54638b60b87d69b31969089c",it={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},H={cu:"SHFE",al:"SHFE",zn:"SHFE",pb:"SHFE",au:"SHFE",ag:"SHFE",rb:"SHFE",wr:"SHFE",fu:"SHFE",ru:"SHFE",bu:"SHFE",hc:"SHFE",ni:"SHFE",sn:"SHFE",sp:"SHFE",ss:"SHFE",ao:"SHFE",br:"SHFE",c:"DCE",a:"DCE",b:"DCE",m:"DCE",y:"DCE",p:"DCE",l:"DCE",v:"DCE",j:"DCE",jm:"DCE",i:"DCE",jd:"DCE",pp:"DCE",cs:"DCE",eg:"DCE",eb:"DCE",pg:"DCE",lh:"DCE",WH:"CZCE",CF:"CZCE",SR:"CZCE",TA:"CZCE",OI:"CZCE",MA:"CZCE",FG:"CZCE",RM:"CZCE",SF:"CZCE",SM:"CZCE",ZC:"CZCE",AP:"CZCE",CJ:"CZCE",UR:"CZCE",SA:"CZCE",PF:"CZCE",PK:"CZCE",PX:"CZCE",SH:"CZCE",sc:"INE",nr:"INE",lu:"INE",bc:"INE",ec:"INE",IF:"CFFEX",IC:"CFFEX",IH:"CFFEX",IM:"CFFEX",TS:"CFFEX",TF:"CFFEX",T:"CFFEX",TL:"CFFEX",si:"GFEX",lc:"GFEX",ps:"GFEX",pt:"GFEX",pd:"GFEX"},ce={HG:101,GC:101,SI:101,QI:101,QO:101,MGC:101,CL:102,NG:102,RB:102,HO:102,PA:102,PL:102,ZW:103,ZM:103,ZS:103,ZC:103,ZL:103,ZR:103,YM:103,NQ:103,ES:103,SB:108,CT:108,LCPT:109,LZNT:109,LALT:109},X="https://stock.finance.sina.com.cn/futures/api/openapi.php/OptionService.getOptionData",Y="https://stock.finance.sina.com.cn/futures/api/jsonp.php/{callback}/FutureOptionAllService.getOptionDayline",st="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName",pe="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay",at="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline",lt="https://stock.finance.sina.com.cn/futures/api/jsonp_v2.php/{callback}/StockOptionDaylineService.getSymbolInfo",ut="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getFiveDayLine",ct="https://futsseapi.eastmoney.com/list/option/221",pt="https://datacenter-web.eastmoney.com/api/data/get",dt="b2884a393a59ad64002292a3e90d46a5";var de={au:{product:"au_o",exchange:"shfe"},ag:{product:"ag_o",exchange:"shfe"},cu:{product:"cu_o",exchange:"shfe"},al:{product:"al_o",exchange:"shfe"},zn:{product:"zn_o",exchange:"shfe"},ru:{product:"ru_o",exchange:"shfe"},sc:{product:"sc_o",exchange:"ine"},m:{product:"m_o",exchange:"dce"},c:{product:"c_o",exchange:"dce"},i:{product:"i_o",exchange:"dce"},p:{product:"p_o",exchange:"dce"},pp:{product:"pp_o",exchange:"dce"},l:{product:"l_o",exchange:"dce"},v:{product:"v_o",exchange:"dce"},pg:{product:"pg_o",exchange:"dce"},y:{product:"y_o",exchange:"dce"},a:{product:"a_o",exchange:"dce"},b:{product:"b_o",exchange:"dce"},eg:{product:"eg_o",exchange:"dce"},eb:{product:"eb_o",exchange:"dce"},SR:{product:"SR_o",exchange:"czce"},CF:{product:"CF_o",exchange:"czce"},TA:{product:"TA_o",exchange:"czce"},MA:{product:"MA_o",exchange:"czce"},RM:{product:"RM_o",exchange:"czce"},OI:{product:"OI_o",exchange:"czce"},PK:{product:"PK_o",exchange:"czce"},PF:{product:"PF_o",exchange:"czce"},SA:{product:"SA_o",exchange:"czce"},UR:{product:"UR_o",exchange:"czce"}},mt=3e4,Z=500,J=500,ee=7,ft=3,gt=1e3,ht=3e4,yt=2,Rt=[408,429,500,502,503,504];var me=class{constructor(e={}){let n=e.requestsPerSecond??5;this.maxTokens=e.maxBurst??n,this.tokens=this.maxTokens,this.refillRate=n/1e3,this.lastRefillTime=Date.now()}refill(){let e=Date.now(),i=(e-this.lastRefillTime)*this.refillRate;this.tokens=Math.min(this.maxTokens,this.tokens+i),this.lastRefillTime=e}tryAcquire(){return this.refill(),this.tokens>=1?(this.tokens-=1,!0):!1}getWaitTime(){if(this.refill(),this.tokens>=1)return 0;let e=1-this.tokens;return Math.ceil(e/this.refillRate)}async acquire(){let e=this.getWaitTime();e>0&&await this.sleep(e),this.refill(),this.tokens-=1}sleep(e){return new Promise(n=>setTimeout(n,e))}getAvailableTokens(){return this.refill(),this.tokens}};var Ft=["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"],Ct=0;function zn(){return typeof window<"u"&&typeof window.document<"u"}function vt(){if(zn())return;let t=Ft[Ct];return Ct=(Ct+1)%Ft.length,t}var te=class extends Error{constructor(e="Circuit breaker is OPEN"){super(e),this.name="CircuitBreakerError"}},fe=class{constructor(e={}){this.state="CLOSED";this.failureCount=0;this.lastFailureTime=0;this.halfOpenSuccessCount=0;this.failureThreshold=e.failureThreshold??5,this.resetTimeout=e.resetTimeout??3e4,this.halfOpenRequests=e.halfOpenRequests??1,this.onStateChange=e.onStateChange}getState(){return this.checkStateTransition(),this.state}canRequest(){switch(this.checkStateTransition(),this.state){case"CLOSED":return!0;case"OPEN":return!1;case"HALF_OPEN":return this.halfOpenSuccessCount<this.halfOpenRequests}}recordSuccess(){this.checkStateTransition(),this.state==="HALF_OPEN"?(this.halfOpenSuccessCount++,this.halfOpenSuccessCount>=this.halfOpenRequests&&this.transitionTo("CLOSED")):this.state==="CLOSED"&&(this.failureCount=0)}recordFailure(){this.lastFailureTime=Date.now(),this.state==="HALF_OPEN"?this.transitionTo("OPEN"):this.state==="CLOSED"&&(this.failureCount++,this.failureCount>=this.failureThreshold&&this.transitionTo("OPEN"))}checkStateTransition(){this.state==="OPEN"&&Date.now()-this.lastFailureTime>=this.resetTimeout&&this.transitionTo("HALF_OPEN")}transitionTo(e){if(this.state===e)return;let n=this.state;this.state=e,e==="CLOSED"?(this.failureCount=0,this.halfOpenSuccessCount=0):e==="HALF_OPEN"&&(this.halfOpenSuccessCount=0),this.onStateChange?.(n,e)}reset(){this.transitionTo("CLOSED"),this.failureCount=0,this.halfOpenSuccessCount=0,this.lastFailureTime=0}async execute(e){if(!this.canRequest())throw new te;try{let n=await e();return this.recordSuccess(),n}catch(n){throw this.recordFailure(),n}}getStats(){return{state:this.getState(),failureCount:this.failureCount,lastFailureTime:this.lastFailureTime,halfOpenSuccessCount:this.halfOpenSuccessCount}}};var q=class extends Error{constructor(n,i,r,o){let s=i?` ${i}`:"",a=r?`, url: ${r}`:"",l=o?`, provider: ${o}`:"";super(`HTTP error! status: ${n}${s}${a}${l}`);this.status=n;this.statusText=i;this.url=r;this.provider=o;this.name="HttpError"}},ne=class{constructor(e={}){this.baseUrl=e.baseUrl??ve;let n={timeout:e.timeout,retry:e.retry,headers:e.headers,userAgent:e.userAgent,rateLimit:e.rateLimit,rotateUserAgent:e.rotateUserAgent,circuitBreaker:e.circuitBreaker};this.defaultPolicy=this.resolveProviderPolicy(n),this.providerPolicies={},this.runtimeStates=new Map;for(let[i,r]of Object.entries(e.providerPolicies??{})){let o=this.mergeProviderPolicy(n,r);this.providerPolicies[i]=this.resolveProviderPolicy(o)}}resolveRetryOptions(e){return{maxRetries:e?.maxRetries??ft,baseDelay:e?.baseDelay??gt,maxDelay:e?.maxDelay??ht,backoffMultiplier:e?.backoffMultiplier??yt,retryableStatusCodes:e?.retryableStatusCodes??Rt,retryOnNetworkError:e?.retryOnNetworkError??!0,retryOnTimeout:e?.retryOnTimeout??!0,onRetry:e?.onRetry}}normalizeHeaders(e,n){let i={...e??{}};return n&&(Object.keys(i).some(o=>o.toLowerCase()==="user-agent")||(i["User-Agent"]=n)),i}mergeProviderPolicy(e,n){return n?{timeout:n.timeout??e.timeout,retry:n.retry?{...e.retry??{},...n.retry}:e.retry?{...e.retry}:void 0,headers:{...e.headers??{},...n.headers??{}},userAgent:n.userAgent??e.userAgent,rateLimit:n.rateLimit?{...e.rateLimit??{},...n.rateLimit}:e.rateLimit?{...e.rateLimit}:void 0,rotateUserAgent:n.rotateUserAgent??e.rotateUserAgent,circuitBreaker:n.circuitBreaker?{...e.circuitBreaker??{},...n.circuitBreaker}:e.circuitBreaker?{...e.circuitBreaker}:void 0}:{...e,headers:{...e.headers??{}},retry:e.retry?{...e.retry}:void 0,rateLimit:e.rateLimit?{...e.rateLimit}:void 0,circuitBreaker:e.circuitBreaker?{...e.circuitBreaker}:void 0}}resolveProviderPolicy(e={}){return{timeout:e.timeout??mt,retry:this.resolveRetryOptions(e.retry),headers:this.normalizeHeaders(e.headers,e.userAgent),rotateUserAgent:e.rotateUserAgent??!1,rateLimit:e.rateLimit?{...e.rateLimit}:void 0,circuitBreaker:e.circuitBreaker?{...e.circuitBreaker}:void 0}}getProviderState(e){let n=this.runtimeStates.get(e);if(n)return n;let i=this.providerPolicies[e]??this.defaultPolicy,r={policy:i,rateLimiter:i.rateLimit?new me(i.rateLimit):null,circuitBreaker:i.circuitBreaker?new fe(i.circuitBreaker):null};return this.runtimeStates.set(e,r),r}inferProvider(e,n){if(n)return n;try{let i=new URL(e).hostname;if(i.includes("eastmoney.com"))return"eastmoney";if(i.includes("gtimg.cn"))return"tencent";if(i.includes("sina.com.cn"))return"sina";if(i.includes("linkdiary.cn"))return"linkdiary"}catch{return"unknown"}return"unknown"}getTimeout(){return this.defaultPolicy.timeout}calculateDelay(e,n){return Math.min(n.baseDelay*Math.pow(n.backoffMultiplier,e),n.maxDelay)+Math.random()*100}sleep(e){return new Promise(n=>setTimeout(n,e))}shouldRetry(e,n,i){return n>=i.maxRetries?!1:e instanceof DOMException&&e.name==="AbortError"?i.retryOnTimeout:e instanceof TypeError?i.retryOnNetworkError:e instanceof q?i.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,n,i,r=0){try{let o=await e();return n.circuitBreaker?.recordSuccess(),o}catch(o){if(this.shouldRetry(o,r,n.policy.retry)){let s=this.calculateDelay(r,n.policy.retry);return n.policy.retry.onRetry&&o instanceof Error&&n.policy.retry.onRetry(r+1,o,s),await this.sleep(s),this.executeWithRetry(e,n,i,r+1)}throw n.circuitBreaker?.recordFailure(),o instanceof Error&&(o.provider=i),o}}async get(e,n={}){let i=this.inferProvider(e,n.provider),r=this.getProviderState(i);if(r.circuitBreaker&&!r.circuitBreaker.canRequest())throw new te("Circuit breaker is OPEN, request rejected");return r.rateLimiter&&await r.rateLimiter.acquire(),this.executeWithRetry(async()=>{let o=new AbortController,s=setTimeout(()=>o.abort(),r.policy.timeout),a={...r.policy.headers};if(r.policy.rotateUserAgent){let l=vt();l&&(a["User-Agent"]=l)}try{let l=await fetch(e,{signal:o.signal,headers:a});if(!l.ok)throw new q(l.status,l.statusText,e,i);switch(n.responseType){case"json":return await l.json();case"arraybuffer":return await l.arrayBuffer();default:return await l.text()}}catch(l){throw l instanceof Error&&(l.url=e,l.provider=i),l}finally{clearTimeout(s)}},r,i)}async getTencentQuote(e){let n=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,i=await this.get(n,{responseType:"arraybuffer",provider:"tencent"}),r=ae(i);return le(r)}};var Vn=new Set(["daily","weekly","monthly"]),Wn=new Set(["1","5","15","30","60"]),Xn=new Set(["","qfq","hfq"]);function K(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function I(t){if(!Vn.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function re(t){if(!Wn.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function k(t){if(!Xn.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function j(t,e){K(e,"chunkSize");let n=[];for(let i=0;i<t.length;i+=e)n.push(t.slice(i,i+e));return n}async function Q(t,e,n=!1){if(K(e,"concurrency"),t.length===0)return[];let i=n?new Array(t.length):[],r=0,o=Array.from({length:Math.min(e,t.length)},async()=>{for(;;){let s=r++;if(s>=t.length)return;let a=await t[s]();n?i[s]=a:i.push(a)}});return await Promise.all(o),i}function ge(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function M(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function N(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var Yn=typeof document<"u"&&typeof window<"u",Zn=0;function wt(){return`__stock_sdk_jsonp_${Date.now()}_${Zn++}`}function St(t){let e=t,n=e.indexOf("*/");n!==-1&&(e=e.slice(n+2).trim());let i=e.indexOf("(");if(i===-1)throw new Error("Invalid JSONP response: no opening parenthesis found");let r=e.lastIndexOf(")");if(r===-1||r<=i)throw new Error("Invalid JSONP response: no closing parenthesis found");let o=e.slice(i+1,r);return JSON.parse(o)}function Jn(t,e){let{timeout:n=15e3,callbackParam:i="callback",callbackMode:r="query"}=e;return new Promise((o,s)=>{let a=wt(),l;if(r==="path")l=t.replace("{callback}",a);else{let y=t.includes("?")?"&":"?";l=`${t}${y}${i}=${a}`}let u=document.createElement("script"),c=!1,m=window,d=()=>{u.parentNode&&u.parentNode.removeChild(u),delete m[a]},g=setTimeout(()=>{c||(c=!0,d(),s(new Error(`JSONP request timed out after ${n}ms: ${t}`)))},n);m[a]=y=>{c||(c=!0,clearTimeout(g),d(),o(y))},u.onerror=()=>{c||(c=!0,clearTimeout(g),d(),s(new Error(`JSONP script load failed: ${t}`)))},u.src=l,document.head.appendChild(u)})}async function er(t,e){let{timeout:n=15e3,callbackParam:i="callback",callbackMode:r="query"}=e,o=wt(),s;if(r==="path")s=t.replace("{callback}",o);else{let u=t.includes("?")?"&":"?";s=`${t}${u}${i}=${o}`}let a=new AbortController,l=setTimeout(()=>a.abort(),n);try{let u=await fetch(s,{signal:a.signal});if(!u.ok)throw new Error(`JSONP fetch failed with status ${u.status}: ${t}`);let c=await u.text();return St(c)}catch(u){throw u instanceof DOMException&&u.name==="AbortError"?new Error(`JSONP request timed out after ${n}ms: ${t}`):u}finally{clearTimeout(l)}}function P(t,e={}){return Yn?Jn(t,e):er(t,e)}var b={};Fe(b,{getAShareCodeList:()=>Gt,getAllHKQuotesByCodes:()=>Xt,getAllQuotesByCodes:()=>Wt,getAllUSQuotesByCodes:()=>Yt,getFullQuotes:()=>he,getFundCodeList:()=>Zt,getFundFlow:()=>qt,getFundQuotes:()=>Qt,getHKCodeList:()=>Vt,getHKQuotes:()=>ye,getPanelLargeOrder:()=>jt,getSimpleQuotes:()=>Ht,getTodayTimeline:()=>$t,getTradingCalendar:()=>Jt,getUSCodeList:()=>zt,getUSQuotes:()=>Re,parseFullQuote:()=>Ot,parseFundFlow:()=>Et,parseFundQuote:()=>At,parseHKQuote:()=>bt,parsePanelLargeOrder:()=>_t,parseSimpleQuote:()=>Tt,parseUSQuote:()=>Pt,search:()=>tn});function Ot(t){let e=[];for(let i=0;i<5;i++)e.push({price:h(t[9+i*2]),volume:h(t[10+i*2])});let n=[];for(let i=0;i<5;i++)n.push({price:h(t[19+i*2]),volume:h(t[20+i*2])});return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),outerVolume:h(t[7]),innerVolume:h(t[8]),bid:e,ask:n,time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),volume2:h(t[36]),amount:h(t[37]),turnoverRate:S(t[38]),pe:S(t[39]),amplitude:S(t[43]),circulatingMarketCap:S(t[44]),totalMarketCap:S(t[45]),pb:S(t[46]),limitUp:S(t[47]),limitDown:S(t[48]),volumeRatio:S(t[49]),avgPrice:S(t[51]),peStatic:S(t[52]),peDynamic:S(t[53]),high52w:S(t[67]),low52w:S(t[68]),circulatingShares:S(t[72]),totalShares:S(t[73]),raw:t}}function Tt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),change:h(t[4]),changePercent:h(t[5]),volume:h(t[6]),amount:h(t[7]),marketCap:S(t[9]),marketType:t[10]??"",raw:t}}function Et(t){return{code:t[0]??"",mainInflow:h(t[1]),mainOutflow:h(t[2]),mainNet:h(t[3]),mainNetRatio:h(t[4]),retailInflow:h(t[5]),retailOutflow:h(t[6]),retailNet:h(t[7]),retailNetRatio:h(t[8]),totalFlow:h(t[9]),name:t[12]??"",date:t[13]??"",raw:t}}function _t(t){return{buyLargeRatio:h(t[0]),buySmallRatio:h(t[1]),sellLargeRatio:h(t[2]),sellSmallRatio:h(t[3]),raw:t}}function bt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),amount:h(t[37]),lotSize:S(t[40]),circulatingMarketCap:S(t[44]),totalMarketCap:S(t[45]),currency:t[t.length-3]??"",raw:t}}function Pt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),amount:h(t[37]),turnoverRate:S(t[38]),pe:S(t[39]),amplitude:S(t[43]),totalMarketCap:S(t[45]),pb:S(t[47]),high52w:S(t[48]),low52w:S(t[49]),raw:t}}function At(t){return{code:t[0]??"",name:t[1]??"",nav:h(t[5]),accNav:h(t[6]),change:h(t[7]),navDate:t[8]??"",raw:t}}async function he(t,e){return!e||e.length===0?[]:(await t.getTencentQuote(e.join(","))).filter(i=>i.fields&&i.fields.length>0&&i.fields[0]!=="").map(i=>Ot(i.fields))}async function Ht(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`s_${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Tt(r.fields))}async function qt(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`ff_${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Et(r.fields))}async function jt(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`s_pk${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>_t(r.fields))}async function ye(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`hk${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>bt(r.fields))}async function Re(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`us${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Pt(r.fields))}async function Qt(t,e){if(!e||e.length===0)return[];let n=e.map(r=>`jj${r}`);return(await t.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>At(r.fields))}async function $t(t,e){let n=t.getTimeout(),i=new AbortController,r=setTimeout(()=>i.abort(),n);try{let o=await fetch(`${we}?code=${e}`,{signal:i.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let s=await o.json();if(s.code!==0)throw new Error(s.msg||"API error");let a=s.data?.[e];if(!a)return{code:e,date:"",data:[]};let l=a.data?.data||[],u=a.data?.date||"",c=!1;if(l.length>0){let d=l[0].split(" "),g=parseFloat(d[1])||0,y=parseInt(d[2],10)||0,f=parseFloat(d[3])||0;y>0&&g>0&&f/y>g*50&&(c=!0)}let m=l.map(d=>{let g=d.split(" "),y=g[0],f=`${y.slice(0,2)}:${y.slice(2,4)}`,C=parseInt(g[2],10)||0,O=parseFloat(g[3])||0,E=c?C*100:C,_=E>0?O/E:0;return{time:f,price:parseFloat(g[1])||0,volume:E,amount:O,avgPrice:Math.round(_*100)/100}});return{code:e,date:u,data:m}}finally{clearTimeout(r)}}var It=null,tr=null,Ce=null,nr=null,Se=null,Mt=null;function rr(t,e){let n=t.replace(/^(sh|sz|bj)/,"");switch(e){case"sh":return n.startsWith("6");case"sz":return n.startsWith("0")||n.startsWith("3");case"bj":return n.startsWith("92");case"kc":return n.startsWith("688");case"cy":return n.startsWith("30");default:return!0}}async function Gt(t,e){let n=!1,i;if(typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,i=e.market),!It){let s=(await t.get(He,{responseType:"json"}))?.list||[];It=s,tr=s.map(a=>a.replace(/^(sh|sz|bj)/,""))}let r=It;return i&&(r=r.filter(o=>rr(o,i))),n?r.map(o=>o.replace(/^(sh|sz|bj)/,"")):r.slice()}var or={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function zt(t,e){let n=!1,i;typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,i=e.market),Ce||(Ce=(await t.get(qe,{responseType:"json"}))?.list||[],nr=Ce.map(s=>s.replace(/^\d{3}\./,"")));let r=Ce.slice();if(i){let o=or[i];r=r.filter(s=>s.startsWith(o))}return n?r.map(o=>o.replace(/^\d{3}\./,"")):r}async function Vt(t){return Se||(Se=(await t.get(je,{responseType:"json"}))?.list||[]),Se.slice()}async function Wt(t,e,n={}){let{batchSize:i=Z,concurrency:r=ee,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,J),a=j(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await he(t,d);return u++,o&&o(u,l),g});return(await Q(c,r,!0)).flat()}async function Xt(t,e,n={}){let{batchSize:i=Z,concurrency:r=ee,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,J),a=j(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await ye(t,d);return u++,o&&o(u,l),g});return(await Q(c,r,!0)).flat()}async function Yt(t,e,n={}){let{batchSize:i=Z,concurrency:r=ee,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,J),a=j(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await Re(t,d);return u++,o&&o(u,l),g});return(await Q(c,r,!0)).flat()}async function Zt(t){if(Mt)return Mt.slice();let i=(await t.get(Qe,{responseType:"text"})).split(",").slice(1).filter(r=>r.trim());return Mt=i,i.slice()}var $=null;async function Jt(t){if($)return $.slice();let e=await t.get(Bt);return!e||e.trim()===""?($=[],$.slice()):($=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),$.slice())}var en="https://smartbox.gtimg.cn/s3/";function ir(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function sr(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let i=n.split("~"),r=i[0]||"",o=i[1]||"",s=ir(i[2]||""),a=i[4]||"";return{code:r+o,name:s,market:r,type:a}})}function ar(t){return new Promise((e,n)=>{let i=`${en}?v=2&t=all&q=${encodeURIComponent(t)}`;window.v_hint="";let r=document.createElement("script");r.src=i,r.charset="utf-8",r.onload=()=>{let o=window.v_hint||"";document.body.removeChild(r),e(o)},r.onerror=()=>{document.body.removeChild(r),n(new Error("Network error calling Smartbox"))},document.body.appendChild(r)})}async function lr(t,e){let n=`${en}?v=2&t=all&q=${encodeURIComponent(e)}`,r=(await t.get(n)).match(/v_hint="([^"]*)"/);return r?r[1]:""}function ur(){return typeof window<"u"&&typeof document<"u"}async function tn(t,e){if(!e||!e.trim())return[];let n;return ur()?n=await ar(e):n=await lr(t,e),sr(n)}var T={};Fe(T,{extractVariety:()=>Lt,getCFFEXOptionQuotes:()=>In,getComexInventory:()=>Un,getConceptConstituents:()=>Sn,getConceptKline:()=>On,getConceptList:()=>Rn,getConceptMinuteKline:()=>Tn,getConceptSpot:()=>Cn,getDividendDetail:()=>En,getFuturesHistoryKline:()=>bn,getFuturesInventory:()=>Kn,getFuturesInventorySymbols:()=>xn,getFuturesMarketCode:()=>Kt,getGlobalFuturesKline:()=>An,getGlobalFuturesSpot:()=>Pn,getHKHistoryKline:()=>on,getHistoryKline:()=>nn,getIndustryConstituents:()=>gn,getIndustryKline:()=>hn,getIndustryList:()=>mn,getIndustryMinuteKline:()=>yn,getIndustrySpot:()=>fn,getMinuteKline:()=>rn,getOptionLHB:()=>Mn,getUSHistoryKline:()=>sn});async function xt(t,e,n,i,r=100,o){let s=[],a=1,l=0;do{let u=new URLSearchParams({...n,pn:String(a),pz:String(r),fields:i}),c=`${e}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data;if(!d||!Array.isArray(d.diff))break;a===1&&(l=d.total??0);let g=d.diff.map((y,f)=>o(y,s.length+f+1));s.push(...g),a++}while(s.length<l);return s}function x(t){let[e,n,i,r,o,s,a,l,u,c,m]=t.split(",");return{date:e,open:R(n),close:R(i),high:R(r),low:R(o),volume:R(s),amount:R(a),amplitude:R(l),changePercent:R(u),change:R(c),turnoverRate:R(m)}}async function L(t,e,n){let i=`${e}?${n.toString()}`,r=await t.get(i,{responseType:"json"});return{klines:r?.data?.klines||[],name:r?.data?.name,code:r?.data?.code}}async function nn(t,e,n={}){let{period:i="daily",adjust:r="qfq",startDate:o="19700101",endDate:s="20500101"}=n;I(i),k(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${ge(e)}.${a}`,u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:M(i),fqt:N(r),secid:l,beg:o,end:s}),c=ue,{klines:m}=await L(t,c,u);return m.length===0?[]:m.map(d=>({...x(d),code:a}))}async function rn(t,e,n={}){let{period:i="1",adjust:r="qfq",startDate:o="1979-09-01 09:32:00",endDate:s="2222-01-01 09:32:00"}=n;re(i),k(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${ge(e)}.${a}`;if(i==="1"){let u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",fields2:"f51,f52,f53,f54,f55,f56,f57,f58",ut:"7eea3edcaed734bea9cbfc24409ed989",ndays:"5",iscr:"0",secid:l}),c=`${$e}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(d)||d.length===0)return[];let g=o.replace("T"," ").slice(0,16),y=s.replace("T"," ").slice(0,16);return d.map(f=>{let[C,O,E,_,z,D,w,$n]=f.split(",");return{time:C,open:R(O),close:R(E),high:R(_),low:R(z),volume:R(D),amount:R(w),avgPrice:R($n)}}).filter(f=>f.time>=g&&f.time<=y)}else{let u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:i,fqt:N(r||""),secid:l,beg:"0",end:"20500000"}),c=ue,{klines:m}=await L(t,c,u);if(m.length===0)return[];let d=o.replace("T"," ").slice(0,16),g=s.replace("T"," ").slice(0,16);return m.map(y=>{let f=x(y);return{...f,time:f.date}}).filter(y=>y.time>=d&&y.time<=g)}}function Oe(t){return async function(n,i,r={}){let{period:o="daily",adjust:s="qfq",startDate:a="19700101",endDate:l="20500101"}=r;I(o),k(s);let u=t.normalizeSymbol(i),c=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:M(o),fqt:N(s),secid:u.secid,beg:a,end:l,lmt:"1000000"}),{klines:m,name:d,code:g}=await L(n,t.url,c);if(m.length===0)return[];let y=t.resolveResultMeta?t.resolveResultMeta(i,u,{code:g,name:d}):{code:g||u.fallbackCode,name:d||""};return m.map(f=>({...x(f),code:y.code,name:y.name}))}}var cr=Oe({url:Ge,normalizeSymbol:t=>{let e=t.replace(/^hk/i,"").padStart(5,"0");return{secid:`116.${e}`,fallbackCode:e}}});async function on(t,e,n={}){return cr(t,e,n)}var pr=Oe({url:ze,normalizeSymbol:t=>({secid:t,fallbackCode:t.split(".")[1]||t}),resolveResultMeta:(t,e,n)=>({code:n.code||e.fallbackCode,name:n.name||""})});async function sn(t,e,n={}){return pr(t,e,n)}function an(t){let e=null;return{async getCode(n,i,r){if(i.startsWith("BK"))return i;if(!e){let s=await r(n);e=new Map(s.map(a=>[a.name,a.code]))}let o=e.get(i);if(!o)throw new Error(`${t.errorPrefix}: ${i}`);return o}}}async function ln(t,e){let n={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:e.type==="concept"?"f12":"f3",fs:e.fsFilter},i=e.type==="concept"?"f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136":"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152,f124,f107,f104,f105,f140,f141,f207,f208,f209,f222",r=await xt(t,e.listUrl,n,i,100,(o,s)=>({rank:s,name:String(o.f14??""),code:String(o.f12??""),price:p(o.f2),change:p(o.f4),changePercent:p(o.f3),totalMarketCap:p(o.f20),turnoverRate:p(o.f8),riseCount:p(o.f104),fallCount:p(o.f105),leadingStock:o.f128?String(o.f128):null,leadingStockChangePercent:p(o.f136)}));return r.sort((o,s)=>(s.changePercent??0)-(o.changePercent??0)),r.forEach((o,s)=>{o.rank=s+1}),r}async function un(t,e,n){let i=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${e}`}),r=`${n}?${i.toString()}`,s=(await t.get(r,{responseType:"json"}))?.data;return s?[{key:"f43",name:"\u6700\u65B0",divide:!0},{key:"f44",name:"\u6700\u9AD8",divide:!0},{key:"f45",name:"\u6700\u4F4E",divide:!0},{key:"f46",name:"\u5F00\u76D8",divide:!0},{key:"f47",name:"\u6210\u4EA4\u91CF",divide:!1},{key:"f48",name:"\u6210\u4EA4\u989D",divide:!1},{key:"f170",name:"\u6DA8\u8DCC\u5E45",divide:!0},{key:"f171",name:"\u632F\u5E45",divide:!0},{key:"f168",name:"\u6362\u624B\u7387",divide:!0},{key:"f169",name:"\u6DA8\u8DCC\u989D",divide:!0}].map(({key:l,name:u,divide:c})=>{let m=s[l],d=null;return typeof m=="number"&&!isNaN(m)&&(d=c?m/100:m),{item:u,value:d}}):[]}async function cn(t,e,n){let i={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return xt(t,n,i,"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152,f45",100,(o,s)=>({rank:s,code:String(o.f12??""),name:String(o.f14??""),price:p(o.f2),changePercent:p(o.f3),change:p(o.f4),volume:p(o.f5),amount:p(o.f6),amplitude:p(o.f7),high:p(o.f15),low:p(o.f16),open:p(o.f17),prevClose:p(o.f18),turnoverRate:p(o.f8),pe:p(o.f9),pb:p(o.f23)}))}async function pn(t,e,n,i={}){let{period:r="daily",adjust:o="",startDate:s="19700101",endDate:a="20500101"}=i;I(r),k(o);let l=new URLSearchParams({secid:`90.${e}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:M(r),fqt:N(o),beg:s,end:a,smplmt:"10000",lmt:"1000000"}),{klines:u}=await L(t,n,l);return u.length===0?[]:u.map(c=>x(c))}async function dn(t,e,n,i,r={}){let{period:o="5"}=r;if(re(o),o==="1"){let s=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",fields2:"f51,f52,f53,f54,f55,f56,f57,f58",iscr:"0",ndays:"1",secid:`90.${e}`}),a=`${i}?${s.toString()}`,u=(await t.get(a,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[m,d,g,y,f,C,O,E]=c.split(",");return{time:m,open:R(d),close:R(g),high:R(y),low:R(f),volume:R(C),amount:R(O),price:R(E)}})}else{let s=new URLSearchParams({secid:`90.${e}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:o,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),a=`${n}?${s.toString()}`,u=(await t.get(a,{responseType:"json"}))?.data?.klines;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[m,d,g,y,f,C,O,E,_,z,D]=c.split(",");return{time:m,open:R(d),close:R(g),high:R(y),low:R(f),changePercent:R(_),change:R(z),volume:R(C),amount:R(O),amplitude:R(E),turnoverRate:R(D)}})}}function Te(t){let e=an(t);async function n(r){return ln(r,t)}async function i(r,o){return e.getCode(r,o,n)}return{async getList(r){return n(r)},async getSpot(r,o){let s=await i(r,o);return un(r,s,t.spotUrl)},async getConstituents(r,o){let s=await i(r,o);return cn(r,s,t.consUrl)},async getKline(r,o,s={}){let a=await i(r,o);return pn(r,a,t.klineUrl,s)},async getMinuteKline(r,o,s={}){let a=await i(r,o);return dn(r,a,t.klineUrl,t.trendsUrl,s)}}}var dr={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Ve,spotUrl:We,consUrl:Xe,klineUrl:Ye,trendsUrl:Ze,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},oe=Te(dr);async function mn(t){return oe.getList(t)}async function fn(t,e){return oe.getSpot(t,e)}async function gn(t,e){return oe.getConstituents(t,e)}async function hn(t,e,n={}){return oe.getKline(t,e,n)}async function yn(t,e,n={}){return oe.getMinuteKline(t,e,n)}var mr={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:Je,spotUrl:et,consUrl:tt,klineUrl:nt,trendsUrl:rt,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},ie=Te(mr);async function Rn(t){return ie.getList(t)}async function Cn(t,e){return ie.getSpot(t,e)}async function Sn(t,e){return ie.getConstituents(t,e)}async function On(t,e,n={}){return ie.getKline(t,e,n)}async function Tn(t,e,n={}){return ie.getMinuteKline(t,e,n)}function F(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function fr(t){return{code:t.SECURITY_CODE??"",name:t.SECURITY_NAME_ABBR??"",reportDate:F(t.REPORT_DATE),planNoticeDate:F(t.PLAN_NOTICE_DATE),disclosureDate:F(t.PUBLISH_DATE??t.PLAN_NOTICE_DATE),assignTransferRatio:t.BONUS_IT_RATIO??null,bonusRatio:t.BONUS_RATIO??null,transferRatio:t.IT_RATIO??null,dividendPretax:t.PRETAX_BONUS_RMB??null,dividendDesc:t.IMPL_PLAN_PROFILE??null,dividendYield:t.DIVIDENT_RATIO??null,eps:t.BASIC_EPS??null,bps:t.BVPS??null,capitalReserve:t.PER_CAPITAL_RESERVE??null,unassignedProfit:t.PER_UNASSIGN_PROFIT??null,netProfitYoy:t.PNP_YOY_RATIO??null,totalShares:t.TOTAL_SHARES??null,equityRecordDate:F(t.EQUITY_RECORD_DATE),exDividendDate:F(t.EX_DIVIDEND_DATE),payDate:F(t.PAY_DATE),assignProgress:t.ASSIGN_PROGRESS??null,noticeDate:F(t.NOTICE_DATE)}}async function En(t,e){let n=e.replace(/^(sh|sz|bj)/,""),i=[],r=1,o=1;do{let s=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:"500",pageNumber:String(r),reportName:"RPT_SHAREBONUS_DET",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(SECURITY_CODE="${n}")`}),a=`${B}?${s.toString()}`,u=(await t.get(a,{responseType:"json"}))?.result;if(!u||!Array.isArray(u.data))break;r===1&&(o=u.pages??1);let c=u.data.map(fr);i.push(...c),r++}while(r<=o);return i}function Lt(t){let e=t.match(/^([a-zA-Z]+)/);if(!e)throw new RangeError(`Invalid futures symbol: "${t}". Expected format: variety + contract (e.g., rb2605, RBM, IF2604)`);return e[1]}function _n(t){return H[t]??H[t.toLowerCase()]??H[t.toUpperCase()]}function Kt(t){let e=_n(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=_n(t.slice(0,-1))),!e){let i=Object.keys(H).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${i}`)}let n=it[e];if(n===void 0)throw new RangeError(`No market code found for exchange: ${e}`);return n}function gr(t){let e=x(t),n=t.split(",");return{...e,openInterest:n.length>12?R(n[12]):null}}async function bn(t,e,n={}){let{period:i="daily",startDate:r="19700101",endDate:o="20500101"}=n;I(i);let s=Lt(e),l=`${Kt(s)}.${e}`,u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:M(i),fqt:"0",secid:l,beg:r,end:o}),{klines:c,name:m,code:d}=await L(t,V,u);return c.length===0?[]:c.map(g=>({...gr(g),code:d||e,name:m||""}))}async function Pn(t,e={}){let n=e.pageSize??20,i=[],r=0,o=0;do{let s=new URLSearchParams({orderBy:"dm",sort:"desc",pageSize:String(n),pageIndex:String(r),token:W,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),a=`${ot}?${s.toString()}`,l=await t.get(a,{responseType:"json"});if(!l||!Array.isArray(l.list))break;r===0&&(o=l.total??0);let u=l.list.map(hr);i.push(...u),r++}while(i.length<o);return i}function hr(t){return{code:t.dm||"",name:t.name||"",price:R(String(t.p)),change:R(String(t.zde)),changePercent:R(String(t.zdf)),open:R(String(t.o)),high:R(String(t.h)),low:R(String(t.l)),prevSettle:R(String(t.zjsj)),volume:R(String(t.vol)),buyVolume:R(String(t.wp)),sellVolume:R(String(t.np)),openInterest:R(String(t.ccl))}}function yr(t){let e=x(t),n=t.split(",");return{...e,openInterest:n.length>12?R(n[12]):null}}function Rr(t){let e=t.match(/^([A-Z]+)/);if(!e)throw new RangeError(`Invalid global futures symbol: "${t}". Expected format like HG00Y, CL2507`);return e[1]}async function An(t,e,n={}){let{period:i="daily",startDate:r="19700101",endDate:o="20500101"}=n;I(i);let s=n.marketCode;if(s===void 0){let d=Rr(e);if(s=ce[d],s===void 0){let g=Object.keys(ce).join(", ");throw new RangeError(`Unknown global futures variety: "${d}". Supported: ${g}. Or specify marketCode manually via options.`)}}let a=`${s}.${e}`,l=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:M(i),fqt:"0",secid:a,beg:r,end:o}),{klines:u,name:c,code:m}=await L(t,V,l);return u.length===0?[]:u.map(d=>({...yr(d),code:m||e,name:c||""}))}async function In(t,e={}){let{pageSize:n=2e4}=e,i=new URLSearchParams({orderBy:"zdf",sort:"desc",pageSize:String(n),pageIndex:"0",token:W,field:"dm,sc,name,p,zsjd,zde,zdf,f152,vol,cje,ccl,xqj,syr,rz,zjsj,o"}),r=`${ct}?${i.toString()}`,s=(await t.get(r,{responseType:"json"}))?.list;return Array.isArray(s)?s.map(a=>({code:String(a.dm??""),name:String(a.name??""),price:p(a.p),change:p(a.zde),changePercent:p(a.zdf),volume:p(a.vol),amount:p(a.cje),openInterest:p(a.ccl),strikePrice:p(a.xqj),remainDays:p(a.syr),dailyChange:p(a.rz),prevSettle:p(a.zjsj),open:p(a.o)})):[]}async function Mn(t,e,n){let i=new URLSearchParams({type:"RPT_IF_BILLBOARD_TD",sty:"ALL",p:"1",ps:"200",source:"IFBILLBOARD",client:"WEB",ut:dt,filter:`(SECURITY_CODE="${e}")(TRADE_DATE='${n}')`}),r=`${pt}?${i.toString()}`,s=(await t.get(r,{responseType:"json"}))?.result?.data;if(!Array.isArray(s))return[];function a(l){if(!l)return"";let u=String(l),c=u.match(/^(\d{4}-\d{2}-\d{2})/);return c?c[1]:u}return s.map(l=>({tradeType:String(l.TRADE_TYPE??""),date:a(l.TRADE_DATE),symbol:String(l.SECURITY_CODE??""),targetName:String(l.TARGET_NAME??""),memberName:String(l.MEMBER_NAME_ABBR??""),rank:p(l.MEMBER_RANK)??0,sellVolume:p(l.SELL_VOLUME),sellVolumeChange:p(l.SELL_VOLUME_CHANGE),netSellVolume:p(l.NET_SELL_VOLUME),sellVolumeRatio:p(l.SELL_VOLUME_RATIO),buyVolume:p(l.BUY_VOLUME),buyVolumeChange:p(l.BUY_VOLUME_CHANGE),netBuyVolume:p(l.NET_BUY_VOLUME),buyVolumeRatio:p(l.BUY_VOLUME_RATIO),sellPosition:p(l.SELL_POSITION),sellPositionChange:p(l.SELL_POSITION_CHANGE),netSellPosition:p(l.NET_SELL_POSITION),sellPositionRatio:p(l.SELL_POSITION_RATIO),buyPosition:p(l.BUY_POSITION),buyPositionChange:p(l.BUY_POSITION_CHANGE),netBuyPosition:p(l.NET_BUY_POSITION),buyPositionRatio:p(l.BUY_POSITION_RATIO)}))}var Cr={gold:"EMI00069026",silver:"EMI00069027"};async function xn(t){let e=new URLSearchParams({reportName:"RPT_FUTU_POSITIONCODE",columns:"TRADE_MARKET_CODE,TRADE_CODE,TRADE_TYPE",filter:'(IS_MAINCODE="1")',pageNumber:"1",pageSize:"500",source:"WEB",client:"WEB"}),n=`${B}?${e.toString()}`,r=(await t.get(n,{responseType:"json"}))?.result?.data;return Array.isArray(r)?r.map(o=>({code:String(o.TRADE_CODE??""),name:String(o.TRADE_TYPE??""),marketCode:String(o.TRADE_MARKET_CODE??"")})):[]}function Ln(t){if(!t)return"";let e=String(t),n=e.match(/^(\d{4}-\d{2}-\d{2})/);return n?n[1]:e}async function Kn(t,e,n={}){let{startDate:i="2020-10-28",pageSize:r=500}=n,o=e.toUpperCase(),s=[],a=1,l=1;do{let u=new URLSearchParams({reportName:"RPT_FUTU_STOCKDATA",columns:"SECURITY_CODE,TRADE_DATE,ON_WARRANT_NUM,ADDCHANGE",filter:`(SECURITY_CODE="${o}")(TRADE_DATE>='${i}')`,pageNumber:String(a),pageSize:String(r),sortTypes:"-1",sortColumns:"TRADE_DATE",source:"WEB",client:"WEB"}),c=`${B}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;a===1&&(l=d.pages??1);let g=d.data.map(y=>({code:String(y.SECURITY_CODE??e),date:Ln(y.TRADE_DATE),inventory:p(y.ON_WARRANT_NUM),change:p(y.ADDCHANGE)}));s.push(...g),a++}while(a<=l);return s}async function Un(t,e,n={}){let i=Cr[e];if(!i)throw new RangeError(`Invalid COMEX symbol: "${e}". Must be "gold" or "silver".`);let{pageSize:r=500}=n,o=[],s=1,a=1,l={gold:"\u9EC4\u91D1",silver:"\u767D\u94F6"};do{let u=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:String(r),pageNumber:String(s),reportName:"RPT_FUTUOPT_GOLDSIL",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(INDICATOR_ID1="${i}")(@STORAGE_TON<>"NULL")`}),c=`${B}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;s===1&&(a=d.pages??1);let g=d.data.map(y=>({date:Ln(y.REPORT_DATE),name:l[e]??e,storageTon:p(y.STORAGE_TON),storageOunce:p(y.STORAGE_OUNCE)}));o.push(...g),s++}while(s<=a);return o}var A={};Fe(A,{getCommodityOptionKline:()=>jn,getCommodityOptionSpot:()=>qn,getETFOption5DayMinute:()=>Hn,getETFOptionDailyKline:()=>wn,getETFOptionExpireDay:()=>Bn,getETFOptionMinute:()=>vn,getETFOptionMonths:()=>Nn,getIndexOptionKline:()=>kn,getIndexOptionSpot:()=>Dn});function Sr(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:p(t[7]),symbol:t[8]??""}}function Or(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:null,symbol:t[7]??""}}async function Dn(t,e){let n=`${X}?type=futures&product=${t}&exchange=cffex&pinzhong=${e}`,i=await P(n),r=i?.result?.data?.up??[],o=i?.result?.data?.down??[];return{calls:r.map(Sr),puts:o.map(Or)}}async function kn(t){let e=`${Y}?symbol=${t}`,n=await P(e,{callbackMode:"path"});return Array.isArray(n)?n.map(i=>({date:i.d,open:p(i.o),high:p(i.h),low:p(i.l),close:p(i.c),volume:p(i.v)})):[]}async function Nn(t){let e=`${st}?exchange=null&cate=${encodeURIComponent(t)}`,i=(await P(e))?.result?.data,r=i?.contractMonth??[];return{months:r.length>1?r.slice(1):r,stockId:i?.stockId??"",cateId:i?.cateId??"",cateList:i?.cateList??[]}}async function Bn(t,e){let n=`${pe}?exchange=null&cate=${encodeURIComponent(t)}&date=${e}`,i=await P(n),r=i?.result?.data?.remainderDays;if(typeof r=="number"&&r<0){let s=`${pe}?exchange=null&cate=${encodeURIComponent("XD"+t)}&date=${e}`;i=await P(s)}let o=i?.result?.data;return{expireDay:o?.expireDay??"",remainderDays:o?.remainderDays??0,stockId:o?.stockId??"",name:o?.other?.name??""}}function Fn(t){let e="";return t.map(n=>(n.d&&(e=n.d),{time:n.i,date:e,price:p(n.p),volume:p(n.v),openInterest:p(n.t),avgPrice:p(n.a)}))}async function vn(t){let e=`CON_OP_${t}`,n=`${at}?symbol=${e}`,r=(await P(n))?.result?.data;return Array.isArray(r)?Fn(r):[]}async function wn(t){let e=`CON_OP_${t}`,n=`${lt}?symbol=${e}`,i=await P(n,{callbackMode:"path"});return Array.isArray(i)?i.map(r=>({date:r.d,open:p(r.o),high:p(r.h),low:p(r.l),close:p(r.c),volume:p(r.v)})):[]}async function Hn(t){let e=`CON_OP_${t}`,n=`${ut}?symbol=${e}`,r=(await P(n))?.result?.data;if(!Array.isArray(r))return[];let o=[];for(let s of r)Array.isArray(s)&&o.push(...Fn(s));return o}function Tr(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:p(t[7]),symbol:t[8]??""}}function Er(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:null,symbol:t[7]??""}}async function qn(t,e){let n=de[t];if(!n)throw new RangeError(`Unknown commodity option variety: "${t}". Available: ${Object.keys(de).join(", ")}`);let i=`${X}?type=futures&product=${n.product}&exchange=${n.exchange}&pinzhong=${e}`,r=await P(i),o=r?.result?.data?.up??[],s=r?.result?.data?.down??[];return{calls:o.map(Tr),puts:s.map(Er)}}async function jn(t){let e=`${Y}?symbol=${t}`,n=await P(e,{callbackMode:"path"});return Array.isArray(n)?n.map(i=>({date:i.d,open:p(i.o),high:p(i.h),low:p(i.l),close:p(i.c),volume:p(i.v)})):[]}function se(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function v(t,e){let n=[];for(let i=0;i<t.length;i++){if(i<e-1){n.push(null);continue}let r=0,o=0;for(let s=i-e+1;s<=i;s++)t[s]!==null&&(r+=t[s],o++);n.push(o===e?se(r/e):null)}return n}function U(t,e){let n=[],i=2/(e+1),r=null,o=!1;for(let s=0;s<t.length;s++){if(s<e-1){n.push(null);continue}if(!o){let l=0,u=0;for(let c=s-e+1;c<=s;c++)t[c]!==null&&(l+=t[c],u++);u===e&&(r=l/e,o=!0),n.push(r!==null?se(r):null);continue}let a=t[s];a===null?n.push(r!==null?se(r):null):(r=i*a+(1-i)*r,n.push(se(r)))}return n}function Ut(t,e){let n=[],i=Array.from({length:e},(o,s)=>s+1),r=i.reduce((o,s)=>o+s,0);for(let o=0;o<t.length;o++){if(o<e-1){n.push(null);continue}let s=0,a=!0;for(let l=0;l<e;l++){let u=t[o-e+1+l];if(u===null){a=!1;break}s+=u*i[l]}n.push(a?se(s/r):null)}return n}function Ee(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:i="sma"}=e,r=i==="ema"?U:i==="wma"?Ut:v,o={};for(let s of n)o[`ma${s}`]=r(t,s);return t.map((s,a)=>{let l={};for(let u of n)l[`ma${u}`]=o[`ma${u}`][a];return l})}function Qn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function _e(t,e={}){let{short:n=12,long:i=26,signal:r=9}=e,o=U(t,n),s=U(t,i),a=t.map((u,c)=>o[c]===null||s[c]===null?null:o[c]-s[c]),l=U(a,r);return t.map((u,c)=>({dif:a[c]!==null?Qn(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?Qn((a[c]-l[c])*2):null}))}function Dt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function _r(t,e,n){let i=[];for(let r=0;r<t.length;r++){if(r<e-1||n[r]===null){i.push(null);continue}let o=0,s=0;for(let a=r-e+1;a<=r;a++)t[a]!==null&&n[r]!==null&&(o+=Math.pow(t[a]-n[r],2),s++);i.push(s===e?Math.sqrt(o/e):null)}return i}function be(t,e={}){let{period:n=20,stdDev:i=2}=e,r=v(t,n),o=_r(t,n,r);return t.map((s,a)=>{if(r[a]===null||o[a]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let l=r[a]+i*o[a],u=r[a]-i*o[a],c=r[a]!==0?Dt((l-u)/r[a]*100):null;return{mid:r[a],upper:Dt(l),lower:Dt(u),bandwidth:c}})}function kt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Pe(t,e={}){let{period:n=9,kPeriod:i=3,dPeriod:r=3}=e,o=[],s=50,a=50;for(let l=0;l<t.length;l++){if(l<n-1){o.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,m=!0;for(let f=l-n+1;f<=l;f++){if(t[f].high===null||t[f].low===null){m=!1;break}u=Math.max(u,t[f].high),c=Math.min(c,t[f].low)}let d=t[l].close;if(!m||d===null||u===c){o.push({k:null,d:null,j:null});continue}let g=(d-c)/(u-c)*100;s=(i-1)/i*s+1/i*g,a=(r-1)/r*a+1/r*s;let y=3*s-2*a;o.push({k:kt(s),d:kt(a),j:kt(y)})}return o}function br(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Ae(t,e={}){let{periods:n=[6,12,24]}=e,i=[null];for(let o=1;o<t.length;o++)t[o]===null||t[o-1]===null?i.push(null):i.push(t[o]-t[o-1]);let r={};for(let o of n){let s=[],a=0,l=0;for(let u=0;u<t.length;u++){if(u<o){s.push(null),i[u]!==null&&(i[u]>0?a+=i[u]:l+=Math.abs(i[u]));continue}if(u===o)a=a/o,l=l/o;else{let c=i[u]??0,m=c>0?c:0,d=c<0?Math.abs(c):0;a=(a*(o-1)+m)/o,l=(l*(o-1)+d)/o}if(l===0)s.push(100);else if(a===0)s.push(0);else{let c=a/l;s.push(br(100-100/(1+c)))}}r[`rsi${o}`]=s}return t.map((o,s)=>{let a={};for(let l of n)a[`rsi${l}`]=r[`rsi${l}`][s];return a})}function Pr(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Ie(t,e={}){let{periods:n=[6,10]}=e,i={};for(let r of n){let o=[];for(let s=0;s<t.length;s++){if(s<r-1){o.push(null);continue}let a=-1/0,l=1/0,u=!0;for(let d=s-r+1;d<=s;d++){if(t[d].high===null||t[d].low===null){u=!1;break}a=Math.max(a,t[d].high),l=Math.min(l,t[d].low)}let c=t[s].close;if(!u||c===null||a===l){o.push(null);continue}let m=(a-c)/(a-l)*100;o.push(Pr(m))}i[`wr${r}`]=o}return t.map((r,o)=>{let s={};for(let a of n)s[`wr${a}`]=i[`wr${a}`][o];return s})}function Ar(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Me(t,e={}){let{periods:n=[6,12,24]}=e,i={};for(let r of n){let o=v(t,r),s=[];for(let a=0;a<t.length;a++)if(t[a]===null||o[a]===null||o[a]===0)s.push(null);else{let l=(t[a]-o[a])/o[a]*100;s.push(Ar(l))}i[`bias${r}`]=s}return t.map((r,o)=>{let s={};for(let a of n)s[`bias${a}`]=i[`bias${a}`][o];return s})}function Ir(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function xe(t,e={}){let{period:n=14}=e,i=[],r=t.map(o=>o.high===null||o.low===null||o.close===null?null:(o.high+o.low+o.close)/3);for(let o=0;o<t.length;o++){if(o<n-1){i.push({cci:null});continue}let s=0,a=0;for(let m=o-n+1;m<=o;m++)r[m]!==null&&(s+=r[m],a++);if(a!==n||r[o]===null){i.push({cci:null});continue}let l=s/n,u=0;for(let m=o-n+1;m<=o;m++)u+=Math.abs(r[m]-l);let c=u/n;if(c===0)i.push({cci:0});else{let m=(r[o]-l)/(.015*c);i.push({cci:Ir(m)})}}return i}function Nt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function G(t,e={}){let{period:n=14}=e,i=[],r=[];for(let s=0;s<t.length;s++){let{high:a,low:l,close:u}=t[s];if(a===null||l===null||u===null){r.push(null);continue}if(s===0)r.push(a-l);else{let c=t[s-1].close;if(c===null)r.push(a-l);else{let m=a-l,d=Math.abs(a-c),g=Math.abs(l-c);r.push(Math.max(m,d,g))}}}let o=null;for(let s=0;s<t.length;s++){if(s<n-1){i.push({tr:r[s]!==null?Nt(r[s]):null,atr:null});continue}if(s===n-1){let a=0,l=0;for(let u=0;u<n;u++)r[u]!==null&&(a+=r[u],l++);l===n&&(o=a/n)}else o!==null&&r[s]!==null&&(o=(o*(n-1)+r[s])/n);i.push({tr:r[s]!==null?Nt(r[s]):null,atr:o!==null?Nt(o):null})}return i}function Le(t,e={}){let{maPeriod:n}=e,i=[];if(t.length===0)return i;let r=t[0].volume??0;i.push({obv:r,obvMa:null});for(let o=1;o<t.length;o++){let s=t[o],a=t[o-1];if(s.close===null||a.close===null||s.volume===null||s.volume===void 0){i.push({obv:null,obvMa:null});continue}s.close>a.close?r+=s.volume:s.close<a.close&&(r-=s.volume),i.push({obv:r,obvMa:null})}if(n&&n>0)for(let o=n-1;o<i.length;o++){let s=0,a=0;for(let l=o-n+1;l<=o;l++)i[l].obv!==null&&(s+=i[l].obv,a++);a===n&&(i[o].obvMa=s/n)}return i}function Ke(t,e={}){let{period:n=12,signalPeriod:i}=e,r=[];for(let o=0;o<t.length;o++){if(o<n){r.push({roc:null,signal:null});continue}let s=t[o].close,a=t[o-n].close;if(s===null||a===null||a===0){r.push({roc:null,signal:null});continue}let l=(s-a)/a*100;r.push({roc:l,signal:null})}if(i&&i>0)for(let o=n+i-1;o<r.length;o++){let s=0,a=0;for(let l=o-i+1;l<=o;l++)r[l].roc!==null&&(s+=r[l].roc,a++);a===i&&(r[o].signal=s/i)}return r}function Ue(t,e={}){let{period:n=14,adxPeriod:i=n}=e,r=[];if(t.length<2)return t.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let o=[],s=[],a=[];for(let f=0;f<t.length;f++){if(f===0){o.push(0),s.push(0),a.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let C=t[f],O=t[f-1];if(C.high===null||C.low===null||C.close===null||O.high===null||O.low===null||O.close===null){o.push(0),s.push(0),a.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let E=C.high-C.low,_=Math.abs(C.high-O.close),z=Math.abs(C.low-O.close);a.push(Math.max(E,_,z));let D=C.high-O.high,w=O.low-C.low;D>w&&D>0?o.push(D):o.push(0),w>D&&w>0?s.push(w):s.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null})}let l=0,u=0,c=0,m=[];for(let f=1;f<t.length;f++){if(f<n){l+=a[f],u+=o[f],c+=s[f],m.push(0);continue}f===n?(l=l,u=u,c=c):(l=l-l/n+a[f],u=u-u/n+o[f],c=c-c/n+s[f]);let C=l>0?u/l*100:0,O=l>0?c/l*100:0;r[f].pdi=C,r[f].mdi=O;let E=C+O,_=E>0?Math.abs(C-O)/E*100:0;m.push(_)}let d=0,g=0,y=0;for(let f=n;f<t.length;f++){if(f<n*2-1){d+=m[f-n+1]||0,g++;continue}if(f===n*2-1)d+=m[f-n+1]||0,y=d/i,r[f].adx=y;else{let C=m[f-n+1]||0;y=(y*(i-1)+C)/i,r[f].adx=y}}for(let f=n*2-1+i;f<t.length;f++){let C=r[f].adx,O=r[f-i]?.adx;C!==null&&O!==null&&(r[f].adxr=(C+O)/2)}return r}function De(t,e={}){let{afStart:n=.02,afIncrement:i=.02,afMax:r=.2}=e,o=[];if(t.length<2)return t.map(()=>({sar:null,trend:null,ep:null,af:null}));let s=1,a=n,l=t[0].high??0,u=t[0].low??0,c=t[0],m=t[1];c.close!==null&&m.close!==null&&m.close<c.close&&(s=-1,l=c.low??0,u=c.high??0),o.push({sar:null,trend:null,ep:null,af:null});for(let d=1;d<t.length;d++){let g=t[d],y=t[d-1];if(g.high===null||g.low===null||y.high===null||y.low===null){o.push({sar:null,trend:null,ep:null,af:null});continue}let f=u+a*(l-u);s===1?(f=Math.min(f,y.low,t[Math.max(0,d-2)]?.low??y.low),g.low<f?(s=-1,f=l,l=g.low,a=n):g.high>l&&(l=g.high,a=Math.min(a+i,r))):(f=Math.max(f,y.high,t[Math.max(0,d-2)]?.high??y.high),g.high>f?(s=1,f=l,l=g.high,a=n):g.low<l&&(l=g.low,a=Math.min(a+i,r))),u=f,o.push({sar:u,trend:s,ep:l,af:a})}return o}function ke(t,e={}){let{emaPeriod:n=20,atrPeriod:i=10,multiplier:r=2}=e,o=[],s=t.map(u=>u.close),a=U(s,n),l=G(t,{period:i});for(let u=0;u<t.length;u++){let c=a[u],m=l[u]?.atr;if(c===null||m===null){o.push({mid:null,upper:null,lower:null,width:null});continue}let d=c+r*m,g=c-r*m,y=c>0?(d-g)/c*100:null;o.push({mid:c,upper:d,lower:g,width:y})}return o}function Ne(t,e={}){if(t.length===0)return[];let n=t.map(E=>E.close),i=t.map(E=>({open:E.open,high:E.high,low:E.low,close:E.close,volume:E.volume})),r=e.ma?Ee(n,typeof e.ma=="object"?e.ma:{}):null,o=e.macd?_e(n,typeof e.macd=="object"?e.macd:{}):null,s=e.boll?be(n,typeof e.boll=="object"?e.boll:{}):null,a=e.kdj?Pe(i,typeof e.kdj=="object"?e.kdj:{}):null,l=e.rsi?Ae(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?Ie(i,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?Me(n,typeof e.bias=="object"?e.bias:{}):null,m=e.cci?xe(i,typeof e.cci=="object"?e.cci:{}):null,d=e.atr?G(i,typeof e.atr=="object"?e.atr:{}):null,g=e.obv?Le(i,typeof e.obv=="object"?e.obv:{}):null,y=e.roc?Ke(i,typeof e.roc=="object"?e.roc:{}):null,f=e.dmi?Ue(i,typeof e.dmi=="object"?e.dmi:{}):null,C=e.sar?De(i,typeof e.sar=="object"?e.sar:{}):null,O=e.kc?ke(i,typeof e.kc=="object"?e.kc:{}):null;return t.map((E,_)=>({...E,...r&&{ma:r[_]},...o&&{macd:o[_]},...s&&{boll:s[_]},...a&&{kdj:a[_]},...l&&{rsi:l[_]},...u&&{wr:u[_]},...c&&{bias:c[_]},...m&&{cci:m[_]},...d&&{atr:d[_]},...g&&{obv:g[_]},...y&&{roc:y[_]},...f&&{dmi:f[_]},...C&&{sar:C[_]},...O&&{kc:O[_]}}))}var Be=class{constructor(e={}){this.client=new ne(e)}getFullQuotes(e){return b.getFullQuotes(this.client,e)}getSimpleQuotes(e){return b.getSimpleQuotes(this.client,e)}getHKQuotes(e){return b.getHKQuotes(this.client,e)}getUSQuotes(e){return b.getUSQuotes(this.client,e)}getFundQuotes(e){return b.getFundQuotes(this.client,e)}getFundFlow(e){return b.getFundFlow(this.client,e)}getPanelLargeOrder(e){return b.getPanelLargeOrder(this.client,e)}getTodayTimeline(e){return b.getTodayTimeline(this.client,e)}getIndustryList(){return T.getIndustryList(this.client)}getIndustrySpot(e){return T.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return T.getIndustryConstituents(this.client,e)}getIndustryKline(e,n){return T.getIndustryKline(this.client,e,n)}getIndustryMinuteKline(e,n){return T.getIndustryMinuteKline(this.client,e,n)}getConceptList(){return T.getConceptList(this.client)}getConceptSpot(e){return T.getConceptSpot(this.client,e)}getConceptConstituents(e){return T.getConceptConstituents(this.client,e)}getConceptKline(e,n){return T.getConceptKline(this.client,e,n)}getConceptMinuteKline(e,n){return T.getConceptMinuteKline(this.client,e,n)}getHistoryKline(e,n){return T.getHistoryKline(this.client,e,n)}getMinuteKline(e,n){return T.getMinuteKline(this.client,e,n)}getHKHistoryKline(e,n){return T.getHKHistoryKline(this.client,e,n)}getUSHistoryKline(e,n){return T.getUSHistoryKline(this.client,e,n)}search(e){return b.search(this.client,e)}getAShareCodeList(e){return b.getAShareCodeList(this.client,e)}getUSCodeList(e){return b.getUSCodeList(this.client,e)}getHKCodeList(){return b.getHKCodeList(this.client)}getFundCodeList(){return b.getFundCodeList(this.client)}async getAllAShareQuotes(e={}){let{market:n,...i}=e,r=await this.getAShareCodeList({market:n});return this.getAllQuotesByCodes(r,i)}async getAllHKShareQuotes(e={}){let n=await this.getHKCodeList();return b.getAllHKQuotesByCodes(this.client,n,e)}async getAllUSShareQuotes(e={}){let{market:n,...i}=e,r=await this.getUSCodeList({simple:!0,market:n});return b.getAllUSQuotesByCodes(this.client,r,i)}getAllQuotesByCodes(e,n={}){return b.getAllQuotesByCodes(this.client,e,n)}async batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return b.getTradingCalendar(this.client)}getDividendDetail(e){return T.getDividendDetail(this.client,e)}getFuturesKline(e,n){return T.getFuturesHistoryKline(this.client,e,n)}getGlobalFuturesSpot(e){return T.getGlobalFuturesSpot(this.client,e)}getGlobalFuturesKline(e,n){return T.getGlobalFuturesKline(this.client,e,n)}getFuturesInventorySymbols(){return T.getFuturesInventorySymbols(this.client)}getFuturesInventory(e,n){return T.getFuturesInventory(this.client,e,n)}getComexInventory(e,n){return T.getComexInventory(this.client,e,n)}getIndexOptionSpot(e,n){return A.getIndexOptionSpot(e,n)}getIndexOptionKline(e){return A.getIndexOptionKline(e)}getCFFEXOptionQuotes(e){return T.getCFFEXOptionQuotes(this.client,e)}getETFOptionMonths(e){return A.getETFOptionMonths(e)}getETFOptionExpireDay(e,n){return A.getETFOptionExpireDay(e,n)}getETFOptionMinute(e){return A.getETFOptionMinute(e)}getETFOptionDailyKline(e){return A.getETFOptionDailyKline(e)}getETFOption5DayMinute(e){return A.getETFOption5DayMinute(e)}getCommodityOptionSpot(e,n){return A.getCommodityOptionSpot(e,n)}getCommodityOptionKline(e){return A.getCommodityOptionKline(e)}getOptionLHB(e,n){return T.getOptionLHB(this.client,e,n)}detectMarket(e){return/^\d{3}\.[A-Z]+$/i.test(e)?"US":/^\d{5}$/.test(e)?"HK":"A"}safeMax(e,n=0){return!e||e.length===0?n:Math.max(...e)}calcRequiredLookback(e){let n=0,i=!1;if(e.ma){let o=typeof e.ma=="object"?e.ma:{},s=o.periods??[5,10,20,30,60,120,250],a=o.type??"sma";n=Math.max(n,this.safeMax(s,20)),a==="ema"&&(i=!0)}if(e.macd){let o=typeof e.macd=="object"?e.macd:{},s=o.long??26,a=o.signal??9;n=Math.max(n,s*3+a),i=!0}if(e.boll){let o=typeof e.boll=="object"&&e.boll.period?e.boll.period:20;n=Math.max(n,o)}if(e.kdj){let o=typeof e.kdj=="object"&&e.kdj.period?e.kdj.period:9;n=Math.max(n,o)}if(e.rsi){let o=typeof e.rsi=="object"&&e.rsi.periods?e.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(o,14)+1)}if(e.wr){let o=typeof e.wr=="object"&&e.wr.periods?e.wr.periods:[6,10];n=Math.max(n,this.safeMax(o,10))}if(e.bias){let o=typeof e.bias=="object"&&e.bias.periods?e.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(o,12))}if(e.cci){let o=typeof e.cci=="object"&&e.cci.period?e.cci.period:14;n=Math.max(n,o)}if(e.atr){let o=typeof e.atr=="object"&&e.atr.period?e.atr.period:14;n=Math.max(n,o)}if(e.obv){let o=typeof e.obv=="object"&&e.obv.maPeriod?e.obv.maPeriod:0;n=Math.max(n,Math.max(2,o))}if(e.roc){let o=typeof e.roc=="object"?e.roc:{},s=o.period??12,a=o.signalPeriod??0;n=Math.max(n,s+a)}if(e.dmi){let o=typeof e.dmi=="object"?e.dmi:{},s=o.period??14,a=o.adxPeriod??s;n=Math.max(n,s*2+a)}if(e.sar&&(n=Math.max(n,5)),e.kc){let o=typeof e.kc=="object"?e.kc:{},s=o.emaPeriod??20,a=o.atrPeriod??10;n=Math.max(n,Math.max(s*3,a)),i=!0}return Math.ceil(n*(i?1.5:1.2))}calcActualStartDate(e,n,i=1.5){let r=Math.ceil(n*i),o=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.slice(6,8)));o.setDate(o.getDate()-r);let s=o.getFullYear(),a=String(o.getMonth()+1).padStart(2,"0"),l=String(o.getDate()).padStart(2,"0");return`${s}${a}${l}`}calcActualStartDateByCalendar(e,n,i){if(!i||i.length===0)return;let r=this.normalizeDate(e),o=i.findIndex(a=>a>=r);o===-1&&(o=i.length-1);let s=Math.max(0,o-n);return this.toCompactDate(i[s])}normalizeDate(e){return e.includes("-")?e:e.length===8?`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`:e}toCompactDate(e){return e.replace(/-/g,"")}dateToTimestamp(e){let n=e.includes("-")?e:`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;return new Date(n).getTime()}async getKlineWithIndicators(e,n={}){let{startDate:i,endDate:r,indicators:o={}}=n,s=n.market??this.detectMarket(e),a=this.calcRequiredLookback(o),l={A:1.5,HK:1.46,US:1.45},u;if(i)if(s==="A")try{let g=await b.getTradingCalendar(this.client);u=this.calcActualStartDateByCalendar(i,a,g)??this.calcActualStartDate(i,a,l[s])}catch{u=this.calcActualStartDate(i,a,l[s])}else u=this.calcActualStartDate(i,a,l[s]);let c={period:n.period,adjust:n.adjust,startDate:u,endDate:n.endDate},m;switch(s){case"HK":m=await this.getHKHistoryKline(e,c);break;case"US":m=await this.getUSHistoryKline(e,c);break;default:m=await this.getHistoryKline(e,c)}if(i&&m.length<a)switch(s){case"HK":m=await this.getHKHistoryKline(e,{...c,startDate:void 0});break;case"US":m=await this.getUSHistoryKline(e,{...c,startDate:void 0});break;default:m=await this.getHistoryKline(e,{...c,startDate:void 0})}let d=Ne(m,o);if(i){let g=this.dateToTimestamp(i),y=r?this.dateToTimestamp(r):1/0;return d.filter(f=>{let C=this.dateToTimestamp(f.date);return C>=g&&C<=y})}return d}},Mr=Be;export{q as HttpError,Be as StockSDK,Ne as addIndicators,Q as asyncPool,G as calcATR,Me as calcBIAS,be as calcBOLL,xe as calcCCI,Ue as calcDMI,U as calcEMA,ke as calcKC,Pe as calcKDJ,Ee as calcMA,_e as calcMACD,Le as calcOBV,Ke as calcROC,Ae as calcRSI,De as calcSAR,v as calcSMA,Ut as calcWMA,Ie as calcWR,j as chunkArray,ae as decodeGBK,Mr as default,St as extractJsonFromJsonp,P as jsonpRequest,le as parseResponse,h as safeNumber,S as safeNumberOrNull};
|
|
1
|
+
var gn=Object.defineProperty;var tt=(t,e)=>{for(var r in e)gn(t,r,{get:e[r],enumerable:!0})};function Oe(t){return new TextDecoder("gbk").decode(t)}function Re(t){let e=t.split(";").map(o=>o.trim()).filter(Boolean),r=[];for(let o of e){let n=o.indexOf("=");if(n<0)continue;let i=o.slice(0,n).trim();i.startsWith("v_")&&(i=i.slice(2));let s=o.slice(n+1).trim();s.startsWith('"')&&s.endsWith('"')&&(s=s.slice(1,-1));let a=s.split("~");r.push({key:i,fields:a})}return r}function g(t){if(!t||t==="")return 0;let e=parseFloat(t);return Number.isNaN(e)?0:e}function O(t){if(!t||t==="")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function S(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function p(t){return t==null?null:S(String(t))}var rt="https://qt.gtimg.cn",nt="https://web.ifzq.gtimg.cn/appstock/app/minute/query",ot="https://assets.linkdiary.cn/shares/zh_a_list.json",it="https://assets.linkdiary.cn/shares/us_list.json",st="https://assets.linkdiary.cn/shares/hk_list.json",at="https://assets.linkdiary.cn/shares/fund_list",er="https://assets.linkdiary.cn/shares/trade-data-list.txt";var Ee="https://push2his.eastmoney.com/api/qt/stock/kline/get",ut="https://push2his.eastmoney.com/api/qt/stock/trends2/get",lt="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",ct="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",pt="https://17.push2.eastmoney.com/api/qt/clist/get",dt="https://91.push2.eastmoney.com/api/qt/stock/get",mt="https://29.push2.eastmoney.com/api/qt/clist/get",ft="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",gt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",ht="https://79.push2.eastmoney.com/api/qt/clist/get",yt="https://91.push2.eastmoney.com/api/qt/stock/get",St="https://29.push2.eastmoney.com/api/qt/clist/get",Ct="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Ot="https://push2his.eastmoney.com/api/qt/stock/trends2/get",H="https://datacenter-web.eastmoney.com/api/data/v1/get",J="https://push2his.eastmoney.com/api/qt/stock/kline/get",Rt="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",ee="58b2fa8f54638b60b87d69b31969089c",Et={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},z={cu:"SHFE",al:"SHFE",zn:"SHFE",pb:"SHFE",au:"SHFE",ag:"SHFE",rb:"SHFE",wr:"SHFE",fu:"SHFE",ru:"SHFE",bu:"SHFE",hc:"SHFE",ni:"SHFE",sn:"SHFE",sp:"SHFE",ss:"SHFE",ao:"SHFE",br:"SHFE",c:"DCE",a:"DCE",b:"DCE",m:"DCE",y:"DCE",p:"DCE",l:"DCE",v:"DCE",j:"DCE",jm:"DCE",i:"DCE",jd:"DCE",pp:"DCE",cs:"DCE",eg:"DCE",eb:"DCE",pg:"DCE",lh:"DCE",WH:"CZCE",CF:"CZCE",SR:"CZCE",TA:"CZCE",OI:"CZCE",MA:"CZCE",FG:"CZCE",RM:"CZCE",SF:"CZCE",SM:"CZCE",ZC:"CZCE",AP:"CZCE",CJ:"CZCE",UR:"CZCE",SA:"CZCE",PF:"CZCE",PK:"CZCE",PX:"CZCE",SH:"CZCE",sc:"INE",nr:"INE",lu:"INE",bc:"INE",ec:"INE",IF:"CFFEX",IC:"CFFEX",IH:"CFFEX",IM:"CFFEX",TS:"CFFEX",TF:"CFFEX",T:"CFFEX",TL:"CFFEX",si:"GFEX",lc:"GFEX",ps:"GFEX",pt:"GFEX",pd:"GFEX"},Te={HG:101,GC:101,SI:101,QI:101,QO:101,MGC:101,CL:102,NG:102,RB:102,HO:102,PA:102,PL:102,ZW:103,ZM:103,ZS:103,ZC:103,ZL:103,ZR:103,YM:103,NQ:103,ES:103,SB:108,CT:108,LCPT:109,LZNT:109,LALT:109},te="https://stock.finance.sina.com.cn/futures/api/openapi.php/OptionService.getOptionData",re="https://stock.finance.sina.com.cn/futures/api/jsonp.php/{callback}/FutureOptionAllService.getOptionDayline",Tt="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName",Ie="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay",It="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline",bt="https://stock.finance.sina.com.cn/futures/api/jsonp_v2.php/{callback}/StockOptionDaylineService.getSymbolInfo",_t="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getFiveDayLine",Pt="https://futsseapi.eastmoney.com/list/option/221",At="https://datacenter-web.eastmoney.com/api/data/get",xt="b2884a393a59ad64002292a3e90d46a5";var be={au:{product:"au_o",exchange:"shfe"},ag:{product:"ag_o",exchange:"shfe"},cu:{product:"cu_o",exchange:"shfe"},al:{product:"al_o",exchange:"shfe"},zn:{product:"zn_o",exchange:"shfe"},ru:{product:"ru_o",exchange:"shfe"},sc:{product:"sc_o",exchange:"ine"},m:{product:"m_o",exchange:"dce"},c:{product:"c_o",exchange:"dce"},i:{product:"i_o",exchange:"dce"},p:{product:"p_o",exchange:"dce"},pp:{product:"pp_o",exchange:"dce"},l:{product:"l_o",exchange:"dce"},v:{product:"v_o",exchange:"dce"},pg:{product:"pg_o",exchange:"dce"},y:{product:"y_o",exchange:"dce"},a:{product:"a_o",exchange:"dce"},b:{product:"b_o",exchange:"dce"},eg:{product:"eg_o",exchange:"dce"},eb:{product:"eb_o",exchange:"dce"},SR:{product:"SR_o",exchange:"czce"},CF:{product:"CF_o",exchange:"czce"},TA:{product:"TA_o",exchange:"czce"},MA:{product:"MA_o",exchange:"czce"},RM:{product:"RM_o",exchange:"czce"},OI:{product:"OI_o",exchange:"czce"},PK:{product:"PK_o",exchange:"czce"},PF:{product:"PF_o",exchange:"czce"},SA:{product:"SA_o",exchange:"czce"},UR:{product:"UR_o",exchange:"czce"}},Mt=3e4,ne=500,oe=500,ie=7,Lt=3,vt=1e3,Kt=3e4,kt=2,Ut=[408,429,500,502,503,504];var _e=class{constructor(e={}){let r=e.requestsPerSecond??5;this.maxTokens=e.maxBurst??r,this.tokens=this.maxTokens,this.refillRate=r/1e3,this.lastRefillTime=Date.now()}refill(){let e=Date.now(),o=(e-this.lastRefillTime)*this.refillRate;this.tokens=Math.min(this.maxTokens,this.tokens+o),this.lastRefillTime=e}tryAcquire(){return this.refill(),this.tokens>=1?(this.tokens-=1,!0):!1}getWaitTime(){if(this.refill(),this.tokens>=1)return 0;let e=1-this.tokens;return Math.ceil(e/this.refillRate)}async acquire(){let e=this.getWaitTime();e>0&&await this.sleep(e),this.refill(),this.tokens-=1}sleep(e){return new Promise(r=>setTimeout(r,e))}getAvailableTokens(){return this.refill(),this.tokens}};var tr=["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"],Ft=0;function hn(){return typeof window<"u"&&typeof window.document<"u"}function rr(){if(hn())return;let t=tr[Ft];return Ft=(Ft+1)%tr.length,t}var x=class extends Error{constructor(e){super(e.message),this.name="SdkError",this.code=e.code,this.provider=e.provider,this.url=e.url,this.status=e.status,this.details=e.details,e.cause!==void 0&&(this.cause=e.cause)}},U=class extends x{constructor(r,o,n,i){let s=o?` ${o}`:"",a=n?`, url: ${n}`:"",u=i?`, provider: ${i}`:"";super({code:r===429?"RATE_LIMITED":"HTTP_ERROR",message:`HTTP error! status: ${r}${s}${a}${u}`,status:r,url:n,provider:i,details:{statusText:o}});this.status=r;this.name="HttpError",this.statusText=o}};var ae=class extends x{constructor(e,r,o){super({code:"NOT_FOUND",message:e,provider:r,url:o}),this.name="NotFoundError"}};function se(t,e){let r=t;return!r.sdkCode&&e.sdkCode&&(r.sdkCode=e.sdkCode),!r.provider&&e.provider&&(r.provider=e.provider),!r.url&&e.url&&(r.url=e.url),r.status===void 0&&e.status!==void 0&&(r.status=e.status),!r.details&&e.details&&(r.details=e.details),r}function yn(t,e){return se(t,{provider:e.provider,url:e.url})}function q(t){if(t instanceof x||t instanceof U)return t.code;if(t instanceof DOMException&&t.name==="AbortError")return"TIMEOUT";if(t instanceof TypeError)return t.sdkCode??"NETWORK_ERROR";if(t instanceof Error)return t.sdkCode}function Pe(t,e={}){return t instanceof x?yn(t,e):t instanceof DOMException&&t.name==="AbortError"?se(t,{sdkCode:"TIMEOUT",provider:e.provider,url:e.url,details:e.timeout?{timeout:e.timeout}:void 0}):t instanceof TypeError?se(t,{sdkCode:"NETWORK_ERROR",provider:e.provider,url:e.url}):t instanceof Error?se(t,{sdkCode:"NETWORK_ERROR",provider:e.provider,url:e.url}):new x({code:"NETWORK_ERROR",message:"Unknown request error",provider:e.provider,url:e.url,cause:t})}var W=class extends x{constructor(e="Circuit breaker is OPEN"){super({code:"CIRCUIT_OPEN",message:e}),this.name="CircuitBreakerError"}},Ae=class{constructor(e={}){this.state="CLOSED";this.failureCount=0;this.lastFailureTime=0;this.halfOpenSuccessCount=0;this.failureThreshold=e.failureThreshold??5,this.resetTimeout=e.resetTimeout??3e4,this.halfOpenRequests=e.halfOpenRequests??1,this.onStateChange=e.onStateChange}getState(){return this.checkStateTransition(),this.state}canRequest(){switch(this.checkStateTransition(),this.state){case"CLOSED":return!0;case"OPEN":return!1;case"HALF_OPEN":return this.halfOpenSuccessCount<this.halfOpenRequests}}recordSuccess(){this.checkStateTransition(),this.state==="HALF_OPEN"?(this.halfOpenSuccessCount++,this.halfOpenSuccessCount>=this.halfOpenRequests&&this.transitionTo("CLOSED")):this.state==="CLOSED"&&(this.failureCount=0)}recordFailure(){this.lastFailureTime=Date.now(),this.state==="HALF_OPEN"?this.transitionTo("OPEN"):this.state==="CLOSED"&&(this.failureCount++,this.failureCount>=this.failureThreshold&&this.transitionTo("OPEN"))}checkStateTransition(){this.state==="OPEN"&&Date.now()-this.lastFailureTime>=this.resetTimeout&&this.transitionTo("HALF_OPEN")}transitionTo(e){if(this.state===e)return;let r=this.state;this.state=e,e==="CLOSED"?(this.failureCount=0,this.halfOpenSuccessCount=0):e==="HALF_OPEN"&&(this.halfOpenSuccessCount=0),this.onStateChange?.(r,e)}reset(){this.transitionTo("CLOSED"),this.failureCount=0,this.halfOpenSuccessCount=0,this.lastFailureTime=0}async execute(e){if(!this.canRequest())throw new W;try{let r=await e();return this.recordSuccess(),r}catch(r){throw this.recordFailure(),r}}getStats(){return{state:this.getState(),failureCount:this.failureCount,lastFailureTime:this.lastFailureTime,halfOpenSuccessCount:this.halfOpenSuccessCount}}};var Sn=3e4,Cn=1,nr=["push2his.eastmoney.com","7.push2his.eastmoney.com","33.push2his.eastmoney.com","63.push2his.eastmoney.com","91.push2his.eastmoney.com"],or=["17.push2.eastmoney.com","29.push2.eastmoney.com","79.push2.eastmoney.com","91.push2.eastmoney.com"];function On(t,e){return e!=="eastmoney"?[t]:t.includes("push2his.eastmoney.com")?nr:t.includes("push2.eastmoney.com")?or:[t]}function Rn(t){return Array.from(new Set(t))}var xe=class{constructor(e=Sn,r=Cn){this.cooldownMs=e;this.failureThreshold=r;this.states=new Map}getCandidateUrls(e,r){let o;try{o=new URL(e)}catch{return[e]}let n=Date.now(),i=On(o.hostname,r);if(i.length<=1)return[e];let s=i.filter(l=>{let c=this.states.get(l);return!c||c.cooldownUntil<=n}),a=i.filter(l=>{let c=this.states.get(l);return c&&c.cooldownUntil>n});return Rn([...s.includes(o.hostname)?[o.hostname]:[],...s.filter(l=>l!==o.hostname),...a.includes(o.hostname)?[o.hostname]:[],...a.filter(l=>l!==o.hostname)]).map(l=>{let c=new URL(e);return c.hostname=l,c.toString()})}recordSuccess(e){let r=this.safeGetHost(e);if(!r)return;let o=this.getState(r);o.failureCount=0,o.cooldownUntil=0,o.successCount++,o.lastErrorCode=void 0}recordFailure(e,r){let o=this.safeGetHost(e);if(!o)return;let n=this.getState(o);n.failureCount++,n.lastFailureAt=Date.now(),n.lastErrorCode=q(r),n.failureCount>=this.failureThreshold&&(n.cooldownUntil=Date.now()+this.cooldownMs)}shouldFallback(e){let r=q(e);return r==="NETWORK_ERROR"||r==="TIMEOUT"?!0:e instanceof U?e.status===408||e.status===429||e.status>=500:!1}getStats(e){let r=Array.from(this.states.values()).map(n=>({...n}));if(!e)return r;if(e!=="eastmoney")return[];let o=new Set([...nr,...or]);return r.filter(n=>o.has(n.host))}safeGetHost(e){try{return new URL(e).hostname}catch{return null}}getState(e){let r=this.states.get(e);if(r)return r;let o={host:e,failureCount:0,successCount:0,cooldownUntil:0,lastFailureAt:0};return this.states.set(e,o),o}};function En(t){return{maxRetries:t?.maxRetries??Lt,baseDelay:t?.baseDelay??vt,maxDelay:t?.maxDelay??Kt,backoffMultiplier:t?.backoffMultiplier??kt,retryableStatusCodes:t?.retryableStatusCodes??Ut,retryOnNetworkError:t?.retryOnNetworkError??!0,retryOnTimeout:t?.retryOnTimeout??!0,onRetry:t?.onRetry}}function Tn(t,e){let r={...t??{}};return e&&(Object.keys(r).some(n=>n.toLowerCase()==="user-agent")||(r["User-Agent"]=e)),r}function ir(t,e){return e?{timeout:e.timeout??t.timeout,retry:e.retry?{...t.retry??{},...e.retry}:t.retry?{...t.retry}:void 0,headers:{...t.headers??{},...e.headers??{}},userAgent:e.userAgent??t.userAgent,rateLimit:e.rateLimit?{...t.rateLimit??{},...e.rateLimit}:t.rateLimit?{...t.rateLimit}:void 0,rotateUserAgent:e.rotateUserAgent??t.rotateUserAgent,circuitBreaker:e.circuitBreaker?{...t.circuitBreaker??{},...e.circuitBreaker}:t.circuitBreaker?{...t.circuitBreaker}:void 0}:{...t,headers:{...t.headers??{}},retry:t.retry?{...t.retry}:void 0,rateLimit:t.rateLimit?{...t.rateLimit}:void 0,circuitBreaker:t.circuitBreaker?{...t.circuitBreaker}:void 0}}function Dt(t={}){return{timeout:t.timeout??Mt,retry:En(t.retry),headers:Tn(t.headers,t.userAgent),rotateUserAgent:t.rotateUserAgent??!1,rateLimit:t.rateLimit?{...t.rateLimit}:void 0,circuitBreaker:t.circuitBreaker?{...t.circuitBreaker}:void 0}}function sr(t,e){if(e)return e;try{let r=new URL(t).hostname;if(r.includes("eastmoney.com"))return"eastmoney";if(r.includes("gtimg.cn"))return"tencent";if(r.includes("sina.com.cn"))return"sina";if(r.includes("linkdiary.cn"))return"linkdiary"}catch{return"unknown"}return"unknown"}var ue=class{constructor(e={}){this.baseUrl=e.baseUrl??rt;let r={timeout:e.timeout,retry:e.retry,headers:e.headers,userAgent:e.userAgent,rateLimit:e.rateLimit,rotateUserAgent:e.rotateUserAgent,circuitBreaker:e.circuitBreaker};this.defaultPolicy=Dt(r),this.providerPolicies={},this.runtimeStates=new Map,this.fallbackManager=new xe;for(let[o,n]of Object.entries(e.providerPolicies??{})){let i=ir(r,n);this.providerPolicies[o]=Dt(i)}}getProviderState(e){let r=this.runtimeStates.get(e);if(r)return r;let o=this.providerPolicies[e]??this.defaultPolicy,n={policy:o,rateLimiter:o.rateLimit?new _e(o.rateLimit):null,circuitBreaker:o.circuitBreaker?new Ae(o.circuitBreaker):null};return this.runtimeStates.set(e,n),n}getTimeout(){return this.defaultPolicy.timeout}getHostHealth(e){return this.fallbackManager.getStats(e)}calculateDelay(e,r){return Math.min(r.baseDelay*Math.pow(r.backoffMultiplier,e),r.maxDelay)+Math.random()*100}sleep(e){return new Promise(r=>setTimeout(r,e))}shouldRetry(e,r,o){if(r>=o.maxRetries)return!1;let n=q(e);return n==="TIMEOUT"?o.retryOnTimeout:n==="NETWORK_ERROR"?o.retryOnNetworkError:e instanceof U?o.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,r,o,n=0){try{return await e()}catch(i){let s=Pe(i,o);if(this.shouldRetry(s,n,r)){let a=this.calculateDelay(n,r);return r.onRetry&&r.onRetry(n+1,s,a),await this.sleep(a),this.executeWithRetry(e,r,o,n+1)}throw s}}async performRequest(e,r,o,n="text"){r.rateLimiter&&await r.rateLimiter.acquire();let i=new AbortController,s=setTimeout(()=>i.abort(),r.policy.timeout),a={...r.policy.headers};if(r.policy.rotateUserAgent){let u=rr();if(u){for(let l of Object.keys(a))l.toLowerCase()==="user-agent"&&delete a[l];a["User-Agent"]=u}}try{let u=await fetch(e,{signal:i.signal,headers:a});if(!u.ok)throw new U(u.status,u.statusText,e,o);switch(n){case"json":return await u.json();case"arraybuffer":return await u.arrayBuffer();default:return await u.text()}}finally{clearTimeout(s)}}async get(e,r={}){let o=sr(e,r.provider),n=this.getProviderState(o);if(n.circuitBreaker&&!n.circuitBreaker.canRequest())throw new W("Circuit breaker is OPEN, request rejected");let i=this.fallbackManager.getCandidateUrls(e,o),s;for(let a=0;a<i.length;a++){let u=i[a],l=a===0?n.policy.retry:{...n.policy.retry,maxRetries:0};try{let c=await this.executeWithRetry(()=>this.performRequest(u,n,o,r.responseType),l,{provider:o,url:u,timeout:n.policy.timeout});return n.circuitBreaker?.recordSuccess(),this.fallbackManager.recordSuccess(u),c}catch(c){let m=Pe(c,{provider:o,url:u,timeout:n.policy.timeout});if(s=m,this.fallbackManager.recordFailure(u,m),a<i.length-1&&this.fallbackManager.shouldFallback(m))continue;throw n.circuitBreaker?.recordFailure(),m}}throw n.circuitBreaker?.recordFailure(),s??new W("Request failed without a concrete error")}async getTencentQuote(e){let r=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,o=await this.get(r,{responseType:"arraybuffer",provider:"tencent"}),n=Oe(o);return Re(n)}};var In=new Set(["daily","weekly","monthly"]),bn=new Set(["1","5","15","30","60"]),_n=new Set(["","qfq","hfq"]);function F(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function M(t){if(!In.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function le(t){if(!bn.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function B(t){if(!_n.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function V(t,e){F(e,"chunkSize");let r=[];for(let o=0;o<t.length;o+=e)r.push(t.slice(o,o+e));return r}async function Y(t,e,r=!1){if(F(e,"concurrency"),t.length===0)return[];let o=r?new Array(t.length):[],n=0,i=Array.from({length:Math.min(e,t.length)},async()=>{for(;;){let s=n++;if(s>=t.length)return;let a=await t[s]();r?o[s]=a:o.push(a)}});return await Promise.all(i),o}function Me(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function L(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function w(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var Le=class{constructor(e={}){this.cache=new Map;this.inflight=new Map;this.defaultTTL=e.defaultTTL??0,this.maxSize=e.maxSize??1e3}get(e){let r=this.cache.get(e);if(r){if(r.expireAt>0&&Date.now()>r.expireAt){this.cache.delete(e);return}return r.lastAccess=Date.now(),r.value}}set(e,r,o){this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU();let n=o??this.defaultTTL,i=Date.now();this.cache.set(e,{value:r,expireAt:n>0?i+n:0,lastAccess:i})}has(e){return this.get(e)!==void 0}delete(e){return this.cache.delete(e)}clear(){this.cache.clear(),this.inflight.clear()}get size(){return this.cache.size}cleanup(){let e=Date.now(),r=0;for(let[o,n]of this.cache)n.expireAt>0&&e>n.expireAt&&(this.cache.delete(o),r++);return r}evictLRU(){let e=null,r=1/0;for(let[o,n]of this.cache)n.lastAccess<r&&(r=n.lastAccess,e=o);e&&this.cache.delete(e)}async getOrFetch(e,r,o){let n=this.get(e);if(n!==void 0)return n;let i=this.inflight.get(e);if(i)return i;let s=r().then(a=>(this.set(e,a,o),a)).finally(()=>{this.inflight.delete(e)});return this.inflight.set(e,s),s}},ar=new Map;function Q(t,e){let r=ar.get(t);if(r)return r;let o=new Le(e);return ar.set(t,o),o}var Pn=typeof document<"u"&&typeof window<"u",An=0;function ur(){return`__stock_sdk_jsonp_${Date.now()}_${An++}`}function Nt(t){let e=t,r=e.indexOf("*/");r!==-1&&(e=e.slice(r+2).trim());let o=e.indexOf("(");if(o===-1)throw new Error("Invalid JSONP response: no opening parenthesis found");let n=e.lastIndexOf(")");if(n===-1||n<=o)throw new Error("Invalid JSONP response: no closing parenthesis found");let i=e.slice(o+1,n);return JSON.parse(i)}function xn(t,e){let{timeout:r=15e3,callbackParam:o="callback",callbackMode:n="query"}=e;return new Promise((i,s)=>{let a=ur(),u;if(n==="path")u=t.replace("{callback}",a);else{let y=t.includes("?")?"&":"?";u=`${t}${y}${o}=${a}`}let l=document.createElement("script"),c=!1,m=window,d=()=>{l.parentNode&&l.parentNode.removeChild(l),delete m[a]},h=setTimeout(()=>{c||(c=!0,d(),s(new Error(`JSONP request timed out after ${r}ms: ${t}`)))},r);m[a]=y=>{c||(c=!0,clearTimeout(h),d(),i(y))},l.onerror=()=>{c||(c=!0,clearTimeout(h),d(),s(new Error(`JSONP script load failed: ${t}`)))},l.src=u,document.head.appendChild(l)})}async function Mn(t,e){let{timeout:r=15e3,callbackParam:o="callback",callbackMode:n="query"}=e,i=ur(),s;if(n==="path")s=t.replace("{callback}",i);else{let l=t.includes("?")?"&":"?";s=`${t}${l}${o}=${i}`}let a=new AbortController,u=setTimeout(()=>a.abort(),r);try{let l=await fetch(s,{signal:a.signal});if(!l.ok)throw new Error(`JSONP fetch failed with status ${l.status}: ${t}`);let c=await l.text();return Nt(c)}catch(l){throw l instanceof DOMException&&l.name==="AbortError"?new Error(`JSONP request timed out after ${r}ms: ${t}`):l}finally{clearTimeout(u)}}function I(t,e={}){return Pn?xn(t,e):Mn(t,e)}var T={};tt(T,{getAShareCodeList:()=>gr,getAllHKQuotesByCodes:()=>Cr,getAllQuotesByCodes:()=>Sr,getAllUSQuotesByCodes:()=>Or,getFullQuotes:()=>ve,getFundCodeList:()=>Rr,getFundFlow:()=>cr,getFundQuotes:()=>dr,getHKCodeList:()=>yr,getHKQuotes:()=>Ke,getPanelLargeOrder:()=>pr,getSimpleQuotes:()=>lr,getTodayTimeline:()=>mr,getTradingCalendar:()=>Er,getUSCodeList:()=>hr,getUSQuotes:()=>ke,parseFullQuote:()=>Bt,parseFundFlow:()=>Ht,parseFundQuote:()=>$t,parseHKQuote:()=>Qt,parsePanelLargeOrder:()=>qt,parseSimpleQuote:()=>wt,parseUSQuote:()=>jt,search:()=>Ir});function Bt(t){let e=[];for(let o=0;o<5;o++)e.push({price:g(t[9+o*2]),volume:g(t[10+o*2])});let r=[];for(let o=0;o<5;o++)r.push({price:g(t[19+o*2]),volume:g(t[20+o*2])});return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:g(t[3]),prevClose:g(t[4]),open:g(t[5]),volume:g(t[6]),outerVolume:g(t[7]),innerVolume:g(t[8]),bid:e,ask:r,time:t[30]??"",change:g(t[31]),changePercent:g(t[32]),high:g(t[33]),low:g(t[34]),volume2:g(t[36]),amount:g(t[37]),turnoverRate:O(t[38]),pe:O(t[39]),amplitude:O(t[43]),circulatingMarketCap:O(t[44]),totalMarketCap:O(t[45]),pb:O(t[46]),limitUp:O(t[47]),limitDown:O(t[48]),volumeRatio:O(t[49]),avgPrice:O(t[51]),peStatic:O(t[52]),peDynamic:O(t[53]),high52w:O(t[67]),low52w:O(t[68]),circulatingShares:O(t[72]),totalShares:O(t[73]),raw:t}}function wt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:g(t[3]),change:g(t[4]),changePercent:g(t[5]),volume:g(t[6]),amount:g(t[7]),marketCap:O(t[9]),marketType:t[10]??"",raw:t}}function Ht(t){return{code:t[0]??"",mainInflow:g(t[1]),mainOutflow:g(t[2]),mainNet:g(t[3]),mainNetRatio:g(t[4]),retailInflow:g(t[5]),retailOutflow:g(t[6]),retailNet:g(t[7]),retailNetRatio:g(t[8]),totalFlow:g(t[9]),name:t[12]??"",date:t[13]??"",raw:t}}function qt(t){return{buyLargeRatio:g(t[0]),buySmallRatio:g(t[1]),sellLargeRatio:g(t[2]),sellSmallRatio:g(t[3]),raw:t}}function Qt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:g(t[3]),prevClose:g(t[4]),open:g(t[5]),volume:g(t[6]),time:t[30]??"",change:g(t[31]),changePercent:g(t[32]),high:g(t[33]),low:g(t[34]),amount:g(t[37]),lotSize:O(t[40]),circulatingMarketCap:O(t[44]),totalMarketCap:O(t[45]),currency:t[t.length-3]??"",raw:t}}function jt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:g(t[3]),prevClose:g(t[4]),open:g(t[5]),volume:g(t[6]),time:t[30]??"",change:g(t[31]),changePercent:g(t[32]),high:g(t[33]),low:g(t[34]),amount:g(t[37]),turnoverRate:O(t[38]),pe:O(t[39]),amplitude:O(t[43]),totalMarketCap:O(t[45]),pb:O(t[47]),high52w:O(t[48]),low52w:O(t[49]),raw:t}}function $t(t){return{code:t[0]??"",name:t[1]??"",nav:g(t[5]),accNav:g(t[6]),change:g(t[7]),navDate:t[8]??"",raw:t}}async function ve(t,e){return!e||e.length===0?[]:(await t.getTencentQuote(e.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Bt(o.fields))}async function lr(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`s_${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>wt(n.fields))}async function cr(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`ff_${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>Ht(n.fields))}async function pr(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`s_pk${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>qt(n.fields))}async function Ke(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`hk${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>Qt(n.fields))}async function ke(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`us${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>jt(n.fields))}async function dr(t,e){if(!e||e.length===0)return[];let r=e.map(n=>`jj${n}`);return(await t.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>$t(n.fields))}async function mr(t,e){let r=t.getTimeout(),o=new AbortController,n=setTimeout(()=>o.abort(),r);try{let i=await fetch(`${nt}?code=${e}`,{signal:o.signal});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);let s=await i.json();if(s.code!==0)throw new Error(s.msg||"API error");let a=s.data?.[e];if(!a)return{code:e,date:"",preClose:0,data:[]};let u=a.data?.data||[],l=a.data?.date||"",c=Array.isArray(a.qt?.[e])?a.qt[e]:[],m=parseFloat(c[4]??"")||0,d=!1;if(u.length>0){let y=u[0].split(" "),f=parseFloat(y[1])||0,C=parseInt(y[2],10)||0,E=parseFloat(y[3])||0;C>0&&f>0&&E/C>f*50&&(d=!0)}let h=u.map(y=>{let f=y.split(" "),C=f[0],E=`${C.slice(0,2)}:${C.slice(2,4)}`,b=parseInt(f[2],10)||0,_=parseFloat(f[3])||0,D=d?b*100:b,k=D>0?_/D:0;return{time:E,price:parseFloat(f[1])||0,volume:D,amount:_,avgPrice:Math.round(k*100)/100}});return{code:e,date:l,preClose:m,data:h}}finally{clearTimeout(n)}}var fr=Q("tencent:code-lists",{defaultTTL:360*60*1e3,maxSize:16});async function Gt(t,e,r){return fr.getOrFetch(e,async()=>(await t.get(r,{responseType:"json"}))?.list||[])}function Ln(t,e){let r=t.replace(/^(sh|sz|bj)/,"");switch(e){case"sh":return r.startsWith("6");case"sz":return r.startsWith("0")||r.startsWith("3");case"bj":return r.startsWith("92");case"kc":return r.startsWith("688");case"cy":return r.startsWith("30");default:return!0}}async function gr(t,e){let r=!1,o;typeof e=="boolean"?r=!e:e&&(r=e.simple??!1,o=e.market);let i=await Gt(t,"a-share:full",ot);return o&&(i=i.filter(s=>Ln(s,o))),r?i.map(s=>s.replace(/^(sh|sz|bj)/,"")):i.slice()}var vn={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function hr(t,e){let r=!1,o;typeof e=="boolean"?r=!e:e&&(r=e.simple??!1,o=e.market);let i=(await Gt(t,"us:full",it)).slice();if(o){let s=vn[o];i=i.filter(a=>a.startsWith(s))}return r?i.map(s=>s.replace(/^\d{3}\./,"")):i}async function yr(t){return(await Gt(t,"hk:full",st)).slice()}async function Sr(t,e,r={}){let{batchSize:o=ne,concurrency:n=ie,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,oe),a=V(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await ve(t,d);return l++,i&&i(l,u),h});return(await Y(c,n,!0)).flat()}async function Cr(t,e,r={}){let{batchSize:o=ne,concurrency:n=ie,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,oe),a=V(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await Ke(t,d);return l++,i&&i(l,u),h});return(await Y(c,n,!0)).flat()}async function Or(t,e,r={}){let{batchSize:o=ne,concurrency:n=ie,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,oe),a=V(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await ke(t,d);return l++,i&&i(l,u),h});return(await Y(c,n,!0)).flat()}async function Rr(t){return(await fr.getOrFetch("fund:full",async()=>(await t.get(at,{responseType:"text"})).split(",").slice(1).filter(n=>n.trim()))).slice()}var Kn=Q("tencent:trade-calendar",{defaultTTL:720*60*1e3,maxSize:4});async function Er(t){return(await Kn.getOrFetch("a-share",async()=>{let r=await t.get(er);return!r||r.trim()===""?[]:r.trim().split(",").map(o=>o.trim()).filter(o=>o.length>0)})).slice()}var Tr="https://smartbox.gtimg.cn/s3/";function kn(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,r)=>String.fromCharCode(parseInt(r,16)))}function Un(t){let e=t.toUpperCase();return e.startsWith("QDII")||e.startsWith("ETF")||e.startsWith("LOF")||e.startsWith("KJ")||e.startsWith("JJ")||e.includes("FUND")?"fund":e.startsWith("GP")||e.includes("STOCK")?"stock":e==="ZS"||e.includes("INDEX")?"index":e.startsWith("ZQ")||e.includes("BOND")?"bond":e.startsWith("QH")||e.includes("FUTURE")?"futures":e.startsWith("QZ")||e.includes("OPTION")?"option":"other"}function Fn(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(r=>{let o=r.split("~"),n=o[0]||"",i=o[1]||"",s=kn(o[2]||""),a=o[4]||"";return{code:n+i,name:s,market:n,type:a,category:Un(a)}})}function Dn(t){return new Promise((e,r)=>{let o=`${Tr}?v=2&t=all&q=${encodeURIComponent(t)}`;window.v_hint="";let n=document.createElement("script");n.src=o,n.charset="utf-8",n.onload=()=>{let i=window.v_hint||"";document.body.removeChild(n),e(i)},n.onerror=()=>{document.body.removeChild(n),r(new Error("Network error calling Smartbox"))},document.body.appendChild(n)})}async function Nn(t,e){let r=`${Tr}?v=2&t=all&q=${encodeURIComponent(e)}`,n=(await t.get(r)).match(/v_hint="([^"]*)"/);return n?n[1]:""}function Bn(){return typeof window<"u"&&typeof document<"u"}async function Ir(t,e){if(!e||!e.trim())return[];let r;return Bn()?r=await Dn(e):r=await Nn(t,e),Fn(r)}var R={};tt(R,{extractVariety:()=>Wt,getCFFEXOptionQuotes:()=>Yr,getComexInventory:()=>tn,getConceptConstituents:()=>qr,getConceptKline:()=>Qr,getConceptList:()=>wr,getConceptMinuteKline:()=>jr,getConceptSpot:()=>Hr,getDividendDetail:()=>$r,getFuturesHistoryKline:()=>zr,getFuturesInventory:()=>en,getFuturesInventorySymbols:()=>Zr,getFuturesMarketCode:()=>Vt,getGlobalFuturesKline:()=>Vr,getGlobalFuturesSpot:()=>Wr,getHKHistoryKline:()=>Pr,getHistoryKline:()=>br,getIndustryConstituents:()=>Dr,getIndustryKline:()=>Nr,getIndustryList:()=>Ur,getIndustryMinuteKline:()=>Br,getIndustrySpot:()=>Fr,getMinuteKline:()=>_r,getOptionLHB:()=>Xr,getUSHistoryKline:()=>Ar});async function zt(t,e,r,o,n=100,i){let s=[],a=1,u=0;do{let l=new URLSearchParams({...r,pn:String(a),pz:String(n),fields:o}),c=`${e}?${l.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data;if(!d||!Array.isArray(d.diff))break;a===1&&(u=d.total??0);let h=d.diff.map((y,f)=>i(y,s.length+f+1));s.push(...h),a++}while(s.length<u);return s}function v(t){let[e,r,o,n,i,s,a,u,l,c,m]=t.split(",");return{date:e,open:S(r),close:S(o),high:S(n),low:S(i),volume:S(s),amount:S(a),amplitude:S(u),changePercent:S(l),change:S(c),turnoverRate:S(m)}}async function K(t,e,r){let o=`${e}?${r.toString()}`,n=await t.get(o,{responseType:"json"});return{klines:n?.data?.klines||[],name:n?.data?.name,code:n?.data?.code}}async function br(t,e,r={}){let{period:o="daily",adjust:n="qfq",startDate:i="19700101",endDate:s="20500101"}=r;M(o),B(n);let a=e.replace(/^(sh|sz|bj)/,""),u=`${Me(e)}.${a}`,l=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:L(o),fqt:w(n),secid:u,beg:i,end:s}),c=Ee,{klines:m}=await K(t,c,l);return m.length===0?[]:m.map(d=>({...v(d),code:a}))}async function _r(t,e,r={}){let{period:o="1",adjust:n="qfq",startDate:i="1979-09-01 09:32:00",endDate:s="2222-01-01 09:32:00"}=r;le(o),B(n);let a=e.replace(/^(sh|sz|bj)/,""),u=`${Me(e)}.${a}`;if(o==="1"){let l=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",fields2:"f51,f52,f53,f54,f55,f56,f57,f58",ut:"7eea3edcaed734bea9cbfc24409ed989",ndays:"5",iscr:"0",secid:u}),c=`${ut}?${l.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(d)||d.length===0)return[];let h=i.replace("T"," ").slice(0,16),y=s.replace("T"," ").slice(0,16);return d.map(f=>{let[C,E,b,_,D,k,G,fn]=f.split(",");return{time:C,open:S(E),close:S(b),high:S(_),low:S(D),volume:S(k),amount:S(G),avgPrice:S(fn)}}).filter(f=>f.time>=h&&f.time<=y)}else{let l=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:o,fqt:w(n||""),secid:u,beg:"0",end:"20500000"}),c=Ee,{klines:m}=await K(t,c,l);if(m.length===0)return[];let d=i.replace("T"," ").slice(0,16),h=s.replace("T"," ").slice(0,16);return m.map(y=>{let f=v(y);return{...f,time:f.date}}).filter(y=>y.time>=d&&y.time<=h)}}function Ue(t){return async function(r,o,n={}){let{period:i="daily",adjust:s="qfq",startDate:a="19700101",endDate:u="20500101"}=n;M(i),B(s);let l=t.normalizeSymbol(o),c=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:L(i),fqt:w(s),secid:l.secid,beg:a,end:u,lmt:"1000000"}),{klines:m,name:d,code:h}=await K(r,t.url,c);if(m.length===0)return[];let y=t.resolveResultMeta?t.resolveResultMeta(o,l,{code:h,name:d}):{code:h||l.fallbackCode,name:d||""};return m.map(f=>({...v(f),code:y.code,name:y.name}))}}var wn=Ue({url:lt,normalizeSymbol:t=>{let e=t.replace(/^hk/i,"").padStart(5,"0");return{secid:`116.${e}`,fallbackCode:e}}});async function Pr(t,e,r={}){return wn(t,e,r)}var Hn=Ue({url:ct,normalizeSymbol:t=>({secid:t,fallbackCode:t.split(".")[1]||t}),resolveResultMeta:(t,e,r)=>({code:r.code||e.fallbackCode,name:r.name||""})});async function Ar(t,e,r={}){return Hn(t,e,r)}function xr(t){let e=Q(`eastmoney:board-code-map:${t.type}`,{defaultTTL:36e5,maxSize:4});return{async getCode(r,o,n){if(o.startsWith("BK"))return o;let s=(await e.getOrFetch("name-code-map",async()=>{let a=await n(r);return Object.fromEntries(a.map(u=>[u.name,u.code]))}))[o];if(!s)throw new ae(`${t.errorPrefix}: ${o}`,"eastmoney");return s}}}async function Mr(t,e){let r={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:e.type==="concept"?"f12":"f3",fs:e.fsFilter},o=e.type==="concept"?"f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136":"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152,f124,f107,f104,f105,f140,f141,f207,f208,f209,f222",n=await zt(t,e.listUrl,r,o,100,(i,s)=>({rank:s,name:String(i.f14??""),code:String(i.f12??""),price:p(i.f2),change:p(i.f4),changePercent:p(i.f3),totalMarketCap:p(i.f20),turnoverRate:p(i.f8),riseCount:p(i.f104),fallCount:p(i.f105),leadingStock:i.f128?String(i.f128):null,leadingStockChangePercent:p(i.f136)}));return n.sort((i,s)=>(s.changePercent??0)-(i.changePercent??0)),n.forEach((i,s)=>{i.rank=s+1}),n}async function Lr(t,e,r){let o=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${e}`}),n=`${r}?${o.toString()}`,s=(await t.get(n,{responseType:"json"}))?.data;return s?[{key:"f43",name:"\u6700\u65B0",divide:!0},{key:"f44",name:"\u6700\u9AD8",divide:!0},{key:"f45",name:"\u6700\u4F4E",divide:!0},{key:"f46",name:"\u5F00\u76D8",divide:!0},{key:"f47",name:"\u6210\u4EA4\u91CF",divide:!1},{key:"f48",name:"\u6210\u4EA4\u989D",divide:!1},{key:"f170",name:"\u6DA8\u8DCC\u5E45",divide:!0},{key:"f171",name:"\u632F\u5E45",divide:!0},{key:"f168",name:"\u6362\u624B\u7387",divide:!0},{key:"f169",name:"\u6DA8\u8DCC\u989D",divide:!0}].map(({key:u,name:l,divide:c})=>{let m=s[u],d=null;return typeof m=="number"&&!isNaN(m)&&(d=c?m/100:m),{item:l,value:d}}):[]}async function vr(t,e,r){let o={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return zt(t,r,o,"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152,f45",100,(i,s)=>({rank:s,code:String(i.f12??""),name:String(i.f14??""),price:p(i.f2),changePercent:p(i.f3),change:p(i.f4),volume:p(i.f5),amount:p(i.f6),amplitude:p(i.f7),high:p(i.f15),low:p(i.f16),open:p(i.f17),prevClose:p(i.f18),turnoverRate:p(i.f8),pe:p(i.f9),pb:p(i.f23)}))}async function Kr(t,e,r,o={}){let{period:n="daily",adjust:i="",startDate:s="19700101",endDate:a="20500101"}=o;M(n),B(i);let u=new URLSearchParams({secid:`90.${e}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:L(n),fqt:w(i),beg:s,end:a,smplmt:"10000",lmt:"1000000"}),{klines:l}=await K(t,r,u);return l.length===0?[]:l.map(c=>v(c))}async function kr(t,e,r,o,n={}){let{period:i="5"}=n;if(le(i),i==="1"){let s=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",fields2:"f51,f52,f53,f54,f55,f56,f57,f58",iscr:"0",ndays:"1",secid:`90.${e}`}),a=`${o}?${s.toString()}`,l=(await t.get(a,{responseType:"json"}))?.data?.trends;return!Array.isArray(l)||l.length===0?[]:l.map(c=>{let[m,d,h,y,f,C,E,b]=c.split(","),_=S(b);return{time:m,open:S(d),close:S(h),high:S(y),low:S(f),volume:S(C),amount:S(E),price:_,avgPrice:_}})}else{let s=new URLSearchParams({secid:`90.${e}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:i,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),a=`${r}?${s.toString()}`,l=(await t.get(a,{responseType:"json"}))?.data?.klines;return!Array.isArray(l)||l.length===0?[]:l.map(c=>{let[m,d,h,y,f,C,E,b,_,D,k]=c.split(",");return{time:m,open:S(d),close:S(h),high:S(y),low:S(f),changePercent:S(_),change:S(D),volume:S(C),amount:S(E),amplitude:S(b),turnoverRate:S(k)}})}}function Fe(t){let e=xr(t);async function r(n){return Mr(n,t)}async function o(n,i){return e.getCode(n,i,r)}return{async getList(n){return r(n)},async getSpot(n,i){let s=await o(n,i);return Lr(n,s,t.spotUrl)},async getConstituents(n,i){let s=await o(n,i);return vr(n,s,t.consUrl)},async getKline(n,i,s={}){let a=await o(n,i);return Kr(n,a,t.klineUrl,s)},async getMinuteKline(n,i,s={}){let a=await o(n,i);return kr(n,a,t.klineUrl,t.trendsUrl,s)}}}var qn={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:pt,spotUrl:dt,consUrl:mt,klineUrl:ft,trendsUrl:gt,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},ce=Fe(qn);async function Ur(t){return ce.getList(t)}async function Fr(t,e){return ce.getSpot(t,e)}async function Dr(t,e){return ce.getConstituents(t,e)}async function Nr(t,e,r={}){return ce.getKline(t,e,r)}async function Br(t,e,r={}){return ce.getMinuteKline(t,e,r)}var Qn={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:ht,spotUrl:yt,consUrl:St,klineUrl:Ct,trendsUrl:Ot,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},pe=Fe(Qn);async function wr(t){return pe.getList(t)}async function Hr(t,e){return pe.getSpot(t,e)}async function qr(t,e){return pe.getConstituents(t,e)}async function Qr(t,e,r={}){return pe.getKline(t,e,r)}async function jr(t,e,r={}){return pe.getMinuteKline(t,e,r)}function j(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function jn(t){return{code:t.SECURITY_CODE??"",name:t.SECURITY_NAME_ABBR??"",reportDate:j(t.REPORT_DATE),planNoticeDate:j(t.PLAN_NOTICE_DATE),disclosureDate:j(t.PUBLISH_DATE??t.PLAN_NOTICE_DATE),assignTransferRatio:t.BONUS_IT_RATIO??null,bonusRatio:t.BONUS_RATIO??null,transferRatio:t.IT_RATIO??null,dividendPretax:t.PRETAX_BONUS_RMB??null,dividendDesc:t.IMPL_PLAN_PROFILE??null,dividendYield:t.DIVIDENT_RATIO??null,eps:t.BASIC_EPS??null,bps:t.BVPS??null,capitalReserve:t.PER_CAPITAL_RESERVE??null,unassignedProfit:t.PER_UNASSIGN_PROFIT??null,netProfitYoy:t.PNP_YOY_RATIO??null,totalShares:t.TOTAL_SHARES??null,equityRecordDate:j(t.EQUITY_RECORD_DATE),exDividendDate:j(t.EX_DIVIDEND_DATE),payDate:j(t.PAY_DATE),assignProgress:t.ASSIGN_PROGRESS??null,noticeDate:j(t.NOTICE_DATE)}}async function $r(t,e){let r=e.replace(/^(sh|sz|bj)/,""),o=[],n=1,i=1;do{let s=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:"500",pageNumber:String(n),reportName:"RPT_SHAREBONUS_DET",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(SECURITY_CODE="${r}")`}),a=`${H}?${s.toString()}`,l=(await t.get(a,{responseType:"json"}))?.result;if(!l||!Array.isArray(l.data))break;n===1&&(i=l.pages??1);let c=l.data.map(jn);o.push(...c),n++}while(n<=i);return o}function Wt(t){let e=t.match(/^([a-zA-Z]+)/);if(!e)throw new RangeError(`Invalid futures symbol: "${t}". Expected format: variety + contract (e.g., rb2605, RBM, IF2604)`);return e[1]}function Gr(t){return z[t]??z[t.toLowerCase()]??z[t.toUpperCase()]}function Vt(t){let e=Gr(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=Gr(t.slice(0,-1))),!e){let o=Object.keys(z).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${o}`)}let r=Et[e];if(r===void 0)throw new RangeError(`No market code found for exchange: ${e}`);return r}function $n(t){let e=v(t),r=t.split(",");return{...e,openInterest:r.length>12?S(r[12]):null}}async function zr(t,e,r={}){let{period:o="daily",startDate:n="19700101",endDate:i="20500101"}=r;M(o);let s=Wt(e),u=`${Vt(s)}.${e}`,l=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:L(o),fqt:"0",secid:u,beg:n,end:i}),{klines:c,name:m,code:d}=await K(t,J,l);return c.length===0?[]:c.map(h=>({...$n(h),code:d||e,name:m||""}))}async function Wr(t,e={}){let r=e.pageSize??20,o=[],n=0,i=0;do{let s=new URLSearchParams({orderBy:"dm",sort:"desc",pageSize:String(r),pageIndex:String(n),token:ee,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),a=`${Rt}?${s.toString()}`,u=await t.get(a,{responseType:"json"});if(!u||!Array.isArray(u.list))break;n===0&&(i=u.total??0);let l=u.list.map(Gn);o.push(...l),n++}while(o.length<i);return o}function Gn(t){return{code:t.dm||"",name:t.name||"",price:S(String(t.p)),change:S(String(t.zde)),changePercent:S(String(t.zdf)),open:S(String(t.o)),high:S(String(t.h)),low:S(String(t.l)),prevSettle:S(String(t.zjsj)),volume:S(String(t.vol)),buyVolume:S(String(t.wp)),sellVolume:S(String(t.np)),openInterest:S(String(t.ccl))}}function zn(t){let e=v(t),r=t.split(",");return{...e,openInterest:r.length>12?S(r[12]):null}}function Wn(t){let e=t.match(/^([A-Z]+)/);if(!e)throw new RangeError(`Invalid global futures symbol: "${t}". Expected format like HG00Y, CL2507`);return e[1]}async function Vr(t,e,r={}){let{period:o="daily",startDate:n="19700101",endDate:i="20500101"}=r;M(o);let s=r.marketCode;if(s===void 0){let d=Wn(e);if(s=Te[d],s===void 0){let h=Object.keys(Te).join(", ");throw new RangeError(`Unknown global futures variety: "${d}". Supported: ${h}. Or specify marketCode manually via options.`)}}let a=`${s}.${e}`,u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:L(o),fqt:"0",secid:a,beg:n,end:i}),{klines:l,name:c,code:m}=await K(t,J,u);return l.length===0?[]:l.map(d=>({...zn(d),code:m||e,name:c||""}))}async function Yr(t,e={}){let{pageSize:r=2e4}=e,o=new URLSearchParams({orderBy:"zdf",sort:"desc",pageSize:String(r),pageIndex:"0",token:ee,field:"dm,sc,name,p,zsjd,zde,zdf,f152,vol,cje,ccl,xqj,syr,rz,zjsj,o"}),n=`${Pt}?${o.toString()}`,s=(await t.get(n,{responseType:"json"}))?.list;return Array.isArray(s)?s.map(a=>({code:String(a.dm??""),name:String(a.name??""),price:p(a.p),change:p(a.zde),changePercent:p(a.zdf),volume:p(a.vol),amount:p(a.cje),openInterest:p(a.ccl),strikePrice:p(a.xqj),remainDays:p(a.syr),dailyChange:p(a.rz),prevSettle:p(a.zjsj),open:p(a.o)})):[]}function Vn(t){return t.includes("\u51C0")?"net":t.includes("\u4E70")?"buy":t.includes("\u5356")?"sell":null}async function Xr(t,e,r){let o=new URLSearchParams({type:"RPT_IF_BILLBOARD_TD",sty:"ALL",p:"1",ps:"200",source:"IFBILLBOARD",client:"WEB",ut:xt,filter:`(SECURITY_CODE="${e}")(TRADE_DATE='${r}')`}),n=`${At}?${o.toString()}`,s=(await t.get(n,{responseType:"json"}))?.result?.data;if(!Array.isArray(s))return[];function a(u){if(!u)return"";let l=String(u),c=l.match(/^(\d{4}-\d{2}-\d{2})/);return c?c[1]:l}return s.map(u=>({tradeType:String(u.TRADE_TYPE??""),date:a(u.TRADE_DATE),symbol:String(u.SECURITY_CODE??""),targetName:String(u.TARGET_NAME??""),memberName:String(u.MEMBER_NAME_ABBR??""),rank:p(u.MEMBER_RANK)??0,sellVolume:p(u.SELL_VOLUME),sellVolumeChange:p(u.SELL_VOLUME_CHANGE),netSellVolume:p(u.NET_SELL_VOLUME),sellVolumeRatio:p(u.SELL_VOLUME_RATIO),buyVolume:p(u.BUY_VOLUME),buyVolumeChange:p(u.BUY_VOLUME_CHANGE),netBuyVolume:p(u.NET_BUY_VOLUME),buyVolumeRatio:p(u.BUY_VOLUME_RATIO),sellPosition:p(u.SELL_POSITION),sellPositionChange:p(u.SELL_POSITION_CHANGE),netSellPosition:p(u.NET_SELL_POSITION),sellPositionRatio:p(u.SELL_POSITION_RATIO),buyPosition:p(u.BUY_POSITION),buyPositionChange:p(u.BUY_POSITION_CHANGE),netBuyPosition:p(u.NET_BUY_POSITION),buyPositionRatio:p(u.BUY_POSITION_RATIO),tradeDate:a(u.TRADE_DATE),volume:p(u.BUY_VOLUME)??p(u.SELL_VOLUME)??p(u.NET_BUY_VOLUME)??p(u.NET_SELL_VOLUME),volumeChange:p(u.BUY_VOLUME_CHANGE)??p(u.SELL_VOLUME_CHANGE),amount:p(u.BUY_POSITION)??p(u.SELL_POSITION)??p(u.NET_BUY_POSITION)??p(u.NET_SELL_POSITION),amountChange:p(u.BUY_POSITION_CHANGE)??p(u.SELL_POSITION_CHANGE),openInterest:p(u.BUY_POSITION)??p(u.SELL_POSITION),openInterestChange:p(u.BUY_POSITION_CHANGE)??p(u.SELL_POSITION_CHANGE),side:Vn(String(u.TRADE_TYPE??""))}))}var Yn={gold:"EMI00069026",silver:"EMI00069027"};async function Zr(t){let e=new URLSearchParams({reportName:"RPT_FUTU_POSITIONCODE",columns:"TRADE_MARKET_CODE,TRADE_CODE,TRADE_TYPE",filter:'(IS_MAINCODE="1")',pageNumber:"1",pageSize:"500",source:"WEB",client:"WEB"}),r=`${H}?${e.toString()}`,n=(await t.get(r,{responseType:"json"}))?.result?.data;return Array.isArray(n)?n.map(i=>({code:String(i.TRADE_CODE??""),name:String(i.TRADE_TYPE??""),marketCode:String(i.TRADE_MARKET_CODE??"")})):[]}function Jr(t){if(!t)return"";let e=String(t),r=e.match(/^(\d{4}-\d{2}-\d{2})/);return r?r[1]:e}async function en(t,e,r={}){let{startDate:o="2020-10-28",pageSize:n=500}=r,i=e.toUpperCase(),s=[],a=1,u=1;do{let l=new URLSearchParams({reportName:"RPT_FUTU_STOCKDATA",columns:"SECURITY_CODE,TRADE_DATE,ON_WARRANT_NUM,ADDCHANGE",filter:`(SECURITY_CODE="${i}")(TRADE_DATE>='${o}')`,pageNumber:String(a),pageSize:String(n),sortTypes:"-1",sortColumns:"TRADE_DATE",source:"WEB",client:"WEB"}),c=`${H}?${l.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;a===1&&(u=d.pages??1);let h=d.data.map(y=>({code:String(y.SECURITY_CODE??e),date:Jr(y.TRADE_DATE),inventory:p(y.ON_WARRANT_NUM),change:p(y.ADDCHANGE)}));s.push(...h),a++}while(a<=u);return s}async function tn(t,e,r={}){let o=Yn[e];if(!o)throw new RangeError(`Invalid COMEX symbol: "${e}". Must be "gold" or "silver".`);let{pageSize:n=500}=r,i=[],s=1,a=1,u={gold:"\u9EC4\u91D1",silver:"\u767D\u94F6"};do{let l=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:String(n),pageNumber:String(s),reportName:"RPT_FUTUOPT_GOLDSIL",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(INDICATOR_ID1="${o}")(@STORAGE_TON<>"NULL")`}),c=`${H}?${l.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;s===1&&(a=d.pages??1);let h=d.data.map(y=>({date:Jr(y.REPORT_DATE),name:u[e]??e,storageTon:p(y.STORAGE_TON),storageOunce:p(y.STORAGE_OUNCE),inventory:p(y.STORAGE_TON),change:null,market:e}));i.push(...h),s++}while(s<=a);return i}var P={};tt(P,{getCommodityOptionKline:()=>dn,getCommodityOptionSpot:()=>pn,getETFOption5DayMinute:()=>cn,getETFOptionDailyKline:()=>ln,getETFOptionExpireDay:()=>sn,getETFOptionMinute:()=>un,getETFOptionMonths:()=>on,getIndexOptionKline:()=>nn,getIndexOptionSpot:()=>rn});function Xn(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:p(t[7]),symbol:t[8]??""}}function Zn(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:null,symbol:t[7]??""}}async function rn(t,e){let r=`${te}?type=futures&product=${t}&exchange=cffex&pinzhong=${e}`,o=await I(r),n=o?.result?.data?.up??[],i=o?.result?.data?.down??[];return{calls:n.map(Xn),puts:i.map(Zn)}}async function nn(t){let e=`${re}?symbol=${t}`,r=await I(e,{callbackMode:"path"});return Array.isArray(r)?r.map(o=>({date:o.d,open:p(o.o),high:p(o.h),low:p(o.l),close:p(o.c),volume:p(o.v)})):[]}async function on(t){let e=`${Tt}?exchange=null&cate=${encodeURIComponent(t)}`,o=(await I(e))?.result?.data,n=o?.contractMonth??[];return{months:n.length>1?n.slice(1):n,stockId:o?.stockId??"",cateId:o?.cateId??"",cateList:o?.cateList??[]}}async function sn(t,e){let r=`${Ie}?exchange=null&cate=${encodeURIComponent(t)}&date=${e}`,o=await I(r),n=o?.result?.data?.remainderDays;if(typeof n=="number"&&n<0){let s=`${Ie}?exchange=null&cate=${encodeURIComponent("XD"+t)}&date=${e}`;o=await I(s)}let i=o?.result?.data;return{expireDay:i?.expireDay??"",remainderDays:i?.remainderDays??0,stockId:i?.stockId??"",name:i?.other?.name??""}}function an(t){let e="";return t.map(r=>(r.d&&(e=r.d),{time:r.i,date:e,price:p(r.p),volume:p(r.v),openInterest:p(r.t),avgPrice:p(r.a)}))}async function un(t){let e=`CON_OP_${t}`,r=`${It}?symbol=${e}`,n=(await I(r))?.result?.data;return Array.isArray(n)?an(n):[]}async function ln(t){let e=`CON_OP_${t}`,r=`${bt}?symbol=${e}`,o=await I(r,{callbackMode:"path"});return Array.isArray(o)?o.map(n=>({date:n.d,open:p(n.o),high:p(n.h),low:p(n.l),close:p(n.c),volume:p(n.v)})):[]}async function cn(t){let e=`CON_OP_${t}`,r=`${_t}?symbol=${e}`,n=(await I(r))?.result?.data;if(!Array.isArray(n))return[];let i=[];for(let s of n)Array.isArray(s)&&i.push(...an(s));return i}function Jn(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:p(t[7]),symbol:t[8]??""}}function eo(t){return{buyVolume:p(t[0]),buyPrice:p(t[1]),price:p(t[2]),askPrice:p(t[3]),askVolume:p(t[4]),openInterest:p(t[5]),change:p(t[6]),strikePrice:null,symbol:t[7]??""}}async function pn(t,e){let r=be[t];if(!r)throw new RangeError(`Unknown commodity option variety: "${t}". Available: ${Object.keys(be).join(", ")}`);let o=`${te}?type=futures&product=${r.product}&exchange=${r.exchange}&pinzhong=${e}`,n=await I(o),i=n?.result?.data?.up??[],s=n?.result?.data?.down??[];return{calls:i.map(Jn),puts:s.map(eo)}}async function dn(t){let e=`${re}?symbol=${t}`,r=await I(e,{callbackMode:"path"});return Array.isArray(r)?r.map(o=>({date:o.d,open:p(o.o),high:p(o.h),low:p(o.l),close:p(o.c),volume:p(o.v)})):[]}var A=class{constructor(e){this.client=e}};var de=class extends A{constructor(e){super(e)}getFullQuotes(e){return T.getFullQuotes(this.client,e)}getSimpleQuotes(e){return T.getSimpleQuotes(this.client,e)}getHKQuotes(e){return T.getHKQuotes(this.client,e)}getUSQuotes(e){return T.getUSQuotes(this.client,e)}getFundQuotes(e){return T.getFundQuotes(this.client,e)}getFundFlow(e){return T.getFundFlow(this.client,e)}getPanelLargeOrder(e){return T.getPanelLargeOrder(this.client,e)}getTodayTimeline(e){return T.getTodayTimeline(this.client,e)}search(e){return T.search(this.client,e)}getAShareCodeList(e){return T.getAShareCodeList(this.client,e)}getUSCodeList(e){return T.getUSCodeList(this.client,e)}getHKCodeList(){return T.getHKCodeList(this.client)}getFundCodeList(){return T.getFundCodeList(this.client)}async getAllAShareQuotes(e={}){let{market:r,...o}=e,n=await this.getAShareCodeList({market:r});return T.getAllQuotesByCodes(this.client,n,o)}async getAllHKShareQuotes(e={}){let r=await this.getHKCodeList();return T.getAllHKQuotesByCodes(this.client,r,e)}async getAllUSShareQuotes(e={}){let{market:r,...o}=e,n=await this.getUSCodeList({simple:!0,market:r});return T.getAllUSQuotesByCodes(this.client,n,o)}getAllQuotesByCodes(e,r={}){return T.getAllQuotesByCodes(this.client,e,r)}batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return T.getTradingCalendar(this.client)}getDividendDetail(e){return R.getDividendDetail(this.client,e)}};var me=class extends A{constructor(e){super(e)}getIndustryList(){return R.getIndustryList(this.client)}getIndustrySpot(e){return R.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return R.getIndustryConstituents(this.client,e)}getIndustryKline(e,r){return R.getIndustryKline(this.client,e,r)}getIndustryMinuteKline(e,r){return R.getIndustryMinuteKline(this.client,e,r)}getConceptList(){return R.getConceptList(this.client)}getConceptSpot(e){return R.getConceptSpot(this.client,e)}getConceptConstituents(e){return R.getConceptConstituents(this.client,e)}getConceptKline(e,r){return R.getConceptKline(this.client,e,r)}getConceptMinuteKline(e,r){return R.getConceptMinuteKline(this.client,e,r)}};var fe=class extends A{constructor(e){super(e)}getHistoryKline(e,r){return R.getHistoryKline(this.client,e,r)}getMinuteKline(e,r){return R.getMinuteKline(this.client,e,r)}getHKHistoryKline(e,r){return R.getHKHistoryKline(this.client,e,r)}getUSHistoryKline(e,r){return R.getUSHistoryKline(this.client,e,r)}};var ge=class extends A{constructor(e){super(e)}getFuturesKline(e,r){return R.getFuturesHistoryKline(this.client,e,r)}getGlobalFuturesSpot(e){return R.getGlobalFuturesSpot(this.client,e)}getGlobalFuturesKline(e,r){return R.getGlobalFuturesKline(this.client,e,r)}getFuturesInventorySymbols(){return R.getFuturesInventorySymbols(this.client)}getFuturesInventory(e,r){return R.getFuturesInventory(this.client,e,r)}getComexInventory(e,r){return R.getComexInventory(this.client,e,r)}};var he=class extends A{constructor(e){super(e)}getIndexOptionSpot(e,r){return P.getIndexOptionSpot(e,r)}getIndexOptionKline(e){return P.getIndexOptionKline(e)}getCFFEXOptionQuotes(e){return R.getCFFEXOptionQuotes(this.client,e)}getETFOptionMonths(e){return P.getETFOptionMonths(e)}getETFOptionExpireDay(e,r){return P.getETFOptionExpireDay(e,r)}getETFOptionMinute(e){return P.getETFOptionMinute(e)}getETFOptionDailyKline(e){return P.getETFOptionDailyKline(e)}getETFOption5DayMinute(e){return P.getETFOption5DayMinute(e)}getCommodityOptionSpot(e,r){return P.getCommodityOptionSpot(e,r)}getCommodityOptionKline(e){return P.getCommodityOptionKline(e)}getOptionLHB(e,r){return R.getOptionLHB(this.client,e,r)}};function ye(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function $(t,e){let r=[];for(let o=0;o<t.length;o++){if(o<e-1){r.push(null);continue}let n=0,i=0;for(let s=o-e+1;s<=o;s++)t[s]!==null&&(n+=t[s],i++);r.push(i===e?ye(n/e):null)}return r}function N(t,e){let r=[],o=2/(e+1),n=null,i=!1;for(let s=0;s<t.length;s++){if(s<e-1){r.push(null);continue}if(!i){let u=0,l=0;for(let c=s-e+1;c<=s;c++)t[c]!==null&&(u+=t[c],l++);l===e&&(n=u/e,i=!0),r.push(n!==null?ye(n):null);continue}let a=t[s];a===null?r.push(n!==null?ye(n):null):(n=o*a+(1-o)*n,r.push(ye(n)))}return r}function Yt(t,e){let r=[],o=Array.from({length:e},(i,s)=>s+1),n=o.reduce((i,s)=>i+s,0);for(let i=0;i<t.length;i++){if(i<e-1){r.push(null);continue}let s=0,a=!0;for(let u=0;u<e;u++){let l=t[i-e+1+u];if(l===null){a=!1;break}s+=l*o[u]}r.push(a?ye(s/n):null)}return r}function De(t,e={}){let{periods:r=[5,10,20,30,60,120,250],type:o="sma"}=e,n=o==="ema"?N:o==="wma"?Yt:$,i={};for(let s of r)i[`ma${s}`]=n(t,s);return t.map((s,a)=>{let u={};for(let l of r)u[`ma${l}`]=i[`ma${l}`][a];return u})}function mn(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Ne(t,e={}){let{short:r=12,long:o=26,signal:n=9}=e,i=N(t,r),s=N(t,o),a=t.map((l,c)=>i[c]===null||s[c]===null?null:i[c]-s[c]),u=N(a,n);return t.map((l,c)=>({dif:a[c]!==null?mn(a[c]):null,dea:u[c],macd:a[c]!==null&&u[c]!==null?mn((a[c]-u[c])*2):null}))}function Xt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function to(t,e,r){let o=[];for(let n=0;n<t.length;n++){if(n<e-1||r[n]===null){o.push(null);continue}let i=0,s=0;for(let a=n-e+1;a<=n;a++)t[a]!==null&&r[n]!==null&&(i+=Math.pow(t[a]-r[n],2),s++);o.push(s===e?Math.sqrt(i/e):null)}return o}function Be(t,e={}){let{period:r=20,stdDev:o=2}=e,n=$(t,r),i=to(t,r,n);return t.map((s,a)=>{if(n[a]===null||i[a]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let u=n[a]+o*i[a],l=n[a]-o*i[a],c=n[a]!==0?Xt((u-l)/n[a]*100):null;return{mid:n[a],upper:Xt(u),lower:Xt(l),bandwidth:c}})}function Zt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function we(t,e={}){let{period:r=9,kPeriod:o=3,dPeriod:n=3}=e,i=[],s=50,a=50;for(let u=0;u<t.length;u++){if(u<r-1){i.push({k:null,d:null,j:null});continue}let l=-1/0,c=1/0,m=!0;for(let f=u-r+1;f<=u;f++){if(t[f].high===null||t[f].low===null){m=!1;break}l=Math.max(l,t[f].high),c=Math.min(c,t[f].low)}let d=t[u].close;if(!m||d===null||l===c){i.push({k:null,d:null,j:null});continue}let h=(d-c)/(l-c)*100;s=(o-1)/o*s+1/o*h,a=(n-1)/n*a+1/n*s;let y=3*s-2*a;i.push({k:Zt(s),d:Zt(a),j:Zt(y)})}return i}function ro(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function He(t,e={}){let{periods:r=[6,12,24]}=e,o=[null];for(let i=1;i<t.length;i++)t[i]===null||t[i-1]===null?o.push(null):o.push(t[i]-t[i-1]);let n={};for(let i of r){let s=[],a=0,u=0;for(let l=0;l<t.length;l++){if(l<i){s.push(null),o[l]!==null&&(o[l]>0?a+=o[l]:u+=Math.abs(o[l]));continue}if(l===i)a=a/i,u=u/i;else{let c=o[l]??0,m=c>0?c:0,d=c<0?Math.abs(c):0;a=(a*(i-1)+m)/i,u=(u*(i-1)+d)/i}if(u===0)s.push(100);else if(a===0)s.push(0);else{let c=a/u;s.push(ro(100-100/(1+c)))}}n[`rsi${i}`]=s}return t.map((i,s)=>{let a={};for(let u of r)a[`rsi${u}`]=n[`rsi${u}`][s];return a})}function no(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function qe(t,e={}){let{periods:r=[6,10]}=e,o={};for(let n of r){let i=[];for(let s=0;s<t.length;s++){if(s<n-1){i.push(null);continue}let a=-1/0,u=1/0,l=!0;for(let d=s-n+1;d<=s;d++){if(t[d].high===null||t[d].low===null){l=!1;break}a=Math.max(a,t[d].high),u=Math.min(u,t[d].low)}let c=t[s].close;if(!l||c===null||a===u){i.push(null);continue}let m=(a-c)/(a-u)*100;i.push(no(m))}o[`wr${n}`]=i}return t.map((n,i)=>{let s={};for(let a of r)s[`wr${a}`]=o[`wr${a}`][i];return s})}function oo(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Qe(t,e={}){let{periods:r=[6,12,24]}=e,o={};for(let n of r){let i=$(t,n),s=[];for(let a=0;a<t.length;a++)if(t[a]===null||i[a]===null||i[a]===0)s.push(null);else{let u=(t[a]-i[a])/i[a]*100;s.push(oo(u))}o[`bias${n}`]=s}return t.map((n,i)=>{let s={};for(let a of r)s[`bias${a}`]=o[`bias${a}`][i];return s})}function io(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function je(t,e={}){let{period:r=14}=e,o=[],n=t.map(i=>i.high===null||i.low===null||i.close===null?null:(i.high+i.low+i.close)/3);for(let i=0;i<t.length;i++){if(i<r-1){o.push({cci:null});continue}let s=0,a=0;for(let m=i-r+1;m<=i;m++)n[m]!==null&&(s+=n[m],a++);if(a!==r||n[i]===null){o.push({cci:null});continue}let u=s/r,l=0;for(let m=i-r+1;m<=i;m++)l+=Math.abs(n[m]-u);let c=l/r;if(c===0)o.push({cci:0});else{let m=(n[i]-u)/(.015*c);o.push({cci:io(m)})}}return o}function Jt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function X(t,e={}){let{period:r=14}=e,o=[],n=[];for(let s=0;s<t.length;s++){let{high:a,low:u,close:l}=t[s];if(a===null||u===null||l===null){n.push(null);continue}if(s===0)n.push(a-u);else{let c=t[s-1].close;if(c===null)n.push(a-u);else{let m=a-u,d=Math.abs(a-c),h=Math.abs(u-c);n.push(Math.max(m,d,h))}}}let i=null;for(let s=0;s<t.length;s++){if(s<r-1){o.push({tr:n[s]!==null?Jt(n[s]):null,atr:null});continue}if(s===r-1){let a=0,u=0;for(let l=0;l<r;l++)n[l]!==null&&(a+=n[l],u++);u===r&&(i=a/r)}else i!==null&&n[s]!==null&&(i=(i*(r-1)+n[s])/r);o.push({tr:n[s]!==null?Jt(n[s]):null,atr:i!==null?Jt(i):null})}return o}function $e(t,e={}){let{maPeriod:r}=e,o=[];if(t.length===0)return o;let n=t[0].volume??0;o.push({obv:n,obvMa:null});for(let i=1;i<t.length;i++){let s=t[i],a=t[i-1];if(s.close===null||a.close===null||s.volume===null||s.volume===void 0){o.push({obv:null,obvMa:null});continue}s.close>a.close?n+=s.volume:s.close<a.close&&(n-=s.volume),o.push({obv:n,obvMa:null})}if(r&&r>0)for(let i=r-1;i<o.length;i++){let s=0,a=0;for(let u=i-r+1;u<=i;u++)o[u].obv!==null&&(s+=o[u].obv,a++);a===r&&(o[i].obvMa=s/r)}return o}function Ge(t,e={}){let{period:r=12,signalPeriod:o}=e,n=[];for(let i=0;i<t.length;i++){if(i<r){n.push({roc:null,signal:null});continue}let s=t[i].close,a=t[i-r].close;if(s===null||a===null||a===0){n.push({roc:null,signal:null});continue}let u=(s-a)/a*100;n.push({roc:u,signal:null})}if(o&&o>0)for(let i=r+o-1;i<n.length;i++){let s=0,a=0;for(let u=i-o+1;u<=i;u++)n[u].roc!==null&&(s+=n[u].roc,a++);a===o&&(n[i].signal=s/o)}return n}function ze(t,e={}){let{period:r=14,adxPeriod:o=r}=e,n=[];if(t.length<2)return t.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let i=[],s=[],a=[];for(let f=0;f<t.length;f++){if(f===0){i.push(0),s.push(0),a.push(0),n.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let C=t[f],E=t[f-1];if(C.high===null||C.low===null||C.close===null||E.high===null||E.low===null||E.close===null){i.push(0),s.push(0),a.push(0),n.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let b=C.high-C.low,_=Math.abs(C.high-E.close),D=Math.abs(C.low-E.close);a.push(Math.max(b,_,D));let k=C.high-E.high,G=E.low-C.low;k>G&&k>0?i.push(k):i.push(0),G>k&&G>0?s.push(G):s.push(0),n.push({pdi:null,mdi:null,adx:null,adxr:null})}let u=0,l=0,c=0,m=[];for(let f=1;f<t.length;f++){if(f<r){u+=a[f],l+=i[f],c+=s[f],m.push(0);continue}f===r?(u=u,l=l,c=c):(u=u-u/r+a[f],l=l-l/r+i[f],c=c-c/r+s[f]);let C=u>0?l/u*100:0,E=u>0?c/u*100:0;n[f].pdi=C,n[f].mdi=E;let b=C+E,_=b>0?Math.abs(C-E)/b*100:0;m.push(_)}let d=0,h=0,y=0;for(let f=r;f<t.length;f++){if(f<r*2-1){d+=m[f-r+1]||0,h++;continue}if(f===r*2-1)d+=m[f-r+1]||0,y=d/o,n[f].adx=y;else{let C=m[f-r+1]||0;y=(y*(o-1)+C)/o,n[f].adx=y}}for(let f=r*2-1+o;f<t.length;f++){let C=n[f].adx,E=n[f-o]?.adx;C!==null&&E!==null&&(n[f].adxr=(C+E)/2)}return n}function We(t,e={}){let{afStart:r=.02,afIncrement:o=.02,afMax:n=.2}=e,i=[];if(t.length<2)return t.map(()=>({sar:null,trend:null,ep:null,af:null}));let s=1,a=r,u=t[0].high??0,l=t[0].low??0,c=t[0],m=t[1];c.close!==null&&m.close!==null&&m.close<c.close&&(s=-1,u=c.low??0,l=c.high??0),i.push({sar:null,trend:null,ep:null,af:null});for(let d=1;d<t.length;d++){let h=t[d],y=t[d-1];if(h.high===null||h.low===null||y.high===null||y.low===null){i.push({sar:null,trend:null,ep:null,af:null});continue}let f=l+a*(u-l);s===1?(f=Math.min(f,y.low,t[Math.max(0,d-2)]?.low??y.low),h.low<f?(s=-1,f=u,u=h.low,a=r):h.high>u&&(u=h.high,a=Math.min(a+o,n))):(f=Math.max(f,y.high,t[Math.max(0,d-2)]?.high??y.high),h.high>f?(s=1,f=u,u=h.high,a=r):h.low<u&&(u=h.low,a=Math.min(a+o,n))),l=f,i.push({sar:l,trend:s,ep:u,af:a})}return i}function Ve(t,e={}){let{emaPeriod:r=20,atrPeriod:o=10,multiplier:n=2}=e,i=[],s=t.map(l=>l.close),a=N(s,r),u=X(t,{period:o});for(let l=0;l<t.length;l++){let c=a[l],m=u[l]?.atr;if(c===null||m===null){i.push({mid:null,upper:null,lower:null,width:null});continue}let d=c+n*m,h=c-n*m,y=c>0?(d-h)/c*100:null;i.push({mid:c,upper:d,lower:h,width:y})}return i}function Ye(t,e=0){return t.length===0?e:Math.max(...t)}function Xe(t){return{closes:t.map(e=>e.close),ohlcv:t.map(e=>({open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume}))}}var Z={ma:{key:"ma",estimateLookback:t=>{let e=typeof t=="object"?t:{},r=e.periods??[5,10,20,30,60,120,250],o=e.type??"sma";return{bars:Ye(r,20),emaBased:o==="ema"}},compute:(t,e)=>De(t.closes,typeof e=="object"?e:{})},macd:{key:"macd",estimateLookback:t=>{let e=typeof t=="object"?t:{},r=e.long??26,o=e.signal??9;return{bars:r*3+o,emaBased:!0}},compute:(t,e)=>Ne(t.closes,typeof e=="object"?e:{})},boll:{key:"boll",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:20}),compute:(t,e)=>Be(t.closes,typeof e=="object"?e:{})},kdj:{key:"kdj",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:9}),compute:(t,e)=>we(t.ohlcv,typeof e=="object"?e:{})},rsi:{key:"rsi",estimateLookback:t=>{let e=typeof t=="object"&&t.periods?t.periods:[6,12,24];return{bars:Ye(e,14)+1}},compute:(t,e)=>He(t.closes,typeof e=="object"?e:{})},wr:{key:"wr",estimateLookback:t=>{let e=typeof t=="object"&&t.periods?t.periods:[6,10];return{bars:Ye(e,10)}},compute:(t,e)=>qe(t.ohlcv,typeof e=="object"?e:{})},bias:{key:"bias",estimateLookback:t=>{let e=typeof t=="object"&&t.periods?t.periods:[6,12,24];return{bars:Ye(e,12)}},compute:(t,e)=>Qe(t.closes,typeof e=="object"?e:{})},cci:{key:"cci",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:14}),compute:(t,e)=>je(t.ohlcv,typeof e=="object"?e:{})},atr:{key:"atr",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:14}),compute:(t,e)=>X(t.ohlcv,typeof e=="object"?e:{})},obv:{key:"obv",estimateLookback:t=>{let e=typeof t=="object"&&t.maPeriod?t.maPeriod:0;return{bars:Math.max(2,e)}},compute:(t,e)=>$e(t.ohlcv,typeof e=="object"?e:{})},roc:{key:"roc",estimateLookback:t=>{let e=typeof t=="object"?t:{},r=e.period??12,o=e.signalPeriod??0;return{bars:r+o}},compute:(t,e)=>Ge(t.ohlcv,typeof e=="object"?e:{})},dmi:{key:"dmi",estimateLookback:t=>{let e=typeof t=="object"?t:{},r=e.period??14,o=e.adxPeriod??r;return{bars:r*2+o}},compute:(t,e)=>ze(t.ohlcv,typeof e=="object"?e:{})},sar:{key:"sar",estimateLookback:()=>({bars:5}),compute:(t,e)=>We(t.ohlcv,typeof e=="object"?e:{})},kc:{key:"kc",estimateLookback:t=>{let e=typeof t=="object"?t:{},r=e.emaPeriod??20,o=e.atrPeriod??10;return{bars:Math.max(r*3,o),emaBased:!0}},compute:(t,e)=>Ve(t.ohlcv,typeof e=="object"?e:{})}};function Se(t){return Object.keys(Z).filter(e=>!!t[e])}function Ze(t){let e=0,r=!1;for(let n of Se(t)){let s=Z[n].estimateLookback(t[n]);e=Math.max(e,s.bars),r||(r=!!s.emaBased)}return{maxLookback:e,hasEmaBasedIndicator:r,requiredBars:Math.ceil(e*(r?1.5:1.2))}}function Je(t,e={}){if(t.length===0)return[];let r=Xe(t),o=new Map;for(let n of Se(e)){let i=Z[n];o.set(n,i.compute(r,e[n]))}return t.map((n,i)=>({...n,...Object.fromEntries(Array.from(o.entries()).map(([s,a])=>[s,a[i]]))}))}var Ce=class{constructor(e,r){this.klineService=e;this.quoteService=r}detectMarket(e){return/^\d{3}\.[A-Z]+$/i.test(e)?"US":/^\d{5}$/.test(e)?"HK":"A"}calcActualStartDate(e,r,o=1.5){let n=Math.ceil(r*o),i=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.slice(6,8)));i.setDate(i.getDate()-n);let s=i.getFullYear(),a=String(i.getMonth()+1).padStart(2,"0"),u=String(i.getDate()).padStart(2,"0");return`${s}${a}${u}`}calcActualStartDateByCalendar(e,r,o){if(!o||o.length===0)return;let n=this.normalizeDate(e),i=o.findIndex(a=>a>=n);i===-1&&(i=o.length-1);let s=Math.max(0,i-r);return this.toCompactDate(o[s])}normalizeDate(e){return e.includes("-")?e:e.length===8?`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`:e}toCompactDate(e){return e.replace(/-/g,"")}dateToTimestamp(e){let r=e.includes("-")?e:`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`;return new Date(r).getTime()}async getKlineWithIndicators(e,r={}){let{startDate:o,endDate:n,indicators:i={}}=r,s=r.market??this.detectMarket(e),{requiredBars:a}=Ze(i),u={A:1.5,HK:1.46,US:1.45},l;if(o)if(s==="A")try{let h=await this.quoteService.getTradingCalendar();l=this.calcActualStartDateByCalendar(o,a,h)??this.calcActualStartDate(o,a,u[s])}catch{l=this.calcActualStartDate(o,a,u[s])}else l=this.calcActualStartDate(o,a,u[s]);let c={period:r.period,adjust:r.adjust,startDate:l,endDate:r.endDate},m;switch(s){case"HK":m=await this.klineService.getHKHistoryKline(e,c);break;case"US":m=await this.klineService.getUSHistoryKline(e,c);break;default:m=await this.klineService.getHistoryKline(e,c)}if(o&&m.length<a)switch(s){case"HK":m=await this.klineService.getHKHistoryKline(e,{...c,startDate:void 0});break;case"US":m=await this.klineService.getUSHistoryKline(e,{...c,startDate:void 0});break;default:m=await this.klineService.getHistoryKline(e,{...c,startDate:void 0})}let d=Je(m,i);if(o){let h=this.dateToTimestamp(o),y=n?this.dateToTimestamp(n):1/0;return d.filter(f=>{let C=this.dateToTimestamp(f.date);return C>=h&&C<=y})}return d}};var et=class{constructor(e={}){this.client=new ue(e),this.quoteService=new de(this.client),this.boardService=new me(this.client),this.klineService=new fe(this.client),this.futuresService=new ge(this.client),this.optionsService=new he(this.client),this.indicatorService=new Ce(this.klineService,this.quoteService)}getFullQuotes(e){return this.quoteService.getFullQuotes(e)}getSimpleQuotes(e){return this.quoteService.getSimpleQuotes(e)}getHKQuotes(e){return this.quoteService.getHKQuotes(e)}getUSQuotes(e){return this.quoteService.getUSQuotes(e)}getFundQuotes(e){return this.quoteService.getFundQuotes(e)}getFundFlow(e){return this.quoteService.getFundFlow(e)}getPanelLargeOrder(e){return this.quoteService.getPanelLargeOrder(e)}getTodayTimeline(e){return this.quoteService.getTodayTimeline(e)}getIndustryList(){return this.boardService.getIndustryList()}getIndustrySpot(e){return this.boardService.getIndustrySpot(e)}getIndustryConstituents(e){return this.boardService.getIndustryConstituents(e)}getIndustryKline(e,r){return this.boardService.getIndustryKline(e,r)}getIndustryMinuteKline(e,r){return this.boardService.getIndustryMinuteKline(e,r)}getConceptList(){return this.boardService.getConceptList()}getConceptSpot(e){return this.boardService.getConceptSpot(e)}getConceptConstituents(e){return this.boardService.getConceptConstituents(e)}getConceptKline(e,r){return this.boardService.getConceptKline(e,r)}getConceptMinuteKline(e,r){return this.boardService.getConceptMinuteKline(e,r)}getHistoryKline(e,r){return this.klineService.getHistoryKline(e,r)}getMinuteKline(e,r){return this.klineService.getMinuteKline(e,r)}getHKHistoryKline(e,r){return this.klineService.getHKHistoryKline(e,r)}getUSHistoryKline(e,r){return this.klineService.getUSHistoryKline(e,r)}search(e){return this.quoteService.search(e)}getAShareCodeList(e){return this.quoteService.getAShareCodeList(e)}getUSCodeList(e){return this.quoteService.getUSCodeList(e)}getHKCodeList(){return this.quoteService.getHKCodeList()}getFundCodeList(){return this.quoteService.getFundCodeList()}getAllAShareQuotes(e={}){return this.quoteService.getAllAShareQuotes(e)}getAllHKShareQuotes(e={}){return this.quoteService.getAllHKShareQuotes(e)}getAllUSShareQuotes(e={}){return this.quoteService.getAllUSShareQuotes(e)}getAllQuotesByCodes(e,r={}){return this.quoteService.getAllQuotesByCodes(e,r)}batchRaw(e){return this.quoteService.batchRaw(e)}getTradingCalendar(){return this.quoteService.getTradingCalendar()}getDividendDetail(e){return this.quoteService.getDividendDetail(e)}getFuturesKline(e,r){return this.futuresService.getFuturesKline(e,r)}getGlobalFuturesSpot(e){return this.futuresService.getGlobalFuturesSpot(e)}getGlobalFuturesKline(e,r){return this.futuresService.getGlobalFuturesKline(e,r)}getFuturesInventorySymbols(){return this.futuresService.getFuturesInventorySymbols()}getFuturesInventory(e,r){return this.futuresService.getFuturesInventory(e,r)}getComexInventory(e,r){return this.futuresService.getComexInventory(e,r)}getIndexOptionSpot(e,r){return this.optionsService.getIndexOptionSpot(e,r)}getIndexOptionKline(e){return this.optionsService.getIndexOptionKline(e)}getCFFEXOptionQuotes(e){return this.optionsService.getCFFEXOptionQuotes(e)}getETFOptionMonths(e){return this.optionsService.getETFOptionMonths(e)}getETFOptionExpireDay(e,r){return this.optionsService.getETFOptionExpireDay(e,r)}getETFOptionMinute(e){return this.optionsService.getETFOptionMinute(e)}getETFOptionDailyKline(e){return this.optionsService.getETFOptionDailyKline(e)}getETFOption5DayMinute(e){return this.optionsService.getETFOption5DayMinute(e)}getCommodityOptionSpot(e,r){return this.optionsService.getCommodityOptionSpot(e,r)}getCommodityOptionKline(e){return this.optionsService.getCommodityOptionKline(e)}getOptionLHB(e,r){return this.optionsService.getOptionLHB(e,r)}getKlineWithIndicators(e,r={}){return this.indicatorService.getKlineWithIndicators(e,r)}},so=et;export{U as HttpError,Z as INDICATOR_REGISTRY,x as SdkError,et as StockSDK,Je as addIndicators,Y as asyncPool,Xe as buildIndicatorContext,X as calcATR,Qe as calcBIAS,Be as calcBOLL,je as calcCCI,ze as calcDMI,N as calcEMA,Ve as calcKC,we as calcKDJ,De as calcMA,Ne as calcMACD,$e as calcOBV,Ge as calcROC,He as calcRSI,We as calcSAR,$ as calcSMA,Yt as calcWMA,qe as calcWR,V as chunkArray,Oe as decodeGBK,so as default,Ze as estimateIndicatorLookback,Nt as extractJsonFromJsonp,Se as getEnabledIndicatorKeys,q as getSdkErrorCode,I as jsonpRequest,Re as parseResponse,g as safeNumber,O as safeNumberOrNull};
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stock-sdk",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup",
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
10
11
|
"test": "vitest run",
|
|
11
12
|
"test:unit": "vitest run",
|
|
12
13
|
"test:integration": "RUN_INTEGRATION=1 vitest run",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
14
|
+
"test:integration:smoke": "RUN_INTEGRATION=1 vitest run test/integration/providers/tencent/quote.int.test.ts test/integration/providers/tencent/batch.int.test.ts test/integration/providers/tencent/tradeCalendar.int.test.ts test/integration/sdk/timeout.int.test.ts",
|
|
15
|
+
"test:integration:full": "RUN_INTEGRATION=1 vitest run test/integration",
|
|
16
|
+
"docs:meta": "yarn build && node ./scripts/generate-doc-meta.js",
|
|
17
|
+
"docs:check": "yarn build && node ./scripts/check-doc-consistency.js",
|
|
15
18
|
"dev": "vitepress dev website",
|
|
16
19
|
"preview": "vitepress preview website",
|
|
17
20
|
"build:docs": "yarn docs:meta && DOCS_BASE=/ vitepress build website",
|