stock-sdk 1.4.5 → 1.5.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.cjs +1 -1
- package/dist/index.d.cts +449 -6
- package/dist/index.d.ts +449 -6
- package/dist/index.js +1 -1
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var xe=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var Ft=Object.getOwnPropertyNames;var $t=Object.prototype.hasOwnProperty;var Le=(t,e)=>{for(var n in e)xe(t,n,{get:e[n],enumerable:!0})},Wt=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ft(e))!$t.call(t,r)&&r!==n&&xe(t,r,{get:()=>e[r],enumerable:!(s=Qt(e,r))||s.enumerable});return t};var zt=t=>Wt(xe({},"__esModule",{value:!0}),t);var cn={};Le(cn,{HttpError:()=>B,StockSDK:()=>ae,addIndicators:()=>ie,asyncPool:()=>k,calcATR:()=>se,calcBIAS:()=>re,calcBOLL:()=>Z,calcCCI:()=>oe,calcEMA:()=>U,calcKDJ:()=>ee,calcMA:()=>J,calcMACD:()=>X,calcRSI:()=>te,calcSMA:()=>E,calcWMA:()=>Me,calcWR:()=>ne,chunkArray:()=>P,decodeGBK:()=>v,default:()=>Nt,parseResponse:()=>j,safeNumber:()=>f,safeNumberOrNull:()=>y});module.exports=zt(cn);function v(t){return new TextDecoder("gbk").decode(t)}function j(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 Oe="https://qt.gtimg.cn",we="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Ie="https://assets.linkdiary.cn/shares/zh_a_list.json",Ee="https://assets.linkdiary.cn/shares/us_list.json",Ue="https://assets.linkdiary.cn/shares/hk_list.json",ft="https://assets.linkdiary.cn/shares/trade-data-list.txt";var le="https://push2his.eastmoney.com/api/qt/stock/kline/get",Be="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Pe="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",ke="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",De="https://17.push2.eastmoney.com/api/qt/clist/get",qe="https://91.push2.eastmoney.com/api/qt/stock/get",He="https://29.push2.eastmoney.com/api/qt/clist/get",Ne="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",ve="https://push2his.eastmoney.com/api/qt/stock/trends2/get",je="https://79.push2.eastmoney.com/api/qt/clist/get",Qe="https://91.push2.eastmoney.com/api/qt/stock/get",Fe="https://29.push2.eastmoney.com/api/qt/clist/get",$e="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",We="https://push2his.eastmoney.com/api/qt/stock/trends2/get",ze=3e4,Q=500,F=500,$=7,Ge=3,Ve=1e3,Ye=3e4,Je=2,Xe=[408,429,500,502,503,504];var B=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"}},W=class{constructor(e={}){this.baseUrl=e.baseUrl??Oe,this.timeout=e.timeout??ze,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??Ge,baseDelay:e?.baseDelay??Ve,maxDelay:e?.maxDelay??Ye,backoffMultiplier:e?.backoffMultiplier??Je,retryableStatusCodes:e?.retryableStatusCodes??Xe,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{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 B(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 j(r)}};var Gt=new Set(["daily","weekly","monthly"]),Vt=new Set(["1","5","15","30","60"]),Yt=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(!Gt.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function z(t){if(!Vt.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function M(t){if(!Yt.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function P(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 k(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 ue(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={};Le(b,{getAShareCodeList:()=>Ct,getAllHKQuotesByCodes:()=>Tt,getAllQuotesByCodes:()=>St,getAllUSQuotesByCodes:()=>Kt,getFullQuotes:()=>ce,getFundFlow:()=>mt,getFundQuotes:()=>ht,getHKCodeList:()=>bt,getHKQuotes:()=>pe,getPanelLargeOrder:()=>gt,getSimpleQuotes:()=>dt,getTodayTimeline:()=>yt,getTradingCalendar:()=>Mt,getUSCodeList:()=>Rt,getUSQuotes:()=>fe,parseFullQuote:()=>Ze,parseFundFlow:()=>tt,parseFundQuote:()=>st,parseHKQuote:()=>rt,parsePanelLargeOrder:()=>nt,parseSimpleQuote:()=>et,parseUSQuote:()=>ot,search:()=>_t});function Ze(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 et(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 tt(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 nt(t){return{buyLargeRatio:f(t[0]),buySmallRatio:f(t[1]),sellLargeRatio:f(t[2]),sellSmallRatio:f(t[3]),raw:t}}function rt(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 ot(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 st(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 ce(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=>Ze(s.fields))}async function dt(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=>et(r.fields))}async function mt(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=>tt(r.fields))}async function gt(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=>nt(r.fields))}async function pe(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=>rt(r.fields))}async function fe(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=>ot(r.fields))}async function ht(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=>st(r.fields))}async function yt(t,e){let n=t.getTimeout(),s=new AbortController,r=setTimeout(()=>s.abort(),n);try{let o=await fetch(`${we}?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 de=null,G=null,me=null,V=null,ge=null;async function Ct(t,e=!0){if(de)return e?de.slice():(G||(G=de.map(r=>r.replace(/^(sh|sz|bj)/,""))),G.slice());let s=(await t.get(Ie,{responseType:"json"}))?.list||[];return de=s,G=s.map(r=>r.replace(/^(sh|sz|bj)/,"")),e?s.slice():G.slice()}async function Rt(t,e=!0){if(me)return e?me.slice():(V||(V=me.map(r=>r.replace(/^\d{3}\./,""))),V.slice());let s=(await t.get(Ee,{responseType:"json"}))?.list||[];return me=s,V=s.map(r=>r.replace(/^\d{3}\./,"")),e?s.slice():V.slice()}async function bt(t){return ge||(ge=(await t.get(Ue,{responseType:"json"}))?.list||[]),ge.slice()}async function St(t,e,n={}){let{batchSize:s=Q,concurrency:r=$,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,F),a=P(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await ce(t,d);return u++,o&&o(u,l),m});return(await k(c,r)).flat()}async function Tt(t,e,n={}){let{batchSize:s=Q,concurrency:r=$,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,F),a=P(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await pe(t,d);return u++,o&&o(u,l),m});return(await k(c,r)).flat()}async function Kt(t,e,n={}){let{batchSize:s=Q,concurrency:r=$,onProgress:o}=n;K(s,"batchSize"),K(r,"concurrency");let i=Math.min(s,F),a=P(e,i),l=a.length,u=0,c=a.map(d=>async()=>{let m=await fe(t,d);return u++,o&&o(u,l),m});return(await k(c,r)).flat()}var H=null;async function Mt(t){if(H)return H.slice();let e=await t.get(ft);return!e||e.trim()===""?(H=[],H.slice()):(H=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),H.slice())}var At="https://smartbox.gtimg.cn/s3/";function Jt(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function Xt(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let s=n.split("~"),r=s[0]||"",o=s[1]||"",i=Jt(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=`${At}?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 en(t,e){let n=`${At}?v=2&t=all&q=${encodeURIComponent(e)}`,r=(await t.get(n)).match(/v_hint="([^"]*)"/);return r?r[1]:""}function tn(){return typeof window<"u"&&typeof document<"u"}async function _t(t,e){if(!e||!e.trim())return[];let n;return tn()?n=await Zt(e):n=await en(t,e),Xt(n)}var S={};Le(S,{getConceptConstituents:()=>kt,getConceptKline:()=>Dt,getConceptList:()=>lt,getConceptMinuteKline:()=>qt,getConceptSpot:()=>Pt,getHKHistoryKline:()=>Ot,getHistoryKline:()=>xt,getIndustryConstituents:()=>Et,getIndustryKline:()=>Ut,getIndustryList:()=>at,getIndustryMinuteKline:()=>Bt,getIndustrySpot:()=>It,getMinuteKline:()=>Lt,getUSHistoryKline:()=>wt});async function it(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 xt(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=`${ue(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=le,{klines:p}=await w(t,c,u);return p.length===0?[]:p.map(d=>({...O(d),code:a}))}async function Lt(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;z(s),M(r);let a=e.replace(/^(sh|sz|bj)/,""),l=`${ue(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=`${Be}?${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,Ae,_e,vt,jt]=C.split(",");return{time:T,open:g(I),close:g(_),high:g(N),low:g(Ae),volume:g(_e),amount:g(vt),avgPrice:g(jt)}}).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=le,{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 Ot(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=Pe,{klines:p,name:d}=await w(t,c,u);return p.length===0?[]:p.map(m=>({...O(m),code:a,name:d||""}))}async function wt(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=ke,{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 he(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 ye(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 it(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 Ce(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 Re(t,e,n){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return it(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 be(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 Se(t,e,n,s,r={}){let{period:o="5"}=r;if(z(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,Ae,_e]=c.split(",");return{time:p,open:g(d),close:g(m),high:g(h),low:g(C),changePercent:g(N),change:g(Ae),volume:g(T),amount:g(I),amplitude:g(_),turnoverRate:g(_e)}})}}var D={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:De,spotUrl:qe,consUrl:He,klineUrl:Ne,trendsUrl:ve,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},nn=he(D);async function Te(t,e){return nn.getCode(t,e,at)}async function at(t){return ye(t,D)}async function It(t,e){let n=await Te(t,e);return Ce(t,n,D.spotUrl)}async function Et(t,e){let n=await Te(t,e);return Re(t,n,D.consUrl)}async function Ut(t,e,n={}){let s=await Te(t,e);return be(t,s,D.klineUrl,n)}async function Bt(t,e,n={}){let s=await Te(t,e);return Se(t,s,D.klineUrl,D.trendsUrl,n)}var q={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:je,spotUrl:Qe,consUrl:Fe,klineUrl:$e,trendsUrl:We,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},rn=he(q);async function Ke(t,e){return rn.getCode(t,e,lt)}async function lt(t){return ye(t,q)}async function Pt(t,e){let n=await Ke(t,e);return Ce(t,n,q.spotUrl)}async function kt(t,e){let n=await Ke(t,e);return Re(t,n,q.consUrl)}async function Dt(t,e,n={}){let s=await Ke(t,e);return be(t,s,q.klineUrl,n)}async function qt(t,e,n={}){let s=await Ke(t,e);return Se(t,s,q.klineUrl,q.trendsUrl,n)}function Y(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function E(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?Y(r/e):null)}return n}function U(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?Y(r):null);continue}let a=t[i];a===null?n.push(r!==null?Y(r):null):(r=s*a+(1-s)*r,n.push(Y(r)))}return n}function Me(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?Y(i/r):null)}return n}function J(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:s="sma"}=e,r=s==="ema"?U:s==="wma"?Me:E,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 Ht(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function X(t,e={}){let{short:n=12,long:s=26,signal:r=9}=e,o=U(t,n),i=U(t,s),a=t.map((u,c)=>o[c]===null||i[c]===null?null:o[c]-i[c]),l=U(a,r);return t.map((u,c)=>({dif:a[c]!==null?Ht(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?Ht((a[c]-l[c])*2):null}))}function ut(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function on(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 Z(t,e={}){let{period:n=20,stdDev:s=2}=e,r=E(t,n),o=on(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?ut((l-u)/r[a]*100):null;return{mid:r[a],upper:ut(l),lower:ut(u),bandwidth:c}})}function ct(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ee(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:ct(i),d:ct(a),j:ct(h)})}return o}function sn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function te(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(sn(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 an(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ne(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(an(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 ln(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=E(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(ln(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 un(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function oe(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:un(p)})}}return s}function pt(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?pt(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?pt(r[i]):null,atr:o!==null?pt(o):null})}return s}function ie(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?J(n,typeof e.ma=="object"?e.ma:{}):null,o=e.macd?X(n,typeof e.macd=="object"?e.macd:{}):null,i=e.boll?Z(n,typeof e.boll=="object"?e.boll:{}):null,a=e.kdj?ee(s,typeof e.kdj=="object"?e.kdj:{}):null,l=e.rsi?te(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?ne(s,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?re(n,typeof e.bias=="object"?e.bias:{}):null,p=e.cci?oe(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 ae=class{constructor(e={}){this.client=new W(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=ie(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}},Nt=ae;0&&(module.exports={HttpError,StockSDK,addIndicators,asyncPool,calcATR,calcBIAS,calcBOLL,calcCCI,calcEMA,calcKDJ,calcMA,calcMACD,calcRSI,calcSMA,calcWMA,calcWR,chunkArray,decodeGBK,parseResponse,safeNumber,safeNumberOrNull});
|
|
1
|
+
"use strict";var Ae=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var Gt=Object.prototype.hasOwnProperty;var Te=(t,e)=>{for(var n in e)Ae(t,n,{get:e[n],enumerable:!0})},zt=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Wt(e))!Gt.call(t,o)&&o!==n&&Ae(t,o,{get:()=>e[o],enumerable:!(s=Vt(e,o))||s.enumerable});return t};var Yt=t=>zt(Ae({},"__esModule",{value:!0}),t);var yn={};Te(yn,{HttpError:()=>k,StockSDK:()=>ae,addIndicators:()=>le,asyncPool:()=>v,calcATR:()=>N,calcBIAS:()=>se,calcBOLL:()=>te,calcCCI:()=>ie,calcDMI:()=>dt,calcEMA:()=>w,calcKC:()=>ht,calcKDJ:()=>ne,calcMA:()=>Z,calcMACD:()=>ee,calcOBV:()=>pt,calcROC:()=>ft,calcRSI:()=>re,calcSAR:()=>mt,calcSMA:()=>P,calcWMA:()=>xe,calcWR:()=>oe,chunkArray:()=>D,decodeGBK:()=>$,default:()=>Ft,parseResponse:()=>V,safeNumber:()=>h,safeNumberOrNull:()=>R});module.exports=Yt(yn);function $(t){return new TextDecoder("gbk").decode(t)}function V(t){let e=t.split(";").map(s=>s.trim()).filter(Boolean),n=[];for(let s of e){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(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 y(t){if(!t||t===""||t==="-")return null;let e=parseFloat(t);return Number.isNaN(e)?null:e}function S(t){return t==null?null:y(String(t))}var Ke="https://qt.gtimg.cn",we="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Le="https://assets.linkdiary.cn/shares/zh_a_list.json",_e="https://assets.linkdiary.cn/shares/us_list.json",Ie="https://assets.linkdiary.cn/shares/hk_list.json",gt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var ue="https://push2his.eastmoney.com/api/qt/stock/kline/get",Ue="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Ee="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Be="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Pe="https://17.push2.eastmoney.com/api/qt/clist/get",ke="https://91.push2.eastmoney.com/api/qt/stock/get",De="https://29.push2.eastmoney.com/api/qt/clist/get",ve="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",He="https://push2his.eastmoney.com/api/qt/stock/trends2/get",qe="https://79.push2.eastmoney.com/api/qt/clist/get",Ne="https://91.push2.eastmoney.com/api/qt/stock/get",je="https://29.push2.eastmoney.com/api/qt/clist/get",Qe="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Fe="https://push2his.eastmoney.com/api/qt/stock/trends2/get",$e=3e4,W=500,G=500,z=7,Ve=3,We=1e3,Ge=3e4,ze=2,Ye=[408,429,500,502,503,504];var k=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"}},Y=class{constructor(e={}){this.baseUrl=e.baseUrl??Ke,this.timeout=e.timeout??$e,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??Ve,baseDelay:e?.baseDelay??We,maxDelay:e?.maxDelay??Ge,backoffMultiplier:e?.backoffMultiplier??ze,retryableStatusCodes:e?.retryableStatusCodes??Ye,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 o=this.calculateDelay(n);return this.retryOptions.onRetry&&s instanceof Error&&this.retryOptions.onRetry(n+1,s,o),await this.sleep(o),this.executeWithRetry(e,n+1)}throw s}}async get(e,n={}){return this.executeWithRetry(async()=>{let s=new AbortController,o=setTimeout(()=>s.abort(),this.timeout),r=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,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=e,i.provider=r),i}finally{clearTimeout(o)}})}async getTencentQuote(e){let n=`${this.baseUrl}/?q=${encodeURIComponent(e)}`,s=await this.get(n,{responseType:"arraybuffer"}),o=$(s);return V(o)}};var Jt=new Set(["daily","weekly","monthly"]),Xt=new Set(["1","5","15","30","60"]),Zt=new Set(["","qfq","hfq"]);function A(t,e){if(!Number.isFinite(t)||!Number.isInteger(t)||t<=0)throw new RangeError(`${e} must be a positive integer`)}function _(t){if(!Jt.has(t))throw new RangeError("period must be one of: daily, weekly, monthly")}function J(t){if(!Xt.has(t))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function T(t){if(!Zt.has(t))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function D(t,e){A(e,"chunkSize");let n=[];for(let s=0;s<t.length;s+=e)n.push(t.slice(s,s+e));return n}async function v(t,e){A(e,"concurrency");let n=[],s=[];for(let o of t){let r=Promise.resolve().then(()=>o()).then(i=>{n.push(i)});if(s.push(r),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 ce(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 K(t){return{"":"0",qfq:"1",hfq:"2"}[t]}var M={};Te(M,{getAShareCodeList:()=>Mt,getAllHKQuotesByCodes:()=>Tt,getAllQuotesByCodes:()=>At,getAllUSQuotesByCodes:()=>Kt,getFullQuotes:()=>pe,getFundFlow:()=>Ct,getFundQuotes:()=>bt,getHKCodeList:()=>xt,getHKQuotes:()=>fe,getPanelLargeOrder:()=>Rt,getSimpleQuotes:()=>yt,getTodayTimeline:()=>St,getTradingCalendar:()=>wt,getUSCodeList:()=>Ot,getUSQuotes:()=>de,parseFullQuote:()=>Je,parseFundFlow:()=>Ze,parseFundQuote:()=>rt,parseHKQuote:()=>tt,parsePanelLargeOrder:()=>et,parseSimpleQuote:()=>Xe,parseUSQuote:()=>nt,search:()=>_t});function Je(t){let e=[];for(let s=0;s<5;s++)e.push({price:h(t[9+s*2]),volume:h(t[10+s*2])});let n=[];for(let s=0;s<5;s++)n.push({price:h(t[19+s*2]),volume:h(t[20+s*2])});return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),outerVolume:h(t[7]),innerVolume:h(t[8]),bid:e,ask:n,time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),volume2:h(t[36]),amount:h(t[37]),turnoverRate: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 Xe(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),change:h(t[4]),changePercent:h(t[5]),volume:h(t[6]),amount:h(t[7]),marketCap:R(t[9]),marketType:t[10]??"",raw:t}}function Ze(t){return{code:t[0]??"",mainInflow:h(t[1]),mainOutflow:h(t[2]),mainNet:h(t[3]),mainNetRatio:h(t[4]),retailInflow:h(t[5]),retailOutflow:h(t[6]),retailNet:h(t[7]),retailNetRatio:h(t[8]),totalFlow:h(t[9]),name:t[12]??"",date:t[13]??"",raw:t}}function et(t){return{buyLargeRatio:h(t[0]),buySmallRatio:h(t[1]),sellLargeRatio:h(t[2]),sellSmallRatio:h(t[3]),raw:t}}function tt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),amount:h(t[37]),lotSize:R(t[40]),circulatingMarketCap:R(t[44]),totalMarketCap:R(t[45]),currency:t[t.length-3]??"",raw:t}}function nt(t){return{marketId:t[0]??"",name:t[1]??"",code:t[2]??"",price:h(t[3]),prevClose:h(t[4]),open:h(t[5]),volume:h(t[6]),time:t[30]??"",change:h(t[31]),changePercent:h(t[32]),high:h(t[33]),low:h(t[34]),amount:h(t[37]),turnoverRate: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 rt(t){return{code:t[0]??"",name:t[1]??"",nav:h(t[5]),accNav:h(t[6]),change:h(t[7]),navDate:t[8]??"",raw:t}}async function pe(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=>Je(s.fields))}async function yt(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`s_${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Xe(o.fields))}async function Ct(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`ff_${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>Ze(o.fields))}async function Rt(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`s_pk${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>et(o.fields))}async function fe(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`hk${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>tt(o.fields))}async function de(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`us${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>nt(o.fields))}async function bt(t,e){if(!e||e.length===0)return[];let n=e.map(o=>`jj${o}`);return(await t.getTencentQuote(n.join(","))).filter(o=>o.fields&&o.fields.length>0&&o.fields[0]!=="").map(o=>rt(o.fields))}async function St(t,e){let n=t.getTimeout(),s=new AbortController,o=setTimeout(()=>s.abort(),n);try{let r=await fetch(`${we}?code=${e}`,{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?.[e];if(!l)return{code:e,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)}`,C=parseInt(m[2],10)||0,b=parseFloat(m[3])||0,x=c?C*100:C,L=x>0?b/x:0;return{time:f,price:parseFloat(m[1])||0,volume:x,amount:b,avgPrice:Math.round(L*100)/100}});return{code:e,date:u,data:p}}finally{clearTimeout(o)}}var ot=null,en=null,me=null,tn=null,he=null;function nn(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 Mt(t,e){let n=!1,s;if(typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,s=e.market),!ot){let i=(await t.get(Le,{responseType:"json"}))?.list||[];ot=i,en=i.map(l=>l.replace(/^(sh|sz|bj)/,""))}let o=ot;return s&&(o=o.filter(r=>nn(r,s))),n?o.map(r=>r.replace(/^(sh|sz|bj)/,"")):o.slice()}var rn={NASDAQ:"105.",NYSE:"106.",AMEX:"107."};async function Ot(t,e){let n=!1,s;typeof e=="boolean"?n=!e:e&&(n=e.simple??!1,s=e.market),me||(me=(await t.get(_e,{responseType:"json"}))?.list||[],tn=me.map(i=>i.replace(/^\d{3}\./,"")));let o=me.slice();if(s){let r=rn[s];o=o.filter(i=>i.startsWith(r))}return n?o.map(r=>r.replace(/^\d{3}\./,"")):o}async function xt(t){return he||(he=(await t.get(Ie,{responseType:"json"}))?.list||[]),he.slice()}async function At(t,e,n={}){let{batchSize:s=W,concurrency:o=z,onProgress:r}=n;A(s,"batchSize"),A(o,"concurrency");let i=Math.min(s,G),l=D(e,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await pe(t,d);return u++,r&&r(u,a),m});return(await v(c,o)).flat()}async function Tt(t,e,n={}){let{batchSize:s=W,concurrency:o=z,onProgress:r}=n;A(s,"batchSize"),A(o,"concurrency");let i=Math.min(s,G),l=D(e,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await fe(t,d);return u++,r&&r(u,a),m});return(await v(c,o)).flat()}async function Kt(t,e,n={}){let{batchSize:s=W,concurrency:o=z,onProgress:r}=n;A(s,"batchSize"),A(o,"concurrency");let i=Math.min(s,G),l=D(e,i),a=l.length,u=0,c=l.map(d=>async()=>{let m=await de(t,d);return u++,r&&r(u,a),m});return(await v(c,o)).flat()}var Q=null;async function wt(t){if(Q)return Q.slice();let e=await t.get(gt);return!e||e.trim()===""?(Q=[],Q.slice()):(Q=e.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0),Q.slice())}var Lt="https://smartbox.gtimg.cn/s3/";function on(t){return t.replace(/\\u([0-9a-fA-F]{4})/g,(e,n)=>String.fromCharCode(parseInt(n,16)))}function sn(t){return!t||t==="N"?[]:t.split("^").filter(Boolean).map(n=>{let s=n.split("~"),o=s[0]||"",r=s[1]||"",i=on(s[2]||""),l=s[4]||"";return{code:o+r,name:i,market:o,type:l}})}function ln(t){return new Promise((e,n)=>{let s=`${Lt}?v=2&t=all&q=${encodeURIComponent(t)}`;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),e(r)},o.onerror=()=>{document.body.removeChild(o),n(new Error("Network error calling Smartbox"))},document.body.appendChild(o)})}async function an(t,e){let n=`${Lt}?v=2&t=all&q=${encodeURIComponent(e)}`,o=(await t.get(n)).match(/v_hint="([^"]*)"/);return o?o[1]:""}function un(){return typeof window<"u"&&typeof document<"u"}async function _t(t,e){if(!e||!e.trim())return[];let n;return un()?n=await ln(e):n=await an(t,e),sn(n)}var O={};Te(O,{getConceptConstituents:()=>qt,getConceptKline:()=>Nt,getConceptList:()=>lt,getConceptMinuteKline:()=>jt,getConceptSpot:()=>Ht,getHKHistoryKline:()=>Et,getHistoryKline:()=>It,getIndustryConstituents:()=>kt,getIndustryKline:()=>Dt,getIndustryList:()=>it,getIndustryMinuteKline:()=>vt,getIndustrySpot:()=>Pt,getMinuteKline:()=>Ut,getUSHistoryKline:()=>Bt});async function st(t,e,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=`${e}?${u.toString()}`,d=(await t.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 U(t){let[e,n,s,o,r,i,l,a,u,c,p]=t.split(",");return{date:e,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 E(t,e,n){let s=`${e}?${n.toString()}`,o=await t.get(s,{responseType:"json"});return{klines:o?.data?.klines||[],name:o?.data?.name,code:o?.data?.code}}async function It(t,e,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;_(s),T(o);let l=e.replace(/^(sh|sz|bj)/,""),a=`${ce(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:I(s),fqt:K(o),secid:a,beg:r,end:i}),c=ue,{klines:p}=await E(t,c,u);return p.length===0?[]:p.map(d=>({...U(d),code:l}))}async function Ut(t,e,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;J(s),T(o);let l=e.replace(/^(sh|sz|bj)/,""),a=`${ce(e)}.${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=`${Ue}?${u.toString()}`,d=(await t.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[C,b,x,L,F,B,j,$t]=f.split(",");return{time:C,open:y(b),close:y(x),high:y(L),low:y(F),volume:y(B),amount:y(j),avgPrice:y($t)}}).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:K(o||""),secid:a,beg:"0",end:"20500000"}),c=ue,{klines:p}=await E(t,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=U(g);return{...f,time:f.date}}).filter(g=>g.time>=d&&g.time<=m)}}async function Et(t,e,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;_(s),T(o);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:I(s),fqt:K(o),secid:a,beg:r,end:i,lmt:"1000000"}),c=Ee,{klines:p,name:d}=await E(t,c,u);return p.length===0?[]:p.map(m=>({...U(m),code:l,name:d||""}))}async function Bt(t,e,n={}){let{period:s="daily",adjust:o="qfq",startDate:r="19700101",endDate:i="20500101"}=n;_(s),T(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:I(s),fqt:K(o),secid:e,beg:r,end:i,lmt:"1000000"}),a=Be,{klines:u,name:c,code:p}=await E(t,a,l),d=p||e.split(".")[1]||e,m=c||"";return u.length===0?[]:u.map(g=>({...U(g),code:d,name:m}))}function ge(t){let e=null;return{async getCode(n,s,o){if(s.startsWith("BK"))return s;if(!e){let i=await o(n);e=new Map(i.map(l=>[l.name,l.code]))}let r=e.get(s);if(!r)throw new Error(`${t.errorPrefix}: ${s}`);return r}}}async function ye(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",o=await st(t,e.listUrl,n,s,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 o.sort((r,i)=>(i.changePercent??0)-(r.changePercent??0)),o.forEach((r,i)=>{r.rank=i+1}),o}async function Ce(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}`}),o=`${n}?${s.toString()}`,i=(await t.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 Re(t,e,n){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${e} f:!50`};return st(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,(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 be(t,e,n,s={}){let{period:o="daily",adjust:r="",startDate:i="19700101",endDate:l="20500101"}=s;_(o),T(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:I(o),fqt:K(r),beg:i,end:l,smplmt:"10000",lmt:"1000000"}),{klines:u}=await E(t,n,a);return u.length===0?[]:u.map(c=>U(c))}async function Se(t,e,n,s,o={}){let{period:r="5"}=o;if(J(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=`${s}?${i.toString()}`,u=(await t.get(l,{responseType:"json"}))?.data?.trends;return!Array.isArray(u)||u.length===0?[]:u.map(c=>{let[p,d,m,g,f,C,b,x]=c.split(",");return{time:p,open:y(d),close:y(m),high:y(g),low:y(f),volume:y(C),amount:y(b),price:y(x)}})}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[p,d,m,g,f,C,b,x,L,F,B]=c.split(",");return{time:p,open:y(d),close:y(m),high:y(g),low:y(f),changePercent:y(L),change:y(F),volume:y(C),amount:y(b),amplitude:y(x),turnoverRate:y(B)}})}}var H={type:"industry",fsFilter:"m:90 t:2 f:!50",listUrl:Pe,spotUrl:ke,consUrl:De,klineUrl:ve,trendsUrl:He,errorPrefix:"\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757"},cn=ge(H);async function Me(t,e){return cn.getCode(t,e,it)}async function it(t){return ye(t,H)}async function Pt(t,e){let n=await Me(t,e);return Ce(t,n,H.spotUrl)}async function kt(t,e){let n=await Me(t,e);return Re(t,n,H.consUrl)}async function Dt(t,e,n={}){let s=await Me(t,e);return be(t,s,H.klineUrl,n)}async function vt(t,e,n={}){let s=await Me(t,e);return Se(t,s,H.klineUrl,H.trendsUrl,n)}var q={type:"concept",fsFilter:"m:90 t:3 f:!50",listUrl:qe,spotUrl:Ne,consUrl:je,klineUrl:Qe,trendsUrl:Fe,errorPrefix:"\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757"},pn=ge(q);async function Oe(t,e){return pn.getCode(t,e,lt)}async function lt(t){return ye(t,q)}async function Ht(t,e){let n=await Oe(t,e);return Ce(t,n,q.spotUrl)}async function qt(t,e){let n=await Oe(t,e);return Re(t,n,q.consUrl)}async function Nt(t,e,n={}){let s=await Oe(t,e);return be(t,s,q.klineUrl,n)}async function jt(t,e,n={}){let s=await Oe(t,e);return Se(t,s,q.klineUrl,q.trendsUrl,n)}function X(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function P(t,e){let n=[];for(let s=0;s<t.length;s++){if(s<e-1){n.push(null);continue}let o=0,r=0;for(let i=s-e+1;i<=s;i++)t[i]!==null&&(o+=t[i],r++);n.push(r===e?X(o/e):null)}return n}function w(t,e){let n=[],s=2/(e+1),o=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&&(o=a/e,r=!0),n.push(o!==null?X(o):null);continue}let l=t[i];l===null?n.push(o!==null?X(o):null):(o=s*l+(1-s)*o,n.push(X(o)))}return n}function xe(t,e){let n=[],s=Array.from({length:e},(r,i)=>i+1),o=s.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*s[a]}n.push(l?X(i/o):null)}return n}function Z(t,e={}){let{periods:n=[5,10,20,30,60,120,250],type:s="sma"}=e,o=s==="ema"?w:s==="wma"?xe:P,r={};for(let i of n)r[`ma${i}`]=o(t,i);return t.map((i,l)=>{let a={};for(let u of n)a[`ma${u}`]=r[`ma${u}`][l];return a})}function Qt(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ee(t,e={}){let{short:n=12,long:s=26,signal:o=9}=e,r=w(t,n),i=w(t,s),l=t.map((u,c)=>r[c]===null||i[c]===null?null:r[c]-i[c]),a=w(l,o);return t.map((u,c)=>({dif:l[c]!==null?Qt(l[c]):null,dea:a[c],macd:l[c]!==null&&a[c]!==null?Qt((l[c]-a[c])*2):null}))}function at(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function fn(t,e,n){let s=[];for(let o=0;o<t.length;o++){if(o<e-1||n[o]===null){s.push(null);continue}let r=0,i=0;for(let l=o-e+1;l<=o;l++)t[l]!==null&&n[o]!==null&&(r+=Math.pow(t[l]-n[o],2),i++);s.push(i===e?Math.sqrt(r/e):null)}return s}function te(t,e={}){let{period:n=20,stdDev:s=2}=e,o=P(t,n),r=fn(t,n,o);return t.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(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ne(t,e={}){let{period:n=9,kPeriod:s=3,dPeriod:o=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,p=!0;for(let f=a-n+1;f<=a;f++){if(t[f].high===null||t[f].low===null){p=!1;break}u=Math.max(u,t[f].high),c=Math.min(c,t[f].low)}let d=t[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 dn(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=[null];for(let r=1;r<t.length;r++)t[r]===null||t[r-1]===null?s.push(null):s.push(t[r]-t[r-1]);let o={};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),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(dn(100-100/(1+c)))}}o[`rsi${r}`]=i}return t.map((r,i)=>{let l={};for(let a of n)l[`rsi${a}`]=o[`rsi${a}`][i];return l})}function mn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function oe(t,e={}){let{periods:n=[6,10]}=e,s={};for(let o of n){let r=[];for(let i=0;i<t.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(t[d].high===null||t[d].low===null){u=!1;break}l=Math.max(l,t[d].high),a=Math.min(a,t[d].low)}let c=t[i].close;if(!u||c===null||l===a){r.push(null);continue}let p=(l-c)/(l-a)*100;r.push(mn(p))}s[`wr${o}`]=r}return t.map((o,r)=>{let i={};for(let l of n)i[`wr${l}`]=s[`wr${l}`][r];return i})}function hn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function se(t,e={}){let{periods:n=[6,12,24]}=e,s={};for(let o of n){let r=P(t,o),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(hn(a))}s[`bias${o}`]=i}return t.map((o,r)=>{let i={};for(let l of n)i[`bias${l}`]=s[`bias${l}`][r];return i})}function gn(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function ie(t,e={}){let{period:n=14}=e,s=[],o=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){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:gn(p)})}}return s}function ct(t,e=2){let n=Math.pow(10,e);return Math.round(t*n)/n}function N(t,e={}){let{period:n=14}=e,s=[],o=[];for(let i=0;i<t.length;i++){let{high:l,low:a,close:u}=t[i];if(l===null||a===null||u===null){o.push(null);continue}if(i===0)o.push(l-a);else{let c=t[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<t.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 pt(t,e={}){let{maPeriod:n}=e,s=[];if(t.length===0)return s;let o=t[0].volume??0;s.push({obv:o,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){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 ft(t,e={}){let{period:n=12,signalPeriod:s}=e,o=[];for(let r=0;r<t.length;r++){if(r<n){o.push({roc:null,signal:null});continue}let i=t[r].close,l=t[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 dt(t,e={}){let{period:n=14,adxPeriod:s=n}=e,o=[];if(t.length<2)return t.map(()=>({pdi:null,mdi:null,adx:null,adxr:null}));let r=[],i=[],l=[];for(let f=0;f<t.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 C=t[f],b=t[f-1];if(C.high===null||C.low===null||C.close===null||b.high===null||b.low===null||b.close===null){r.push(0),i.push(0),l.push(0),o.push({pdi:null,mdi:null,adx:null,adxr:null});continue}let x=C.high-C.low,L=Math.abs(C.high-b.close),F=Math.abs(C.low-b.close);l.push(Math.max(x,L,F));let B=C.high-b.high,j=b.low-C.low;B>j&&B>0?r.push(B):r.push(0),j>B&&j>0?i.push(j):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<t.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 C=a>0?u/a*100:0,b=a>0?c/a*100:0;o[f].pdi=C,o[f].mdi=b;let x=C+b,L=x>0?Math.abs(C-b)/x*100:0;p.push(L)}let d=0,m=0,g=0;for(let f=n;f<t.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 C=p[f-n+1]||0;g=(g*(s-1)+C)/s,o[f].adx=g}}for(let f=n*2-1+s;f<t.length;f++){let C=o[f].adx,b=o[f-s]?.adx;C!==null&&b!==null&&(o[f].adxr=(C+b)/2)}return o}function mt(t,e={}){let{afStart:n=.02,afIncrement:s=.02,afMax:o=.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],p=t[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<t.length;d++){let m=t[d],g=t[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,t[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,t[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 ht(t,e={}){let{emaPeriod:n=20,atrPeriod:s=10,multiplier:o=2}=e,r=[],i=t.map(u=>u.close),l=w(i,n),a=N(t,{period:s});for(let u=0;u<t.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 le(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})),o=e.ma?Z(n,typeof e.ma=="object"?e.ma:{}):null,r=e.macd?ee(n,typeof e.macd=="object"?e.macd:{}):null,i=e.boll?te(n,typeof e.boll=="object"?e.boll:{}):null,l=e.kdj?ne(s,typeof e.kdj=="object"?e.kdj:{}):null,a=e.rsi?re(n,typeof e.rsi=="object"?e.rsi:{}):null,u=e.wr?oe(s,typeof e.wr=="object"?e.wr:{}):null,c=e.bias?se(n,typeof e.bias=="object"?e.bias:{}):null,p=e.cci?ie(s,typeof e.cci=="object"?e.cci:{}):null,d=e.atr?N(s,typeof e.atr=="object"?e.atr:{}):null;return t.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 ae=class{constructor(e={}){this.client=new Y(e)}getFullQuotes(e){return M.getFullQuotes(this.client,e)}getSimpleQuotes(e){return M.getSimpleQuotes(this.client,e)}getHKQuotes(e){return M.getHKQuotes(this.client,e)}getUSQuotes(e){return M.getUSQuotes(this.client,e)}getFundQuotes(e){return M.getFundQuotes(this.client,e)}getFundFlow(e){return M.getFundFlow(this.client,e)}getPanelLargeOrder(e){return M.getPanelLargeOrder(this.client,e)}getTodayTimeline(e){return M.getTodayTimeline(this.client,e)}getIndustryList(){return O.getIndustryList(this.client)}getIndustrySpot(e){return O.getIndustrySpot(this.client,e)}getIndustryConstituents(e){return O.getIndustryConstituents(this.client,e)}getIndustryKline(e,n){return O.getIndustryKline(this.client,e,n)}getIndustryMinuteKline(e,n){return O.getIndustryMinuteKline(this.client,e,n)}getConceptList(){return O.getConceptList(this.client)}getConceptSpot(e){return O.getConceptSpot(this.client,e)}getConceptConstituents(e){return O.getConceptConstituents(this.client,e)}getConceptKline(e,n){return O.getConceptKline(this.client,e,n)}getConceptMinuteKline(e,n){return O.getConceptMinuteKline(this.client,e,n)}getHistoryKline(e,n){return O.getHistoryKline(this.client,e,n)}getMinuteKline(e,n){return O.getMinuteKline(this.client,e,n)}getHKHistoryKline(e,n){return O.getHKHistoryKline(this.client,e,n)}getUSHistoryKline(e,n){return O.getUSHistoryKline(this.client,e,n)}search(e){return M.search(this.client,e)}getAShareCodeList(e){return M.getAShareCodeList(this.client,e)}getUSCodeList(e){return M.getUSCodeList(this.client,e)}getHKCodeList(){return M.getHKCodeList(this.client)}async getAllAShareQuotes(e={}){let{market:n,...s}=e,o=await this.getAShareCodeList({market:n});return this.getAllQuotesByCodes(o,s)}async getAllHKShareQuotes(e={}){let n=await this.getHKCodeList();return M.getAllHKQuotesByCodes(this.client,n,e)}async getAllUSShareQuotes(e={}){let{market:n,...s}=e,o=await this.getUSCodeList({simple:!0,market:n});return M.getAllUSQuotesByCodes(this.client,o,s)}getAllQuotesByCodes(e,n={}){return M.getAllQuotesByCodes(this.client,e,n)}async batchRaw(e){return this.client.getTencentQuote(e)}getTradingCalendar(){return M.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 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"&&(s=!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),s=!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*(s?1.5:1.2))}calcActualStartDate(e,n,s=1.5){let o=Math.ceil(n*s),r=new Date(parseInt(e.slice(0,4)),parseInt(e.slice(4,6))-1,parseInt(e.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(e,n,s){if(!s||s.length===0)return;let o=this.normalizeDate(e),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(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:o,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(s)if(i==="A")try{let m=await M.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(e,c);break;case"US":p=await this.getUSHistoryKline(e,c);break;default:p=await this.getHistoryKline(e,c)}if(s&&p.length<l)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=le(p,r);if(s){let m=this.dateToTimestamp(s),g=o?this.dateToTimestamp(o):1/0;return d.filter(f=>{let C=this.dateToTimestamp(f.date);return C>=m&&C<=g})}return d}},Ft=ae;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});
|