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 CHANGED
@@ -107,6 +107,45 @@ const allQuotes = await sdk.getAllAShareQuotes({
107
107
  console.log(`共获取 ${allQuotes.length} 只股票`);
108
108
  ```
109
109
 
110
+ ## 请求治理与错误码
111
+
112
+ ```ts
113
+ import { StockSDK, HttpError, getSdkErrorCode } from 'stock-sdk';
114
+
115
+ const sdk = new StockSDK({
116
+ retry: { maxRetries: 2, baseDelay: 500 },
117
+ providerPolicies: {
118
+ eastmoney: {
119
+ timeout: 12000,
120
+ rateLimit: { requestsPerSecond: 3, maxBurst: 3 },
121
+ },
122
+ },
123
+ });
124
+
125
+ try {
126
+ await sdk.getSimpleQuotes(['sh600519']);
127
+ } catch (error) {
128
+ if (error instanceof HttpError) {
129
+ console.log(error.status, error.statusText);
130
+ }
131
+
132
+ console.log(getSdkErrorCode(error)); // HTTP_ERROR / NETWORK_ERROR / TIMEOUT ...
133
+ }
134
+ ```
135
+
136
+ `getSdkErrorCode` 只做标准化识别,不会改变原始错误实例类型。网络错误仍然保持 `TypeError`,超时仍然保持 `AbortError` / `DOMException` 的兼容行为。
137
+
138
+ ## 开发校验命令
139
+
140
+ ```bash
141
+ yarn typecheck
142
+ yarn build
143
+ yarn test
144
+ yarn test:integration:smoke
145
+ # 全量集成回归
146
+ yarn test:integration:full
147
+ ```
148
+
110
149
  ## 🤖 AI / MCP 集成
111
150
 
112
151
  Stock SDK 配套 MCP Server([stock-sdk-mcp](https://www.npmjs.com/package/stock-sdk-mcp)),可一键接入主流 AI 工具:
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var He=Object.defineProperty;var Vn=Object.getOwnPropertyDescriptor;var Wn=Object.getOwnPropertyNames;var Xn=Object.prototype.hasOwnProperty;var _e=(t,e)=>{for(var n in e)He(t,n,{get:e[n],enumerable:!0})},Yn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Wn(e))!Xn.call(t,r)&&r!==n&&He(t,r,{get:()=>e[r],enumerable:!(i=Vn(e,r))||i.enumerable});return t};var Zn=t=>Yn(He({},"__esModule",{value:!0}),t);var kr={};_e(kr,{HttpError:()=>v,StockSDK:()=>Ee,addIndicators:()=>Te,asyncPool:()=>H,calcATR:()=>j,calcBIAS:()=>ge,calcBOLL:()=>pe,calcCCI:()=>he,calcDMI:()=>Ce,calcEMA:()=>U,calcKC:()=>Oe,calcKDJ:()=>de,calcMA:()=>ue,calcMACD:()=>ce,calcOBV:()=>ye,calcROC:()=>Re,calcRSI:()=>me,calcSAR:()=>Se,calcSMA:()=>B,calcWMA:()=>we,calcWR:()=>fe,chunkArray:()=>w,decodeGBK:()=>V,default:()=>Gn,extractJsonFromJsonp:()=>Ke,jsonpRequest:()=>P,parseResponse:()=>W,safeNumber:()=>h,safeNumberOrNull:()=>S});module.exports=Zn(kr);function V(t){return new TextDecoder("gbk").decode(t)}function W(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 qe="https://qt.gtimg.cn",je="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Qe="https://assets.linkdiary.cn/shares/zh_a_list.json",$e="https://assets.linkdiary.cn/shares/us_list.json",Ge="https://assets.linkdiary.cn/shares/hk_list.json",ze="https://assets.linkdiary.cn/shares/fund_list",Ft="https://assets.linkdiary.cn/shares/trade-data-list.txt";var be="https://push2his.eastmoney.com/api/qt/stock/kline/get",Ve="https://push2his.eastmoney.com/api/qt/stock/trends2/get",We="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Xe="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Ye="https://17.push2.eastmoney.com/api/qt/clist/get",Ze="https://91.push2.eastmoney.com/api/qt/stock/get",Je="https://29.push2.eastmoney.com/api/qt/clist/get",et="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",tt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",nt="https://79.push2.eastmoney.com/api/qt/clist/get",rt="https://91.push2.eastmoney.com/api/qt/stock/get",ot="https://29.push2.eastmoney.com/api/qt/clist/get",it="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",st="https://push2his.eastmoney.com/api/qt/stock/trends2/get",F="https://datacenter-web.eastmoney.com/api/data/v1/get",X="https://push2his.eastmoney.com/api/qt/stock/kline/get",at="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",Y="58b2fa8f54638b60b87d69b31969089c",lt={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},$={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"},Pe={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},Z="https://stock.finance.sina.com.cn/futures/api/openapi.php/OptionService.getOptionData",J="https://stock.finance.sina.com.cn/futures/api/jsonp.php/{callback}/FutureOptionAllService.getOptionDayline",ut="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName",Ae="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay",ct="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline",pt="https://stock.finance.sina.com.cn/futures/api/jsonp_v2.php/{callback}/StockOptionDaylineService.getSymbolInfo",dt="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getFiveDayLine",mt="https://futsseapi.eastmoney.com/list/option/221",ft="https://datacenter-web.eastmoney.com/api/data/get",gt="b2884a393a59ad64002292a3e90d46a5";var Ie={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"}},ht=3e4,ee=500,te=500,ne=7,yt=3,Rt=1e3,Ct=3e4,St=2,Ot=[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 vt=["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"],Tt=0;function Jn(){return typeof window<"u"&&typeof window.document<"u"}function wt(){if(Jn())return;let t=vt[Tt];return Tt=(Tt+1)%vt.length,t}var re=class extends Error{constructor(e="Circuit breaker is OPEN"){super(e),this.name="CircuitBreakerError"}},xe=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 re;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 v=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"}},oe=class{constructor(e={}){this.baseUrl=e.baseUrl??qe;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??yt,baseDelay:e?.baseDelay??Rt,maxDelay:e?.maxDelay??Ct,backoffMultiplier:e?.backoffMultiplier??St,retryableStatusCodes:e?.retryableStatusCodes??Ot,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??ht,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 xe(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 v?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 re("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=wt();l&&(a["User-Agent"]=l)}try{let l=await fetch(e,{signal:o.signal,headers:a});if(!l.ok)throw new v(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=V(i);return W(r)}};var er=new Set(["daily","weekly","monthly"]),tr=new Set(["1","5","15","30","60"]),nr=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(!er.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function ie(t){if(!tr.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function k(t){if(!nr.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function w(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 H(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 Le(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 rr=typeof document<"u"&&typeof window<"u",or=0;function Ht(){return`__stock_sdk_jsonp_${Date.now()}_${or++}`}function Ke(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 ir(t,e){let{timeout:n=15e3,callbackParam:i="callback",callbackMode:r="query"}=e;return new Promise((o,s)=>{let a=Ht(),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 sr(t,e){let{timeout:n=15e3,callbackParam:i="callback",callbackMode:r="query"}=e,o=Ht(),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 Ke(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 rr?ir(t,e):sr(t,e)}var b={};_e(b,{getAShareCodeList:()=>zt,getAllHKQuotesByCodes:()=>Yt,getAllQuotesByCodes:()=>Xt,getAllUSQuotesByCodes:()=>Zt,getFullQuotes:()=>Ue,getFundCodeList:()=>Jt,getFundFlow:()=>jt,getFundQuotes:()=>$t,getHKCodeList:()=>Wt,getHKQuotes:()=>De,getPanelLargeOrder:()=>Qt,getSimpleQuotes:()=>qt,getTodayTimeline:()=>Gt,getTradingCalendar:()=>en,getUSCodeList:()=>Vt,getUSQuotes:()=>ke,parseFullQuote:()=>Et,parseFundFlow:()=>bt,parseFundQuote:()=>Mt,parseHKQuote:()=>At,parsePanelLargeOrder:()=>Pt,parseSimpleQuote:()=>_t,parseUSQuote:()=>It,search:()=>nn});function Et(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 _t(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 bt(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 Pt(t){return{buyLargeRatio:h(t[0]),buySmallRatio:h(t[1]),sellLargeRatio:h(t[2]),sellSmallRatio:h(t[3]),raw:t}}function At(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 It(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 Mt(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 Ue(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=>Et(i.fields))}async function qt(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=>_t(r.fields))}async function jt(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=>bt(r.fields))}async function Qt(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=>Pt(r.fields))}async function De(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=>At(r.fields))}async function ke(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=>It(r.fields))}async function $t(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=>Mt(r.fields))}async function Gt(t,e){let n=t.getTimeout(),i=new AbortController,r=setTimeout(()=>i.abort(),n);try{let o=await fetch(`${je}?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 xt=null,ar=null,Ne=null,lr=null,Be=null,Lt=null;function ur(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 zt(t,e){let n=!1,i;if(typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,i=e.market),!xt){let s=(await t.get(Qe,{responseType:"json"}))?.list||[];xt=s,ar=s.map(a=>a.replace(/^(sh|sz|bj)/,""))}let r=xt;return i&&(r=r.filter(o=>ur(o,i))),n?r.map(o=>o.replace(/^(sh|sz|bj)/,"")):r.slice()}var cr={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function Vt(t,e){let n=!1,i;typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,i=e.market),Ne||(Ne=(await t.get($e,{responseType:"json"}))?.list||[],lr=Ne.map(s=>s.replace(/^\d{3}\./,"")));let r=Ne.slice();if(i){let o=cr[i];r=r.filter(s=>s.startsWith(o))}return n?r.map(o=>o.replace(/^\d{3}\./,"")):r}async function Wt(t){return Be||(Be=(await t.get(Ge,{responseType:"json"}))?.list||[]),Be.slice()}async function Xt(t,e,n={}){let{batchSize:i=ee,concurrency:r=ne,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,te),a=w(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await Ue(t,d);return u++,o&&o(u,l),g});return(await H(c,r,!0)).flat()}async function Yt(t,e,n={}){let{batchSize:i=ee,concurrency:r=ne,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,te),a=w(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await De(t,d);return u++,o&&o(u,l),g});return(await H(c,r,!0)).flat()}async function Zt(t,e,n={}){let{batchSize:i=ee,concurrency:r=ne,onProgress:o}=n;K(i,"batchSize"),K(r,"concurrency");let s=Math.min(i,te),a=w(e,s),l=a.length,u=0,c=a.map(d=>async()=>{let g=await ke(t,d);return u++,o&&o(u,l),g});return(await H(c,r,!0)).flat()}async function Jt(t){if(Lt)return Lt.slice();let i=(await t.get(ze,{responseType:"text"})).split(",").slice(1).filter(r=>r.trim());return Lt=i,i.slice()}var G=null;async function en(t){if(G)return G.slice();let e=await t.get(Ft);return!e||e.trim()===""?(G=[],G.slice()):(G=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),G.slice())}var tn="https://smartbox.gtimg.cn/s3/";function pr(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function dr(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let i=n.split("~"),r=i[0]||"",o=i[1]||"",s=pr(i[2]||""),a=i[4]||"";return{code:r+o,name:s,market:r,type:a}})}function mr(t){return new Promise((e,n)=>{let i=`${tn}?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 fr(t,e){let n=`${tn}?v=2&t=all&q=${encodeURIComponent(e)}`,r=(await t.get(n)).match(/v_hint="([^"]*)"/);return r?r[1]:""}function gr(){return typeof window<"u"&&typeof document<"u"}async function nn(t,e){if(!e||!e.trim())return[];let n;return gr()?n=await mr(e):n=await fr(t,e),dr(n)}var T={};_e(T,{extractVariety:()=>Ut,getCFFEXOptionQuotes:()=>Mn,getComexInventory:()=>Dn,getConceptConstituents:()=>On,getConceptKline:()=>Tn,getConceptList:()=>Cn,getConceptMinuteKline:()=>En,getConceptSpot:()=>Sn,getDividendDetail:()=>_n,getFuturesHistoryKline:()=>Pn,getFuturesInventory:()=>Un,getFuturesInventorySymbols:()=>Ln,getFuturesMarketCode:()=>Dt,getGlobalFuturesKline:()=>In,getGlobalFuturesSpot:()=>An,getHKHistoryKline:()=>sn,getHistoryKline:()=>rn,getIndustryConstituents:()=>hn,getIndustryKline:()=>yn,getIndustryList:()=>fn,getIndustryMinuteKline:()=>Rn,getIndustrySpot:()=>gn,getMinuteKline:()=>on,getOptionLHB:()=>xn,getUSHistoryKline:()=>an});async function Kt(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 rn(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=`${Le(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=be,{klines:m}=await L(t,c,u);return m.length===0?[]:m.map(d=>({...x(d),code:a}))}async function on(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;ie(i),k(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${Le(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=`${Ve}?${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,Q,zn]=f.split(",");return{time:C,open:R(O),close:R(E),high:R(_),low:R(z),volume:R(D),amount:R(Q),avgPrice:R(zn)}}).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=be,{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 Fe(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 hr=Fe({url:We,normalizeSymbol:t=>{let e=t.replace(/^hk/i,"").padStart(5,"0");return{secid:`116.${e}`,fallbackCode:e}}});async function sn(t,e,n={}){return hr(t,e,n)}var yr=Fe({url:Xe,normalizeSymbol:t=>({secid:t,fallbackCode:t.split(".")[1]||t}),resolveResultMeta:(t,e,n)=>({code:n.code||e.fallbackCode,name:n.name||""})});async function an(t,e,n={}){return yr(t,e,n)}function ln(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 un(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 Kt(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 cn(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 pn(t,e,n){let i={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return Kt(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 dn(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 mn(t,e,n,i,r={}){let{period:o="5"}=r;if(ie(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 ve(t){let e=ln(t);async function n(r){return un(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 cn(r,s,t.spotUrl)},async getConstituents(r,o){let s=await i(r,o);return pn(r,s,t.consUrl)},async getKline(r,o,s={}){let a=await i(r,o);return dn(r,a,t.klineUrl,s)},async getMinuteKline(r,o,s={}){let a=await i(r,o);return mn(r,a,t.klineUrl,t.trendsUrl,s)}}}var Rr={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Ye,spotUrl:Ze,consUrl:Je,klineUrl:et,trendsUrl:tt,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},se=ve(Rr);async function fn(t){return se.getList(t)}async function gn(t,e){return se.getSpot(t,e)}async function hn(t,e){return se.getConstituents(t,e)}async function yn(t,e,n={}){return se.getKline(t,e,n)}async function Rn(t,e,n={}){return se.getMinuteKline(t,e,n)}var Cr={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:nt,spotUrl:rt,consUrl:ot,klineUrl:it,trendsUrl:st,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},ae=ve(Cr);async function Cn(t){return ae.getList(t)}async function Sn(t,e){return ae.getSpot(t,e)}async function On(t,e){return ae.getConstituents(t,e)}async function Tn(t,e,n={}){return ae.getKline(t,e,n)}async function En(t,e,n={}){return ae.getMinuteKline(t,e,n)}function q(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function Sr(t){return{code:t.SECURITY_CODE??"",name:t.SECURITY_NAME_ABBR??"",reportDate:q(t.REPORT_DATE),planNoticeDate:q(t.PLAN_NOTICE_DATE),disclosureDate:q(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:q(t.EQUITY_RECORD_DATE),exDividendDate:q(t.EX_DIVIDEND_DATE),payDate:q(t.PAY_DATE),assignProgress:t.ASSIGN_PROGRESS??null,noticeDate:q(t.NOTICE_DATE)}}async function _n(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=`${F}?${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(Sr);i.push(...c),r++}while(r<=o);return i}function Ut(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 bn(t){return $[t]??$[t.toLowerCase()]??$[t.toUpperCase()]}function Dt(t){let e=bn(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=bn(t.slice(0,-1))),!e){let i=Object.keys($).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${i}`)}let n=lt[e];if(n===void 0)throw new RangeError(`No market code found for exchange: ${e}`);return n}function Or(t){let e=x(t),n=t.split(",");return{...e,openInterest:n.length>12?R(n[12]):null}}async function Pn(t,e,n={}){let{period:i="daily",startDate:r="19700101",endDate:o="20500101"}=n;I(i);let s=Ut(e),l=`${Dt(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,X,u);return c.length===0?[]:c.map(g=>({...Or(g),code:d||e,name:m||""}))}async function An(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:Y,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),a=`${at}?${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(Tr);i.push(...u),r++}while(i.length<o);return i}function Tr(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 Er(t){let e=x(t),n=t.split(",");return{...e,openInterest:n.length>12?R(n[12]):null}}function _r(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 In(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=_r(e);if(s=Pe[d],s===void 0){let g=Object.keys(Pe).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,X,l);return u.length===0?[]:u.map(d=>({...Er(d),code:m||e,name:c||""}))}async function Mn(t,e={}){let{pageSize:n=2e4}=e,i=new URLSearchParams({orderBy:"zdf",sort:"desc",pageSize:String(n),pageIndex:"0",token:Y,field:"dm,sc,name,p,zsjd,zde,zdf,f152,vol,cje,ccl,xqj,syr,rz,zjsj,o"}),r=`${mt}?${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 xn(t,e,n){let i=new URLSearchParams({type:"RPT_IF_BILLBOARD_TD",sty:"ALL",p:"1",ps:"200",source:"IFBILLBOARD",client:"WEB",ut:gt,filter:`(SECURITY_CODE="${e}")(TRADE_DATE='${n}')`}),r=`${ft}?${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 br={gold:"EMI00069026",silver:"EMI00069027"};async function Ln(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=`${F}?${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 Kn(t){if(!t)return"";let e=String(t),n=e.match(/^(\d{4}-\d{2}-\d{2})/);return n?n[1]:e}async function Un(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=`${F}?${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:Kn(y.TRADE_DATE),inventory:p(y.ON_WARRANT_NUM),change:p(y.ADDCHANGE)}));s.push(...g),a++}while(a<=l);return s}async function Dn(t,e,n={}){let i=br[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=`${F}?${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:Kn(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={};_e(A,{getCommodityOptionKline:()=>Qn,getCommodityOptionSpot:()=>jn,getETFOption5DayMinute:()=>qn,getETFOptionDailyKline:()=>Hn,getETFOptionExpireDay:()=>Fn,getETFOptionMinute:()=>wn,getETFOptionMonths:()=>Bn,getIndexOptionKline:()=>Nn,getIndexOptionSpot:()=>kn});function Pr(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 Ar(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 kn(t,e){let n=`${Z}?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(Pr),puts:o.map(Ar)}}async function Nn(t){let e=`${J}?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 Bn(t){let e=`${ut}?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 Fn(t,e){let n=`${Ae}?exchange=null&cate=${encodeURIComponent(t)}&date=${e}`,i=await P(n),r=i?.result?.data?.remainderDays;if(typeof r=="number"&&r<0){let s=`${Ae}?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 vn(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 wn(t){let e=`CON_OP_${t}`,n=`${ct}?symbol=${e}`,r=(await P(n))?.result?.data;return Array.isArray(r)?vn(r):[]}async function Hn(t){let e=`CON_OP_${t}`,n=`${pt}?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 qn(t){let e=`CON_OP_${t}`,n=`${dt}?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(...vn(s));return o}function Ir(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 Mr(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 jn(t,e){let n=Ie[t];if(!n)throw new RangeError(`Unknown commodity option variety: "${t}". Available: ${Object.keys(Ie).join(", ")}`);let i=`${Z}?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(Ir),puts:s.map(Mr)}}async function Qn(t){let e=`${J}?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 le(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function B(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?le(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?le(r):null);continue}let a=t[s];a===null?n.push(r!==null?le(r):null):(r=i*a+(1-i)*r,n.push(le(r)))}return n}function we(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?le(s/r):null)}return n}function ue(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:i="sma"}=e,r=i==="ema"?U:i==="wma"?we:B,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 $n(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ce(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?$n(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?$n((a[c]-l[c])*2):null}))}function kt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function xr(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 pe(t,e={}){let{period:n=20,stdDev:i=2}=e,r=B(t,n),o=xr(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?kt((l-u)/r[a]*100):null;return{mid:r[a],upper:kt(l),lower:kt(u),bandwidth:c}})}function Nt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function de(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:Nt(s),d:Nt(a),j:Nt(y)})}return o}function Lr(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=[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(Lr(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 Kr(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function fe(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(Kr(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 Ur(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ge(t,e={}){let{periods:n=[6,12,24]}=e,i={};for(let r of n){let o=B(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(Ur(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 Dr(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function he(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:Dr(m)})}}return i}function Bt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function j(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?Bt(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?Bt(r[s]):null,atr:o!==null?Bt(o):null})}return i}function ye(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 Re(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 Ce(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,Q=O.low-C.low;D>Q&&D>0?o.push(D):o.push(0),Q>D&&Q>0?s.push(Q):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 Se(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 Oe(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=j(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 Te(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?ue(n,typeof e.ma=="object"?e.ma:{}):null,o=e.macd?ce(n,typeof e.macd=="object"?e.macd:{}):null,s=e.boll?pe(n,typeof e.boll=="object"?e.boll:{}):null,a=e.kdj?de(i,typeof e.kdj=="object"?e.kdj:{}):null,l=e.rsi?me(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?fe(i,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?ge(n,typeof e.bias=="object"?e.bias:{}):null,m=e.cci?he(i,typeof e.cci=="object"?e.cci:{}):null,d=e.atr?j(i,typeof e.atr=="object"?e.atr:{}):null,g=e.obv?ye(i,typeof e.obv=="object"?e.obv:{}):null,y=e.roc?Re(i,typeof e.roc=="object"?e.roc:{}):null,f=e.dmi?Ce(i,typeof e.dmi=="object"?e.dmi:{}):null,C=e.sar?Se(i,typeof e.sar=="object"?e.sar:{}):null,O=e.kc?Oe(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 Ee=class{constructor(e={}){this.client=new oe(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=Te(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}},Gn=Ee;0&&(module.exports={HttpError,StockSDK,addIndicators,asyncPool,calcATR,calcBIAS,calcBOLL,calcCCI,calcDMI,calcEMA,calcKC,calcKDJ,calcMA,calcMACD,calcOBV,calcROC,calcRSI,calcSAR,calcSMA,calcWMA,calcWR,chunkArray,decodeGBK,extractJsonFromJsonp,jsonpRequest,parseResponse,safeNumber,safeNumberOrNull});
1
+ "use strict";var ot=Object.defineProperty;var yn=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var Cn=Object.prototype.hasOwnProperty;var Be=(t,e)=>{for(var r in e)ot(t,r,{get:e[r],enumerable:!0})},On=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Sn(e))!Cn.call(t,n)&&n!==r&&ot(t,n,{get:()=>e[n],enumerable:!(o=yn(e,n))||o.enumerable});return t};var Rn=t=>On(ot({},"__esModule",{value:!0}),t);var mo={};Be(mo,{HttpError:()=>M,INDICATOR_REGISTRY:()=>V,SdkError:()=>P,StockSDK:()=>Ne,addIndicators:()=>Fe,asyncPool:()=>$,buildIndicatorContext:()=>ke,calcATR:()=>W,calcBIAS:()=>Pe,calcBOLL:()=>Te,calcCCI:()=>Ae,calcDMI:()=>Le,calcEMA:()=>D,calcKC:()=>Ke,calcKDJ:()=>Ie,calcMA:()=>Re,calcMACD:()=>Ee,calcOBV:()=>xe,calcROC:()=>Me,calcRSI:()=>be,calcSAR:()=>ve,calcSMA:()=>q,calcWMA:()=>rt,calcWR:()=>_e,chunkArray:()=>j,decodeGBK:()=>ee,default:()=>gn,estimateIndicatorLookback:()=>Ue,extractJsonFromJsonp:()=>Ye,getEnabledIndicatorKeys:()=>J,getSdkErrorCode:()=>B,jsonpRequest:()=>I,parseResponse:()=>te,safeNumber:()=>g,safeNumberOrNull:()=>O});module.exports=Rn(mo);function ee(t){return new TextDecoder("gbk").decode(t)}function te(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 it="https://qt.gtimg.cn",st="https://web.ifzq.gtimg.cn/appstock/app/minute/query",at="https://assets.linkdiary.cn/shares/zh_a_list.json",ut="https://assets.linkdiary.cn/shares/us_list.json",lt="https://assets.linkdiary.cn/shares/hk_list.json",ct="https://assets.linkdiary.cn/shares/fund_list",tr="https://assets.linkdiary.cn/shares/trade-data-list.txt";var we="https://push2his.eastmoney.com/api/qt/stock/kline/get",pt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",dt="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",mt="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",ft="https://17.push2.eastmoney.com/api/qt/clist/get",gt="https://91.push2.eastmoney.com/api/qt/stock/get",ht="https://29.push2.eastmoney.com/api/qt/clist/get",yt="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",St="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Ct="https://79.push2.eastmoney.com/api/qt/clist/get",Ot="https://91.push2.eastmoney.com/api/qt/stock/get",Rt="https://29.push2.eastmoney.com/api/qt/clist/get",Et="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Tt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Q="https://datacenter-web.eastmoney.com/api/data/v1/get",re="https://push2his.eastmoney.com/api/qt/stock/kline/get",It="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",ne="58b2fa8f54638b60b87d69b31969089c",bt={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},X={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"},He={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},oe="https://stock.finance.sina.com.cn/futures/api/openapi.php/OptionService.getOptionData",ie="https://stock.finance.sina.com.cn/futures/api/jsonp.php/{callback}/FutureOptionAllService.getOptionDayline",_t="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName",qe="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay",Pt="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline",At="https://stock.finance.sina.com.cn/futures/api/jsonp_v2.php/{callback}/StockOptionDaylineService.getSymbolInfo",xt="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getFiveDayLine",Mt="https://futsseapi.eastmoney.com/list/option/221",Lt="https://datacenter-web.eastmoney.com/api/data/get",vt="b2884a393a59ad64002292a3e90d46a5";var Qe={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"}},Kt=3e4,se=500,ae=500,ue=7,kt=3,Ut=1e3,Ft=3e4,Dt=2,Nt=[408,429,500,502,503,504];var je=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 rr=["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"],Bt=0;function En(){return typeof window<"u"&&typeof window.document<"u"}function nr(){if(En())return;let t=rr[Bt];return Bt=(Bt+1)%rr.length,t}var P=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)}},M=class extends P{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 ce=class extends P{constructor(e,r,o){super({code:"NOT_FOUND",message:e,provider:r,url:o}),this.name="NotFoundError"}};function le(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 Tn(t,e){return le(t,{provider:e.provider,url:e.url})}function B(t){if(t instanceof P||t instanceof M)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 $e(t,e={}){return t instanceof P?Tn(t,e):t instanceof DOMException&&t.name==="AbortError"?le(t,{sdkCode:"TIMEOUT",provider:e.provider,url:e.url,details:e.timeout?{timeout:e.timeout}:void 0}):t instanceof TypeError?le(t,{sdkCode:"NETWORK_ERROR",provider:e.provider,url:e.url}):t instanceof Error?le(t,{sdkCode:"NETWORK_ERROR",provider:e.provider,url:e.url}):new P({code:"NETWORK_ERROR",message:"Unknown request error",provider:e.provider,url:e.url,cause:t})}var Z=class extends P{constructor(e="Circuit breaker is OPEN"){super({code:"CIRCUIT_OPEN",message:e}),this.name="CircuitBreakerError"}},Ge=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 Z;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 In=3e4,bn=1,or=["push2his.eastmoney.com","7.push2his.eastmoney.com","33.push2his.eastmoney.com","63.push2his.eastmoney.com","91.push2his.eastmoney.com"],ir=["17.push2.eastmoney.com","29.push2.eastmoney.com","79.push2.eastmoney.com","91.push2.eastmoney.com"];function _n(t,e){return e!=="eastmoney"?[t]:t.includes("push2his.eastmoney.com")?or:t.includes("push2.eastmoney.com")?ir:[t]}function Pn(t){return Array.from(new Set(t))}var ze=class{constructor(e=In,r=bn){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=_n(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 Pn([...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=B(r),n.failureCount>=this.failureThreshold&&(n.cooldownUntil=Date.now()+this.cooldownMs)}shouldFallback(e){let r=B(e);return r==="NETWORK_ERROR"||r==="TIMEOUT"?!0:e instanceof M?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([...or,...ir]);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 An(t){return{maxRetries:t?.maxRetries??kt,baseDelay:t?.baseDelay??Ut,maxDelay:t?.maxDelay??Ft,backoffMultiplier:t?.backoffMultiplier??Dt,retryableStatusCodes:t?.retryableStatusCodes??Nt,retryOnNetworkError:t?.retryOnNetworkError??!0,retryOnTimeout:t?.retryOnTimeout??!0,onRetry:t?.onRetry}}function xn(t,e){let r={...t??{}};return e&&(Object.keys(r).some(n=>n.toLowerCase()==="user-agent")||(r["User-Agent"]=e)),r}function sr(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 wt(t={}){return{timeout:t.timeout??Kt,retry:An(t.retry),headers:xn(t.headers,t.userAgent),rotateUserAgent:t.rotateUserAgent??!1,rateLimit:t.rateLimit?{...t.rateLimit}:void 0,circuitBreaker:t.circuitBreaker?{...t.circuitBreaker}:void 0}}function ar(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 pe=class{constructor(e={}){this.baseUrl=e.baseUrl??it;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=wt(r),this.providerPolicies={},this.runtimeStates=new Map,this.fallbackManager=new ze;for(let[o,n]of Object.entries(e.providerPolicies??{})){let i=sr(r,n);this.providerPolicies[o]=wt(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 je(o.rateLimit):null,circuitBreaker:o.circuitBreaker?new Ge(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=B(e);return n==="TIMEOUT"?o.retryOnTimeout:n==="NETWORK_ERROR"?o.retryOnNetworkError:e instanceof M?o.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,r,o,n=0){try{return await e()}catch(i){let s=$e(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=nr();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 M(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=ar(e,r.provider),n=this.getProviderState(o);if(n.circuitBreaker&&!n.circuitBreaker.canRequest())throw new Z("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=$e(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 Z("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=ee(o);return te(n)}};var Mn=new Set(["daily","weekly","monthly"]),Ln=new Set(["1","5","15","30","60"]),vn=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 L(t){if(!Mn.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function de(t){if(!Ln.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function w(t){if(!vn.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function j(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 $(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 We(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function v(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function H(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var Ve=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}},ur=new Map;function G(t,e){let r=ur.get(t);if(r)return r;let o=new Ve(e);return ur.set(t,o),o}var Kn=typeof document<"u"&&typeof window<"u",kn=0;function lr(){return`__stock_sdk_jsonp_${Date.now()}_${kn++}`}function Ye(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 Un(t,e){let{timeout:r=15e3,callbackParam:o="callback",callbackMode:n="query"}=e;return new Promise((i,s)=>{let a=lr(),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 Fn(t,e){let{timeout:r=15e3,callbackParam:o="callback",callbackMode:n="query"}=e,i=lr(),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 Ye(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 Kn?Un(t,e):Fn(t,e)}var T={};Be(T,{getAShareCodeList:()=>hr,getAllHKQuotesByCodes:()=>Or,getAllQuotesByCodes:()=>Cr,getAllUSQuotesByCodes:()=>Rr,getFullQuotes:()=>Xe,getFundCodeList:()=>Er,getFundFlow:()=>pr,getFundQuotes:()=>mr,getHKCodeList:()=>Sr,getHKQuotes:()=>Ze,getPanelLargeOrder:()=>dr,getSimpleQuotes:()=>cr,getTodayTimeline:()=>fr,getTradingCalendar:()=>Tr,getUSCodeList:()=>yr,getUSQuotes:()=>Je,parseFullQuote:()=>Ht,parseFundFlow:()=>Qt,parseFundQuote:()=>zt,parseHKQuote:()=>$t,parsePanelLargeOrder:()=>jt,parseSimpleQuote:()=>qt,parseUSQuote:()=>Gt,search:()=>br});function Ht(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 qt(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 Qt(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 jt(t){return{buyLargeRatio:g(t[0]),buySmallRatio:g(t[1]),sellLargeRatio:g(t[2]),sellSmallRatio:g(t[3]),raw:t}}function $t(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 Gt(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 zt(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 Xe(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=>Ht(o.fields))}async function cr(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=>qt(n.fields))}async function pr(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=>Qt(n.fields))}async function dr(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=>jt(n.fields))}async function Ze(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=>$t(n.fields))}async function Je(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=>Gt(n.fields))}async function mr(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=>zt(n.fields))}async function fr(t,e){let r=t.getTimeout(),o=new AbortController,n=setTimeout(()=>o.abort(),r);try{let i=await fetch(`${st}?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,N=d?b*100:b,U=N>0?_/N:0;return{time:E,price:parseFloat(f[1])||0,volume:N,amount:_,avgPrice:Math.round(U*100)/100}});return{code:e,date:l,preClose:m,data:h}}finally{clearTimeout(n)}}var gr=G("tencent:code-lists",{defaultTTL:360*60*1e3,maxSize:16});async function Wt(t,e,r){return gr.getOrFetch(e,async()=>(await t.get(r,{responseType:"json"}))?.list||[])}function Dn(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 hr(t,e){let r=!1,o;typeof e=="boolean"?r=!e:e&&(r=e.simple??!1,o=e.market);let i=await Wt(t,"a-share:full",at);return o&&(i=i.filter(s=>Dn(s,o))),r?i.map(s=>s.replace(/^(sh|sz|bj)/,"")):i.slice()}var Nn={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function yr(t,e){let r=!1,o;typeof e=="boolean"?r=!e:e&&(r=e.simple??!1,o=e.market);let i=(await Wt(t,"us:full",ut)).slice();if(o){let s=Nn[o];i=i.filter(a=>a.startsWith(s))}return r?i.map(s=>s.replace(/^\d{3}\./,"")):i}async function Sr(t){return(await Wt(t,"hk:full",lt)).slice()}async function Cr(t,e,r={}){let{batchSize:o=se,concurrency:n=ue,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,ae),a=j(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await Xe(t,d);return l++,i&&i(l,u),h});return(await $(c,n,!0)).flat()}async function Or(t,e,r={}){let{batchSize:o=se,concurrency:n=ue,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,ae),a=j(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await Ze(t,d);return l++,i&&i(l,u),h});return(await $(c,n,!0)).flat()}async function Rr(t,e,r={}){let{batchSize:o=se,concurrency:n=ue,onProgress:i}=r;F(o,"batchSize"),F(n,"concurrency");let s=Math.min(o,ae),a=j(e,s),u=a.length,l=0,c=a.map(d=>async()=>{let h=await Je(t,d);return l++,i&&i(l,u),h});return(await $(c,n,!0)).flat()}async function Er(t){return(await gr.getOrFetch("fund:full",async()=>(await t.get(ct,{responseType:"text"})).split(",").slice(1).filter(n=>n.trim()))).slice()}var Bn=G("tencent:trade-calendar",{defaultTTL:720*60*1e3,maxSize:4});async function Tr(t){return(await Bn.getOrFetch("a-share",async()=>{let r=await t.get(tr);return!r||r.trim()===""?[]:r.trim().split(",").map(o=>o.trim()).filter(o=>o.length>0)})).slice()}var Ir="https://smartbox.gtimg.cn/s3/";function wn(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,r)=>String.fromCharCode(parseInt(r,16)))}function Hn(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 qn(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(r=>{let o=r.split("~"),n=o[0]||"",i=o[1]||"",s=wn(o[2]||""),a=o[4]||"";return{code:n+i,name:s,market:n,type:a,category:Hn(a)}})}function Qn(t){return new Promise((e,r)=>{let o=`${Ir}?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 jn(t,e){let r=`${Ir}?v=2&t=all&q=${encodeURIComponent(e)}`,n=(await t.get(r)).match(/v_hint="([^"]*)"/);return n?n[1]:""}function $n(){return typeof window<"u"&&typeof document<"u"}async function br(t,e){if(!e||!e.trim())return[];let r;return $n()?r=await Qn(e):r=await jn(t,e),qn(r)}var R={};Be(R,{extractVariety:()=>Yt,getCFFEXOptionQuotes:()=>Xr,getComexInventory:()=>rn,getConceptConstituents:()=>Qr,getConceptKline:()=>jr,getConceptList:()=>Hr,getConceptMinuteKline:()=>$r,getConceptSpot:()=>qr,getDividendDetail:()=>Gr,getFuturesHistoryKline:()=>Wr,getFuturesInventory:()=>tn,getFuturesInventorySymbols:()=>Jr,getFuturesMarketCode:()=>Xt,getGlobalFuturesKline:()=>Yr,getGlobalFuturesSpot:()=>Vr,getHKHistoryKline:()=>Ar,getHistoryKline:()=>_r,getIndustryConstituents:()=>Nr,getIndustryKline:()=>Br,getIndustryList:()=>Fr,getIndustryMinuteKline:()=>wr,getIndustrySpot:()=>Dr,getMinuteKline:()=>Pr,getOptionLHB:()=>Zr,getUSHistoryKline:()=>xr});async function Vt(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 K(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 _r(t,e,r={}){let{period:o="daily",adjust:n="qfq",startDate:i="19700101",endDate:s="20500101"}=r;L(o),w(n);let a=e.replace(/^(sh|sz|bj)/,""),u=`${We(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:v(o),fqt:H(n),secid:u,beg:i,end:s}),c=we,{klines:m}=await k(t,c,l);return m.length===0?[]:m.map(d=>({...K(d),code:a}))}async function Pr(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;de(o),w(n);let a=e.replace(/^(sh|sz|bj)/,""),u=`${We(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=`${pt}?${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,_,N,U,Y,hn]=f.split(",");return{time:C,open:S(E),close:S(b),high:S(_),low:S(N),volume:S(U),amount:S(Y),avgPrice:S(hn)}}).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:H(n||""),secid:u,beg:"0",end:"20500000"}),c=we,{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=K(y);return{...f,time:f.date}}).filter(y=>y.time>=d&&y.time<=h)}}function et(t){return async function(r,o,n={}){let{period:i="daily",adjust:s="qfq",startDate:a="19700101",endDate:u="20500101"}=n;L(i),w(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:v(i),fqt:H(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=>({...K(f),code:y.code,name:y.name}))}}var Gn=et({url:dt,normalizeSymbol:t=>{let e=t.replace(/^hk/i,"").padStart(5,"0");return{secid:`116.${e}`,fallbackCode:e}}});async function Ar(t,e,r={}){return Gn(t,e,r)}var zn=et({url:mt,normalizeSymbol:t=>({secid:t,fallbackCode:t.split(".")[1]||t}),resolveResultMeta:(t,e,r)=>({code:r.code||e.fallbackCode,name:r.name||""})});async function xr(t,e,r={}){return zn(t,e,r)}function Mr(t){let e=G(`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 ce(`${t.errorPrefix}: ${o}`,"eastmoney");return s}}}async function Lr(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 Vt(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 vr(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 Kr(t,e,r){let o={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return Vt(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;L(n),w(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:v(n),fqt:H(i),beg:s,end:a,smplmt:"10000",lmt:"1000000"}),{klines:l}=await k(t,r,u);return l.length===0?[]:l.map(c=>K(c))}async function Ur(t,e,r,o,n={}){let{period:i="5"}=n;if(de(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,_,N,U]=c.split(",");return{time:m,open:S(d),close:S(h),high:S(y),low:S(f),changePercent:S(_),change:S(N),volume:S(C),amount:S(E),amplitude:S(b),turnoverRate:S(U)}})}}function tt(t){let e=Mr(t);async function r(n){return Lr(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 vr(n,s,t.spotUrl)},async getConstituents(n,i){let s=await o(n,i);return Kr(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 Ur(n,a,t.klineUrl,t.trendsUrl,s)}}}var Wn={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:ft,spotUrl:gt,consUrl:ht,klineUrl:yt,trendsUrl:St,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},me=tt(Wn);async function Fr(t){return me.getList(t)}async function Dr(t,e){return me.getSpot(t,e)}async function Nr(t,e){return me.getConstituents(t,e)}async function Br(t,e,r={}){return me.getKline(t,e,r)}async function wr(t,e,r={}){return me.getMinuteKline(t,e,r)}var Vn={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:Ct,spotUrl:Ot,consUrl:Rt,klineUrl:Et,trendsUrl:Tt,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},fe=tt(Vn);async function Hr(t){return fe.getList(t)}async function qr(t,e){return fe.getSpot(t,e)}async function Qr(t,e){return fe.getConstituents(t,e)}async function jr(t,e,r={}){return fe.getKline(t,e,r)}async function $r(t,e,r={}){return fe.getMinuteKline(t,e,r)}function z(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function Yn(t){return{code:t.SECURITY_CODE??"",name:t.SECURITY_NAME_ABBR??"",reportDate:z(t.REPORT_DATE),planNoticeDate:z(t.PLAN_NOTICE_DATE),disclosureDate:z(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:z(t.EQUITY_RECORD_DATE),exDividendDate:z(t.EX_DIVIDEND_DATE),payDate:z(t.PAY_DATE),assignProgress:t.ASSIGN_PROGRESS??null,noticeDate:z(t.NOTICE_DATE)}}async function Gr(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=`${Q}?${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(Yn);o.push(...c),n++}while(n<=i);return o}function Yt(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 zr(t){return X[t]??X[t.toLowerCase()]??X[t.toUpperCase()]}function Xt(t){let e=zr(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=zr(t.slice(0,-1))),!e){let o=Object.keys(X).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${o}`)}let r=bt[e];if(r===void 0)throw new RangeError(`No market code found for exchange: ${e}`);return r}function Xn(t){let e=K(t),r=t.split(",");return{...e,openInterest:r.length>12?S(r[12]):null}}async function Wr(t,e,r={}){let{period:o="daily",startDate:n="19700101",endDate:i="20500101"}=r;L(o);let s=Yt(e),u=`${Xt(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:v(o),fqt:"0",secid:u,beg:n,end:i}),{klines:c,name:m,code:d}=await k(t,re,l);return c.length===0?[]:c.map(h=>({...Xn(h),code:d||e,name:m||""}))}async function Vr(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:ne,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),a=`${It}?${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(Zn);o.push(...l),n++}while(o.length<i);return o}function Zn(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 Jn(t){let e=K(t),r=t.split(",");return{...e,openInterest:r.length>12?S(r[12]):null}}function eo(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 Yr(t,e,r={}){let{period:o="daily",startDate:n="19700101",endDate:i="20500101"}=r;L(o);let s=r.marketCode;if(s===void 0){let d=eo(e);if(s=He[d],s===void 0){let h=Object.keys(He).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:v(o),fqt:"0",secid:a,beg:n,end:i}),{klines:l,name:c,code:m}=await k(t,re,u);return l.length===0?[]:l.map(d=>({...Jn(d),code:m||e,name:c||""}))}async function Xr(t,e={}){let{pageSize:r=2e4}=e,o=new URLSearchParams({orderBy:"zdf",sort:"desc",pageSize:String(r),pageIndex:"0",token:ne,field:"dm,sc,name,p,zsjd,zde,zdf,f152,vol,cje,ccl,xqj,syr,rz,zjsj,o"}),n=`${Mt}?${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 to(t){return t.includes("\u51C0")?"net":t.includes("\u4E70")?"buy":t.includes("\u5356")?"sell":null}async function Zr(t,e,r){let o=new URLSearchParams({type:"RPT_IF_BILLBOARD_TD",sty:"ALL",p:"1",ps:"200",source:"IFBILLBOARD",client:"WEB",ut:vt,filter:`(SECURITY_CODE="${e}")(TRADE_DATE='${r}')`}),n=`${Lt}?${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:to(String(u.TRADE_TYPE??""))}))}var ro={gold:"EMI00069026",silver:"EMI00069027"};async function Jr(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=`${Q}?${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 en(t){if(!t)return"";let e=String(t),r=e.match(/^(\d{4}-\d{2}-\d{2})/);return r?r[1]:e}async function tn(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=`${Q}?${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:en(y.TRADE_DATE),inventory:p(y.ON_WARRANT_NUM),change:p(y.ADDCHANGE)}));s.push(...h),a++}while(a<=u);return s}async function rn(t,e,r={}){let o=ro[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=`${Q}?${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:en(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 A={};Be(A,{getCommodityOptionKline:()=>mn,getCommodityOptionSpot:()=>dn,getETFOption5DayMinute:()=>pn,getETFOptionDailyKline:()=>cn,getETFOptionExpireDay:()=>an,getETFOptionMinute:()=>ln,getETFOptionMonths:()=>sn,getIndexOptionKline:()=>on,getIndexOptionSpot:()=>nn});function no(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 oo(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 nn(t,e){let r=`${oe}?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(no),puts:i.map(oo)}}async function on(t){let e=`${ie}?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 sn(t){let e=`${_t}?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 an(t,e){let r=`${qe}?exchange=null&cate=${encodeURIComponent(t)}&date=${e}`,o=await I(r),n=o?.result?.data?.remainderDays;if(typeof n=="number"&&n<0){let s=`${qe}?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 un(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 ln(t){let e=`CON_OP_${t}`,r=`${Pt}?symbol=${e}`,n=(await I(r))?.result?.data;return Array.isArray(n)?un(n):[]}async function cn(t){let e=`CON_OP_${t}`,r=`${At}?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 pn(t){let e=`CON_OP_${t}`,r=`${xt}?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(...un(s));return i}function io(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 so(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 r=Qe[t];if(!r)throw new RangeError(`Unknown commodity option variety: "${t}". Available: ${Object.keys(Qe).join(", ")}`);let o=`${oe}?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(io),puts:s.map(so)}}async function mn(t){let e=`${ie}?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 x=class{constructor(e){this.client=e}};var ge=class extends x{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 he=class extends x{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 ye=class extends x{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 Se=class extends x{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 Ce=class extends x{constructor(e){super(e)}getIndexOptionSpot(e,r){return A.getIndexOptionSpot(e,r)}getIndexOptionKline(e){return A.getIndexOptionKline(e)}getCFFEXOptionQuotes(e){return R.getCFFEXOptionQuotes(this.client,e)}getETFOptionMonths(e){return A.getETFOptionMonths(e)}getETFOptionExpireDay(e,r){return A.getETFOptionExpireDay(e,r)}getETFOptionMinute(e){return A.getETFOptionMinute(e)}getETFOptionDailyKline(e){return A.getETFOptionDailyKline(e)}getETFOption5DayMinute(e){return A.getETFOption5DayMinute(e)}getCommodityOptionSpot(e,r){return A.getCommodityOptionSpot(e,r)}getCommodityOptionKline(e){return A.getCommodityOptionKline(e)}getOptionLHB(e,r){return R.getOptionLHB(this.client,e,r)}};function Oe(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function q(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?Oe(n/e):null)}return r}function D(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?Oe(n):null);continue}let a=t[s];a===null?r.push(n!==null?Oe(n):null):(n=o*a+(1-o)*n,r.push(Oe(n)))}return r}function rt(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?Oe(s/n):null)}return r}function Re(t,e={}){let{periods:r=[5,10,20,30,60,120,250],type:o="sma"}=e,n=o==="ema"?D:o==="wma"?rt:q,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 fn(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Ee(t,e={}){let{short:r=12,long:o=26,signal:n=9}=e,i=D(t,r),s=D(t,o),a=t.map((l,c)=>i[c]===null||s[c]===null?null:i[c]-s[c]),u=D(a,n);return t.map((l,c)=>({dif:a[c]!==null?fn(a[c]):null,dea:u[c],macd:a[c]!==null&&u[c]!==null?fn((a[c]-u[c])*2):null}))}function Zt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function ao(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 Te(t,e={}){let{period:r=20,stdDev:o=2}=e,n=q(t,r),i=ao(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?Zt((u-l)/n[a]*100):null;return{mid:n[a],upper:Zt(u),lower:Zt(l),bandwidth:c}})}function Jt(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Ie(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:Jt(s),d:Jt(a),j:Jt(y)})}return i}function uo(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function be(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(uo(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 lo(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function _e(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(lo(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 co(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Pe(t,e={}){let{periods:r=[6,12,24]}=e,o={};for(let n of r){let i=q(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(co(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 po(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function Ae(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:po(m)})}}return o}function er(t,e=2){let r=Math.pow(10,e);return Math.round(t*r)/r}function W(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?er(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?er(n[s]):null,atr:i!==null?er(i):null})}return o}function xe(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 Me(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 Le(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),N=Math.abs(C.low-E.close);a.push(Math.max(b,_,N));let U=C.high-E.high,Y=E.low-C.low;U>Y&&U>0?i.push(U):i.push(0),Y>U&&Y>0?s.push(Y):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 ve(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 Ke(t,e={}){let{emaPeriod:r=20,atrPeriod:o=10,multiplier:n=2}=e,i=[],s=t.map(l=>l.close),a=D(s,r),u=W(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 nt(t,e=0){return t.length===0?e:Math.max(...t)}function ke(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 V={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:nt(r,20),emaBased:o==="ema"}},compute:(t,e)=>Re(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)=>Ee(t.closes,typeof e=="object"?e:{})},boll:{key:"boll",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:20}),compute:(t,e)=>Te(t.closes,typeof e=="object"?e:{})},kdj:{key:"kdj",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:9}),compute:(t,e)=>Ie(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:nt(e,14)+1}},compute:(t,e)=>be(t.closes,typeof e=="object"?e:{})},wr:{key:"wr",estimateLookback:t=>{let e=typeof t=="object"&&t.periods?t.periods:[6,10];return{bars:nt(e,10)}},compute:(t,e)=>_e(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:nt(e,12)}},compute:(t,e)=>Pe(t.closes,typeof e=="object"?e:{})},cci:{key:"cci",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:14}),compute:(t,e)=>Ae(t.ohlcv,typeof e=="object"?e:{})},atr:{key:"atr",estimateLookback:t=>({bars:typeof t=="object"&&t.period?t.period:14}),compute:(t,e)=>W(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)=>xe(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)=>Me(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)=>Le(t.ohlcv,typeof e=="object"?e:{})},sar:{key:"sar",estimateLookback:()=>({bars:5}),compute:(t,e)=>ve(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)=>Ke(t.ohlcv,typeof e=="object"?e:{})}};function J(t){return Object.keys(V).filter(e=>!!t[e])}function Ue(t){let e=0,r=!1;for(let n of J(t)){let s=V[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 Fe(t,e={}){if(t.length===0)return[];let r=ke(t),o=new Map;for(let n of J(e)){let i=V[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 De=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}=Ue(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=Fe(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 Ne=class{constructor(e={}){this.client=new pe(e),this.quoteService=new ge(this.client),this.boardService=new he(this.client),this.klineService=new ye(this.client),this.futuresService=new Se(this.client),this.optionsService=new Ce(this.client),this.indicatorService=new De(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)}},gn=Ne;0&&(module.exports={HttpError,INDICATOR_REGISTRY,SdkError,StockSDK,addIndicators,asyncPool,buildIndicatorContext,calcATR,calcBIAS,calcBOLL,calcCCI,calcDMI,calcEMA,calcKC,calcKDJ,calcMA,calcMACD,calcOBV,calcROC,calcRSI,calcSAR,calcSMA,calcWMA,calcWR,chunkArray,decodeGBK,estimateIndicatorLookback,extractJsonFromJsonp,getEnabledIndicatorKeys,getSdkErrorCode,jsonpRequest,parseResponse,safeNumber,safeNumberOrNull});