stock-sdk 1.7.0 → 1.8.0

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
@@ -56,6 +56,7 @@
56
56
  - ✅ **历史 K 线**(日/周/月)、**分钟 K 线**(1/5/15/30/60 分钟)和**当日分时走势**数据
57
57
  - ✅ **技术指标**:内置 MA、MACD、BOLL、KDJ、RSI、WR 等常用指标计算
58
58
  - ✅ **期货行情**:国内期货 K 线、全球期货实时行情与 K 线、期货库存数据
59
+ - ✅ **期权数据**:中金所股指期权、上交所 ETF 期权、商品期权的报价 / K 线 / 分钟行情
59
60
  - ✅ **资金流向**、**盘口大单**等扩展数据
60
61
  - ✅ 获取全部 **A 股代码列表**(5000+ 只股票)和批量获取**全市场行情**(内置并发控制)
61
62
 
@@ -173,6 +174,22 @@ console.log(`共获取 ${allQuotes.length} 只股票`);
173
174
  | `getFuturesInventory` | 期货库存数据 |
174
175
  | `getComexInventory` | COMEX 黄金/白银库存 |
175
176
 
177
+ ### 期权数据
178
+
179
+ | 方法 | 说明 |
180
+ |------|------|
181
+ | `getIndexOptionSpot` | 中金所股指期权 T 型报价(看涨 + 看跌) |
182
+ | `getIndexOptionKline` | 股指期权合约日 K 线 |
183
+ | `getCFFEXOptionQuotes` | 中金所全部期权实时行情列表 |
184
+ | `getETFOptionMonths` | 上交所 ETF 期权到期月份列表 |
185
+ | `getETFOptionExpireDay` | ETF 期权到期日与剩余天数 |
186
+ | `getETFOptionMinute` | ETF 期权当日分钟行情 |
187
+ | `getETFOptionDailyKline` | ETF 期权历史日 K 线 |
188
+ | `getETFOption5DayMinute` | ETF 期权 5 日分钟行情 |
189
+ | `getCommodityOptionSpot` | 商品期权 T 型报价 |
190
+ | `getCommodityOptionKline` | 商品期权合约日 K 线 |
191
+ | `getOptionLHB` | 期权龙虎榜 |
192
+
176
193
  ### 扩展数据
177
194
 
