stock-sdk 1.4.5 → 1.6.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/dist/index.js CHANGED
@@ -1 +1 @@
1
- var vt=Object.defineProperty;var ct=(t,e)=>{for(var n in e)vt(t,n,{get:e[n],enumerable:!0})};function V(t){return new TextDecoder("gbk").decode(t)}function Y(t){let e=t.split(";").map(s=>s.trim()).filter(Boolean),n=[];for(let s of e){let r=s.indexOf("=");if(r<0)continue;let o=s.slice(0,r).trim();o.startsWith("v_")&&(o=o.slice(2));let i=s.slice(r+1).trim();i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1));let a=i.split("~");n.push({key:o,fields:a})}return n}function f(t){if(!t||t==="")return 0;let e=parseFloat(t);return Number.isNaN(e)?0:e}function y(t){if(!t||t==="")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function g(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function R(t){return t==null?null:g(String(t))}var _e="https://qt.gtimg.cn",xe="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Le="https://assets.linkdiary.cn/shares/zh_a_list.json",Oe="https://assets.linkdiary.cn/shares/us_list.json",we="https://assets.linkdiary.cn/shares/hk_list.json",pt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var J="https://push2his.eastmoney.com/api/qt/stock/kline/get",Ie="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Ee="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Ue="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Be="https://17.push2.eastmoney.com/api/qt/clist/get",Pe="https://91.push2.eastmoney.com/api/qt/stock/get",ke="https://29.push2.eastmoney.com/api/qt/clist/get",De="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",qe="https://push2his.eastmoney.com/api/qt/stock/trends2/get",He="https://79.push2.eastmoney.com/api/qt/clist/get",Ne="https://91.push2.eastmoney.com/api/qt/stock/get",ve="https://29.push2.eastmoney.com/api/qt/clist/get",je="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Qe="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Fe=3e4,v=500,j=500,Q=7,$e=3,We=1e3,ze=3e4,Ge=2,Ve=[408,429,500,502,503,504];var k=class extends Error{constructor(n,s,r,o){let i=s?` ${s}`:"",a=r?`, url: ${r}`:"",l=o?`, provider: ${o}`:"";super(`HTTP error! status: ${n}${i}${a}${l}`);this.status=n;this.statusText=s;this.url=r;this.provider=o;this.name="HttpError"}},F=class{constructor(e={}){this.baseUrl=e.baseUrl??_e,this.timeout=e.timeout??Fe,this.retryOptions=this.resolveRetryOptions(e.retry),this.headers={...e.headers??{}},e.userAgent&&(Object.keys(this.headers).some(s=>s.toLowerCase()==="user-agent")||(this.headers["User-Agent"]=e.userAgent))}resolveRetryOptions(e){return{maxRetries:e?.maxRetries??$e,baseDelay:e?.baseDelay??We,maxDelay:e?.maxDelay??ze,backoffMultiplier:e?.backoffMultiplier??Ge,retryableStatusCodes:e?.retryableStatusCodes??Ve,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 k?this.retryOptions.retryableStatusCodes.includes(e.status):!1}async executeWithRetry(e,n=0){try{return await e()}catch(s){if(this.shouldRetry(s,n)){let r=this.calculateDelay(n);return this.retryOptions.onRetry&&s instanceof Error&&this.retryOptions.onRetry(n+1,s,r),await this.sleep(r),this.executeWithRetry(e,n+1)}throw s}}async get(e,n={}){return this.executeWithRetry(async()=>{let s=new AbortController,r=setTimeout(()=>s.abort(),this.timeout),o=this.inferProvider(e);try{let i=await fetch(e,{signal:s.signal,headers:{...this.headers}});if(!i.ok)throw new k(i.status,i.statusText,e,o);switch(n.responseType){case"json":return await i.json();case"arraybuffer":return await i.arrayBuffer();default:return await i.text()}}catch(i){throw i instanceof Error&&(i.url=e,i.provider=o),i}finally{clearTimeout(r)}})}async getTencentQuote(e){let n=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,s=await this.get(n,{responseType:"arraybuffer"}),r=V(s);return Y(r)}};var jt=new Set(["daily","weekly","monthly"]),Qt=new Set(["1","5","15","30","60"]),Ft=new Set(["","qfq","hfq"]);function K(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function x(t){if(!jt.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function $(t){if(!Qt.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function M(t){if(!Ft.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function D(t,e){K(e,"chunkSize");let n=[];for(let s=0;s<t.length;s+=e)n.push(t.slice(s,s+e));return n}async function q(t,e){K(e,"concurrency");let n=[],s=[];for(let r of t){let o=Promise.resolve().then(()=>r()).then(i=>{n.push(i)});if(s.push(o),s.length>=e){await Promise.race(s);for(let i=s.length-1;i>=0;i--)await Promise.race([s[i].then(()=>"fulfilled"),Promise.resolve("pending")])==="fulfilled"&&s.splice(i,1)}}return await Promise.all(s),n}function X(t){return t.startsWith("sh")?"1":t.startsWith("sz")||t.startsWith("bj")?"0":t.startsWith("6")?"1":"0"}function L(t){return{daily:"101",weekly:"102",monthly:"103"}[t]}function A(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var b={};ct(b,{getAShareCodeList:()=>yt,getAllHKQuotesByCodes:()=>St,getAllQuotesByCodes:()=>bt,getAllUSQuotesByCodes:()=>Tt,getFullQuotes:()=>Z,getFundFlow:()=>dt,getFundQuotes:()=>gt,getHKCodeList:()=>Rt,getHKQuotes:()=>ee,getPanelLargeOrder:()=>mt,getSimpleQuotes:()=>ft,getTodayTimeline:()=>ht,getTradingCalendar:()=>Kt,getUSCodeList:()=>Ct,getUSQuotes:()=>te,parseFullQuote:()=>Ye,parseFundFlow:()=>Xe,parseFundQuote:()=>nt,parseHKQuote:()=>et,parsePanelLargeOrder:()=>Ze,parseSimpleQuote:()=>Je,parseUSQuote:()=>tt,search:()=>At});function Ye(t){let e=[];for(let s=0;s<5;s++)e.push({price:f(t[9+s*2]),volume:f(t[10+s*2])});let n=[];for(let s=0;s<5;s++)n.push({price:f(t[19+s*2]),volume:f(t[20+s*2])});return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:f(t[3]),prevClose:f(t[4]),open:f(t[5]),volume:f(t[6]),outerVolume:f(t[7]),innerVolume:f(t[8]),bid:e,ask:n,time:t[30]??"",change:f(t[31]),changePercent:f(t[32]),high:f(t[33]),low:f(t[34]),volume2:f(t[36]),amount:f(t[37]),turnoverRate:y(t[38]),pe:y(t[39]),amplitude:y(t[43]),circulatingMarketCap:y(t[44]),totalMarketCap:y(t[45]),pb:y(t[46]),limitUp:y(t[47]),limitDown:y(t[48]),volumeRatio:y(t[49]),avgPrice:y(t[51]),peStatic:y(t[52]),peDynamic:y(t[53]),high52w:y(t[67]),low52w:y(t[68]),circulatingShares:y(t[72]),totalShares:y(t[73]),raw:t}}function Je(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:f(t[3]),change:f(t[4]),changePercent:f(t[5]),volume:f(t[6]),amount:f(t[7]),marketCap:y(t[9]),marketType:t[10]??"",raw:t}}function Xe(t){return{code:t[0]??"",mainInflow:f(t[1]),mainOutflow:f(t[2]),mainNet:f(t[3]),mainNetRatio:f(t[4]),retailInflow:f(t[5]),retailOutflow:f(t[6]),retailNet:f(t[7]),retailNetRatio:f(t[8]),totalFlow:f(t[9]),name:t[12]??"",date:t[13]??"",raw:t}}function Ze(t){return{buyLargeRatio:f(t[0]),buySmallRatio:f(t[1]),sellLargeRatio:f(t[2]),sellSmallRatio:f(t[3]),raw:t}}function et(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:f(t[3]),prevClose:f(t[4]),open:f(t[5]),volume:f(t[6]),time:t[30]??"",change:f(t[31]),changePercent:f(t[32]),high:f(t[33]),low:f(t[34]),amount:f(t[37]),lotSize:y(t[40]),circulatingMarketCap:y(t[44]),totalMarketCap:y(t[45]),currency:t[t.length-3]??"",raw:t}}function tt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:f(t[3]),prevClose:f(t[4]),open:f(t[5]),volume:f(t[6]),time:t[30]??"",change:f(t[31]),changePercent:f(t[32]),high:f(t[33]),low:f(t[34]),amount:f(t[37]),turnoverRate:y(t[38]),pe:y(t[39]),amplitude:y(t[43]),totalMarketCap:y(t[45]),pb:y(t[47]),high52w:y(t[48]),low52w:y(t[49]),raw:t}}function nt(t){return{code:t[0]??"",name:t[1]??"",nav:f(t[5]),accNav:f(t[6]),change:f(t[7]),navDate:t[8]??"",raw:t}}async function Z(t,e){return!e||e.length===0?[]:(await t.getTencentQuote(e.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>Ye(s.fields))}async function ft(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=>Je(r.fields))}async function dt(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=>Xe(r.fields))}async function mt(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=>Ze(r.fields))}async function ee(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=>et(r.fields))}async function te(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=>tt(r.fields))}async function gt(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=>nt(r.fields))}async function ht(t,e){let n=t.getTimeout(),s=new AbortController,r=setTimeout(()=>s.abort(),n);try{let o=await fetch(`${xe}?code=${e}`,{signal:s.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let i=await o.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(" "),m=parseFloat(d[1])||0,h=parseInt(d[2],10)||0,C=parseFloat(d[3])||0;h>0&&m>0&&C/h>m*50&&(c=!0)}let p=l.map(d=>{let m=d.split(" "),h=m[0],C=`${h.slice(0,2)}:${h.slice(2,4)}`,T=parseInt(m[2],10)||0,I=parseFloat(m[3])||0,_=c?T*100:T,N=_>0?I/_:0;return{time:C,price:parseFloat(m[1])||0,volume:_,amount:I,avgPrice:Math.round(N*100)/100}});return{code:e,date:u,data:p}}finally{clearTimeout(r)}}var ne=null,W=null,re=null,z=null,oe=null;async function yt(t,e=!0){if(ne)return e?ne.slice():(W||(W=ne.map(r=>r.replace(/^(sh|sz|bj)/,""))),W.slice());let s=(await t.get(Le,{responseType:"json"}))?.list||[];return ne=s,W=s.map(r=>r.replace(/^(sh|sz|bj)/,"")),e?s.slice():W.slice()}async function Ct(t,e=!0){if(re)return e?re.slice():(z||(z=re.map(r=>r.replace(/^\d{3}\./,""))),z.slice());let s=(await t.get(Oe,{responseType:"json"}))?.list||[];return re=s,z=s.map(r=>r.replace(/^\d{3}\./,"")),e?s.slice():z.slice()}async function Rt(t){return oe||(oe=(await t.get(we,{responseType:"json"}))?.list||[]),oe.slice()}async function bt(t,e,n={}){let{batchSize:s=v,concurrency:r=Q,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,j),a=D(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await Z(t,d);return u++,o&&o(u,l),m});return(await q(c,r)).flat()}async function St(t,e,n={}){let{batchSize:s=v,concurrency:r=Q,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,j),a=D(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await ee(t,d);return u++,o&&o(u,l),m});return(await q(c,r)).flat()}async function Tt(t,e,n={}){let{batchSize:s=v,concurrency:r=Q,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,j),a=D(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await te(t,d);return u++,o&&o(u,l),m});return(await q(c,r)).flat()}var H=null;async function Kt(t){if(H)return H.slice();let e=await t.get(pt);return!e||e.trim()===""?(H=[],H.slice()):(H=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),H.slice())}var Mt="https://smartbox.gtimg.cn/s3/";function $t(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function Wt(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let s=n.split("~"),r=s[0]||"",o=s[1]||"",i=$t(s[2]||""),a=s[4]||"";return{code:r+o,name:i,market:r,type:a}})}function zt(t){return new Promise((e,n)=>{let s=`${Mt}?v=2&t=all&q=${encodeURIComponent(t)}`;window.v_hint="";let r=document.createElement("script");r.src=s,r.charset="utf-8",r.onload=()=>{let o=window.v_hint||"";document.body.removeChild(r),e(o)},r.onerror=()=>{document.body.removeChild(r),n(new Error("Network error calling Smartbox"))},document.body.appendChild(r)})}async function Gt(t,e){let n=`${Mt}?v=2&t=all&q=${encodeURIComponent(e)}`,r=(await t.get(n)).match(/v_hint="([^"]*)"/);return r?r[1]:""}function Vt(){return typeof window<"u"&&typeof document<"u"}async function At(t,e){if(!e||!e.trim())return[];let n;return Vt()?n=await zt(e):n=await Gt(t,e),Wt(n)}var S={};ct(S,{getConceptConstituents:()=>Pt,getConceptKline:()=>kt,getConceptList:()=>st,getConceptMinuteKline:()=>Dt,getConceptSpot:()=>Bt,getHKHistoryKline:()=>Lt,getHistoryKline:()=>_t,getIndustryConstituents:()=>It,getIndustryKline:()=>Et,getIndustryList:()=>ot,getIndustryMinuteKline:()=>Ut,getIndustrySpot:()=>wt,getMinuteKline:()=>xt,getUSHistoryKline:()=>Ot});async function rt(t,e,n,s,r=100,o){let i=[],a=1,l=0;do{let u=new URLSearchParams({...n,pn:String(a),pz:String(r),fields:s}),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 m=d.diff.map((h,C)=>o(h,i.length+C+1));i.push(...m),a++}while(i.length<l);return i}function O(t){let[e,n,s,r,o,i,a,l,u,c,p]=t.split(",");return{date:e,open:g(n),close:g(s),high:g(r),low:g(o),volume:g(i),amount:g(a),amplitude:g(l),changePercent:g(u),change:g(c),turnoverRate:g(p)}}async function w(t,e,n){let s=`${e}?${n.toString()}`,r=await t.get(s,{responseType:"json"});return{klines:r?.data?.klines||[],name:r?.data?.name,code:r?.data?.code}}async function _t(t,e,n={}){let{period:s="daily",adjust:r="qfq",startDate:o="19700101",endDate:i="20500101"}=n;x(s),M(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${X(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:L(s),fqt:A(r),secid:l,beg:o,end:i}),c=J,{klines:p}=await w(t,c,u);return p.length===0?[]:p.map(d=>({...O(d),code:a}))}async function xt(t,e,n={}){let{period:s="1",adjust:r="qfq",startDate:o="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=n;$(s),M(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${X(e)}.${a}`;if(s==="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=`${Ie}?${u.toString()}`,d=(await t.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(d)||d.length===0)return[];let m=o.replace("T"," ").slice(0,16),h=i.replace("T"," ").slice(0,16);return d.map(C=>{let[T,I,_,N,Me,Ae,Ht,Nt]=C.split(",");return{time:T,open:g(I),close:g(_),high:g(N),low:g(Me),volume:g(Ae),amount:g(Ht),avgPrice:g(Nt)}}).filter(C=>C.time>=m&&C.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:s,fqt:A(r||""),secid:l,beg:"0",end:"20500000"}),c=J,{klines:p}=await w(t,c,u);if(p.length===0)return[];let d=o.replace("T"," ").slice(0,16),m=i.replace("T"," ").slice(0,16);return p.map(h=>{let C=O(h);return{...C,time:C.date}}).filter(h=>h.time>=d&&h.time<=m)}}async function Lt(t,e,n={}){let{period:s="daily",adjust:r="qfq",startDate:o="19700101",endDate:i="20500101"}=n;x(s),M(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:L(s),fqt:A(r),secid:l,beg:o,end:i,lmt:"1000000"}),c=Ee,{klines:p,name:d}=await w(t,c,u);return p.length===0?[]:p.map(m=>({...O(m),code:a,name:d||""}))}async function Ot(t,e,n={}){let{period:s="daily",adjust:r="qfq",startDate:o="19700101",endDate:i="20500101"}=n;x(s),M(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:L(s),fqt:A(r),secid:e,beg:o,end:i,lmt:"1000000"}),l=Ue,{klines:u,name:c,code:p}=await w(t,l,a),d=p||e.split(".")[1]||e,m=c||"";return u.length===0?[]:u.map(h=>({...O(h),code:d,name:m}))}function se(t){let e=null;return{async getCode(n,s,r){if(s.startsWith("BK"))return s;if(!e){let i=await r(n);e=new Map(i.map(a=>[a.name,a.code]))}let o=e.get(s);if(!o)throw new Error(`${t.errorPrefix}: ${s}`);return o}}}async function ie(t,e){let n={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:e.type==="concept"?"f12":"f3",fs:e.fsFilter},s=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 rt(t,e.listUrl,n,s,100,(o,i)=>({rank:i,name:String(o.f14??""),code:String(o.f12??""),price:R(o.f2),change:R(o.f4),changePercent:R(o.f3),totalMarketCap:R(o.f20),turnoverRate:R(o.f8),riseCount:R(o.f104),fallCount:R(o.f105),leadingStock:o.f128?String(o.f128):null,leadingStockChangePercent:R(o.f136)}));return r.sort((o,i)=>(i.changePercent??0)-(o.changePercent??0)),r.forEach((o,i)=>{o.rank=i+1}),r}async function ae(t,e,n){let s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${e}`}),r=`${n}?${s.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 p=i[l],d=null;return typeof p=="number"&&!isNaN(p)&&(d=c?p/100:p),{item:u,value:d}}):[]}async function le(t,e,n){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return rt(t,n,s,"f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152,f45",100,(o,i)=>({rank:i,code:String(o.f12??""),name:String(o.f14??""),price:R(o.f2),changePercent:R(o.f3),change:R(o.f4),volume:R(o.f5),amount:R(o.f6),amplitude:R(o.f7),high:R(o.f15),low:R(o.f16),open:R(o.f17),prevClose:R(o.f18),turnoverRate:R(o.f8),pe:R(o.f9),pb:R(o.f23)}))}async function ue(t,e,n,s={}){let{period:r="daily",adjust:o="",startDate:i="19700101",endDate:a="20500101"}=s;x(r),M(o);let l=new URLSearchParams({secid:`90.${e}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:L(r),fqt:A(o),beg:i,end:a,smplmt:"10000",lmt:"1000000"}),{klines:u}=await w(t,n,l);return u.length===0?[]:u.map(c=>O(c))}async function ce(t,e,n,s,r={}){let{period:o="5"}=r;if($(o),o==="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=`${s}?${i.toString()}`,u=(await t.get(a,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[p,d,m,h,C,T,I,_]=c.split(",");return{time:p,open:g(d),close:g(m),high:g(h),low:g(C),volume:g(T),amount:g(I),price:g(_)}})}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:o,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[p,d,m,h,C,T,I,_,N,Me,Ae]=c.split(",");return{time:p,open:g(d),close:g(m),high:g(h),low:g(C),changePercent:g(N),change:g(Me),volume:g(T),amount:g(I),amplitude:g(_),turnoverRate:g(Ae)}})}}var E={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Be,spotUrl:Pe,consUrl:ke,klineUrl:De,trendsUrl:qe,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},Yt=se(E);async function pe(t,e){return Yt.getCode(t,e,ot)}async function ot(t){return ie(t,E)}async function wt(t,e){let n=await pe(t,e);return ae(t,n,E.spotUrl)}async function It(t,e){let n=await pe(t,e);return le(t,n,E.consUrl)}async function Et(t,e,n={}){let s=await pe(t,e);return ue(t,s,E.klineUrl,n)}async function Ut(t,e,n={}){let s=await pe(t,e);return ce(t,s,E.klineUrl,E.trendsUrl,n)}var U={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:He,spotUrl:Ne,consUrl:ve,klineUrl:je,trendsUrl:Qe,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},Jt=se(U);async function fe(t,e){return Jt.getCode(t,e,st)}async function st(t){return ie(t,U)}async function Bt(t,e){let n=await fe(t,e);return ae(t,n,U.spotUrl)}async function Pt(t,e){let n=await fe(t,e);return le(t,n,U.consUrl)}async function kt(t,e,n={}){let s=await fe(t,e);return ue(t,s,U.klineUrl,n)}async function Dt(t,e,n={}){let s=await fe(t,e);return ce(t,s,U.klineUrl,U.trendsUrl,n)}function G(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function B(t,e){let n=[];for(let s=0;s<t.length;s++){if(s<e-1){n.push(null);continue}let r=0,o=0;for(let i=s-e+1;i<=s;i++)t[i]!==null&&(r+=t[i],o++);n.push(o===e?G(r/e):null)}return n}function P(t,e){let n=[],s=2/(e+1),r=null,o=!1;for(let i=0;i<t.length;i++){if(i<e-1){n.push(null);continue}if(!o){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,o=!0),n.push(r!==null?G(r):null);continue}let a=t[i];a===null?n.push(r!==null?G(r):null):(r=s*a+(1-s)*r,n.push(G(r)))}return n}function it(t,e){let n=[],s=Array.from({length:e},(o,i)=>i+1),r=s.reduce((o,i)=>o+i,0);for(let o=0;o<t.length;o++){if(o<e-1){n.push(null);continue}let i=0,a=!0;for(let l=0;l<e;l++){let u=t[o-e+1+l];if(u===null){a=!1;break}i+=u*s[l]}n.push(a?G(i/r):null)}return n}function de(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:s="sma"}=e,r=s==="ema"?P:s==="wma"?it:B,o={};for(let i of n)o[`ma${i}`]=r(t,i);return t.map((i,a)=>{let l={};for(let u of n)l[`ma${u}`]=o[`ma${u}`][a];return l})}function qt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function me(t,e={}){let{short:n=12,long:s=26,signal:r=9}=e,o=P(t,n),i=P(t,s),a=t.map((u,c)=>o[c]===null||i[c]===null?null:o[c]-i[c]),l=P(a,r);return t.map((u,c)=>({dif:a[c]!==null?qt(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?qt((a[c]-l[c])*2):null}))}function at(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Xt(t,e,n){let s=[];for(let r=0;r<t.length;r++){if(r<e-1||n[r]===null){s.push(null);continue}let o=0,i=0;for(let a=r-e+1;a<=r;a++)t[a]!==null&&n[r]!==null&&(o+=Math.pow(t[a]-n[r],2),i++);s.push(i===e?Math.sqrt(o/e):null)}return s}function ge(t,e={}){let{period:n=20,stdDev:s=2}=e,r=B(t,n),o=Xt(t,n,r);return t.map((i,a)=>{if(r[a]===null||o[a]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let l=r[a]+s*o[a],u=r[a]-s*o[a],c=r[a]!==0?at((l-u)/r[a]*100):null;return{mid:r[a],upper:at(l),lower:at(u),bandwidth:c}})}function lt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function he(t,e={}){let{period:n=9,kPeriod:s=3,dPeriod:r=3}=e,o=[],i=50,a=50;for(let l=0;l<t.length;l++){if(l<n-1){o.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,p=!0;for(let C=l-n+1;C<=l;C++){if(t[C].high===null||t[C].low===null){p=!1;break}u=Math.max(u,t[C].high),c=Math.min(c,t[C].low)}let d=t[l].close;if(!p||d===null||u===c){o.push({k:null,d:null,j:null});continue}let m=(d-c)/(u-c)*100;i=(s-1)/s*i+1/s*m,a=(r-1)/r*a+1/r*i;let h=3*i-2*a;o.push({k:lt(i),d:lt(a),j:lt(h)})}return o}function Zt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ye(t,e={}){let{periods:n=[6,12,24]}=e,s=[null];for(let o=1;o<t.length;o++)t[o]===null||t[o-1]===null?s.push(null):s.push(t[o]-t[o-1]);let r={};for(let o of n){let i=[],a=0,l=0;for(let u=0;u<t.length;u++){if(u<o){i.push(null),s[u]!==null&&(s[u]>0?a+=s[u]:l+=Math.abs(s[u]));continue}if(u===o)a=a/o,l=l/o;else{let c=s[u]??0,p=c>0?c:0,d=c<0?Math.abs(c):0;a=(a*(o-1)+p)/o,l=(l*(o-1)+d)/o}if(l===0)i.push(100);else if(a===0)i.push(0);else{let c=a/l;i.push(Zt(100-100/(1+c)))}}r[`rsi${o}`]=i}return t.map((o,i)=>{let a={};for(let l of n)a[`rsi${l}`]=r[`rsi${l}`][i];return a})}function en(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Ce(t,e={}){let{periods:n=[6,10]}=e,s={};for(let r of n){let o=[];for(let i=0;i<t.length;i++){if(i<r-1){o.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){o.push(null);continue}let p=(a-c)/(a-l)*100;o.push(en(p))}s[`wr${r}`]=o}return t.map((r,o)=>{let i={};for(let a of n)i[`wr${a}`]=s[`wr${a}`][o];return i})}function tn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Re(t,e={}){let{periods:n=[6,12,24]}=e,s={};for(let r of n){let o=B(t,r),i=[];for(let a=0;a<t.length;a++)if(t[a]===null||o[a]===null||o[a]===0)i.push(null);else{let l=(t[a]-o[a])/o[a]*100;i.push(tn(l))}s[`bias${r}`]=i}return t.map((r,o)=>{let i={};for(let a of n)i[`bias${a}`]=s[`bias${a}`][o];return i})}function nn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function be(t,e={}){let{period:n=14}=e,s=[],r=t.map(o=>o.high===null||o.low===null||o.close===null?null:(o.high+o.low+o.close)/3);for(let o=0;o<t.length;o++){if(o<n-1){s.push({cci:null});continue}let i=0,a=0;for(let p=o-n+1;p<=o;p++)r[p]!==null&&(i+=r[p],a++);if(a!==n||r[o]===null){s.push({cci:null});continue}let l=i/n,u=0;for(let p=o-n+1;p<=o;p++)u+=Math.abs(r[p]-l);let c=u/n;if(c===0)s.push({cci:0});else{let p=(r[o]-l)/(.015*c);s.push({cci:nn(p)})}}return s}function ut(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function Se(t,e={}){let{period:n=14}=e,s=[],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 p=a-l,d=Math.abs(a-c),m=Math.abs(l-c);r.push(Math.max(p,d,m))}}}let o=null;for(let i=0;i<t.length;i++){if(i<n-1){s.push({tr:r[i]!==null?ut(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&&(o=a/n)}else o!==null&&r[i]!==null&&(o=(o*(n-1)+r[i])/n);s.push({tr:r[i]!==null?ut(r[i]):null,atr:o!==null?ut(o):null})}return s}function Te(t,e={}){if(t.length===0)return[];let n=t.map(m=>m.close),s=t.map(m=>({open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume})),r=e.ma?de(n,typeof e.ma=="object"?e.ma:{}):null,o=e.macd?me(n,typeof e.macd=="object"?e.macd:{}):null,i=e.boll?ge(n,typeof e.boll=="object"?e.boll:{}):null,a=e.kdj?he(s,typeof e.kdj=="object"?e.kdj:{}):null,l=e.rsi?ye(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?Ce(s,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?Re(n,typeof e.bias=="object"?e.bias:{}):null,p=e.cci?be(s,typeof e.cci=="object"?e.cci:{}):null,d=e.atr?Se(s,typeof e.atr=="object"?e.atr:{}):null;return t.map((m,h)=>({...m,...r&&{ma:r[h]},...o&&{macd:o[h]},...i&&{boll:i[h]},...a&&{kdj:a[h]},...l&&{rsi:l[h]},...u&&{wr:u[h]},...c&&{bias:c[h]},...p&&{cci:p[h]},...d&&{atr:d[h]}}))}var Ke=class{constructor(e={}){this.client=new F(e)}getFullQuotes(e){return b.getFullQuotes(this.client,e)}getSimpleQuotes(e){return b.getSimpleQuotes(this.client,e)}getHKQuotes(e){return b.getHKQuotes(this.client,e)}getUSQuotes(e){return b.getUSQuotes(this.client,e)}getFundQuotes(e){return b.getFundQuotes(this.client,e)}getFundFlow(e){return b.getFundFlow(this.client,e)}getPanelLargeOrder(e){return b.getPanelLargeOrder(this.client,e)}getTodayTimeline(e){return b.getTodayTimeline(this.client,e)}getIndustryList(){return S.getIndustryList(this.client)}getIndustrySpot(e){return S.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return S.getIndustryConstituents(this.client,e)}getIndustryKline(e,n){return S.getIndustryKline(this.client,e,n)}getIndustryMinuteKline(e,n){return S.getIndustryMinuteKline(this.client,e,n)}getConceptList(){return S.getConceptList(this.client)}getConceptSpot(e){return S.getConceptSpot(this.client,e)}getConceptConstituents(e){return S.getConceptConstituents(this.client,e)}getConceptKline(e,n){return S.getConceptKline(this.client,e,n)}getConceptMinuteKline(e,n){return S.getConceptMinuteKline(this.client,e,n)}getHistoryKline(e,n){return S.getHistoryKline(this.client,e,n)}getMinuteKline(e,n){return S.getMinuteKline(this.client,e,n)}getHKHistoryKline(e,n){return S.getHKHistoryKline(this.client,e,n)}getUSHistoryKline(e,n){return S.getUSHistoryKline(this.client,e,n)}search(e){return b.search(this.client,e)}getAShareCodeList(e=!0){return b.getAShareCodeList(this.client,e)}getUSCodeList(e=!0){return b.getUSCodeList(this.client,e)}getHKCodeList(){return b.getHKCodeList(this.client)}async getAllAShareQuotes(e={}){let n=await this.getAShareCodeList();return this.getAllQuotesByCodes(n,e)}async getAllHKShareQuotes(e={}){let n=await this.getHKCodeList();return b.getAllHKQuotesByCodes(this.client,n,e)}async getAllUSShareQuotes(e={}){let n=await this.getUSCodeList(!1);return b.getAllUSQuotesByCodes(this.client,n,e)}getAllQuotesByCodes(e,n={}){return b.getAllQuotesByCodes(this.client,e,n)}async batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return b.getTradingCalendar(this.client)}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,s=!1;if(e.ma){let o=typeof e.ma=="object"?e.ma:{},i=o.periods??[5,10,20,30,60,120,250],a=o.type??"sma";n=Math.max(n,this.safeMax(i,20)),a==="ema"&&(s=!0)}if(e.macd){let o=typeof e.macd=="object"?e.macd:{},i=o.long??26,a=o.signal??9;n=Math.max(n,i*3+a),s=!0}if(e.boll){let o=typeof e.boll=="object"&&e.boll.period?e.boll.period:20;n=Math.max(n,o)}if(e.kdj){let o=typeof e.kdj=="object"&&e.kdj.period?e.kdj.period:9;n=Math.max(n,o)}if(e.rsi){let o=typeof e.rsi=="object"&&e.rsi.periods?e.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(o,14)+1)}if(e.wr){let o=typeof e.wr=="object"&&e.wr.periods?e.wr.periods:[6,10];n=Math.max(n,this.safeMax(o,10))}if(e.bias){let o=typeof e.bias=="object"&&e.bias.periods?e.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(o,12))}if(e.cci){let o=typeof e.cci=="object"&&e.cci.period?e.cci.period:14;n=Math.max(n,o)}if(e.atr){let o=typeof e.atr=="object"&&e.atr.period?e.atr.period:14;n=Math.max(n,o)}return Math.ceil(n*(s?1.5:1.2))}calcActualStartDate(e,n,s=1.5){let r=Math.ceil(n*s),o=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.slice(6,8)));o.setDate(o.getDate()-r);let i=o.getFullYear(),a=String(o.getMonth()+1).padStart(2,"0"),l=String(o.getDate()).padStart(2,"0");return`${i}${a}${l}`}calcActualStartDateByCalendar(e,n,s){if(!s||s.length===0)return;let r=this.normalizeDate(e),o=s.findIndex(a=>a>=r);o===-1&&(o=s.length-1);let i=Math.max(0,o-n);return this.toCompactDate(s[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:s,endDate:r,indicators:o={}}=n,i=n.market??this.detectMarket(e),a=this.calcRequiredLookback(o),l={A:1.5,HK:1.46,US:1.45},u;if(s)if(i==="A")try{let m=await b.getTradingCalendar(this.client);u=this.calcActualStartDateByCalendar(s,a,m)??this.calcActualStartDate(s,a,l[i])}catch{u=this.calcActualStartDate(s,a,l[i])}else u=this.calcActualStartDate(s,a,l[i]);let c={period:n.period,adjust:n.adjust,startDate:u,endDate:n.endDate},p;switch(i){case"HK":p=await this.getHKHistoryKline(e,c);break;case"US":p=await this.getUSHistoryKline(e,c);break;default:p=await this.getHistoryKline(e,c)}if(s&&p.length<a)switch(i){case"HK":p=await this.getHKHistoryKline(e,{...c,startDate:void 0});break;case"US":p=await this.getUSHistoryKline(e,{...c,startDate:void 0});break;default:p=await this.getHistoryKline(e,{...c,startDate:void 0})}let d=Te(p,o);if(s){let m=this.dateToTimestamp(s),h=r?this.dateToTimestamp(r):1/0;return d.filter(C=>{let T=this.dateToTimestamp(C.date);return T>=m&&T<=h})}return d}},rn=Ke;export{k as HttpError,Ke as StockSDK,Te as addIndicators,q as asyncPool,Se as calcATR,Re as calcBIAS,ge as calcBOLL,be as calcCCI,P as calcEMA,he as calcKDJ,de as calcMA,me as calcMACD,ye as calcRSI,B as calcSMA,it as calcWMA,Ce as calcWR,D as chunkArray,V as decodeGBK,rn as default,Y as parseResponse,f as safeNumber,y as safeNumberOrNull};
1
+ var Wt=Object.defineProperty;var pt=(e,t)=>{for(var n in t)Wt(e,n,{get:t[n],enumerable:!0})};function J(e){return new TextDecoder("gbk").decode(e)}function Z(e){let t=e.split(";").map(s=>s.trim()).filter(Boolean),n=[];for(let s of t){let o=s.indexOf("=");if(o<0)continue;let r=s.slice(0,o).trim();r.startsWith("v_")&&(r=r.slice(2));let i=s.slice(o+1).trim();i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1));let l=i.split("~");n.push({key:r,fields:l})}return n}function h(e){if(!e||e==="")return 0;let t=parseFloat(e);return Number.isNaN(t)?0:t}function C(e){if(!e||e==="")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function y(e){if(!e||e===""||e==="-")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function b(e){return e==null?null:y(String(e))}var Me="https://qt.gtimg.cn",_e="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Ee="https://assets.linkdiary.cn/shares/zh_a_list.json",xe="https://assets.linkdiary.cn/shares/us_list.json",Ie="https://assets.linkdiary.cn/shares/hk_list.json",ft="https://assets.linkdiary.cn/shares/trade-data-list.txt";var ee="https://push2his.eastmoney.com/api/qt/stock/kline/get",Ke="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Le="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Pe="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",we="https://17.push2.eastmoney.com/api/qt/clist/get",Ue="https://91.push2.eastmoney.com/api/qt/stock/get",De="https://29.push2.eastmoney.com/api/qt/clist/get",Be="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",ke="https://push2his.eastmoney.com/api/qt/stock/trends2/get",ve="https://79.push2.eastmoney.com/api/qt/clist/get",Ne="https://91.push2.eastmoney.com/api/qt/stock/get",He="https://29.push2.eastmoney.com/api/qt/clist/get",qe="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",je="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Qe="https://datacenter-web.eastmoney.com/api/data/v1/get",Fe=3e4,V=500,W=500,G=7,$e=3,Ve=1e3,We=3e4,Ge=2,ze=[408,429,500,502,503,504];var H=class extends Error{constructor(n,s,o,r){let i=s?` ${s}`:"",l=o?`, url: ${o}`:"",a=r?`, provider: ${r}`:"";super(`HTTP error! status: ${n}${i}${l}${a}`);this.status=n;this.statusText=s;this.url=o;this.provider=r;this.name="HttpError"}},z=class{constructor(t={}){this.baseUrl=t.baseUrl??Me,this.timeout=t.timeout??Fe,this.retryOptions=this.resolveRetryOptions(t.retry),this.headers={...t.headers??{}},t.userAgent&&(Object.keys(this.headers).some(s=>s.toLowerCase()==="user-agent")||(this.headers["User-Agent"]=t.userAgent))}resolveRetryOptions(t){return{maxRetries:t?.maxRetries??$e,baseDelay:t?.baseDelay??Ve,maxDelay:t?.maxDelay??We,backoffMultiplier:t?.backoffMultiplier??Ge,retryableStatusCodes:t?.retryableStatusCodes??ze,retryOnNetworkError:t?.retryOnNetworkError??!0,retryOnTimeout:t?.retryOnTimeout??!0,onRetry:t?.onRetry}}inferProvider(t){try{let n=new URL(t).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(t){return Math.min(this.retryOptions.baseDelay*Math.pow(this.retryOptions.backoffMultiplier,t),this.retryOptions.maxDelay)+Math.random()*100}sleep(t){return new Promise(n=>setTimeout(n,t))}shouldRetry(t,n){return n>=this.retryOptions.maxRetries?!1:t instanceof DOMException&&t.name==="AbortError"?this.retryOptions.retryOnTimeout:t instanceof TypeError?this.retryOptions.retryOnNetworkError:t instanceof H?this.retryOptions.retryableStatusCodes.includes(t.status):!1}async executeWithRetry(t,n=0){try{return await t()}catch(s){if(this.shouldRetry(s,n)){let o=this.calculateDelay(n);return this.retryOptions.onRetry&&s instanceof Error&&this.retryOptions.onRetry(n+1,s,o),await this.sleep(o),this.executeWithRetry(t,n+1)}throw s}}async get(t,n={}){return this.executeWithRetry(async()=>{let s=new AbortController,o=setTimeout(()=>s.abort(),this.timeout),r=this.inferProvider(t);try{let i=await fetch(t,{signal:s.signal,headers:{...this.headers}});if(!i.ok)throw new H(i.status,i.statusText,t,r);switch(n.responseType){case"json":return await i.json();case"arraybuffer":return await i.arrayBuffer();default:return await i.text()}}catch(i){throw i instanceof Error&&(i.url=t,i.provider=r),i}finally{clearTimeout(o)}})}async getTencentQuote(t){let n=`${this.baseUrl}/?q=${encodeURIComponent(t)}`,s=await this.get(n,{responseType:"arraybuffer"}),o=J(s);return Z(o)}};var Gt=new Set(["daily","weekly","monthly"]),zt=new Set(["1","5","15","30","60"]),Yt=new Set(["","qfq","hfq"]);function M(e,t){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new RangeError(`${t} must be a positive integer`)}function I(e){if(!Gt.has(e))throw new RangeError("period must be one of: daily, weekly, monthly")}function Y(e){if(!zt.has(e))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function _(e){if(!Yt.has(e))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function q(e,t){M(t,"chunkSize");let n=[];for(let s=0;s<e.length;s+=t)n.push(e.slice(s,s+t));return n}async function j(e,t){M(t,"concurrency");let n=[],s=[];for(let o of e){let r=Promise.resolve().then(()=>o()).then(i=>{n.push(i)});if(s.push(r),s.length>=t){await Promise.race(s);for(let i=s.length-1;i>=0;i--)await Promise.race([s[i].then(()=>"fulfilled"),Promise.resolve("pending")])==="fulfilled"&&s.splice(i,1)}}return await Promise.all(s),n}function te(e){return e.startsWith("sh")?"1":e.startsWith("sz")||e.startsWith("bj")?"0":e.startsWith("6")?"1":"0"}function K(e){return{daily:"101",weekly:"102",monthly:"103"}[e]}function E(e){return{"":"0",qfq:"1",hfq:"2"}[e]}var A={};pt(A,{getAShareCodeList:()=>Rt,getAllHKQuotesByCodes:()=>At,getAllQuotesByCodes:()=>bt,getAllUSQuotesByCodes:()=>Tt,getFullQuotes:()=>ne,getFundFlow:()=>mt,getFundQuotes:()=>gt,getHKCodeList:()=>St,getHKQuotes:()=>re,getPanelLargeOrder:()=>ht,getSimpleQuotes:()=>dt,getTodayTimeline:()=>yt,getTradingCalendar:()=>Ot,getUSCodeList:()=>Ct,getUSQuotes:()=>oe,parseFullQuote:()=>Ye,parseFundFlow:()=>Je,parseFundQuote:()=>nt,parseHKQuote:()=>et,parsePanelLargeOrder:()=>Ze,parseSimpleQuote:()=>Xe,parseUSQuote:()=>tt,search:()=>_t});function Ye(e){let t=[];for(let s=0;s<5;s++)t.push({price:h(e[9+s*2]),volume:h(e[10+s*2])});let n=[];for(let s=0;s<5;s++)n.push({price:h(e[19+s*2]),volume:h(e[20+s*2])});return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:h(e[3]),prevClose:h(e[4]),open:h(e[5]),volume:h(e[6]),outerVolume:h(e[7]),innerVolume:h(e[8]),bid:t,ask:n,time:e[30]??"",change:h(e[31]),changePercent:h(e[32]),high:h(e[33]),low:h(e[34]),volume2:h(e[36]),amount:h(e[37]),turnoverRate:C(e[38]),pe:C(e[39]),amplitude:C(e[43]),circulatingMarketCap:C(e[44]),totalMarketCap:C(e[45]),pb:C(e[46]),limitUp:C(e[47]),limitDown:C(e[48]),volumeRatio:C(e[49]),avgPrice:C(e[51]),peStatic:C(e[52]),peDynamic:C(e[53]),high52w:C(e[67]),low52w:C(e[68]),circulatingShares:C(e[72]),totalShares:C(e[73]),raw:e}}function Xe(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:h(e[3]),change:h(e[4]),changePercent:h(e[5]),volume:h(e[6]),amount:h(e[7]),marketCap:C(e[9]),marketType:e[10]??"",raw:e}}function Je(e){return{code:e[0]??"",mainInflow:h(e[1]),mainOutflow:h(e[2]),mainNet:h(e[3]),mainNetRatio:h(e[4]),retailInflow:h(e[5]),retailOutflow:h(e[6]),retailNet:h(e[7]),retailNetRatio:h(e[8]),totalFlow:h(e[9]),name:e[12]??"",date:e[13]??"",raw:e}}function Ze(e){return{buyLargeRatio:h(e[0]),buySmallRatio:h(e[1]),sellLargeRatio:h(e[2]),sellSmallRatio:h(e[3]),raw:e}}function et(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:h(e[3]),prevClose:h(e[4]),open:h(e[5]),volume:h(e[6]),time:e[30]??"",change:h(e[31]),changePercent:h(e[32]),high:h(e[33]),low:h(e[34]),amount:h(e[37]),lotSize:C(e[40]),circulatingMarketCap:C(e[44]),totalMarketCap:C(e[45]),currency:e[e.length-3]??"",raw:e}}function tt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:h(e[3]),prevClose:h(e[4]),open:h(e[5]),volume:h(e[6]),time:e[30]??"",change:h(e[31]),changePercent:h(e[32]),high:h(e[33]),low:h(e[34]),amount:h(e[37]),turnoverRate:C(e[38]),pe:C(e[39]),amplitude:C(e[43]),totalMarketCap:C(e[45]),pb:C(e[47]),high52w:C(e[48]),low52w:C(e[49]),raw:e}}function nt(e){return{code:e[0]??"",name:e[1]??"",nav:h(e[5]),accNav:h(e[6]),change:h(e[7]),navDate:e[8]??"",raw:e}}async function ne(e,t){return!t||t.length===0?[]:(await e.getTencentQuote(t.join(","))).filter(s=>s.fields&&s.fields.length>0&&s.fields[0]!=="").map(s=>Ye(s.fields))}async function dt(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`s_${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Xe(o.fields))}async function mt(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`ff_${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Je(o.fields))}async function ht(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`s_pk${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Ze(o.fields))}async function re(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`hk${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>et(o.fields))}async function oe(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`us${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>tt(o.fields))}async function gt(e,t){if(!t||t.length===0)return[];let n=t.map(o=>`jj${o}`);return(await e.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>nt(o.fields))}async function yt(e,t){let n=e.getTimeout(),s=new AbortController,o=setTimeout(()=>s.abort(),n);try{let r=await fetch(`${_e}?code=${t}`,{signal:s.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?.[t];if(!l)return{code:t,date:"",data:[]};let a=l.data?.data||[],u=l.data?.date||"",c=!1;if(a.length>0){let d=a[0].split(" "),m=parseFloat(d[1])||0,g=parseInt(d[2],10)||0,f=parseFloat(d[3])||0;g>0&&m>0&&f/g>m*50&&(c=!0)}let p=a.map(d=>{let m=d.split(" "),g=m[0],f=`${g.slice(0,2)}:${g.slice(2,4)}`,R=parseInt(m[2],10)||0,S=parseFloat(m[3])||0,O=c?R*100:R,x=O>0?S/O:0;return{time:f,price:parseFloat(m[1])||0,volume:O,amount:S,avgPrice:Math.round(x*100)/100}});return{code:t,date:u,data:p}}finally{clearTimeout(o)}}var rt=null,Xt=null,se=null,Jt=null,ie=null;function Zt(e,t){let n=e.replace(/^(sh|sz|bj)/,"");switch(t){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 Rt(e,t){let n=!1,s;if(typeof t=="boolean"?n=!t:t&&(n=t.simple??!1,s=t.market),!rt){let i=(await e.get(Ee,{responseType:"json"}))?.list||[];rt=i,Xt=i.map(l=>l.replace(/^(sh|sz|bj)/,""))}let o=rt;return s&&(o=o.filter(r=>Zt(r,s))),n?o.map(r=>r.replace(/^(sh|sz|bj)/,"")):o.slice()}var en={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function Ct(e,t){let n=!1,s;typeof t=="boolean"?n=!t:t&&(n=t.simple??!1,s=t.market),se||(se=(await e.get(xe,{responseType:"json"}))?.list||[],Jt=se.map(i=>i.replace(/^\d{3}\./,"")));let o=se.slice();if(s){let r=en[s];o=o.filter(i=>i.startsWith(r))}return n?o.map(r=>r.replace(/^\d{3}\./,"")):o}async function St(e){return ie||(ie=(await e.get(Ie,{responseType:"json"}))?.list||[]),ie.slice()}async function bt(e,t,n={}){let{batchSize:s=V,concurrency:o=G,onProgress:r}=n;M(s,"batchSize"),M(o,"concurrency");let i=Math.min(s,W),l=q(t,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await ne(e,d);return u++,r&&r(u,a),m});return(await j(c,o)).flat()}async function At(e,t,n={}){let{batchSize:s=V,concurrency:o=G,onProgress:r}=n;M(s,"batchSize"),M(o,"concurrency");let i=Math.min(s,W),l=q(t,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await re(e,d);return u++,r&&r(u,a),m});return(await j(c,o)).flat()}async function Tt(e,t,n={}){let{batchSize:s=V,concurrency:o=G,onProgress:r}=n;M(s,"batchSize"),M(o,"concurrency");let i=Math.min(s,W),l=q(t,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await oe(e,d);return u++,r&&r(u,a),m});return(await j(c,o)).flat()}var Q=null;async function Ot(e){if(Q)return Q.slice();let t=await e.get(ft);return!t||t.trim()===""?(Q=[],Q.slice()):(Q=t.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),Q.slice())}var Mt="https://smartbox.gtimg.cn/s3/";function tn(e){return e.replace(/\\u([0-9a-fA-F]{4})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function nn(e){return!e||e==="N"?[]:e.split("^").filter(Boolean).map(n=>{let s=n.split("~"),o=s[0]||"",r=s[1]||"",i=tn(s[2]||""),l=s[4]||"";return{code:o+r,name:i,market:o,type:l}})}function rn(e){return new Promise((t,n)=>{let s=`${Mt}?v=2&t=all&q=${encodeURIComponent(e)}`;window.v_hint="";let o=document.createElement("script");o.src=s,o.charset="utf-8",o.onload=()=>{let r=window.v_hint||"";document.body.removeChild(o),t(r)},o.onerror=()=>{document.body.removeChild(o),n(new Error("Network error calling Smartbox"))},document.body.appendChild(o)})}async function on(e,t){let n=`${Mt}?v=2&t=all&q=${encodeURIComponent(t)}`,o=(await e.get(n)).match(/v_hint="([^"]*)"/);return o?o[1]:""}function sn(){return typeof window<"u"&&typeof document<"u"}async function _t(e,t){if(!t||!t.trim())return[];let n;return sn()?n=await rn(t):n=await on(e,t),nn(n)}var T={};pt(T,{getConceptConstituents:()=>Bt,getConceptKline:()=>kt,getConceptList:()=>it,getConceptMinuteKline:()=>vt,getConceptSpot:()=>Dt,getDividendDetail:()=>Nt,getHKHistoryKline:()=>It,getHistoryKline:()=>Et,getIndustryConstituents:()=>Pt,getIndustryKline:()=>wt,getIndustryList:()=>st,getIndustryMinuteKline:()=>Ut,getIndustrySpot:()=>Lt,getMinuteKline:()=>xt,getUSHistoryKline:()=>Kt});async function ot(e,t,n,s,o=100,r){let i=[],l=1,a=0;do{let u=new URLSearchParams({...n,pn:String(l),pz:String(o),fields:s}),c=`${t}?${u.toString()}`,d=(await e.get(c,{responseType:"json"}))?.data;if(!d||!Array.isArray(d.diff))break;l===1&&(a=d.total??0);let m=d.diff.map((g,f)=>r(g,i.length+f+1));i.push(...m),l++}while(i.length<a);return i}function L(e){let[t,n,s,o,r,i,l,a,u,c,p]=e.split(",");return{date:t,open:y(n),close:y(s),high:y(o),low:y(r),volume:y(i),amount:y(l),amplitude:y(a),changePercent:y(u),change:y(c),turnoverRate:y(p)}}async function P(e,t,n){let s=`${t}?${n.toString()}`,o=await e.get(s,{responseType:"json"});return{klines:o?.data?.klines||[],name:o?.data?.name,code:o?.data?.code}}async function Et(e,t,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;I(s),_(o);let l=t.replace(/^(sh|sz|bj)/,""),a=`${te(t)}.${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:K(s),fqt:E(o),secid:a,beg:r,end:i}),c=ee,{klines:p}=await P(e,c,u);return p.length===0?[]:p.map(d=>({...L(d),code:l}))}async function xt(e,t,n={}){let{period:s="1",adjust:o="qfq",startDate:r="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=n;Y(s),_(o);let l=t.replace(/^(sh|sz|bj)/,""),a=`${te(t)}.${l}`;if(s==="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=`${Ke}?${u.toString()}`,d=(await e.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(d)||d.length===0)return[];let m=r.replace("T"," ").slice(0,16),g=i.replace("T"," ").slice(0,16);return d.map(f=>{let[R,S,O,x,$,U,N,Vt]=f.split(",");return{time:R,open:y(S),close:y(O),high:y(x),low:y($),volume:y(U),amount:y(N),avgPrice:y(Vt)}}).filter(f=>f.time>=m&&f.time<=g)}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:s,fqt:E(o||""),secid:a,beg:"0",end:"20500000"}),c=ee,{klines:p}=await P(e,c,u);if(p.length===0)return[];let d=r.replace("T"," ").slice(0,16),m=i.replace("T"," ").slice(0,16);return p.map(g=>{let f=L(g);return{...f,time:f.date}}).filter(g=>g.time>=d&&g.time<=m)}}async function It(e,t,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;I(s),_(o);let l=t.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:K(s),fqt:E(o),secid:a,beg:r,end:i,lmt:"1000000"}),c=Le,{klines:p,name:d}=await P(e,c,u);return p.length===0?[]:p.map(m=>({...L(m),code:l,name:d||""}))}async function Kt(e,t,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;I(s),_(o);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:K(s),fqt:E(o),secid:t,beg:r,end:i,lmt:"1000000"}),a=Pe,{klines:u,name:c,code:p}=await P(e,a,l),d=p||t.split(".")[1]||t,m=c||"";return u.length===0?[]:u.map(g=>({...L(g),code:d,name:m}))}function le(e){let t=null;return{async getCode(n,s,o){if(s.startsWith("BK"))return s;if(!t){let i=await o(n);t=new Map(i.map(l=>[l.name,l.code]))}let r=t.get(s);if(!r)throw new Error(`${e.errorPrefix}: ${s}`);return r}}}async function ae(e,t){let n={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:t.type==="concept"?"f12":"f3",fs:t.fsFilter},s=t.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",o=await ot(e,t.listUrl,n,s,100,(r,i)=>({rank:i,name:String(r.f14??""),code:String(r.f12??""),price:b(r.f2),change:b(r.f4),changePercent:b(r.f3),totalMarketCap:b(r.f20),turnoverRate:b(r.f8),riseCount:b(r.f104),fallCount:b(r.f105),leadingStock:r.f128?String(r.f128):null,leadingStockChangePercent:b(r.f136)}));return o.sort((r,i)=>(i.changePercent??0)-(r.changePercent??0)),o.forEach((r,i)=>{r.rank=i+1}),o}async function ue(e,t,n){let s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${t}`}),o=`${n}?${s.toString()}`,i=(await e.get(o,{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 p=i[a],d=null;return typeof p=="number"&&!isNaN(p)&&(d=c?p/100:p),{item:u,value:d}}):[]}async function ce(e,t,n){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${t} f:!50`};return ot(e,n,s,"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:b(r.f2),changePercent:b(r.f3),change:b(r.f4),volume:b(r.f5),amount:b(r.f6),amplitude:b(r.f7),high:b(r.f15),low:b(r.f16),open:b(r.f17),prevClose:b(r.f18),turnoverRate:b(r.f8),pe:b(r.f9),pb:b(r.f23)}))}async function pe(e,t,n,s={}){let{period:o="daily",adjust:r="",startDate:i="19700101",endDate:l="20500101"}=s;I(o),_(r);let a=new URLSearchParams({secid:`90.${t}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:K(o),fqt:E(r),beg:i,end:l,smplmt:"10000",lmt:"1000000"}),{klines:u}=await P(e,n,a);return u.length===0?[]:u.map(c=>L(c))}async function fe(e,t,n,s,o={}){let{period:r="5"}=o;if(Y(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.${t}`}),l=`${s}?${i.toString()}`,u=(await e.get(l,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[p,d,m,g,f,R,S,O]=c.split(",");return{time:p,open:y(d),close:y(m),high:y(g),low:y(f),volume:y(R),amount:y(S),price:y(O)}})}else{let i=new URLSearchParams({secid:`90.${t}`,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 e.get(l,{responseType:"json"}))?.data?.klines;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[p,d,m,g,f,R,S,O,x,$,U]=c.split(",");return{time:p,open:y(d),close:y(m),high:y(g),low:y(f),changePercent:y(x),change:y($),volume:y(R),amount:y(S),amplitude:y(O),turnoverRate:y(U)}})}}var D={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:we,spotUrl:Ue,consUrl:De,klineUrl:Be,trendsUrl:ke,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},ln=le(D);async function de(e,t){return ln.getCode(e,t,st)}async function st(e){return ae(e,D)}async function Lt(e,t){let n=await de(e,t);return ue(e,n,D.spotUrl)}async function Pt(e,t){let n=await de(e,t);return ce(e,n,D.consUrl)}async function wt(e,t,n={}){let s=await de(e,t);return pe(e,s,D.klineUrl,n)}async function Ut(e,t,n={}){let s=await de(e,t);return fe(e,s,D.klineUrl,D.trendsUrl,n)}var B={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:ve,spotUrl:Ne,consUrl:He,klineUrl:qe,trendsUrl:je,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},an=le(B);async function me(e,t){return an.getCode(e,t,it)}async function it(e){return ae(e,B)}async function Dt(e,t){let n=await me(e,t);return ue(e,n,B.spotUrl)}async function Bt(e,t){let n=await me(e,t);return ce(e,n,B.consUrl)}async function kt(e,t,n={}){let s=await me(e,t);return pe(e,s,B.klineUrl,n)}async function vt(e,t,n={}){let s=await me(e,t);return fe(e,s,B.klineUrl,B.trendsUrl,n)}function k(e){if(!e)return null;let t=e.match(/^(\d{4}-\d{2}-\d{2})/);return t?t[1]:null}function un(e){return{code:e.SECURITY_CODE??"",name:e.SECURITY_NAME_ABBR??"",reportDate:k(e.REPORT_DATE),planNoticeDate:k(e.PLAN_NOTICE_DATE),disclosureDate:k(e.PUBLISH_DATE??e.PLAN_NOTICE_DATE),assignTransferRatio:e.BONUS_IT_RATIO??null,bonusRatio:e.BONUS_RATIO??null,transferRatio:e.IT_RATIO??null,dividendPretax:e.PRETAX_BONUS_RMB??null,dividendDesc:e.IMPL_PLAN_PROFILE??null,dividendYield:e.DIVIDENT_RATIO??null,eps:e.BASIC_EPS??null,bps:e.BVPS??null,capitalReserve:e.PER_CAPITAL_RESERVE??null,unassignedProfit:e.PER_UNASSIGN_PROFIT??null,netProfitYoy:e.PNP_YOY_RATIO??null,totalShares:e.TOTAL_SHARES??null,equityRecordDate:k(e.EQUITY_RECORD_DATE),exDividendDate:k(e.EX_DIVIDEND_DATE),payDate:k(e.PAY_DATE),assignProgress:e.ASSIGN_PROGRESS??null,noticeDate:k(e.NOTICE_DATE)}}async function Nt(e,t){let n=t.replace(/^(sh|sz|bj)/,""),s=[],o=1,r=1;do{let i=new URLSearchParams({sortColumns:"REPORT_DATE",sortTypes:"-1",pageSize:"500",pageNumber:String(o),reportName:"RPT_SHAREBONUS_DET",columns:"ALL",quoteColumns:"",source:"WEB",client:"WEB",filter:`(SECURITY_CODE="${n}")`}),l=`${Qe}?${i.toString()}`,u=(await e.get(l,{responseType:"json"}))?.result;if(!u||!Array.isArray(u.data))break;o===1&&(r=u.pages??1);let c=u.data.map(un);s.push(...c),o++}while(o<=r);return s}function X(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function v(e,t){let n=[];for(let s=0;s<e.length;s++){if(s<t-1){n.push(null);continue}let o=0,r=0;for(let i=s-t+1;i<=s;i++)e[i]!==null&&(o+=e[i],r++);n.push(r===t?X(o/t):null)}return n}function w(e,t){let n=[],s=2/(t+1),o=null,r=!1;for(let i=0;i<e.length;i++){if(i<t-1){n.push(null);continue}if(!r){let a=0,u=0;for(let c=i-t+1;c<=i;c++)e[c]!==null&&(a+=e[c],u++);u===t&&(o=a/t,r=!0),n.push(o!==null?X(o):null);continue}let l=e[i];l===null?n.push(o!==null?X(o):null):(o=s*l+(1-s)*o,n.push(X(o)))}return n}function lt(e,t){let n=[],s=Array.from({length:t},(r,i)=>i+1),o=s.reduce((r,i)=>r+i,0);for(let r=0;r<e.length;r++){if(r<t-1){n.push(null);continue}let i=0,l=!0;for(let a=0;a<t;a++){let u=e[r-t+1+a];if(u===null){l=!1;break}i+=u*s[a]}n.push(l?X(i/o):null)}return n}function he(e,t={}){let{periods:n=[5,10,20,30,60,120,250],type:s="sma"}=t,o=s==="ema"?w:s==="wma"?lt:v,r={};for(let i of n)r[`ma${i}`]=o(e,i);return e.map((i,l)=>{let a={};for(let u of n)a[`ma${u}`]=r[`ma${u}`][l];return a})}function Ht(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function ge(e,t={}){let{short:n=12,long:s=26,signal:o=9}=t,r=w(e,n),i=w(e,s),l=e.map((u,c)=>r[c]===null||i[c]===null?null:r[c]-i[c]),a=w(l,o);return e.map((u,c)=>({dif:l[c]!==null?Ht(l[c]):null,dea:a[c],macd:l[c]!==null&&a[c]!==null?Ht((l[c]-a[c])*2):null}))}function at(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function cn(e,t,n){let s=[];for(let o=0;o<e.length;o++){if(o<t-1||n[o]===null){s.push(null);continue}let r=0,i=0;for(let l=o-t+1;l<=o;l++)e[l]!==null&&n[o]!==null&&(r+=Math.pow(e[l]-n[o],2),i++);s.push(i===t?Math.sqrt(r/t):null)}return s}function ye(e,t={}){let{period:n=20,stdDev:s=2}=t,o=v(e,n),r=cn(e,n,o);return e.map((i,l)=>{if(o[l]===null||r[l]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let a=o[l]+s*r[l],u=o[l]-s*r[l],c=o[l]!==0?at((a-u)/o[l]*100):null;return{mid:o[l],upper:at(a),lower:at(u),bandwidth:c}})}function ut(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function Re(e,t={}){let{period:n=9,kPeriod:s=3,dPeriod:o=3}=t,r=[],i=50,l=50;for(let a=0;a<e.length;a++){if(a<n-1){r.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,p=!0;for(let f=a-n+1;f<=a;f++){if(e[f].high===null||e[f].low===null){p=!1;break}u=Math.max(u,e[f].high),c=Math.min(c,e[f].low)}let d=e[a].close;if(!p||d===null||u===c){r.push({k:null,d:null,j:null});continue}let m=(d-c)/(u-c)*100;i=(s-1)/s*i+1/s*m,l=(o-1)/o*l+1/o*i;let g=3*i-2*l;r.push({k:ut(i),d:ut(l),j:ut(g)})}return r}function pn(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function Ce(e,t={}){let{periods:n=[6,12,24]}=t,s=[null];for(let r=1;r<e.length;r++)e[r]===null||e[r-1]===null?s.push(null):s.push(e[r]-e[r-1]);let o={};for(let r of n){let i=[],l=0,a=0;for(let u=0;u<e.length;u++){if(u<r){i.push(null),s[u]!==null&&(s[u]>0?l+=s[u]:a+=Math.abs(s[u]));continue}if(u===r)l=l/r,a=a/r;else{let c=s[u]??0,p=c>0?c:0,d=c<0?Math.abs(c):0;l=(l*(r-1)+p)/r,a=(a*(r-1)+d)/r}if(a===0)i.push(100);else if(l===0)i.push(0);else{let c=l/a;i.push(pn(100-100/(1+c)))}}o[`rsi${r}`]=i}return e.map((r,i)=>{let l={};for(let a of n)l[`rsi${a}`]=o[`rsi${a}`][i];return l})}function fn(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function Se(e,t={}){let{periods:n=[6,10]}=t,s={};for(let o of n){let r=[];for(let i=0;i<e.length;i++){if(i<o-1){r.push(null);continue}let l=-1/0,a=1/0,u=!0;for(let d=i-o+1;d<=i;d++){if(e[d].high===null||e[d].low===null){u=!1;break}l=Math.max(l,e[d].high),a=Math.min(a,e[d].low)}let c=e[i].close;if(!u||c===null||l===a){r.push(null);continue}let p=(l-c)/(l-a)*100;r.push(fn(p))}s[`wr${o}`]=r}return e.map((o,r)=>{let i={};for(let l of n)i[`wr${l}`]=s[`wr${l}`][r];return i})}function dn(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function be(e,t={}){let{periods:n=[6,12,24]}=t,s={};for(let o of n){let r=v(e,o),i=[];for(let l=0;l<e.length;l++)if(e[l]===null||r[l]===null||r[l]===0)i.push(null);else{let a=(e[l]-r[l])/r[l]*100;i.push(dn(a))}s[`bias${o}`]=i}return e.map((o,r)=>{let i={};for(let l of n)i[`bias${l}`]=s[`bias${l}`][r];return i})}function mn(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function Ae(e,t={}){let{period:n=14}=t,s=[],o=e.map(r=>r.high===null||r.low===null||r.close===null?null:(r.high+r.low+r.close)/3);for(let r=0;r<e.length;r++){if(r<n-1){s.push({cci:null});continue}let i=0,l=0;for(let p=r-n+1;p<=r;p++)o[p]!==null&&(i+=o[p],l++);if(l!==n||o[r]===null){s.push({cci:null});continue}let a=i/n,u=0;for(let p=r-n+1;p<=r;p++)u+=Math.abs(o[p]-a);let c=u/n;if(c===0)s.push({cci:0});else{let p=(o[r]-a)/(.015*c);s.push({cci:mn(p)})}}return s}function ct(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function F(e,t={}){let{period:n=14}=t,s=[],o=[];for(let i=0;i<e.length;i++){let{high:l,low:a,close:u}=e[i];if(l===null||a===null||u===null){o.push(null);continue}if(i===0)o.push(l-a);else{let c=e[i-1].close;if(c===null)o.push(l-a);else{let p=l-a,d=Math.abs(l-c),m=Math.abs(a-c);o.push(Math.max(p,d,m))}}}let r=null;for(let i=0;i<e.length;i++){if(i<n-1){s.push({tr:o[i]!==null?ct(o[i]):null,atr:null});continue}if(i===n-1){let l=0,a=0;for(let u=0;u<n;u++)o[u]!==null&&(l+=o[u],a++);a===n&&(r=l/n)}else r!==null&&o[i]!==null&&(r=(r*(n-1)+o[i])/n);s.push({tr:o[i]!==null?ct(o[i]):null,atr:r!==null?ct(r):null})}return s}function qt(e,t={}){let{maPeriod:n}=t,s=[];if(e.length===0)return s;let o=e[0].volume??0;s.push({obv:o,obvMa:null});for(let r=1;r<e.length;r++){let i=e[r],l=e[r-1];if(i.close===null||l.close===null||i.volume===null||i.volume===void 0){s.push({obv:null,obvMa:null});continue}i.close>l.close?o+=i.volume:i.close<l.close&&(o-=i.volume),s.push({obv:o,obvMa:null})}if(n&&n>0)for(let r=n-1;r<s.length;r++){let i=0,l=0;for(let a=r-n+1;a<=r;a++)s[a].obv!==null&&(i+=s[a].obv,l++);l===n&&(s[r].obvMa=i/n)}return s}function jt(e,t={}){let{period:n=12,signalPeriod:s}=t,o=[];for(let r=0;r<e.length;r++){if(r<n){o.push({roc:null,signal:null});continue}let i=e[r].close,l=e[r-n].close;if(i===null||l===null||l===0){o.push({roc:null,signal:null});continue}let a=(i-l)/l*100;o.push({roc:a,signal:null})}if(s&&s>0)for(let r=n+s-1;r<o.length;r++){let i=0,l=0;for(let a=r-s+1;a<=r;a++)o[a].roc!==null&&(i+=o[a].roc,l++);l===s&&(o[r].signal=i/s)}return o}function Qt(e,t={}){let{period:n=14,adxPeriod:s=n}=t,o=[];if(e.length<2)return e.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let r=[],i=[],l=[];for(let f=0;f<e.length;f++){if(f===0){r.push(0),i.push(0),l.push(0),o.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let R=e[f],S=e[f-1];if(R.high===null||R.low===null||R.close===null||S.high===null||S.low===null||S.close===null){r.push(0),i.push(0),l.push(0),o.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let O=R.high-R.low,x=Math.abs(R.high-S.close),$=Math.abs(R.low-S.close);l.push(Math.max(O,x,$));let U=R.high-S.high,N=S.low-R.low;U>N&&U>0?r.push(U):r.push(0),N>U&&N>0?i.push(N):i.push(0),o.push({pdi:null,mdi:null,adx:null,adxr:null})}let a=0,u=0,c=0,p=[];for(let f=1;f<e.length;f++){if(f<n){a+=l[f],u+=r[f],c+=i[f],p.push(0);continue}f===n?(a=a,u=u,c=c):(a=a-a/n+l[f],u=u-u/n+r[f],c=c-c/n+i[f]);let R=a>0?u/a*100:0,S=a>0?c/a*100:0;o[f].pdi=R,o[f].mdi=S;let O=R+S,x=O>0?Math.abs(R-S)/O*100:0;p.push(x)}let d=0,m=0,g=0;for(let f=n;f<e.length;f++){if(f<n*2-1){d+=p[f-n+1]||0,m++;continue}if(f===n*2-1)d+=p[f-n+1]||0,g=d/s,o[f].adx=g;else{let R=p[f-n+1]||0;g=(g*(s-1)+R)/s,o[f].adx=g}}for(let f=n*2-1+s;f<e.length;f++){let R=o[f].adx,S=o[f-s]?.adx;R!==null&&S!==null&&(o[f].adxr=(R+S)/2)}return o}function Ft(e,t={}){let{afStart:n=.02,afIncrement:s=.02,afMax:o=.2}=t,r=[];if(e.length<2)return e.map(()=>({sar:null,trend:null,ep:null,af:null}));let i=1,l=n,a=e[0].high??0,u=e[0].low??0,c=e[0],p=e[1];c.close!==null&&p.close!==null&&p.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 d=1;d<e.length;d++){let m=e[d],g=e[d-1];if(m.high===null||m.low===null||g.high===null||g.low===null){r.push({sar:null,trend:null,ep:null,af:null});continue}let f=u+l*(a-u);i===1?(f=Math.min(f,g.low,e[Math.max(0,d-2)]?.low??g.low),m.low<f?(i=-1,f=a,a=m.low,l=n):m.high>a&&(a=m.high,l=Math.min(l+s,o))):(f=Math.max(f,g.high,e[Math.max(0,d-2)]?.high??g.high),m.high>f?(i=1,f=a,a=m.high,l=n):m.low<a&&(a=m.low,l=Math.min(l+s,o))),u=f,r.push({sar:u,trend:i,ep:a,af:l})}return r}function $t(e,t={}){let{emaPeriod:n=20,atrPeriod:s=10,multiplier:o=2}=t,r=[],i=e.map(u=>u.close),l=w(i,n),a=F(e,{period:s});for(let u=0;u<e.length;u++){let c=l[u],p=a[u]?.atr;if(c===null||p===null){r.push({mid:null,upper:null,lower:null,width:null});continue}let d=c+o*p,m=c-o*p,g=c>0?(d-m)/c*100:null;r.push({mid:c,upper:d,lower:m,width:g})}return r}function Te(e,t={}){if(e.length===0)return[];let n=e.map(m=>m.close),s=e.map(m=>({open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume})),o=t.ma?he(n,typeof t.ma=="object"?t.ma:{}):null,r=t.macd?ge(n,typeof t.macd=="object"?t.macd:{}):null,i=t.boll?ye(n,typeof t.boll=="object"?t.boll:{}):null,l=t.kdj?Re(s,typeof t.kdj=="object"?t.kdj:{}):null,a=t.rsi?Ce(n,typeof t.rsi=="object"?t.rsi:{}):null,u=t.wr?Se(s,typeof t.wr=="object"?t.wr:{}):null,c=t.bias?be(n,typeof t.bias=="object"?t.bias:{}):null,p=t.cci?Ae(s,typeof t.cci=="object"?t.cci:{}):null,d=t.atr?F(s,typeof t.atr=="object"?t.atr:{}):null;return e.map((m,g)=>({...m,...o&&{ma:o[g]},...r&&{macd:r[g]},...i&&{boll:i[g]},...l&&{kdj:l[g]},...a&&{rsi:a[g]},...u&&{wr:u[g]},...c&&{bias:c[g]},...p&&{cci:p[g]},...d&&{atr:d[g]}}))}var Oe=class{constructor(t={}){this.client=new z(t)}getFullQuotes(t){return A.getFullQuotes(this.client,t)}getSimpleQuotes(t){return A.getSimpleQuotes(this.client,t)}getHKQuotes(t){return A.getHKQuotes(this.client,t)}getUSQuotes(t){return A.getUSQuotes(this.client,t)}getFundQuotes(t){return A.getFundQuotes(this.client,t)}getFundFlow(t){return A.getFundFlow(this.client,t)}getPanelLargeOrder(t){return A.getPanelLargeOrder(this.client,t)}getTodayTimeline(t){return A.getTodayTimeline(this.client,t)}getIndustryList(){return T.getIndustryList(this.client)}getIndustrySpot(t){return T.getIndustrySpot(this.client,t)}getIndustryConstituents(t){return T.getIndustryConstituents(this.client,t)}getIndustryKline(t,n){return T.getIndustryKline(this.client,t,n)}getIndustryMinuteKline(t,n){return T.getIndustryMinuteKline(this.client,t,n)}getConceptList(){return T.getConceptList(this.client)}getConceptSpot(t){return T.getConceptSpot(this.client,t)}getConceptConstituents(t){return T.getConceptConstituents(this.client,t)}getConceptKline(t,n){return T.getConceptKline(this.client,t,n)}getConceptMinuteKline(t,n){return T.getConceptMinuteKline(this.client,t,n)}getHistoryKline(t,n){return T.getHistoryKline(this.client,t,n)}getMinuteKline(t,n){return T.getMinuteKline(this.client,t,n)}getHKHistoryKline(t,n){return T.getHKHistoryKline(this.client,t,n)}getUSHistoryKline(t,n){return T.getUSHistoryKline(this.client,t,n)}search(t){return A.search(this.client,t)}getAShareCodeList(t){return A.getAShareCodeList(this.client,t)}getUSCodeList(t){return A.getUSCodeList(this.client,t)}getHKCodeList(){return A.getHKCodeList(this.client)}async getAllAShareQuotes(t={}){let{market:n,...s}=t,o=await this.getAShareCodeList({market:n});return this.getAllQuotesByCodes(o,s)}async getAllHKShareQuotes(t={}){let n=await this.getHKCodeList();return A.getAllHKQuotesByCodes(this.client,n,t)}async getAllUSShareQuotes(t={}){let{market:n,...s}=t,o=await this.getUSCodeList({simple:!0,market:n});return A.getAllUSQuotesByCodes(this.client,o,s)}getAllQuotesByCodes(t,n={}){return A.getAllQuotesByCodes(this.client,t,n)}async batchRaw(t){return this.client.getTencentQuote(t)}getTradingCalendar(){return A.getTradingCalendar(this.client)}getDividendDetail(t){return T.getDividendDetail(this.client,t)}detectMarket(t){return/^\d{3}\.[A-Z]+$/i.test(t)?"US":/^\d{5}$/.test(t)?"HK":"A"}safeMax(t,n=0){return!t||t.length===0?n:Math.max(...t)}calcRequiredLookback(t){let n=0,s=!1;if(t.ma){let r=typeof t.ma=="object"?t.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"&&(s=!0)}if(t.macd){let r=typeof t.macd=="object"?t.macd:{},i=r.long??26,l=r.signal??9;n=Math.max(n,i*3+l),s=!0}if(t.boll){let r=typeof t.boll=="object"&&t.boll.period?t.boll.period:20;n=Math.max(n,r)}if(t.kdj){let r=typeof t.kdj=="object"&&t.kdj.period?t.kdj.period:9;n=Math.max(n,r)}if(t.rsi){let r=typeof t.rsi=="object"&&t.rsi.periods?t.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(r,14)+1)}if(t.wr){let r=typeof t.wr=="object"&&t.wr.periods?t.wr.periods:[6,10];n=Math.max(n,this.safeMax(r,10))}if(t.bias){let r=typeof t.bias=="object"&&t.bias.periods?t.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(r,12))}if(t.cci){let r=typeof t.cci=="object"&&t.cci.period?t.cci.period:14;n=Math.max(n,r)}if(t.atr){let r=typeof t.atr=="object"&&t.atr.period?t.atr.period:14;n=Math.max(n,r)}return Math.ceil(n*(s?1.5:1.2))}calcActualStartDate(t,n,s=1.5){let o=Math.ceil(n*s),r=new Date(parseInt(t.slice(0,4)),parseInt(t.slice(4,6))-1,parseInt(t.slice(6,8)));r.setDate(r.getDate()-o);let i=r.getFullYear(),l=String(r.getMonth()+1).padStart(2,"0"),a=String(r.getDate()).padStart(2,"0");return`${i}${l}${a}`}calcActualStartDateByCalendar(t,n,s){if(!s||s.length===0)return;let o=this.normalizeDate(t),r=s.findIndex(l=>l>=o);r===-1&&(r=s.length-1);let i=Math.max(0,r-n);return this.toCompactDate(s[i])}normalizeDate(t){return t.includes("-")?t:t.length===8?`${t.slice(0,4)}-${t.slice(4,6)}-${t.slice(6,8)}`:t}toCompactDate(t){return t.replace(/-/g,"")}dateToTimestamp(t){let n=t.includes("-")?t:`${t.slice(0,4)}-${t.slice(4,6)}-${t.slice(6,8)}`;return new Date(n).getTime()}async getKlineWithIndicators(t,n={}){let{startDate:s,endDate:o,indicators:r={}}=n,i=n.market??this.detectMarket(t),l=this.calcRequiredLookback(r),a={A:1.5,HK:1.46,US:1.45},u;if(s)if(i==="A")try{let m=await A.getTradingCalendar(this.client);u=this.calcActualStartDateByCalendar(s,l,m)??this.calcActualStartDate(s,l,a[i])}catch{u=this.calcActualStartDate(s,l,a[i])}else u=this.calcActualStartDate(s,l,a[i]);let c={period:n.period,adjust:n.adjust,startDate:u,endDate:n.endDate},p;switch(i){case"HK":p=await this.getHKHistoryKline(t,c);break;case"US":p=await this.getUSHistoryKline(t,c);break;default:p=await this.getHistoryKline(t,c)}if(s&&p.length<l)switch(i){case"HK":p=await this.getHKHistoryKline(t,{...c,startDate:void 0});break;case"US":p=await this.getUSHistoryKline(t,{...c,startDate:void 0});break;default:p=await this.getHistoryKline(t,{...c,startDate:void 0})}let d=Te(p,r);if(s){let m=this.dateToTimestamp(s),g=o?this.dateToTimestamp(o):1/0;return d.filter(f=>{let R=this.dateToTimestamp(f.date);return R>=m&&R<=g})}return d}},hn=Oe;export{H as HttpError,Oe as StockSDK,Te as addIndicators,j as asyncPool,F as calcATR,be as calcBIAS,ye as calcBOLL,Ae as calcCCI,Qt as calcDMI,w as calcEMA,$t as calcKC,Re as calcKDJ,he as calcMA,ge as calcMACD,qt as calcOBV,jt as calcROC,Ce as calcRSI,Ft as calcSAR,v as calcSMA,lt as calcWMA,Se as calcWR,q as chunkArray,J as decodeGBK,hn as default,Z as parseResponse,h as safeNumber,C as safeNumberOrNull};
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "stock-sdk",
3
- "version": "1.4.5",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsup",
10
+ "test": "vitest run",
11
+ "test:unit": "vitest run",
12
+ "test:integration": "RUN_INTEGRATION=1 vitest run",
13
+ "dev": "vitepress dev website",
14
+ "preview": "vitepress preview website",
15
+ "build:docs": "DOCS_BASE=/ vitepress build website",
16
+ "build:pages": "DOCS_BASE=/stock-sdk/ vitepress build website"
17
+ },
8
18
  "exports": {
9
19
  ".": {
10
20
  "import": {
@@ -21,16 +31,6 @@
21
31
  "dist"
22
32
  ],
23
33
  "sideEffects": false,
24
- "scripts": {
25
- "build": "tsup",
26
- "test": "vitest run",
27
- "test:unit": "vitest run",
28
- "test:integration": "RUN_INTEGRATION=1 vitest run",
29
- "dev": "vitepress dev website",
30
- "preview": "vitepress preview website",
31
- "build:docs": "DOCS_BASE=/ vitepress build website",
32
- "build:pages": "DOCS_BASE=/stock-sdk/ vitepress build website"
33
- },
34
34
  "keywords": [
35
35
  "JavaScript",
36
36
  "TypeScript",