178
195
  | 方法 | 说明 |
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var Pe=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var bn=Object.getOwnPropertyNames;var Tn=Object.prototype.hasOwnProperty;var De=(t,e)=>{for(var n in e)Pe(t,n,{get:e[n],enumerable:!0})},On=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of bn(e))!Tn.call(t,s)&&s!==n&&Pe(t,s,{get:()=>e[s],enumerable:!(o=En(e,s))||o.enumerable});return t};var An=t=>On(Pe({},"__esModule",{value:!0}),t);var Zn={};De(Zn,{HttpError:()=>B,StockSDK:()=>me,addIndicators:()=>fe,asyncPool:()=>v,calcATR:()=>j,calcBIAS:()=>ce,calcBOLL:()=>ie,calcCCI:()=>pe,calcDMI:()=>xt,calcEMA:()=>K,calcKC:()=>Ut,calcKDJ:()=>le,calcMA:()=>se,calcMACD:()=>oe,calcOBV:()=>Mt,calcROC:()=>It,calcRSI:()=>ae,calcSAR:()=>Lt,calcSMA:()=>w,calcWMA:()=>Ke,calcWR:()=>ue,chunkArray:()=>F,decodeGBK:()=>z,default:()=>Rn,parseResponse:()=>V,safeNumber:()=>g,safeNumberOrNull:()=>R});module.exports=An(Zn);function z(t){return new TextDecoder("gbk").decode(t)}function V(t){let e=t.split(";").map(o=>o.trim()).filter(Boolean),n=[];for(let o of e){let s=o.indexOf("=");if(s<0)continue;let r=o.slice(0,s).trim();r.startsWith("v_")&&(r=r.slice(2));let i=o.slice(s+1).trim();i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1));let l=i.split("~");n.push({key:r,fields:l})}return n}function g(t){if(!t||t==="")return 0;let e=parseFloat(t);return Number.isNaN(e)?0:e}function R(t){if(!t||t==="")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function C(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function S(t){return t==null?null:C(String(t))}var we="https://qt.gtimg.cn",ke="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Be="https://assets.linkdiary.cn/shares/zh_a_list.json",Fe="https://assets.linkdiary.cn/shares/us_list.json",ve="https://assets.linkdiary.cn/shares/hk_list.json",Ne="https://assets.linkdiary.cn/shares/fund_list",Kt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var de="https://push2his.eastmoney.com/api/qt/stock/kline/get",He="https://push2his.eastmoney.com/api/qt/stock/trends2/get",qe="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",je="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Qe="https://17.push2.eastmoney.com/api/qt/clist/get",Ge="https://91.push2.eastmoney.com/api/qt/stock/get",$e="https://29.push2.eastmoney.com/api/qt/clist/get",We="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",ze="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Ve="https://79.push2.eastmoney.com/api/qt/clist/get",Xe="https://91.push2.eastmoney.com/api/qt/stock/get",Ye="https://29.push2.eastmoney.com/api/qt/clist/get",Ze="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Je="https://push2his.eastmoney.com/api/qt/stock/trends2/get",k="https://datacenter-web.eastmoney.com/api/data/v1/get",X="https://push2his.eastmoney.com/api/qt/stock/kline/get",et="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",tt="58b2fa8f54638b60b87d69b31969089c",nt={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},G={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},rt=3e4,Y=500,Z=500,J=7,st=3,ot=1e3,it=3e4,lt=2,at=[408,429,500,502,503,504];var ge=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(),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(n=>setTimeout(n,e))}getAvailableTokens(){return this.refill(),this.tokens}};var Pt=["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"],ut=0;function _n(){return typeof window<"u"&&typeof window.document<"u"}function Dt(){if(_n())return;let t=Pt[ut];return ut=(ut+1)%Pt.length,t}var ee=class extends Error{constructor(e="Circuit breaker is OPEN"){super(e),this.name="CircuitBreakerError"}},Ce=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 ee;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 B=class extends Error{constructor(n,o,s,r){let i=o?` ${o}`:"",l=s?`, url: ${s}`:"",a=r?`, provider: ${r}`:"";super(`HTTP error! status: ${n}${i}${l}${a}`);this.status=n;this.statusText=o;this.url=s;this.provider=r;this.name="HttpError"}},te=class{constructor(e={}){this.baseUrl=e.baseUrl??we,this.timeout=e.timeout??rt,this.retryOptions=this.resolveRetryOptions(e.retry),this.headers={...e.headers??{}},this.rotateUserAgent=e.rotateUserAgent??!1,this.rateLimiter=e.rateLimit?new ge(e.rateLimit):null,this.circuitBreaker=e.circuitBreaker?new Ce(e.circuitBreaker):null,e.userAgent&&(Object.keys(this.headers).some(o=>o.toLowerCase()==="user-agent")||(this.headers["User-Agent"]=e.userAgent))}resolveRetryOptions(e){return{maxRetries:e?.maxRetries??st,baseDelay:e?.baseDelay??ot,maxDelay:e?.maxDelay??it,backoffMultiplier:e?.backoffMultiplier??lt,retryableStatusCodes:e?.retryableStatusCodes??at,retryOnNetworkError:e?.retryOnNetworkError??!0,retryOnTimeout:e?.retryOnTimeout??!0,onRetry:e?.onRetry}}inferProvider(e){try{let n=new URL(e).hostname;if(n.includes("eastmoney.com"))return"eastmoney";if(n.includes("gtimg.cn"))return"tencent";if(n.includes("linkdiary.cn"))return"linkdiary"}catch{return}}getTimeout(){return this.timeout}calculateDelay(e){return Math.min(this.retryOptions.baseDelay*Math.pow(this.retryOptions.backoffMultiplier,e),this.retryOptions.maxDelay)+Math.random()*100}sleep(e){return new Promise(n=>setTimeout(n,e))}shouldRetry(e,n){return n>=this.retryOptions.maxRetries?!1:e instanceof DOMException&&e.name==="AbortError"?this.retryOptions.retryOnTimeout:e instanceof TypeError?this.retryOptions.retryOnNetworkError:e instanceof B?this.retryOptions.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,n=0){try{let o=await e();return this.circuitBreaker?.recordSuccess(),o}catch(o){if(this.shouldRetry(o,n)){let s=this.calculateDelay(n);return this.retryOptions.onRetry&&o instanceof Error&&this.retryOptions.onRetry(n+1,o,s),await this.sleep(s),this.executeWithRetry(e,n+1)}throw this.circuitBreaker?.recordFailure(),o}}async get(e,n={}){if(this.circuitBreaker&&!this.circuitBreaker.canRequest())throw new ee("Circuit breaker is OPEN, request rejected");return this.rateLimiter&&await this.rateLimiter.acquire(),this.executeWithRetry(async()=>{let o=new AbortController,s=setTimeout(()=>o.abort(),this.timeout),r=this.inferProvider(e),i={...this.headers};if(this.rotateUserAgent){let l=Dt();l&&(i["User-Agent"]=l)}try{let l=await fetch(e,{signal:o.signal,headers:i});if(!l.ok)throw new B(l.status,l.statusText,e,r);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=r),l}finally{clearTimeout(s)}})}async getTencentQuote(e){let n=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,o=await this.get(n,{responseType:"arraybuffer"}),s=z(o);return V(s)}};var Mn=new Set(["daily","weekly","monthly"]),In=new Set(["1","5","15","30","60"]),xn=new Set(["","qfq","hfq"]);function x(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function A(t){if(!Mn.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function ne(t){if(!In.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function L(t){if(!xn.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function F(t,e){x(e,"chunkSize");let n=[];for(let o=0;o<t.length;o+=e)n.push(t.slice(o,o+e));return n}async function v(t,e){x(e,"concurrency");let n=[],o=[];for(let s of t){let r=Promise.resolve().then(()=>s()).then(i=>{n.push(i)});if(o.push(r),o.length>=e){await Promise.race(o);for(let i=o.length-1;i>=0;i--)await Promise.race([o[i].then(()=>"fulfilled"),Promise.resolve("pending")])==="fulfilled"&&o.splice(i,1)}}return await Promise.all(o),n}function ye(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function _(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function U(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var T={};De(T,{getAShareCodeList:()=>Nt,getAllHKQuotesByCodes:()=>Qt,getAllQuotesByCodes:()=>jt,getAllUSQuotesByCodes:()=>Gt,getFullQuotes:()=>Re,getFundCodeList:()=>$t,getFundFlow:()=>kt,getFundQuotes:()=>Ft,getHKCodeList:()=>qt,getHKQuotes:()=>Se,getPanelLargeOrder:()=>Bt,getSimpleQuotes:()=>wt,getTodayTimeline:()=>vt,getTradingCalendar:()=>Wt,getUSCodeList:()=>Ht,getUSQuotes:()=>Ee,parseFullQuote:()=>ct,parseFundFlow:()=>ft,parseFundQuote:()=>gt,parseHKQuote:()=>dt,parsePanelLargeOrder:()=>mt,parseSimpleQuote:()=>pt,parseUSQuote:()=>ht,search:()=>Vt});function ct(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 n=[];for(let o=0;o<5;o++)n.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:n,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:R(t[38]),pe:R(t[39]),amplitude:R(t[43]),circulatingMarketCap:R(t[44]),totalMarketCap:R(t[45]),pb:R(t[46]),limitUp:R(t[47]),limitDown:R(t[48]),volumeRatio:R(t[49]),avgPrice:R(t[51]),peStatic:R(t[52]),peDynamic:R(t[53]),high52w:R(t[67]),low52w:R(t[68]),circulatingShares:R(t[72]),totalShares:R(t[73]),raw:t}}function pt(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:R(t[9]),marketType:t[10]??"",raw:t}}function ft(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 mt(t){return{buyLargeRatio:g(t[0]),buySmallRatio:g(t[1]),sellLargeRatio:g(t[2]),sellSmallRatio:g(t[3]),raw:t}}function dt(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:R(t[40]),circulatingMarketCap:R(t[44]),totalMarketCap:R(t[45]),currency:t[t.length-3]??"",raw:t}}function ht(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:R(t[38]),pe:R(t[39]),amplitude:R(t[43]),totalMarketCap:R(t[45]),pb:R(t[47]),high52w:R(t[48]),low52w:R(t[49]),raw:t}}function gt(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 Re(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=>ct(o.fields))}async function wt(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`s_${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>pt(s.fields))}async function kt(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`ff_${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>ft(s.fields))}async function Bt(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`s_pk${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>mt(s.fields))}async function Se(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`hk${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>dt(s.fields))}async function Ee(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`us${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>ht(s.fields))}async function Ft(t,e){if(!e||e.length===0)return[];let n=e.map(s=>`jj${s}`);return(await t.getTencentQuote(n.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>gt(s.fields))}async function vt(t,e){let n=t.getTimeout(),o=new AbortController,s=setTimeout(()=>o.abort(),n);try{let r=await fetch(`${ke}?code=${e}`,{signal:o.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);let i=await r.json();if(i.code!==0)throw new Error(i.msg||"API error");let l=i.data?.[e];if(!l)return{code:e,date:"",data:[]};let a=l.data?.data||[],u=l.data?.date||"",c=!1;if(a.length>0){let p=a[0].split(" "),d=parseFloat(p[1])||0,h=parseInt(p[2],10)||0,m=parseFloat(p[3])||0;h>0&&d>0&&m/h>d*50&&(c=!0)}let f=a.map(p=>{let d=p.split(" "),h=d[0],m=`${h.slice(0,2)}:${h.slice(2,4)}`,y=parseInt(d[2],10)||0,b=parseFloat(d[3])||0,O=c?y*100:y,P=O>0?b/O:0;return{time:m,price:parseFloat(d[1])||0,volume:O,amount:b,avgPrice:Math.round(P*100)/100}});return{code:e,date:u,data:f}}finally{clearTimeout(s)}}var Ct=null,Ln=null,be=null,Un=null,Te=null,yt=null;function Kn(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 Nt(t,e){let n=!1,o;if(typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,o=e.market),!Ct){let i=(await t.get(Be,{responseType:"json"}))?.list||[];Ct=i,Ln=i.map(l=>l.replace(/^(sh|sz|bj)/,""))}let s=Ct;return o&&(s=s.filter(r=>Kn(r,o))),n?s.map(r=>r.replace(/^(sh|sz|bj)/,"")):s.slice()}var Pn={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function Ht(t,e){let n=!1,o;typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,o=e.market),be||(be=(await t.get(Fe,{responseType:"json"}))?.list||[],Un=be.map(i=>i.replace(/^\d{3}\./,"")));let s=be.slice();if(o){let r=Pn[o];s=s.filter(i=>i.startsWith(r))}return n?s.map(r=>r.replace(/^\d{3}\./,"")):s}async function qt(t){return Te||(Te=(await t.get(ve,{responseType:"json"}))?.list||[]),Te.slice()}async function jt(t,e,n={}){let{batchSize:o=Y,concurrency:s=J,onProgress:r}=n;x(o,"batchSize"),x(s,"concurrency");let i=Math.min(o,Z),l=F(e,i),a=l.length,u=0,c=l.map(p=>async()=>{let d=await Re(t,p);return u++,r&&r(u,a),d});return(await v(c,s)).flat()}async function Qt(t,e,n={}){let{batchSize:o=Y,concurrency:s=J,onProgress:r}=n;x(o,"batchSize"),x(s,"concurrency");let i=Math.min(o,Z),l=F(e,i),a=l.length,u=0,c=l.map(p=>async()=>{let d=await Se(t,p);return u++,r&&r(u,a),d});return(await v(c,s)).flat()}async function Gt(t,e,n={}){let{batchSize:o=Y,concurrency:s=J,onProgress:r}=n;x(o,"batchSize"),x(s,"concurrency");let i=Math.min(o,Z),l=F(e,i),a=l.length,u=0,c=l.map(p=>async()=>{let d=await Ee(t,p);return u++,r&&r(u,a),d});return(await v(c,s)).flat()}async function $t(t){if(yt)return yt.slice();let o=(await t.get(Ne,{responseType:"text"})).split(",").slice(1).filter(s=>s.trim());return yt=o,o.slice()}var $=null;async function Wt(t){if($)return $.slice();let e=await t.get(Kt);return!e||e.trim()===""?($=[],$.slice()):($=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),$.slice())}var zt="https://smartbox.gtimg.cn/s3/";function Dn(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function wn(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let o=n.split("~"),s=o[0]||"",r=o[1]||"",i=Dn(o[2]||""),l=o[4]||"";return{code:s+r,name:i,market:s,type:l}})}function kn(t){return new Promise((e,n)=>{let o=`${zt}?v=2&t=all&q=${encodeURIComponent(t)}`;window.v_hint="";let s=document.createElement("script");s.src=o,s.charset="utf-8",s.onload=()=>{let r=window.v_hint||"";document.body.removeChild(s),e(r)},s.onerror=()=>{document.body.removeChild(s),n(new Error("Network error calling Smartbox"))},document.body.appendChild(s)})}async function Bn(t,e){let n=`${zt}?v=2&t=all&q=${encodeURIComponent(e)}`,s=(await t.get(n)).match(/v_hint="([^"]*)"/);return s?s[1]:""}function Fn(){return typeof window<"u"&&typeof document<"u"}async function Vt(t,e){if(!e||!e.trim())return[];let n;return Fn()?n=await kn(e):n=await Bn(t,e),wn(n)}var E={};De(E,{extractVariety:()=>bt,getComexInventory:()=>Cn,getConceptConstituents:()=>on,getConceptKline:()=>ln,getConceptList:()=>Et,getConceptMinuteKline:()=>an,getConceptSpot:()=>sn,getDividendDetail:()=>un,getFuturesHistoryKline:()=>pn,getFuturesInventory:()=>gn,getFuturesInventorySymbols:()=>dn,getFuturesMarketCode:()=>Tt,getGlobalFuturesKline:()=>mn,getGlobalFuturesSpot:()=>fn,getHKHistoryKline:()=>Zt,getHistoryKline:()=>Xt,getIndustryConstituents:()=>tn,getIndustryKline:()=>nn,getIndustryList:()=>St,getIndustryMinuteKline:()=>rn,getIndustrySpot:()=>en,getMinuteKline:()=>Yt,getUSHistoryKline:()=>Jt});async function Rt(t,e,n,o,s=100,r){let i=[],l=1,a=0;do{let u=new URLSearchParams({...n,pn:String(l),pz:String(s),fields:o}),c=`${e}?${u.toString()}`,p=(await t.get(c,{responseType:"json"}))?.data;if(!p||!Array.isArray(p.diff))break;l===1&&(a=p.total??0);let d=p.diff.map((h,m)=>r(h,i.length+m+1));i.push(...d),l++}while(i.length<a);return i}function M(t){let[e,n,o,s,r,i,l,a,u,c,f]=t.split(",");return{date:e,open:C(n),close:C(o),high:C(s),low:C(r),volume:C(i),amount:C(l),amplitude:C(a),changePercent:C(u),change:C(c),turnoverRate:C(f)}}async function I(t,e,n){let o=`${e}?${n.toString()}`,s=await t.get(o,{responseType:"json"});return{klines:s?.data?.klines||[],name:s?.data?.name,code:s?.data?.code}}async function Xt(t,e,n={}){let{period:o="daily",adjust:s="qfq",startDate:r="19700101",endDate:i="20500101"}=n;A(o),L(s);let l=e.replace(/^(sh|sz|bj)/,""),a=`${ye(e)}.${l}`,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:_(o),fqt:U(s),secid:a,beg:r,end:i}),c=de,{klines:f}=await I(t,c,u);return f.length===0?[]:f.map(p=>({...M(p),code:l}))}async function Yt(t,e,n={}){let{period:o="1",adjust:s="qfq",startDate:r="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=n;ne(o),L(s);let l=e.replace(/^(sh|sz|bj)/,""),a=`${ye(e)}.${l}`;if(o==="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:a}),c=`${He}?${u.toString()}`,p=(await t.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(p)||p.length===0)return[];let d=r.replace("T"," ").slice(0,16),h=i.replace("T"," ").slice(0,16);return p.map(m=>{let[y,b,O,P,W,D,Q,Sn]=m.split(",");return{time:y,open:C(b),close:C(O),high:C(P),low:C(W),volume:C(D),amount:C(Q),avgPrice:C(Sn)}}).filter(m=>m.time>=d&&m.time<=h)}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:o,fqt:U(s||""),secid:a,beg:"0",end:"20500000"}),c=de,{klines:f}=await I(t,c,u);if(f.length===0)return[];let p=r.replace("T"," ").slice(0,16),d=i.replace("T"," ").slice(0,16);return f.map(h=>{let m=M(h);return{...m,time:m.date}}).filter(h=>h.time>=p&&h.time<=d)}}async function Zt(t,e,n={}){let{period:o="daily",adjust:s="qfq",startDate:r="19700101",endDate:i="20500101"}=n;A(o),L(s);let l=e.replace(/^hk/i,"").padStart(5,"0"),a=`116.${l}`,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:_(o),fqt:U(s),secid:a,beg:r,end:i,lmt:"1000000"}),c=qe,{klines:f,name:p}=await I(t,c,u);return f.length===0?[]:f.map(d=>({...M(d),code:l,name:p||""}))}async function Jt(t,e,n={}){let{period:o="daily",adjust:s="qfq",startDate:r="19700101",endDate:i="20500101"}=n;A(o),L(s);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:U(s),secid:e,beg:r,end:i,lmt:"1000000"}),a=je,{klines:u,name:c,code:f}=await I(t,a,l),p=f||e.split(".")[1]||e,d=c||"";return u.length===0?[]:u.map(h=>({...M(h),code:p,name:d}))}function Oe(t){let e=null;return{async getCode(n,o,s){if(o.startsWith("BK"))return o;if(!e){let i=await s(n);e=new Map(i.map(l=>[l.name,l.code]))}let r=e.get(o);if(!r)throw new Error(`${t.errorPrefix}: ${o}`);return r}}}async function Ae(t,e){let n={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",s=await Rt(t,e.listUrl,n,o,100,(r,i)=>({rank:i,name:String(r.f14??""),code:String(r.f12??""),price:S(r.f2),change:S(r.f4),changePercent:S(r.f3),totalMarketCap:S(r.f20),turnoverRate:S(r.f8),riseCount:S(r.f104),fallCount:S(r.f105),leadingStock:r.f128?String(r.f128):null,leadingStockChangePercent:S(r.f136)}));return s.sort((r,i)=>(i.changePercent??0)-(r.changePercent??0)),s.forEach((r,i)=>{r.rank=i+1}),s}async function _e(t,e,n){let o=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${e}`}),s=`${n}?${o.toString()}`,i=(await t.get(s,{responseType:"json"}))?.data;return i?[{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:a,name:u,divide:c})=>{let f=i[a],p=null;return typeof f=="number"&&!isNaN(f)&&(p=c?f/100:f),{item:u,value:p}}):[]}async function Me(t,e,n){let o={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return Rt(t,n,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,(r,i)=>({rank:i,code:String(r.f12??""),name:String(r.f14??""),price:S(r.f2),changePercent:S(r.f3),change:S(r.f4),volume:S(r.f5),amount:S(r.f6),amplitude:S(r.f7),high:S(r.f15),low:S(r.f16),open:S(r.f17),prevClose:S(r.f18),turnoverRate:S(r.f8),pe:S(r.f9),pb:S(r.f23)}))}async function Ie(t,e,n,o={}){let{period:s="daily",adjust:r="",startDate:i="19700101",endDate:l="20500101"}=o;A(s),L(r);let a=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:_(s),fqt:U(r),beg:i,end:l,smplmt:"10000",lmt:"1000000"}),{klines:u}=await I(t,n,a);return u.length===0?[]:u.map(c=>M(c))}async function xe(t,e,n,o,s={}){let{period:r="5"}=s;if(ne(r),r==="1"){let i=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}`}),l=`${o}?${i.toString()}`,u=(await t.get(l,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[f,p,d,h,m,y,b,O]=c.split(",");return{time:f,open:C(p),close:C(d),high:C(h),low:C(m),volume:C(y),amount:C(b),price:C(O)}})}else{let i=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:r,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),l=`${n}?${i.toString()}`,u=(await t.get(l,{responseType:"json"}))?.data?.klines;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[f,p,d,h,m,y,b,O,P,W,D]=c.split(",");return{time:f,open:C(p),close:C(d),high:C(h),low:C(m),changePercent:C(P),change:C(W),volume:C(y),amount:C(b),amplitude:C(O),turnoverRate:C(D)}})}}var N={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Qe,spotUrl:Ge,consUrl:$e,klineUrl:We,trendsUrl:ze,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},vn=Oe(N);async function Le(t,e){return vn.getCode(t,e,St)}async function St(t){return Ae(t,N)}async function en(t,e){let n=await Le(t,e);return _e(t,n,N.spotUrl)}async function tn(t,e){let n=await Le(t,e);return Me(t,n,N.consUrl)}async function nn(t,e,n={}){let o=await Le(t,e);return Ie(t,o,N.klineUrl,n)}async function rn(t,e,n={}){let o=await Le(t,e);return xe(t,o,N.klineUrl,N.trendsUrl,n)}var H={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:Ve,spotUrl:Xe,consUrl:Ye,klineUrl:Ze,trendsUrl:Je,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},Nn=Oe(H);async function Ue(t,e){return Nn.getCode(t,e,Et)}async function Et(t){return Ae(t,H)}async function sn(t,e){let n=await Ue(t,e);return _e(t,n,H.spotUrl)}async function on(t,e){let n=await Ue(t,e);return Me(t,n,H.consUrl)}async function ln(t,e,n={}){let o=await Ue(t,e);return Ie(t,o,H.klineUrl,n)}async function an(t,e,n={}){let o=await Ue(t,e);return xe(t,o,H.klineUrl,H.trendsUrl,n)}function q(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function Hn(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 un(t,e){let n=e.replace(/^(sh|sz|bj)/,""),o=[],s=1,r=1;do{let i=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:"500",pageNumber:String(s),reportName:"RPT_SHAREBONUS_DET",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(SECURITY_CODE="${n}")`}),l=`${k}?${i.toString()}`,u=(await t.get(l,{responseType:"json"}))?.result;if(!u||!Array.isArray(u.data))break;s===1&&(r=u.pages??1);let c=u.data.map(Hn);o.push(...c),s++}while(s<=r);return o}function bt(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 cn(t){return G[t]??G[t.toLowerCase()]??G[t.toUpperCase()]}function Tt(t){let e=cn(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=cn(t.slice(0,-1))),!e){let o=Object.keys(G).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${o}`)}let n=nt[e];if(n===void 0)throw new RangeError(`No market code found for exchange: ${e}`);return n}function qn(t){let e=M(t),n=t.split(",");return{...e,openInterest:n.length>12?C(n[12]):null}}async function pn(t,e,n={}){let{period:o="daily",startDate:s="19700101",endDate:r="20500101"}=n;A(o);let i=bt(e),a=`${Tt(i)}.${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:_(o),fqt:"0",secid:a,beg:s,end:r}),{klines:c,name:f,code:p}=await I(t,X,u);return c.length===0?[]:c.map(d=>({...qn(d),code:p||e,name:f||""}))}async function fn(t,e={}){let n=e.pageSize??20,o=[],s=0,r=0;do{let i=new URLSearchParams({orderBy:"dm",sort:"desc",pageSize:String(n),pageIndex:String(s),token:tt,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),l=`${et}?${i.toString()}`,a=await t.get(l,{responseType:"json"});if(!a||!Array.isArray(a.list))break;s===0&&(r=a.total??0);let u=a.list.map(jn);o.push(...u),s++}while(o.length<r);return o}function jn(t){return{code:t.dm||"",name:t.name||"",price:C(String(t.p)),change:C(String(t.zde)),changePercent:C(String(t.zdf)),open:C(String(t.o)),high:C(String(t.h)),low:C(String(t.l)),prevSettle:C(String(t.zjsj)),volume:C(String(t.vol)),buyVolume:C(String(t.wp)),sellVolume:C(String(t.np)),openInterest:C(String(t.ccl))}}function Qn(t){let e=M(t),n=t.split(",");return{...e,openInterest:n.length>12?C(n[12]):null}}function Gn(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 mn(t,e,n={}){let{period:o="daily",startDate:s="19700101",endDate:r="20500101"}=n;A(o);let i=n.marketCode;if(i===void 0){let p=Gn(e);if(i=he[p],i===void 0){let d=Object.keys(he).join(", ");throw new RangeError(`Unknown global futures variety: "${p}". Supported: ${d}. Or specify marketCode manually via options.`)}}let l=`${i}.${e}`,a=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:_(o),fqt:"0",secid:l,beg:s,end:r}),{klines:u,name:c,code:f}=await I(t,X,a);return u.length===0?[]:u.map(p=>({...Qn(p),code:f||e,name:c||""}))}var $n={gold:"EMI00069026",silver:"EMI00069027"};async function dn(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=`${k}?${e.toString()}`,s=(await t.get(n,{responseType:"json"}))?.result?.data;return Array.isArray(s)?s.map(r=>({code:String(r.TRADE_CODE??""),name:String(r.TRADE_TYPE??""),marketCode:String(r.TRADE_MARKET_CODE??"")})):[]}function hn(t){if(!t)return"";let e=String(t),n=e.match(/^(\d{4}-\d{2}-\d{2})/);return n?n[1]:e}async function gn(t,e,n={}){let{startDate:o="2020-10-28",pageSize:s=500}=n,r=e.toUpperCase(),i=[],l=1,a=1;do{let u=new URLSearchParams({reportName:"RPT_FUTU_STOCKDATA",columns:"SECURITY_CODE,TRADE_DATE,ON_WARRANT_NUM,ADDCHANGE",filter:`(SECURITY_CODE="${r}")(TRADE_DATE>='${o}')`,pageNumber:String(l),pageSize:String(s),sortTypes:"-1",sortColumns:"TRADE_DATE",source:"WEB",client:"WEB"}),c=`${k}?${u.toString()}`,p=(await t.get(c,{responseType:"json"}))?.result;if(!p||!Array.isArray(p.data))break;l===1&&(a=p.pages??1);let d=p.data.map(h=>({code:String(h.SECURITY_CODE??e),date:hn(h.TRADE_DATE),inventory:S(h.ON_WARRANT_NUM),change:S(h.ADDCHANGE)}));i.push(...d),l++}while(l<=a);return i}async function Cn(t,e,n={}){let o=$n[e];if(!o)throw new RangeError(`Invalid COMEX symbol: "${e}". Must be "gold" or "silver".`);let{pageSize:s=500}=n,r=[],i=1,l=1,a={gold:"\u9EC4\u91D1",silver:"\u767D\u94F6"};do{let u=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:String(s),pageNumber:String(i),reportName:"RPT_FUTUOPT_GOLDSIL",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(INDICATOR_ID1="${o}")(@STORAGE_TON<>"NULL")`}),c=`${k}?${u.toString()}`,p=(await t.get(c,{responseType:"json"}))?.result;if(!p||!Array.isArray(p.data))break;i===1&&(l=p.pages??1);let d=p.data.map(h=>({date:hn(h.REPORT_DATE),name:a[e]??e,storageTon:S(h.STORAGE_TON),storageOunce:S(h.STORAGE_OUNCE)}));r.push(...d),i++}while(i<=l);return r}function re(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function w(t,e){let n=[];for(let o=0;o<t.length;o++){if(o<e-1){n.push(null);continue}let s=0,r=0;for(let i=o-e+1;i<=o;i++)t[i]!==null&&(s+=t[i],r++);n.push(r===e?re(s/e):null)}return n}function K(t,e){let n=[],o=2/(e+1),s=null,r=!1;for(let i=0;i<t.length;i++){if(i<e-1){n.push(null);continue}if(!r){let a=0,u=0;for(let c=i-e+1;c<=i;c++)t[c]!==null&&(a+=t[c],u++);u===e&&(s=a/e,r=!0),n.push(s!==null?re(s):null);continue}let l=t[i];l===null?n.push(s!==null?re(s):null):(s=o*l+(1-o)*s,n.push(re(s)))}return n}function Ke(t,e){let n=[],o=Array.from({length:e},(r,i)=>i+1),s=o.reduce((r,i)=>r+i,0);for(let r=0;r<t.length;r++){if(r<e-1){n.push(null);continue}let i=0,l=!0;for(let a=0;a<e;a++){let u=t[r-e+1+a];if(u===null){l=!1;break}i+=u*o[a]}n.push(l?re(i/s):null)}return n}function se(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:o="sma"}=e,s=o==="ema"?K:o==="wma"?Ke:w,r={};for(let i of n)r[`ma${i}`]=s(t,i);return t.map((i,l)=>{let a={};for(let u of n)a[`ma${u}`]=r[`ma${u}`][l];return a})}function yn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function oe(t,e={}){let{short:n=12,long:o=26,signal:s=9}=e,r=K(t,n),i=K(t,o),l=t.map((u,c)=>r[c]===null||i[c]===null?null:r[c]-i[c]),a=K(l,s);return t.map((u,c)=>({dif:l[c]!==null?yn(l[c]):null,dea:a[c],macd:l[c]!==null&&a[c]!==null?yn((l[c]-a[c])*2):null}))}function Ot(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Wn(t,e,n){let o=[];for(let s=0;s<t.length;s++){if(s<e-1||n[s]===null){o.push(null);continue}let r=0,i=0;for(let l=s-e+1;l<=s;l++)t[l]!==null&&n[s]!==null&&(r+=Math.pow(t[l]-n[s],2),i++);o.push(i===e?Math.sqrt(r/e):null)}return o}function ie(t,e={}){let{period:n=20,stdDev:o=2}=e,s=w(t,n),r=Wn(t,n,s);return t.map((i,l)=>{if(s[l]===null||r[l]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let a=s[l]+o*r[l],u=s[l]-o*r[l],c=s[l]!==0?Ot((a-u)/s[l]*100):null;return{mid:s[l],upper:Ot(a),lower:Ot(u),bandwidth:c}})}function At(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function le(t,e={}){let{period:n=9,kPeriod:o=3,dPeriod:s=3}=e,r=[],i=50,l=50;for(let a=0;a<t.length;a++){if(a<n-1){r.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,f=!0;for(let m=a-n+1;m<=a;m++){if(t[m].high===null||t[m].low===null){f=!1;break}u=Math.max(u,t[m].high),c=Math.min(c,t[m].low)}let p=t[a].close;if(!f||p===null||u===c){r.push({k:null,d:null,j:null});continue}let d=(p-c)/(u-c)*100;i=(o-1)/o*i+1/o*d,l=(s-1)/s*l+1/s*i;let h=3*i-2*l;r.push({k:At(i),d:At(l),j:At(h)})}return r}function zn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ae(t,e={}){let{periods:n=[6,12,24]}=e,o=[null];for(let r=1;r<t.length;r++)t[r]===null||t[r-1]===null?o.push(null):o.push(t[r]-t[r-1]);let s={};for(let r of n){let i=[],l=0,a=0;for(let u=0;u<t.length;u++){if(u<r){i.push(null),o[u]!==null&&(o[u]>0?l+=o[u]:a+=Math.abs(o[u]));continue}if(u===r)l=l/r,a=a/r;else{let c=o[u]??0,f=c>0?c:0,p=c<0?Math.abs(c):0;l=(l*(r-1)+f)/r,a=(a*(r-1)+p)/r}if(a===0)i.push(100);else if(l===0)i.push(0);else{let c=l/a;i.push(zn(100-100/(1+c)))}}s[`rsi${r}`]=i}return t.map((r,i)=>{let l={};for(let a of n)l[`rsi${a}`]=s[`rsi${a}`][i];return l})}function Vn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ue(t,e={}){let{periods:n=[6,10]}=e,o={};for(let s of n){let r=[];for(let i=0;i<t.length;i++){if(i<s-1){r.push(null);continue}let l=-1/0,a=1/0,u=!0;for(let p=i-s+1;p<=i;p++){if(t[p].high===null||t[p].low===null){u=!1;break}l=Math.max(l,t[p].high),a=Math.min(a,t[p].low)}let c=t[i].close;if(!u||c===null||l===a){r.push(null);continue}let f=(l-c)/(l-a)*100;r.push(Vn(f))}o[`wr${s}`]=r}return t.map((s,r)=>{let i={};for(let l of n)i[`wr${l}`]=o[`wr${l}`][r];return i})}function Xn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ce(t,e={}){let{periods:n=[6,12,24]}=e,o={};for(let s of n){let r=w(t,s),i=[];for(let l=0;l<t.length;l++)if(t[l]===null||r[l]===null||r[l]===0)i.push(null);else{let a=(t[l]-r[l])/r[l]*100;i.push(Xn(a))}o[`bias${s}`]=i}return t.map((s,r)=>{let i={};for(let l of n)i[`bias${l}`]=o[`bias${l}`][r];return i})}function Yn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function pe(t,e={}){let{period:n=14}=e,o=[],s=t.map(r=>r.high===null||r.low===null||r.close===null?null:(r.high+r.low+r.close)/3);for(let r=0;r<t.length;r++){if(r<n-1){o.push({cci:null});continue}let i=0,l=0;for(let f=r-n+1;f<=r;f++)s[f]!==null&&(i+=s[f],l++);if(l!==n||s[r]===null){o.push({cci:null});continue}let a=i/n,u=0;for(let f=r-n+1;f<=r;f++)u+=Math.abs(s[f]-a);let c=u/n;if(c===0)o.push({cci:0});else{let f=(s[r]-a)/(.015*c);o.push({cci:Yn(f)})}}return o}function _t(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function j(t,e={}){let{period:n=14}=e,o=[],s=[];for(let i=0;i<t.length;i++){let{high:l,low:a,close:u}=t[i];if(l===null||a===null||u===null){s.push(null);continue}if(i===0)s.push(l-a);else{let c=t[i-1].close;if(c===null)s.push(l-a);else{let f=l-a,p=Math.abs(l-c),d=Math.abs(a-c);s.push(Math.max(f,p,d))}}}let r=null;for(let i=0;i<t.length;i++){if(i<n-1){o.push({tr:s[i]!==null?_t(s[i]):null,atr:null});continue}if(i===n-1){let l=0,a=0;for(let u=0;u<n;u++)s[u]!==null&&(l+=s[u],a++);a===n&&(r=l/n)}else r!==null&&s[i]!==null&&(r=(r*(n-1)+s[i])/n);o.push({tr:s[i]!==null?_t(s[i]):null,atr:r!==null?_t(r):null})}return o}function Mt(t,e={}){let{maPeriod:n}=e,o=[];if(t.length===0)return o;let s=t[0].volume??0;o.push({obv:s,obvMa:null});for(let r=1;r<t.length;r++){let i=t[r],l=t[r-1];if(i.close===null||l.close===null||i.volume===null||i.volume===void 0){o.push({obv:null,obvMa:null});continue}i.close>l.close?s+=i.volume:i.close<l.close&&(s-=i.volume),o.push({obv:s,obvMa:null})}if(n&&n>0)for(let r=n-1;r<o.length;r++){let i=0,l=0;for(let a=r-n+1;a<=r;a++)o[a].obv!==null&&(i+=o[a].obv,l++);l===n&&(o[r].obvMa=i/n)}return o}function It(t,e={}){let{period:n=12,signalPeriod:o}=e,s=[];for(let r=0;r<t.length;r++){if(r<n){s.push({roc:null,signal:null});continue}let i=t[r].close,l=t[r-n].close;if(i===null||l===null||l===0){s.push({roc:null,signal:null});continue}let a=(i-l)/l*100;s.push({roc:a,signal:null})}if(o&&o>0)for(let r=n+o-1;r<s.length;r++){let i=0,l=0;for(let a=r-o+1;a<=r;a++)s[a].roc!==null&&(i+=s[a].roc,l++);l===o&&(s[r].signal=i/o)}return s}function xt(t,e={}){let{period:n=14,adxPeriod:o=n}=e,s=[];if(t.length<2)return t.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let r=[],i=[],l=[];for(let m=0;m<t.length;m++){if(m===0){r.push(0),i.push(0),l.push(0),s.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let y=t[m],b=t[m-1];if(y.high===null||y.low===null||y.close===null||b.high===null||b.low===null||b.close===null){r.push(0),i.push(0),l.push(0),s.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let O=y.high-y.low,P=Math.abs(y.high-b.close),W=Math.abs(y.low-b.close);l.push(Math.max(O,P,W));let D=y.high-b.high,Q=b.low-y.low;D>Q&&D>0?r.push(D):r.push(0),Q>D&&Q>0?i.push(Q):i.push(0),s.push({pdi:null,mdi:null,adx:null,adxr:null})}let a=0,u=0,c=0,f=[];for(let m=1;m<t.length;m++){if(m<n){a+=l[m],u+=r[m],c+=i[m],f.push(0);continue}m===n?(a=a,u=u,c=c):(a=a-a/n+l[m],u=u-u/n+r[m],c=c-c/n+i[m]);let y=a>0?u/a*100:0,b=a>0?c/a*100:0;s[m].pdi=y,s[m].mdi=b;let O=y+b,P=O>0?Math.abs(y-b)/O*100:0;f.push(P)}let p=0,d=0,h=0;for(let m=n;m<t.length;m++){if(m<n*2-1){p+=f[m-n+1]||0,d++;continue}if(m===n*2-1)p+=f[m-n+1]||0,h=p/o,s[m].adx=h;else{let y=f[m-n+1]||0;h=(h*(o-1)+y)/o,s[m].adx=h}}for(let m=n*2-1+o;m<t.length;m++){let y=s[m].adx,b=s[m-o]?.adx;y!==null&&b!==null&&(s[m].adxr=(y+b)/2)}return s}function Lt(t,e={}){let{afStart:n=.02,afIncrement:o=.02,afMax:s=.2}=e,r=[];if(t.length<2)return t.map(()=>({sar:null,trend:null,ep:null,af:null}));let i=1,l=n,a=t[0].high??0,u=t[0].low??0,c=t[0],f=t[1];c.close!==null&&f.close!==null&&f.close<c.close&&(i=-1,a=c.low??0,u=c.high??0),r.push({sar:null,trend:null,ep:null,af:null});for(let p=1;p<t.length;p++){let d=t[p],h=t[p-1];if(d.high===null||d.low===null||h.high===null||h.low===null){r.push({sar:null,trend:null,ep:null,af:null});continue}let m=u+l*(a-u);i===1?(m=Math.min(m,h.low,t[Math.max(0,p-2)]?.low??h.low),d.low<m?(i=-1,m=a,a=d.low,l=n):d.high>a&&(a=d.high,l=Math.min(l+o,s))):(m=Math.max(m,h.high,t[Math.max(0,p-2)]?.high??h.high),d.high>m?(i=1,m=a,a=d.high,l=n):d.low<a&&(a=d.low,l=Math.min(l+o,s))),u=m,r.push({sar:u,trend:i,ep:a,af:l})}return r}function Ut(t,e={}){let{emaPeriod:n=20,atrPeriod:o=10,multiplier:s=2}=e,r=[],i=t.map(u=>u.close),l=K(i,n),a=j(t,{period:o});for(let u=0;u<t.length;u++){let c=l[u],f=a[u]?.atr;if(c===null||f===null){r.push({mid:null,upper:null,lower:null,width:null});continue}let p=c+s*f,d=c-s*f,h=c>0?(p-d)/c*100:null;r.push({mid:c,upper:p,lower:d,width:h})}return r}function fe(t,e={}){if(t.length===0)return[];let n=t.map(d=>d.close),o=t.map(d=>({open:d.open,high:d.high,low:d.low,close:d.close,volume:d.volume})),s=e.ma?se(n,typeof e.ma=="object"?e.ma:{}):null,r=e.macd?oe(n,typeof e.macd=="object"?e.macd:{}):null,i=e.boll?ie(n,typeof e.boll=="object"?e.boll:{}):null,l=e.kdj?le(o,typeof e.kdj=="object"?e.kdj:{}):null,a=e.rsi?ae(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?ue(o,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?ce(n,typeof e.bias=="object"?e.bias:{}):null,f=e.cci?pe(o,typeof e.cci=="object"?e.cci:{}):null,p=e.atr?j(o,typeof e.atr=="object"?e.atr:{}):null;return t.map((d,h)=>({...d,...s&&{ma:s[h]},...r&&{macd:r[h]},...i&&{boll:i[h]},...l&&{kdj:l[h]},...a&&{rsi:a[h]},...u&&{wr:u[h]},...c&&{bias:c[h]},...f&&{cci:f[h]},...p&&{atr:p[h]}}))}var me=class{constructor(e={}){this.client=new te(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)}getIndustryList(){return E.getIndustryList(this.client)}getIndustrySpot(e){return E.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return E.getIndustryConstituents(this.client,e)}getIndustryKline(e,n){return E.getIndustryKline(this.client,e,n)}getIndustryMinuteKline(e,n){return E.getIndustryMinuteKline(this.client,e,n)}getConceptList(){return E.getConceptList(this.client)}getConceptSpot(e){return E.getConceptSpot(this.client,e)}getConceptConstituents(e){return E.getConceptConstituents(this.client,e)}getConceptKline(e,n){return E.getConceptKline(this.client,e,n)}getConceptMinuteKline(e,n){return E.getConceptMinuteKline(this.client,e,n)}getHistoryKline(e,n){return E.getHistoryKline(this.client,e,n)}getMinuteKline(e,n){return E.getMinuteKline(this.client,e,n)}getHKHistoryKline(e,n){return E.getHKHistoryKline(this.client,e,n)}getUSHistoryKline(e,n){return E.getUSHistoryKline(this.client,e,n)}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:n,...o}=e,s=await this.getAShareCodeList({market:n});return this.getAllQuotesByCodes(s,o)}async getAllHKShareQuotes(e={}){let n=await this.getHKCodeList();return T.getAllHKQuotesByCodes(this.client,n,e)}async getAllUSShareQuotes(e={}){let{market:n,...o}=e,s=await this.getUSCodeList({simple:!0,market:n});return T.getAllUSQuotesByCodes(this.client,s,o)}getAllQuotesByCodes(e,n={}){return T.getAllQuotesByCodes(this.client,e,n)}async batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return T.getTradingCalendar(this.client)}getDividendDetail(e){return E.getDividendDetail(this.client,e)}getFuturesKline(e,n){return E.getFuturesHistoryKline(this.client,e,n)}getGlobalFuturesSpot(e){return E.getGlobalFuturesSpot(this.client,e)}getGlobalFuturesKline(e,n){return E.getGlobalFuturesKline(this.client,e,n)}getFuturesInventorySymbols(){return E.getFuturesInventorySymbols(this.client)}getFuturesInventory(e,n){return E.getFuturesInventory(this.client,e,n)}getComexInventory(e,n){return E.getComexInventory(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,o=!1;if(e.ma){let r=typeof e.ma=="object"?e.ma:{},i=r.periods??[5,10,20,30,60,120,250],l=r.type??"sma";n=Math.max(n,this.safeMax(i,20)),l==="ema"&&(o=!0)}if(e.macd){let r=typeof e.macd=="object"?e.macd:{},i=r.long??26,l=r.signal??9;n=Math.max(n,i*3+l),o=!0}if(e.boll){let r=typeof e.boll=="object"&&e.boll.period?e.boll.period:20;n=Math.max(n,r)}if(e.kdj){let r=typeof e.kdj=="object"&&e.kdj.period?e.kdj.period:9;n=Math.max(n,r)}if(e.rsi){let r=typeof e.rsi=="object"&&e.rsi.periods?e.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(r,14)+1)}if(e.wr){let r=typeof e.wr=="object"&&e.wr.periods?e.wr.periods:[6,10];n=Math.max(n,this.safeMax(r,10))}if(e.bias){let r=typeof e.bias=="object"&&e.bias.periods?e.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(r,12))}if(e.cci){let r=typeof e.cci=="object"&&e.cci.period?e.cci.period:14;n=Math.max(n,r)}if(e.atr){let r=typeof e.atr=="object"&&e.atr.period?e.atr.period:14;n=Math.max(n,r)}return Math.ceil(n*(o?1.5:1.2))}calcActualStartDate(e,n,o=1.5){let s=Math.ceil(n*o),r=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.slice(6,8)));r.setDate(r.getDate()-s);let i=r.getFullYear(),l=String(r.getMonth()+1).padStart(2,"0"),a=String(r.getDate()).padStart(2,"0");return`${i}${l}${a}`}calcActualStartDateByCalendar(e,n,o){if(!o||o.length===0)return;let s=this.normalizeDate(e),r=o.findIndex(l=>l>=s);r===-1&&(r=o.length-1);let i=Math.max(0,r-n);return this.toCompactDate(o[i])}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:o,endDate:s,indicators:r={}}=n,i=n.market??this.detectMarket(e),l=this.calcRequiredLookback(r),a={A:1.5,HK:1.46,US:1.45},u;if(o)if(i==="A")try{let d=await T.getTradingCalendar(this.client);u=this.calcActualStartDateByCalendar(o,l,d)??this.calcActualStartDate(o,l,a[i])}catch{u=this.calcActualStartDate(o,l,a[i])}else u=this.calcActualStartDate(o,l,a[i]);let c={period:n.period,adjust:n.adjust,startDate:u,endDate:n.endDate},f;switch(i){case"HK":f=await this.getHKHistoryKline(e,c);break;case"US":f=await this.getUSHistoryKline(e,c);break;default:f=await this.getHistoryKline(e,c)}if(o&&f.length<l)switch(i){case"HK":f=await this.getHKHistoryKline(e,{...c,startDate:void 0});break;case"US":f=await this.getUSHistoryKline(e,{...c,startDate:void 0});break;default:f=await this.getHistoryKline(e,{...c,startDate:void 0})}let p=fe(f,r);if(o){let d=this.dateToTimestamp(o),h=s?this.dateToTimestamp(s):1/0;return p.filter(m=>{let y=this.dateToTimestamp(m.date);return y>=d&&y<=h})}return p}},Rn=me;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,parseResponse,safeNumber,safeNumberOrNull});
1
+ "use strict";var qe=Object.defineProperty;var Vn=Object.getOwnPropertyDescriptor;var Wn=Object.getOwnPropertyNames;var Xn=Object.prototype.hasOwnProperty;var Oe=(t,e)=>{for(var n in e)qe(t,n,{get:e[n],enumerable:!0})},Yn=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Wn(e))!Xn.call(t,r)&&r!==n&&qe(t,r,{get:()=>e[r],enumerable:!(o=Vn(e,r))||o.enumerable});return t};var Zn=t=>Yn(qe({},"__esModule",{value:!0}),t);var Dr={};Oe(Dr,{HttpError:()=>B,StockSDK:()=>Ce,addIndicators:()=>ye,asyncPool:()=>H,calcATR:()=>$,calcBIAS:()=>ge,calcBOLL:()=>pe,calcCCI:()=>he,calcDMI:()=>jt,calcEMA:()=>K,calcKC:()=>$t,calcKDJ:()=>de,calcMA:()=>ue,calcMACD:()=>ce,calcOBV:()=>Ht,calcROC:()=>qt,calcRSI:()=>me,calcSAR:()=>Qt,calcSMA:()=>N,calcWMA:()=>He,calcWR:()=>fe,chunkArray:()=>v,decodeGBK:()=>X,default:()=>Gn,extractJsonFromJsonp:()=>Ie,jsonpRequest:()=>_,parseResponse:()=>Y,safeNumber:()=>y,safeNumberOrNull:()=>S});module.exports=Zn(Dr);function X(t){return new TextDecoder("gbk").decode(t)}function Y(t){let e=t.split(";").map(o=>o.trim()).filter(Boolean),n=[];for(let o of e){let r=o.indexOf("=");if(r<0)continue;let s=o.slice(0,r).trim();s.startsWith("v_")&&(s=s.slice(2));let i=o.slice(r+1).trim();i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1));let a=i.split("~");n.push({key:s,fields:a})}return n}function y(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 C(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function p(t){return t==null?null:C(String(t))}var je="https://qt.gtimg.cn",Qe="https://web.ifzq.gtimg.cn/appstock/app/minute/query",$e="https://assets.linkdiary.cn/shares/zh_a_list.json",Ge="https://assets.linkdiary.cn/shares/us_list.json",ze="https://assets.linkdiary.cn/shares/hk_list.json",Ve="https://assets.linkdiary.cn/shares/fund_list",Gt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var Se="https://push2his.eastmoney.com/api/qt/stock/kline/get",We="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Xe="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Ye="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Ze="https://17.push2.eastmoney.com/api/qt/clist/get",Je="https://91.push2.eastmoney.com/api/qt/stock/get",et="https://29.push2.eastmoney.com/api/qt/clist/get",tt="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",nt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",rt="https://79.push2.eastmoney.com/api/qt/clist/get",ot="https://91.push2.eastmoney.com/api/qt/stock/get",st="https://29.push2.eastmoney.com/api/qt/clist/get",it="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",at="https://push2his.eastmoney.com/api/qt/stock/trends2/get",w="https://datacenter-web.eastmoney.com/api/data/v1/get",Z="https://push2his.eastmoney.com/api/qt/stock/kline/get",lt="https://futsseapi.eastmoney.com/list/COMEX,NYMEX,COBOT,SGX,NYBOT,LME,MDEX,TOCOM,IPE",J="58b2fa8f54638b60b87d69b31969089c",ut={SHFE:113,DCE:114,CZCE:115,INE:142,CFFEX:220,GFEX:225},z={cu:"SHFE",al:"SHFE",zn:"SHFE",pb:"SHFE",au:"SHFE",ag:"SHFE",rb:"SHFE",wr:"SHFE",fu:"SHFE",ru:"SHFE",bu:"SHFE",hc:"SHFE",ni:"SHFE",sn:"SHFE",sp:"SHFE",ss:"SHFE",ao:"SHFE",br:"SHFE",c:"DCE",a:"DCE",b:"DCE",m:"DCE",y:"DCE",p:"DCE",l:"DCE",v:"DCE",j:"DCE",jm:"DCE",i:"DCE",jd:"DCE",pp:"DCE",cs:"DCE",eg:"DCE",eb:"DCE",pg:"DCE",lh:"DCE",WH:"CZCE",CF:"CZCE",SR:"CZCE",TA:"CZCE",OI:"CZCE",MA:"CZCE",FG:"CZCE",RM:"CZCE",SF:"CZCE",SM:"CZCE",ZC:"CZCE",AP:"CZCE",CJ:"CZCE",UR:"CZCE",SA:"CZCE",PF:"CZCE",PK:"CZCE",PX:"CZCE",SH:"CZCE",sc:"INE",nr:"INE",lu:"INE",bc:"INE",ec:"INE",IF:"CFFEX",IC:"CFFEX",IH:"CFFEX",IM:"CFFEX",TS:"CFFEX",TF:"CFFEX",T:"CFFEX",TL:"CFFEX",si:"GFEX",lc:"GFEX",ps:"GFEX",pt:"GFEX",pd:"GFEX"},Re={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},ee="https://stock.finance.sina.com.cn/futures/api/openapi.php/OptionService.getOptionData",te="https://stock.finance.sina.com.cn/futures/api/jsonp.php/{callback}/FutureOptionAllService.getOptionDayline",ct="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName",Ee="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",dt="https://stock.finance.sina.com.cn/futures/api/jsonp_v2.php/{callback}/StockOptionDaylineService.getSymbolInfo",mt="https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getFiveDayLine",ft="https://futsseapi.eastmoney.com/list/option/221",gt="https://datacenter-web.eastmoney.com/api/data/get",ht="b2884a393a59ad64002292a3e90d46a5";var Te={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"}},yt=3e4,ne=500,re=500,oe=7,Ct=3,Ot=1e3,St=3e4,Rt=2,Et=[408,429,500,502,503,504];var _e=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(),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(n=>setTimeout(n,e))}getAvailableTokens(){return this.refill(),this.tokens}};var zt=["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 Vt(){if(Jn())return;let t=zt[Tt];return Tt=(Tt+1)%zt.length,t}var se=class extends Error{constructor(e="Circuit breaker is OPEN"){super(e),this.name="CircuitBreakerError"}},be=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 se;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 B=class extends Error{constructor(n,o,r,s){let i=o?` ${o}`:"",a=r?`, url: ${r}`:"",l=s?`, provider: ${s}`:"";super(`HTTP error! status: ${n}${i}${a}${l}`);this.status=n;this.statusText=o;this.url=r;this.provider=s;this.name="HttpError"}},ie=class{constructor(e={}){this.baseUrl=e.baseUrl??je,this.timeout=e.timeout??yt,this.retryOptions=this.resolveRetryOptions(e.retry),this.headers={...e.headers??{}},this.rotateUserAgent=e.rotateUserAgent??!1,this.rateLimiter=e.rateLimit?new _e(e.rateLimit):null,this.circuitBreaker=e.circuitBreaker?new be(e.circuitBreaker):null,e.userAgent&&(Object.keys(this.headers).some(o=>o.toLowerCase()==="user-agent")||(this.headers["User-Agent"]=e.userAgent))}resolveRetryOptions(e){return{maxRetries:e?.maxRetries??Ct,baseDelay:e?.baseDelay??Ot,maxDelay:e?.maxDelay??St,backoffMultiplier:e?.backoffMultiplier??Rt,retryableStatusCodes:e?.retryableStatusCodes??Et,retryOnNetworkError:e?.retryOnNetworkError??!0,retryOnTimeout:e?.retryOnTimeout??!0,onRetry:e?.onRetry}}inferProvider(e){try{let n=new URL(e).hostname;if(n.includes("eastmoney.com"))return"eastmoney";if(n.includes("gtimg.cn"))return"tencent";if(n.includes("linkdiary.cn"))return"linkdiary"}catch{return}}getTimeout(){return this.timeout}calculateDelay(e){return Math.min(this.retryOptions.baseDelay*Math.pow(this.retryOptions.backoffMultiplier,e),this.retryOptions.maxDelay)+Math.random()*100}sleep(e){return new Promise(n=>setTimeout(n,e))}shouldRetry(e,n){return n>=this.retryOptions.maxRetries?!1:e instanceof DOMException&&e.name==="AbortError"?this.retryOptions.retryOnTimeout:e instanceof TypeError?this.retryOptions.retryOnNetworkError:e instanceof B?this.retryOptions.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,n=0){try{let o=await e();return this.circuitBreaker?.recordSuccess(),o}catch(o){if(this.shouldRetry(o,n)){let r=this.calculateDelay(n);return this.retryOptions.onRetry&&o instanceof Error&&this.retryOptions.onRetry(n+1,o,r),await this.sleep(r),this.executeWithRetry(e,n+1)}throw this.circuitBreaker?.recordFailure(),o}}async get(e,n={}){if(this.circuitBreaker&&!this.circuitBreaker.canRequest())throw new se("Circuit breaker is OPEN, request rejected");return this.rateLimiter&&await this.rateLimiter.acquire(),this.executeWithRetry(async()=>{let o=new AbortController,r=setTimeout(()=>o.abort(),this.timeout),s=this.inferProvider(e),i={...this.headers};if(this.rotateUserAgent){let a=Vt();a&&(i["User-Agent"]=a)}try{let a=await fetch(e,{signal:o.signal,headers:i});if(!a.ok)throw new B(a.status,a.statusText,e,s);switch(n.responseType){case"json":return await a.json();case"arraybuffer":return await a.arrayBuffer();default:return await a.text()}}catch(a){throw a instanceof Error&&(a.url=e,a.provider=s),a}finally{clearTimeout(r)}})}async getTencentQuote(e){let n=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,o=await this.get(n,{responseType:"arraybuffer"}),r=X(o);return Y(r)}};var er=new Set(["daily","weekly","monthly"]),tr=new Set(["1","5","15","30","60"]),nr=new Set(["","qfq","hfq"]);function L(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function A(t){if(!er.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function ae(t){if(!tr.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function U(t){if(!nr.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function v(t,e){L(e,"chunkSize");let n=[];for(let o=0;o<t.length;o+=e)n.push(t.slice(o,o+e));return n}async function H(t,e){L(e,"concurrency");let n=[],o=[];for(let r of t){let s=Promise.resolve().then(()=>r()).then(i=>{n.push(i)});if(o.push(s),o.length>=e){await Promise.race(o);for(let i=o.length-1;i>=0;i--)await Promise.race([o[i].then(()=>"fulfilled"),Promise.resolve("pending")])==="fulfilled"&&o.splice(i,1)}}return await Promise.all(o),n}function Ae(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function I(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function D(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var rr=typeof document<"u"&&typeof window<"u",or=0;function Wt(){return`__stock_sdk_jsonp_${Date.now()}_${or++}`}function Ie(t){let e=t,n=e.indexOf("*/");n!==-1&&(e=e.slice(n+2).trim());let o=e.indexOf("(");if(o===-1)throw new Error("Invalid JSONP response: no opening parenthesis found");let r=e.lastIndexOf(")");if(r===-1||r<=o)throw new Error("Invalid JSONP response: no closing parenthesis found");let s=e.slice(o+1,r);return JSON.parse(s)}function sr(t,e){let{timeout:n=15e3,callbackParam:o="callback",callbackMode:r="query"}=e;return new Promise((s,i)=>{let a=Wt(),l;if(r==="path")l=t.replace("{callback}",a);else{let h=t.includes("?")?"&":"?";l=`${t}${h}${o}=${a}`}let u=document.createElement("script"),c=!1,m=window,d=()=>{u.parentNode&&u.parentNode.removeChild(u),delete m[a]},f=setTimeout(()=>{c||(c=!0,d(),i(new Error(`JSONP request timed out after ${n}ms: ${t}`)))},n);m[a]=h=>{c||(c=!0,clearTimeout(f),d(),s(h))},u.onerror=()=>{c||(c=!0,clearTimeout(f),d(),i(new Error(`JSONP script load failed: ${t}`)))},u.src=l,document.head.appendChild(u)})}async function ir(t,e){let{timeout:n=15e3,callbackParam:o="callback",callbackMode:r="query"}=e,s=Wt(),i;if(r==="path")i=t.replace("{callback}",s);else{let u=t.includes("?")?"&":"?";i=`${t}${u}${o}=${s}`}let a=new AbortController,l=setTimeout(()=>a.abort(),n);try{let u=await fetch(i,{signal:a.signal});if(!u.ok)throw new Error(`JSONP fetch failed with status ${u.status}: ${t}`);let c=await u.text();return Ie(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 _(t,e={}){return rr?sr(t,e):ir(t,e)}var T={};Oe(T,{getAShareCodeList:()=>tn,getAllHKQuotesByCodes:()=>sn,getAllQuotesByCodes:()=>on,getAllUSQuotesByCodes:()=>an,getFullQuotes:()=>xe,getFundCodeList:()=>ln,getFundFlow:()=>Yt,getFundQuotes:()=>Jt,getHKCodeList:()=>rn,getHKQuotes:()=>Me,getPanelLargeOrder:()=>Zt,getSimpleQuotes:()=>Xt,getTodayTimeline:()=>en,getTradingCalendar:()=>un,getUSCodeList:()=>nn,getUSQuotes:()=>Pe,parseFullQuote:()=>_t,parseFundFlow:()=>At,parseFundQuote:()=>Pt,parseHKQuote:()=>xt,parsePanelLargeOrder:()=>It,parseSimpleQuote:()=>bt,parseUSQuote:()=>Mt,search:()=>pn});function _t(t){let e=[];for(let o=0;o<5;o++)e.push({price:y(t[9+o*2]),volume:y(t[10+o*2])});let n=[];for(let o=0;o<5;o++)n.push({price:y(t[19+o*2]),volume:y(t[20+o*2])});return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:y(t[3]),prevClose:y(t[4]),open:y(t[5]),volume:y(t[6]),outerVolume:y(t[7]),innerVolume:y(t[8]),bid:e,ask:n,time:t[30]??"",change:y(t[31]),changePercent:y(t[32]),high:y(t[33]),low:y(t[34]),volume2:y(t[36]),amount:y(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 bt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:y(t[3]),change:y(t[4]),changePercent:y(t[5]),volume:y(t[6]),amount:y(t[7]),marketCap:S(t[9]),marketType:t[10]??"",raw:t}}function At(t){return{code:t[0]??"",mainInflow:y(t[1]),mainOutflow:y(t[2]),mainNet:y(t[3]),mainNetRatio:y(t[4]),retailInflow:y(t[5]),retailOutflow:y(t[6]),retailNet:y(t[7]),retailNetRatio:y(t[8]),totalFlow:y(t[9]),name:t[12]??"",date:t[13]??"",raw:t}}function It(t){return{buyLargeRatio:y(t[0]),buySmallRatio:y(t[1]),sellLargeRatio:y(t[2]),sellSmallRatio:y(t[3]),raw:t}}function xt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:y(t[3]),prevClose:y(t[4]),open:y(t[5]),volume:y(t[6]),time:t[30]??"",change:y(t[31]),changePercent:y(t[32]),high:y(t[33]),low:y(t[34]),amount:y(t[37]),lotSize:S(t[40]),circulatingMarketCap:S(t[44]),totalMarketCap:S(t[45]),currency:t[t.length-3]??"",raw:t}}function Mt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:y(t[3]),prevClose:y(t[4]),open:y(t[5]),volume:y(t[6]),time:t[30]??"",change:y(t[31]),changePercent:y(t[32]),high:y(t[33]),low:y(t[34]),amount:y(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 Pt(t){return{code:t[0]??"",name:t[1]??"",nav:y(t[5]),accNav:y(t[6]),change:y(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=>_t(o.fields))}async function Xt(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=>bt(r.fields))}async function Yt(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=>At(r.fields))}async function Zt(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=>It(r.fields))}async function Me(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=>xt(r.fields))}async function Pe(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=>Mt(r.fields))}async function Jt(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=>Pt(r.fields))}async function en(t,e){let n=t.getTimeout(),o=new AbortController,r=setTimeout(()=>o.abort(),n);try{let s=await fetch(`${Qe}?code=${e}`,{signal:o.signal});if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);let i=await s.json();if(i.code!==0)throw new Error(i.msg||"API error");let a=i.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(" "),f=parseFloat(d[1])||0,h=parseInt(d[2],10)||0,g=parseFloat(d[3])||0;h>0&&f>0&&g/h>f*50&&(c=!0)}let m=l.map(d=>{let f=d.split(" "),h=f[0],g=`${h.slice(0,2)}:${h.slice(2,4)}`,O=parseInt(f[2],10)||0,E=parseFloat(f[3])||0,b=c?O*100:O,k=b>0?E/b:0;return{time:g,price:parseFloat(f[1])||0,volume:b,amount:E,avgPrice:Math.round(k*100)/100}});return{code:e,date:u,data:m}}finally{clearTimeout(r)}}var Lt=null,ar=null,Le=null,lr=null,Ue=null,Ut=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 tn(t,e){let n=!1,o;if(typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,o=e.market),!Lt){let i=(await t.get($e,{responseType:"json"}))?.list||[];Lt=i,ar=i.map(a=>a.replace(/^(sh|sz|bj)/,""))}let r=Lt;return o&&(r=r.filter(s=>ur(s,o))),n?r.map(s=>s.replace(/^(sh|sz|bj)/,"")):r.slice()}var cr={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function nn(t,e){let n=!1,o;typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,o=e.market),Le||(Le=(await t.get(Ge,{responseType:"json"}))?.list||[],lr=Le.map(i=>i.replace(/^\d{3}\./,"")));let r=Le.slice();if(o){let s=cr[o];r=r.filter(i=>i.startsWith(s))}return n?r.map(s=>s.replace(/^\d{3}\./,"")):r}async function rn(t){return Ue||(Ue=(await t.get(ze,{responseType:"json"}))?.list||[]),Ue.slice()}async function on(t,e,n={}){let{batchSize:o=ne,concurrency:r=oe,onProgress:s}=n;L(o,"batchSize"),L(r,"concurrency");let i=Math.min(o,re),a=v(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let f=await xe(t,d);return u++,s&&s(u,l),f});return(await H(c,r)).flat()}async function sn(t,e,n={}){let{batchSize:o=ne,concurrency:r=oe,onProgress:s}=n;L(o,"batchSize"),L(r,"concurrency");let i=Math.min(o,re),a=v(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let f=await Me(t,d);return u++,s&&s(u,l),f});return(await H(c,r)).flat()}async function an(t,e,n={}){let{batchSize:o=ne,concurrency:r=oe,onProgress:s}=n;L(o,"batchSize"),L(r,"concurrency");let i=Math.min(o,re),a=v(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let f=await Pe(t,d);return u++,s&&s(u,l),f});return(await H(c,r)).flat()}async function ln(t){if(Ut)return Ut.slice();let o=(await t.get(Ve,{responseType:"text"})).split(",").slice(1).filter(r=>r.trim());return Ut=o,o.slice()}var V=null;async function un(t){if(V)return V.slice();let e=await t.get(Gt);return!e||e.trim()===""?(V=[],V.slice()):(V=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),V.slice())}var cn="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 o=n.split("~"),r=o[0]||"",s=o[1]||"",i=pr(o[2]||""),a=o[4]||"";return{code:r+s,name:i,market:r,type:a}})}function mr(t){return new Promise((e,n)=>{let o=`${cn}?v=2&t=all&q=${encodeURIComponent(t)}`;window.v_hint="";let r=document.createElement("script");r.src=o,r.charset="utf-8",r.onload=()=>{let s=window.v_hint||"";document.body.removeChild(r),e(s)},r.onerror=()=>{document.body.removeChild(r),n(new Error("Network error calling Smartbox"))},document.body.appendChild(r)})}async function fr(t,e){let n=`${cn}?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 pn(t,e){if(!e||!e.trim())return[];let n;return gr()?n=await mr(e):n=await fr(t,e),dr(n)}var R={};Oe(R,{extractVariety:()=>Ft,getCFFEXOptionQuotes:()=>Mn,getComexInventory:()=>Kn,getConceptConstituents:()=>Rn,getConceptKline:()=>En,getConceptList:()=>kt,getConceptMinuteKline:()=>Tn,getConceptSpot:()=>Sn,getDividendDetail:()=>_n,getFuturesHistoryKline:()=>An,getFuturesInventory:()=>Dn,getFuturesInventorySymbols:()=>Ln,getFuturesMarketCode:()=>Nt,getGlobalFuturesKline:()=>xn,getGlobalFuturesSpot:()=>In,getHKHistoryKline:()=>fn,getHistoryKline:()=>dn,getIndustryConstituents:()=>yn,getIndustryKline:()=>Cn,getIndustryList:()=>Kt,getIndustryMinuteKline:()=>On,getIndustrySpot:()=>hn,getMinuteKline:()=>mn,getOptionLHB:()=>Pn,getUSHistoryKline:()=>gn});async function Dt(t,e,n,o,r=100,s){let i=[],a=1,l=0;do{let u=new URLSearchParams({...n,pn:String(a),pz:String(r),fields:o}),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 f=d.diff.map((h,g)=>s(h,i.length+g+1));i.push(...f),a++}while(i.length<l);return i}function x(t){let[e,n,o,r,s,i,a,l,u,c,m]=t.split(",");return{date:e,open:C(n),close:C(o),high:C(r),low:C(s),volume:C(i),amount:C(a),amplitude:C(l),changePercent:C(u),change:C(c),turnoverRate:C(m)}}async function M(t,e,n){let o=`${e}?${n.toString()}`,r=await t.get(o,{responseType:"json"});return{klines:r?.data?.klines||[],name:r?.data?.name,code:r?.data?.code}}async function dn(t,e,n={}){let{period:o="daily",adjust:r="qfq",startDate:s="19700101",endDate:i="20500101"}=n;A(o),U(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${Ae(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:I(o),fqt:D(r),secid:l,beg:s,end:i}),c=Se,{klines:m}=await M(t,c,u);return m.length===0?[]:m.map(d=>({...x(d),code:a}))}async function mn(t,e,n={}){let{period:o="1",adjust:r="qfq",startDate:s="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=n;ae(o),U(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${Ae(e)}.${a}`;if(o==="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=`${We}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(d)||d.length===0)return[];let f=s.replace("T"," ").slice(0,16),h=i.replace("T"," ").slice(0,16);return d.map(g=>{let[O,E,b,k,W,F,G,zn]=g.split(",");return{time:O,open:C(E),close:C(b),high:C(k),low:C(W),volume:C(F),amount:C(G),avgPrice:C(zn)}}).filter(g=>g.time>=f&&g.time<=h)}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:o,fqt:D(r||""),secid:l,beg:"0",end:"20500000"}),c=Se,{klines:m}=await M(t,c,u);if(m.length===0)return[];let d=s.replace("T"," ").slice(0,16),f=i.replace("T"," ").slice(0,16);return m.map(h=>{let g=x(h);return{...g,time:g.date}}).filter(h=>h.time>=d&&h.time<=f)}}async function fn(t,e,n={}){let{period:o="daily",adjust:r="qfq",startDate:s="19700101",endDate:i="20500101"}=n;A(o),U(r);let a=e.replace(/^hk/i,"").padStart(5,"0"),l=`116.${a}`,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(o),fqt:D(r),secid:l,beg:s,end:i,lmt:"1000000"}),c=Xe,{klines:m,name:d}=await M(t,c,u);return m.length===0?[]:m.map(f=>({...x(f),code:a,name:d||""}))}async function gn(t,e,n={}){let{period:o="daily",adjust:r="qfq",startDate:s="19700101",endDate:i="20500101"}=n;A(o),U(r);let a=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(o),fqt:D(r),secid:e,beg:s,end:i,lmt:"1000000"}),l=Ye,{klines:u,name:c,code:m}=await M(t,l,a),d=m||e.split(".")[1]||e,f=c||"";return u.length===0?[]:u.map(h=>({...x(h),code:d,name:f}))}function De(t){let e=null;return{async getCode(n,o,r){if(o.startsWith("BK"))return o;if(!e){let i=await r(n);e=new Map(i.map(a=>[a.name,a.code]))}let s=e.get(o);if(!s)throw new Error(`${t.errorPrefix}: ${o}`);return s}}}async function Ke(t,e){let n={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",r=await Dt(t,e.listUrl,n,o,100,(s,i)=>({rank:i,name:String(s.f14??""),code:String(s.f12??""),price:p(s.f2),change:p(s.f4),changePercent:p(s.f3),totalMarketCap:p(s.f20),turnoverRate:p(s.f8),riseCount:p(s.f104),fallCount:p(s.f105),leadingStock:s.f128?String(s.f128):null,leadingStockChangePercent:p(s.f136)}));return r.sort((s,i)=>(i.changePercent??0)-(s.changePercent??0)),r.forEach((s,i)=>{s.rank=i+1}),r}async function ke(t,e,n){let o=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${e}`}),r=`${n}?${o.toString()}`,i=(await t.get(r,{responseType:"json"}))?.data;return i?[{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=i[l],d=null;return typeof m=="number"&&!isNaN(m)&&(d=c?m/100:m),{item:u,value:d}}):[]}async function Fe(t,e,n){let o={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return Dt(t,n,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,(s,i)=>({rank:i,code:String(s.f12??""),name:String(s.f14??""),price:p(s.f2),changePercent:p(s.f3),change:p(s.f4),volume:p(s.f5),amount:p(s.f6),amplitude:p(s.f7),high:p(s.f15),low:p(s.f16),open:p(s.f17),prevClose:p(s.f18),turnoverRate:p(s.f8),pe:p(s.f9),pb:p(s.f23)}))}async function Ne(t,e,n,o={}){let{period:r="daily",adjust:s="",startDate:i="19700101",endDate:a="20500101"}=o;A(r),U(s);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:I(r),fqt:D(s),beg:i,end:a,smplmt:"10000",lmt:"1000000"}),{klines:u}=await M(t,n,l);return u.length===0?[]:u.map(c=>x(c))}async function we(t,e,n,o,r={}){let{period:s="5"}=r;if(ae(s),s==="1"){let i=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}?${i.toString()}`,u=(await t.get(a,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[m,d,f,h,g,O,E,b]=c.split(",");return{time:m,open:C(d),close:C(f),high:C(h),low:C(g),volume:C(O),amount:C(E),price:C(b)}})}else{let i=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:s,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),a=`${n}?${i.toString()}`,u=(await t.get(a,{responseType:"json"}))?.data?.klines;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[m,d,f,h,g,O,E,b,k,W,F]=c.split(",");return{time:m,open:C(d),close:C(f),high:C(h),low:C(g),changePercent:C(k),change:C(W),volume:C(O),amount:C(E),amplitude:C(b),turnoverRate:C(F)}})}}var q={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Ze,spotUrl:Je,consUrl:et,klineUrl:tt,trendsUrl:nt,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},hr=De(q);async function Be(t,e){return hr.getCode(t,e,Kt)}async function Kt(t){return Ke(t,q)}async function hn(t,e){let n=await Be(t,e);return ke(t,n,q.spotUrl)}async function yn(t,e){let n=await Be(t,e);return Fe(t,n,q.consUrl)}async function Cn(t,e,n={}){let o=await Be(t,e);return Ne(t,o,q.klineUrl,n)}async function On(t,e,n={}){let o=await Be(t,e);return we(t,o,q.klineUrl,q.trendsUrl,n)}var j={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:rt,spotUrl:ot,consUrl:st,klineUrl:it,trendsUrl:at,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},yr=De(j);async function ve(t,e){return yr.getCode(t,e,kt)}async function kt(t){return Ke(t,j)}async function Sn(t,e){let n=await ve(t,e);return ke(t,n,j.spotUrl)}async function Rn(t,e){let n=await ve(t,e);return Fe(t,n,j.consUrl)}async function En(t,e,n={}){let o=await ve(t,e);return Ne(t,o,j.klineUrl,n)}async function Tn(t,e,n={}){let o=await ve(t,e);return we(t,o,j.klineUrl,j.trendsUrl,n)}function Q(t){if(!t)return null;let e=t.match(/^(\d{4}-\d{2}-\d{2})/);return e?e[1]:null}function Cr(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)/,""),o=[],r=1,s=1;do{let i=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=`${w}?${i.toString()}`,u=(await t.get(a,{responseType:"json"}))?.result;if(!u||!Array.isArray(u.data))break;r===1&&(s=u.pages??1);let c=u.data.map(Cr);o.push(...c),r++}while(r<=s);return o}function Ft(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 z[t]??z[t.toLowerCase()]??z[t.toUpperCase()]}function Nt(t){let e=bn(t);if(!e&&t.length>1&&t.endsWith("M")&&(e=bn(t.slice(0,-1))),!e){let o=Object.keys(z).join(", ");throw new RangeError(`Unknown futures variety: "${t}". Supported varieties: ${o}`)}let n=ut[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?C(n[12]):null}}async function An(t,e,n={}){let{period:o="daily",startDate:r="19700101",endDate:s="20500101"}=n;A(o);let i=Ft(e),l=`${Nt(i)}.${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:I(o),fqt:"0",secid:l,beg:r,end:s}),{klines:c,name:m,code:d}=await M(t,Z,u);return c.length===0?[]:c.map(f=>({...Or(f),code:d||e,name:m||""}))}async function In(t,e={}){let n=e.pageSize??20,o=[],r=0,s=0;do{let i=new URLSearchParams({orderBy:"dm",sort:"desc",pageSize:String(n),pageIndex:String(r),token:J,field:"dm,sc,name,p,zsjd,zde,zdf,f152,o,h,l,zjsj,vol,wp,np,ccl",blockName:"callback"}),a=`${lt}?${i.toString()}`,l=await t.get(a,{responseType:"json"});if(!l||!Array.isArray(l.list))break;r===0&&(s=l.total??0);let u=l.list.map(Sr);o.push(...u),r++}while(o.length<s);return o}function Sr(t){return{code:t.dm||"",name:t.name||"",price:C(String(t.p)),change:C(String(t.zde)),changePercent:C(String(t.zdf)),open:C(String(t.o)),high:C(String(t.h)),low:C(String(t.l)),prevSettle:C(String(t.zjsj)),volume:C(String(t.vol)),buyVolume:C(String(t.wp)),sellVolume:C(String(t.np)),openInterest:C(String(t.ccl))}}function Rr(t){let e=x(t),n=t.split(",");return{...e,openInterest:n.length>12?C(n[12]):null}}function Er(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 xn(t,e,n={}){let{period:o="daily",startDate:r="19700101",endDate:s="20500101"}=n;A(o);let i=n.marketCode;if(i===void 0){let d=Er(e);if(i=Re[d],i===void 0){let f=Object.keys(Re).join(", ");throw new RangeError(`Unknown global futures variety: "${d}". Supported: ${f}. Or specify marketCode manually via options.`)}}let a=`${i}.${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:I(o),fqt:"0",secid:a,beg:r,end:s}),{klines:u,name:c,code:m}=await M(t,Z,l);return u.length===0?[]:u.map(d=>({...Rr(d),code:m||e,name:c||""}))}async function Mn(t,e={}){let{pageSize:n=2e4}=e,o=new URLSearchParams({orderBy:"zdf",sort:"desc",pageSize:String(n),pageIndex:"0",token:J,field:"dm,sc,name,p,zsjd,zde,zdf,f152,vol,cje,ccl,xqj,syr,rz,zjsj,o"}),r=`${ft}?${o.toString()}`,i=(await t.get(r,{responseType:"json"}))?.list;return Array.isArray(i)?i.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 Pn(t,e,n){let o=new URLSearchParams({type:"RPT_IF_BILLBOARD_TD",sty:"ALL",p:"1",ps:"200",source:"IFBILLBOARD",client:"WEB",ut:ht,filter:`(SECURITY_CODE="${e}")(TRADE_DATE='${n}')`}),r=`${gt}?${o.toString()}`,i=(await t.get(r,{responseType:"json"}))?.result?.data;if(!Array.isArray(i))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 i.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 Tr={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=`${w}?${e.toString()}`,r=(await t.get(n,{responseType:"json"}))?.result?.data;return Array.isArray(r)?r.map(s=>({code:String(s.TRADE_CODE??""),name:String(s.TRADE_TYPE??""),marketCode:String(s.TRADE_MARKET_CODE??"")})):[]}function Un(t){if(!t)return"";let e=String(t),n=e.match(/^(\d{4}-\d{2}-\d{2})/);return n?n[1]:e}async function Dn(t,e,n={}){let{startDate:o="2020-10-28",pageSize:r=500}=n,s=e.toUpperCase(),i=[],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="${s}")(TRADE_DATE>='${o}')`,pageNumber:String(a),pageSize:String(r),sortTypes:"-1",sortColumns:"TRADE_DATE",source:"WEB",client:"WEB"}),c=`${w}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;a===1&&(l=d.pages??1);let f=d.data.map(h=>({code:String(h.SECURITY_CODE??e),date:Un(h.TRADE_DATE),inventory:p(h.ON_WARRANT_NUM),change:p(h.ADDCHANGE)}));i.push(...f),a++}while(a<=l);return i}async function Kn(t,e,n={}){let o=Tr[e];if(!o)throw new RangeError(`Invalid COMEX symbol: "${e}". Must be "gold" or "silver".`);let{pageSize:r=500}=n,s=[],i=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(i),reportName:"RPT_FUTUOPT_GOLDSIL",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(INDICATOR_ID1="${o}")(@STORAGE_TON<>"NULL")`}),c=`${w}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.result;if(!d||!Array.isArray(d.data))break;i===1&&(a=d.pages??1);let f=d.data.map(h=>({date:Un(h.REPORT_DATE),name:l[e]??e,storageTon:p(h.STORAGE_TON),storageOunce:p(h.STORAGE_OUNCE)}));s.push(...f),i++}while(i<=a);return s}var P={};Oe(P,{getCommodityOptionKline:()=>Qn,getCommodityOptionSpot:()=>jn,getETFOption5DayMinute:()=>qn,getETFOptionDailyKline:()=>Hn,getETFOptionExpireDay:()=>wn,getETFOptionMinute:()=>vn,getETFOptionMonths:()=>Nn,getIndexOptionKline:()=>Fn,getIndexOptionSpot:()=>kn});function _r(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 br(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=`${ee}?type=futures&product=${t}&exchange=cffex&pinzhong=${e}`,o=await _(n),r=o?.result?.data?.up??[],s=o?.result?.data?.down??[];return{calls:r.map(_r),puts:s.map(br)}}async function Fn(t){let e=`${te}?symbol=${t}`,n=await _(e,{callbackMode:"path"});return Array.isArray(n)?n.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 Nn(t){let e=`${ct}?exchange=null&cate=${encodeURIComponent(t)}`,o=(await _(e))?.result?.data,r=o?.contractMonth??[];return{months:r.length>1?r.slice(1):r,stockId:o?.stockId??"",cateId:o?.cateId??"",cateList:o?.cateList??[]}}async function wn(t,e){let n=`${Ee}?exchange=null&cate=${encodeURIComponent(t)}&date=${e}`,o=await _(n),r=o?.result?.data?.remainderDays;if(typeof r=="number"&&r<0){let i=`${Ee}?exchange=null&cate=${encodeURIComponent("XD"+t)}&date=${e}`;o=await _(i)}let s=o?.result?.data;return{expireDay:s?.expireDay??"",remainderDays:s?.remainderDays??0,stockId:s?.stockId??"",name:s?.other?.name??""}}function Bn(t){let e="";return t.map(n=>(n.d&&(e=n.d),{time:n.i,date:e,price:p(n.p),volume:p(n.v),openInterest:p(n.t),avgPrice:p(n.a)}))}async function vn(t){let e=`CON_OP_${t}`,n=`${pt}?symbol=${e}`,r=(await _(n))?.result?.data;return Array.isArray(r)?Bn(r):[]}async function Hn(t){let e=`CON_OP_${t}`,n=`${dt}?symbol=${e}`,o=await _(n,{callbackMode:"path"});return Array.isArray(o)?o.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=`${mt}?symbol=${e}`,r=(await _(n))?.result?.data;if(!Array.isArray(r))return[];let s=[];for(let i of r)Array.isArray(i)&&s.push(...Bn(i));return s}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:p(t[7]),symbol:t[8]??""}}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:null,symbol:t[7]??""}}async function jn(t,e){let n=Te[t];if(!n)throw new RangeError(`Unknown commodity option variety: "${t}". Available: ${Object.keys(Te).join(", ")}`);let o=`${ee}?type=futures&product=${n.product}&exchange=${n.exchange}&pinzhong=${e}`,r=await _(o),s=r?.result?.data?.up??[],i=r?.result?.data?.down??[];return{calls:s.map(Ar),puts:i.map(Ir)}}async function Qn(t){let e=`${te}?symbol=${t}`,n=await _(e,{callbackMode:"path"});return Array.isArray(n)?n.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)})):[]}function le(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function N(t,e){let n=[];for(let o=0;o<t.length;o++){if(o<e-1){n.push(null);continue}let r=0,s=0;for(let i=o-e+1;i<=o;i++)t[i]!==null&&(r+=t[i],s++);n.push(s===e?le(r/e):null)}return n}function K(t,e){let n=[],o=2/(e+1),r=null,s=!1;for(let i=0;i<t.length;i++){if(i<e-1){n.push(null);continue}if(!s){let l=0,u=0;for(let c=i-e+1;c<=i;c++)t[c]!==null&&(l+=t[c],u++);u===e&&(r=l/e,s=!0),n.push(r!==null?le(r):null);continue}let a=t[i];a===null?n.push(r!==null?le(r):null):(r=o*a+(1-o)*r,n.push(le(r)))}return n}function He(t,e){let n=[],o=Array.from({length:e},(s,i)=>i+1),r=o.reduce((s,i)=>s+i,0);for(let s=0;s<t.length;s++){if(s<e-1){n.push(null);continue}let i=0,a=!0;for(let l=0;l<e;l++){let u=t[s-e+1+l];if(u===null){a=!1;break}i+=u*o[l]}n.push(a?le(i/r):null)}return n}function ue(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:o="sma"}=e,r=o==="ema"?K:o==="wma"?He:N,s={};for(let i of n)s[`ma${i}`]=r(t,i);return t.map((i,a)=>{let l={};for(let u of n)l[`ma${u}`]=s[`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:o=26,signal:r=9}=e,s=K(t,n),i=K(t,o),a=t.map((u,c)=>s[c]===null||i[c]===null?null:s[c]-i[c]),l=K(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 wt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function xr(t,e,n){let o=[];for(let r=0;r<t.length;r++){if(r<e-1||n[r]===null){o.push(null);continue}let s=0,i=0;for(let a=r-e+1;a<=r;a++)t[a]!==null&&n[r]!==null&&(s+=Math.pow(t[a]-n[r],2),i++);o.push(i===e?Math.sqrt(s/e):null)}return o}function pe(t,e={}){let{period:n=20,stdDev:o=2}=e,r=N(t,n),s=xr(t,n,r);return t.map((i,a)=>{if(r[a]===null||s[a]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let l=r[a]+o*s[a],u=r[a]-o*s[a],c=r[a]!==0?wt((l-u)/r[a]*100):null;return{mid:r[a],upper:wt(l),lower:wt(u),bandwidth:c}})}function Bt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function de(t,e={}){let{period:n=9,kPeriod:o=3,dPeriod:r=3}=e,s=[],i=50,a=50;for(let l=0;l<t.length;l++){if(l<n-1){s.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,m=!0;for(let g=l-n+1;g<=l;g++){if(t[g].high===null||t[g].low===null){m=!1;break}u=Math.max(u,t[g].high),c=Math.min(c,t[g].low)}let d=t[l].close;if(!m||d===null||u===c){s.push({k:null,d:null,j:null});continue}let f=(d-c)/(u-c)*100;i=(o-1)/o*i+1/o*f,a=(r-1)/r*a+1/r*i;let h=3*i-2*a;s.push({k:Bt(i),d:Bt(a),j:Bt(h)})}return s}function Mr(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,o=[null];for(let s=1;s<t.length;s++)t[s]===null||t[s-1]===null?o.push(null):o.push(t[s]-t[s-1]);let r={};for(let s of n){let i=[],a=0,l=0;for(let u=0;u<t.length;u++){if(u<s){i.push(null),o[u]!==null&&(o[u]>0?a+=o[u]:l+=Math.abs(o[u]));continue}if(u===s)a=a/s,l=l/s;else{let c=o[u]??0,m=c>0?c:0,d=c<0?Math.abs(c):0;a=(a*(s-1)+m)/s,l=(l*(s-1)+d)/s}if(l===0)i.push(100);else if(a===0)i.push(0);else{let c=a/l;i.push(Mr(100-100/(1+c)))}}r[`rsi${s}`]=i}return t.map((s,i)=>{let a={};for(let l of n)a[`rsi${l}`]=r[`rsi${l}`][i];return a})}function Pr(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,o={};for(let r of n){let s=[];for(let i=0;i<t.length;i++){if(i<r-1){s.push(null);continue}let a=-1/0,l=1/0,u=!0;for(let d=i-r+1;d<=i;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[i].close;if(!u||c===null||a===l){s.push(null);continue}let m=(a-c)/(a-l)*100;s.push(Pr(m))}o[`wr${r}`]=s}return t.map((r,s)=>{let i={};for(let a of n)i[`wr${a}`]=o[`wr${a}`][s];return i})}function Lr(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,o={};for(let r of n){let s=N(t,r),i=[];for(let a=0;a<t.length;a++)if(t[a]===null||s[a]===null||s[a]===0)i.push(null);else{let l=(t[a]-s[a])/s[a]*100;i.push(Lr(l))}o[`bias${r}`]=i}return t.map((r,s)=>{let i={};for(let a of n)i[`bias${a}`]=o[`bias${a}`][s];return i})}function Ur(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function he(t,e={}){let{period:n=14}=e,o=[],r=t.map(s=>s.high===null||s.low===null||s.close===null?null:(s.high+s.low+s.close)/3);for(let s=0;s<t.length;s++){if(s<n-1){o.push({cci:null});continue}let i=0,a=0;for(let m=s-n+1;m<=s;m++)r[m]!==null&&(i+=r[m],a++);if(a!==n||r[s]===null){o.push({cci:null});continue}let l=i/n,u=0;for(let m=s-n+1;m<=s;m++)u+=Math.abs(r[m]-l);let c=u/n;if(c===0)o.push({cci:0});else{let m=(r[s]-l)/(.015*c);o.push({cci:Ur(m)})}}return o}function vt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function $(t,e={}){let{period:n=14}=e,o=[],r=[];for(let i=0;i<t.length;i++){let{high:a,low:l,close:u}=t[i];if(a===null||l===null||u===null){r.push(null);continue}if(i===0)r.push(a-l);else{let c=t[i-1].close;if(c===null)r.push(a-l);else{let m=a-l,d=Math.abs(a-c),f=Math.abs(l-c);r.push(Math.max(m,d,f))}}}let s=null;for(let i=0;i<t.length;i++){if(i<n-1){o.push({tr:r[i]!==null?vt(r[i]):null,atr:null});continue}if(i===n-1){let a=0,l=0;for(let u=0;u<n;u++)r[u]!==null&&(a+=r[u],l++);l===n&&(s=a/n)}else s!==null&&r[i]!==null&&(s=(s*(n-1)+r[i])/n);o.push({tr:r[i]!==null?vt(r[i]):null,atr:s!==null?vt(s):null})}return o}function Ht(t,e={}){let{maPeriod:n}=e,o=[];if(t.length===0)return o;let r=t[0].volume??0;o.push({obv:r,obvMa:null});for(let s=1;s<t.length;s++){let i=t[s],a=t[s-1];if(i.close===null||a.close===null||i.volume===null||i.volume===void 0){o.push({obv:null,obvMa:null});continue}i.close>a.close?r+=i.volume:i.close<a.close&&(r-=i.volume),o.push({obv:r,obvMa:null})}if(n&&n>0)for(let s=n-1;s<o.length;s++){let i=0,a=0;for(let l=s-n+1;l<=s;l++)o[l].obv!==null&&(i+=o[l].obv,a++);a===n&&(o[s].obvMa=i/n)}return o}function qt(t,e={}){let{period:n=12,signalPeriod:o}=e,r=[];for(let s=0;s<t.length;s++){if(s<n){r.push({roc:null,signal:null});continue}let i=t[s].close,a=t[s-n].close;if(i===null||a===null||a===0){r.push({roc:null,signal:null});continue}let l=(i-a)/a*100;r.push({roc:l,signal:null})}if(o&&o>0)for(let s=n+o-1;s<r.length;s++){let i=0,a=0;for(let l=s-o+1;l<=s;l++)r[l].roc!==null&&(i+=r[l].roc,a++);a===o&&(r[s].signal=i/o)}return r}function jt(t,e={}){let{period:n=14,adxPeriod:o=n}=e,r=[];if(t.length<2)return t.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let s=[],i=[],a=[];for(let g=0;g<t.length;g++){if(g===0){s.push(0),i.push(0),a.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let O=t[g],E=t[g-1];if(O.high===null||O.low===null||O.close===null||E.high===null||E.low===null||E.close===null){s.push(0),i.push(0),a.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let b=O.high-O.low,k=Math.abs(O.high-E.close),W=Math.abs(O.low-E.close);a.push(Math.max(b,k,W));let F=O.high-E.high,G=E.low-O.low;F>G&&F>0?s.push(F):s.push(0),G>F&&G>0?i.push(G):i.push(0),r.push({pdi:null,mdi:null,adx:null,adxr:null})}let l=0,u=0,c=0,m=[];for(let g=1;g<t.length;g++){if(g<n){l+=a[g],u+=s[g],c+=i[g],m.push(0);continue}g===n?(l=l,u=u,c=c):(l=l-l/n+a[g],u=u-u/n+s[g],c=c-c/n+i[g]);let O=l>0?u/l*100:0,E=l>0?c/l*100:0;r[g].pdi=O,r[g].mdi=E;let b=O+E,k=b>0?Math.abs(O-E)/b*100:0;m.push(k)}let d=0,f=0,h=0;for(let g=n;g<t.length;g++){if(g<n*2-1){d+=m[g-n+1]||0,f++;continue}if(g===n*2-1)d+=m[g-n+1]||0,h=d/o,r[g].adx=h;else{let O=m[g-n+1]||0;h=(h*(o-1)+O)/o,r[g].adx=h}}for(let g=n*2-1+o;g<t.length;g++){let O=r[g].adx,E=r[g-o]?.adx;O!==null&&E!==null&&(r[g].adxr=(O+E)/2)}return r}function Qt(t,e={}){let{afStart:n=.02,afIncrement:o=.02,afMax:r=.2}=e,s=[];if(t.length<2)return t.map(()=>({sar:null,trend:null,ep:null,af:null}));let i=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&&(i=-1,l=c.low??0,u=c.high??0),s.push({sar:null,trend:null,ep:null,af:null});for(let d=1;d<t.length;d++){let f=t[d],h=t[d-1];if(f.high===null||f.low===null||h.high===null||h.low===null){s.push({sar:null,trend:null,ep:null,af:null});continue}let g=u+a*(l-u);i===1?(g=Math.min(g,h.low,t[Math.max(0,d-2)]?.low??h.low),f.low<g?(i=-1,g=l,l=f.low,a=n):f.high>l&&(l=f.high,a=Math.min(a+o,r))):(g=Math.max(g,h.high,t[Math.max(0,d-2)]?.high??h.high),f.high>g?(i=1,g=l,l=f.high,a=n):f.low<l&&(l=f.low,a=Math.min(a+o,r))),u=g,s.push({sar:u,trend:i,ep:l,af:a})}return s}function $t(t,e={}){let{emaPeriod:n=20,atrPeriod:o=10,multiplier:r=2}=e,s=[],i=t.map(u=>u.close),a=K(i,n),l=$(t,{period:o});for(let u=0;u<t.length;u++){let c=a[u],m=l[u]?.atr;if(c===null||m===null){s.push({mid:null,upper:null,lower:null,width:null});continue}let d=c+r*m,f=c-r*m,h=c>0?(d-f)/c*100:null;s.push({mid:c,upper:d,lower:f,width:h})}return s}function ye(t,e={}){if(t.length===0)return[];let n=t.map(f=>f.close),o=t.map(f=>({open:f.open,high:f.high,low:f.low,close:f.close,volume:f.volume})),r=e.ma?ue(n,typeof e.ma=="object"?e.ma:{}):null,s=e.macd?ce(n,typeof e.macd=="object"?e.macd:{}):null,i=e.boll?pe(n,typeof e.boll=="object"?e.boll:{}):null,a=e.kdj?de(o,typeof e.kdj=="object"?e.kdj:{}):null,l=e.rsi?me(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?fe(o,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?ge(n,typeof e.bias=="object"?e.bias:{}):null,m=e.cci?he(o,typeof e.cci=="object"?e.cci:{}):null,d=e.atr?$(o,typeof e.atr=="object"?e.atr:{}):null;return t.map((f,h)=>({...f,...r&&{ma:r[h]},...s&&{macd:s[h]},...i&&{boll:i[h]},...a&&{kdj:a[h]},...l&&{rsi:l[h]},...u&&{wr:u[h]},...c&&{bias:c[h]},...m&&{cci:m[h]},...d&&{atr:d[h]}}))}var Ce=class{constructor(e={}){this.client=new ie(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)}getIndustryList(){return R.getIndustryList(this.client)}getIndustrySpot(e){return R.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return R.getIndustryConstituents(this.client,e)}getIndustryKline(e,n){return R.getIndustryKline(this.client,e,n)}getIndustryMinuteKline(e,n){return R.getIndustryMinuteKline(this.client,e,n)}getConceptList(){return R.getConceptList(this.client)}getConceptSpot(e){return R.getConceptSpot(this.client,e)}getConceptConstituents(e){return R.getConceptConstituents(this.client,e)}getConceptKline(e,n){return R.getConceptKline(this.client,e,n)}getConceptMinuteKline(e,n){return R.getConceptMinuteKline(this.client,e,n)}getHistoryKline(e,n){return R.getHistoryKline(this.client,e,n)}getMinuteKline(e,n){return R.getMinuteKline(this.client,e,n)}getHKHistoryKline(e,n){return R.getHKHistoryKline(this.client,e,n)}getUSHistoryKline(e,n){return R.getUSHistoryKline(this.client,e,n)}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:n,...o}=e,r=await this.getAShareCodeList({market:n});return this.getAllQuotesByCodes(r,o)}async getAllHKShareQuotes(e={}){let n=await this.getHKCodeList();return T.getAllHKQuotesByCodes(this.client,n,e)}async getAllUSShareQuotes(e={}){let{market:n,...o}=e,r=await this.getUSCodeList({simple:!0,market:n});return T.getAllUSQuotesByCodes(this.client,r,o)}getAllQuotesByCodes(e,n={}){return T.getAllQuotesByCodes(this.client,e,n)}async batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return T.getTradingCalendar(this.client)}getDividendDetail(e){return R.getDividendDetail(this.client,e)}getFuturesKline(e,n){return R.getFuturesHistoryKline(this.client,e,n)}getGlobalFuturesSpot(e){return R.getGlobalFuturesSpot(this.client,e)}getGlobalFuturesKline(e,n){return R.getGlobalFuturesKline(this.client,e,n)}getFuturesInventorySymbols(){return R.getFuturesInventorySymbols(this.client)}getFuturesInventory(e,n){return R.getFuturesInventory(this.client,e,n)}getComexInventory(e,n){return R.getComexInventory(this.client,e,n)}getIndexOptionSpot(e,n){return P.getIndexOptionSpot(e,n)}getIndexOptionKline(e){return P.getIndexOptionKline(e)}getCFFEXOptionQuotes(e){return R.getCFFEXOptionQuotes(this.client,e)}getETFOptionMonths(e){return P.getETFOptionMonths(e)}getETFOptionExpireDay(e,n){return P.getETFOptionExpireDay(e,n)}getETFOptionMinute(e){return P.getETFOptionMinute(e)}getETFOptionDailyKline(e){return P.getETFOptionDailyKline(e)}getETFOption5DayMinute(e){return P.getETFOption5DayMinute(e)}getCommodityOptionSpot(e,n){return P.getCommodityOptionSpot(e,n)}getCommodityOptionKline(e){return P.getCommodityOptionKline(e)}getOptionLHB(e,n){return R.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,o=!1;if(e.ma){let s=typeof e.ma=="object"?e.ma:{},i=s.periods??[5,10,20,30,60,120,250],a=s.type??"sma";n=Math.max(n,this.safeMax(i,20)),a==="ema"&&(o=!0)}if(e.macd){let s=typeof e.macd=="object"?e.macd:{},i=s.long??26,a=s.signal??9;n=Math.max(n,i*3+a),o=!0}if(e.boll){let s=typeof e.boll=="object"&&e.boll.period?e.boll.period:20;n=Math.max(n,s)}if(e.kdj){let s=typeof e.kdj=="object"&&e.kdj.period?e.kdj.period:9;n=Math.max(n,s)}if(e.rsi){let s=typeof e.rsi=="object"&&e.rsi.periods?e.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(s,14)+1)}if(e.wr){let s=typeof e.wr=="object"&&e.wr.periods?e.wr.periods:[6,10];n=Math.max(n,this.safeMax(s,10))}if(e.bias){let s=typeof e.bias=="object"&&e.bias.periods?e.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(s,12))}if(e.cci){let s=typeof e.cci=="object"&&e.cci.period?e.cci.period:14;n=Math.max(n,s)}if(e.atr){let s=typeof e.atr=="object"&&e.atr.period?e.atr.period:14;n=Math.max(n,s)}return Math.ceil(n*(o?1.5:1.2))}calcActualStartDate(e,n,o=1.5){let r=Math.ceil(n*o),s=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.slice(6,8)));s.setDate(s.getDate()-r);let i=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0");return`${i}${a}${l}`}calcActualStartDateByCalendar(e,n,o){if(!o||o.length===0)return;let r=this.normalizeDate(e),s=o.findIndex(a=>a>=r);s===-1&&(s=o.length-1);let i=Math.max(0,s-n);return this.toCompactDate(o[i])}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:o,endDate:r,indicators:s={}}=n,i=n.market??this.detectMarket(e),a=this.calcRequiredLookback(s),l={A:1.5,HK:1.46,US:1.45},u;if(o)if(i==="A")try{let f=await T.getTradingCalendar(this.client);u=this.calcActualStartDateByCalendar(o,a,f)??this.calcActualStartDate(o,a,l[i])}catch{u=this.calcActualStartDate(o,a,l[i])}else u=this.calcActualStartDate(o,a,l[i]);let c={period:n.period,adjust:n.adjust,startDate:u,endDate:n.endDate},m;switch(i){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(o&&m.length<a)switch(i){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=ye(m,s);if(o){let f=this.dateToTimestamp(o),h=r?this.dateToTimestamp(r):1/0;return d.filter(g=>{let O=this.dateToTimestamp(g.date);return O>=f&&O<=h})}return d}},Gn=Ce;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});