stock-sdk 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +38 -18
- package/dist/index.d.ts +38 -18
- package/dist/index.js +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
**[English](./README_EN.md)** | 中文
|
|
9
9
|
|
|
10
|
-
为 **前端和 Node.js 设计的股票行情 SDK**。
|
|
10
|
+
为 **前端和 Node.js 设计的股票行情 JavaScript SDK**。
|
|
11
11
|
|
|
12
12
|
无需 Python、无需后端服务,直接在 **浏览器或 Node.js** 中获取 **A 股 / 港股 / 美股 / 公募基金** 的实时行情与 K 线数据。
|
|
13
13
|
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk) | 🎮 [在线演示](https://stock-sdk.linkdiary.cn/playground/)
|
|
21
21
|
|
|
22
|
+
🧭 [Stock Dashboard](https://chengzuopeng.github.io/stock-dashboard/):基于 stock-sdk 搭建的股票数据大盘演示站点,欢迎体验。
|
|
23
|
+
|
|
22
24
|
## Why stock-sdk?
|
|
23
25
|
|
|
24
26
|
如果你是前端工程师,可能遇到过这些问题:
|
|
@@ -193,8 +195,8 @@ console.log(`共获取 ${allQuotes.length} 只股票`);
|
|
|
193
195
|
|
|
194
196
|
---
|
|
195
197
|
|
|
196
|
-
🌐 [官网](https://stock-sdk.linkdiary.cn) | 📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk) | 🎮 [在线演示](https://stock-sdk.linkdiary.cn/playground) | 🐛 [Issues](https://github.com/chengzuopeng/stock-sdk/issues)
|
|
198
|
+
🌐 [官网](https://stock-sdk.linkdiary.cn) | 📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk) | 🎮 [在线演示](https://stock-sdk.linkdiary.cn/playground) | 🧭 [Stock Dashboard](https://chengzuopeng.github.io/stock-dashboard/) | 🐛 [Issues](https://github.com/chengzuopeng/stock-sdk/issues)
|
|
197
199
|
|
|
198
200
|
---
|
|
199
201
|
|
|
200
|
-
如果这个项目对你有帮助,欢迎 Star ⭐ 或提出 Issue 反馈。
|
|
202
|
+
如果这个项目对你有帮助,欢迎 Star ⭐ 或提出 Issue 反馈。
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var gt=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var ht=(e,t)=>{for(var r in t)gt(e,r,{get:t[r],enumerable:!0})},ke=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Pe(t))!Ie.call(e,n)&&n!==r&>(e,n,{get:()=>t[n],enumerable:!(s=Oe(t,n))||s.enumerable});return e};var Ue=e=>ke(gt({},"__esModule",{value:!0}),e);var Ge={};ht(Ge,{HttpError:()=>U,StockSDK:()=>ot,addIndicators:()=>rt,asyncPool:()=>H,calcATR:()=>nt,calcBIAS:()=>tt,calcBOLL:()=>J,calcCCI:()=>et,calcEMA:()=>I,calcKDJ:()=>Y,calcMA:()=>V,calcMACD:()=>G,calcRSI:()=>X,calcSMA:()=>P,calcWMA:()=>mt,calcWR:()=>Z,chunkArray:()=>D,decodeGBK:()=>N,default:()=>_e,parseResponse:()=>j,safeNumber:()=>d,safeNumberOrNull:()=>R});module.exports=Ue(Ge);function N(e){return new TextDecoder("gbk").decode(e)}function j(e){let t=e.split(";").map(s=>s.trim()).filter(Boolean),r=[];for(let s of t){let n=s.indexOf("=");if(n<0)continue;let o=s.slice(0,n).trim();o.startsWith("v_")&&(o=o.slice(2));let i=s.slice(n+1).trim();i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1));let a=i.split("~");r.push({key:o,fields:a})}return r}function d(e){if(!e||e==="")return 0;let t=parseFloat(e);return Number.isNaN(t)?0:t}function R(e){if(!e||e==="")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function m(e){if(!e||e===""||e==="-")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function h(e){return e==null?null:m(String(e))}var yt="https://qt.gtimg.cn",Ct="https://web.ifzq.gtimg.cn/appstock/app/minute/query",Rt="https://assets.linkdiary.cn/shares/zh_a_list.json",bt="https://assets.linkdiary.cn/shares/us_list.json",St="https://assets.linkdiary.cn/shares/hk_list.json",Zt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var st="https://push2his.eastmoney.com/api/qt/stock/kline/get",Tt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",wt="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",Mt="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Kt="https://17.push2.eastmoney.com/api/qt/clist/get",At="https://91.push2.eastmoney.com/api/qt/stock/get",_t="https://29.push2.eastmoney.com/api/qt/clist/get",it="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",Lt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",Et="https://79.push2.eastmoney.com/api/qt/clist/get",xt="https://91.push2.eastmoney.com/api/qt/stock/get",Ot="https://29.push2.eastmoney.com/api/qt/clist/get",at="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Pt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",It=3e4,Q=500,F=500,$=7,kt=3,Ut=1e3,Bt=3e4,Dt=2,Ht=[408,429,500,502,503,504];var U=class extends Error{constructor(r,s){super(`HTTP error! status: ${r}`);this.status=r;this.statusText=s;this.name="HttpError"}},W=class{constructor(t={}){this.baseUrl=t.baseUrl??yt,this.timeout=t.timeout??It,this.retryOptions=this.resolveRetryOptions(t.retry)}resolveRetryOptions(t){return{maxRetries:t?.maxRetries??kt,baseDelay:t?.baseDelay??Ut,maxDelay:t?.maxDelay??Bt,backoffMultiplier:t?.backoffMultiplier??Dt,retryableStatusCodes:t?.retryableStatusCodes??Ht,retryOnNetworkError:t?.retryOnNetworkError??!0,retryOnTimeout:t?.retryOnTimeout??!0,onRetry:t?.onRetry}}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(r=>setTimeout(r,t))}shouldRetry(t,r){return r>=this.retryOptions.maxRetries?!1:t instanceof DOMException&&t.name==="AbortError"?this.retryOptions.retryOnTimeout:t instanceof TypeError?this.retryOptions.retryOnNetworkError:t instanceof U?this.retryOptions.retryableStatusCodes.includes(t.status):!1}async executeWithRetry(t,r=0){try{return await t()}catch(s){if(this.shouldRetry(s,r)){let n=this.calculateDelay(r);return this.retryOptions.onRetry&&s instanceof Error&&this.retryOptions.onRetry(r+1,s,n),await this.sleep(n),this.executeWithRetry(t,r+1)}throw s}}async get(t,r={}){return this.executeWithRetry(async()=>{let s=new AbortController,n=setTimeout(()=>s.abort(),this.timeout);try{let o=await fetch(t,{signal:s.signal});if(!o.ok)throw new U(o.status,o.statusText);switch(r.responseType){case"json":return await o.json();case"arraybuffer":return await o.arrayBuffer();default:return await o.text()}}finally{clearTimeout(n)}})}async getTencentQuote(t){let r=`${this.baseUrl}/?q=${encodeURIComponent(t)}`,s=await this.get(r,{responseType:"arraybuffer"}),n=N(s);return j(n)}};var Be=new Set(["daily","weekly","monthly"]),De=new Set(["1","5","15","30","60"]),He=new Set(["","qfq","hfq"]);function x(e,t){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new RangeError(`${t} must be a positive integer`)}function A(e){if(!Be.has(e))throw new RangeError("period must be one of: daily, weekly, monthly")}function B(e){if(!De.has(e))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function M(e){if(!He.has(e))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function D(e,t){x(t,"chunkSize");let r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r}async function H(e,t){x(t,"concurrency");let r=[],s=[];for(let n of e){let o=Promise.resolve().then(()=>n()).then(i=>{r.push(i)});if(s.push(o),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),r}function lt(e){return e.startsWith("sh")?"1":e.startsWith("sz")||e.startsWith("bj")?"0":e.startsWith("6")?"1":"0"}function _(e){return{daily:"101",weekly:"102",monthly:"103"}[e]}function K(e){return{"":"0",qfq:"1",hfq:"2"}[e]}var b={};ht(b,{getAShareCodeList:()=>se,getAllHKQuotesByCodes:()=>ue,getAllQuotesByCodes:()=>le,getAllUSQuotesByCodes:()=>ce,getFullQuotes:()=>ut,getFundFlow:()=>ee,getFundQuotes:()=>re,getHKCodeList:()=>ae,getHKQuotes:()=>ct,getPanelLargeOrder:()=>ne,getSimpleQuotes:()=>te,getTodayTimeline:()=>oe,getTradingCalendar:()=>fe,getUSCodeList:()=>ie,getUSQuotes:()=>ft,parseFullQuote:()=>vt,parseFundFlow:()=>Nt,parseFundQuote:()=>$t,parseHKQuote:()=>Qt,parsePanelLargeOrder:()=>jt,parseSimpleQuote:()=>qt,parseUSQuote:()=>Ft,search:()=>de});function vt(e){let t=[];for(let s=0;s<5;s++)t.push({price:d(e[9+s*2]),volume:d(e[10+s*2])});let r=[];for(let s=0;s<5;s++)r.push({price:d(e[19+s*2]),volume:d(e[20+s*2])});return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),outerVolume:d(e[7]),innerVolume:d(e[8]),bid:t,ask:r,time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),volume2:d(e[36]),amount:d(e[37]),turnoverRate:R(e[38]),pe:R(e[39]),amplitude:R(e[43]),circulatingMarketCap:R(e[44]),totalMarketCap:R(e[45]),pb:R(e[46]),limitUp:R(e[47]),limitDown:R(e[48]),volumeRatio:R(e[49]),avgPrice:R(e[51]),peStatic:R(e[52]),peDynamic:R(e[53]),high52w:R(e[67]),low52w:R(e[68]),circulatingShares:R(e[72]),totalShares:R(e[73]),raw:e}}function qt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),change:d(e[4]),changePercent:d(e[5]),volume:d(e[6]),amount:d(e[7]),marketCap:R(e[9]),marketType:e[10]??"",raw:e}}function Nt(e){return{code:e[0]??"",mainInflow:d(e[1]),mainOutflow:d(e[2]),mainNet:d(e[3]),mainNetRatio:d(e[4]),retailInflow:d(e[5]),retailOutflow:d(e[6]),retailNet:d(e[7]),retailNetRatio:d(e[8]),totalFlow:d(e[9]),name:e[12]??"",date:e[13]??"",raw:e}}function jt(e){return{buyLargeRatio:d(e[0]),buySmallRatio:d(e[1]),sellLargeRatio:d(e[2]),sellSmallRatio:d(e[3]),raw:e}}function Qt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),amount:d(e[37]),lotSize:R(e[40]),circulatingMarketCap:R(e[44]),totalMarketCap:R(e[45]),currency:e[e.length-3]??"",raw:e}}function Ft(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),amount:d(e[37]),turnoverRate:R(e[38]),pe:R(e[39]),amplitude:R(e[43]),totalMarketCap:R(e[45]),pb:R(e[47]),high52w:R(e[48]),low52w:R(e[49]),raw:e}}function $t(e){return{code:e[0]??"",name:e[1]??"",nav:d(e[5]),accNav:d(e[6]),change:d(e[7]),navDate:e[8]??"",raw:e}}async function ut(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=>vt(s.fields))}async function te(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`s_${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>qt(n.fields))}async function ee(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`ff_${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>Nt(n.fields))}async function ne(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`s_pk${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>jt(n.fields))}async function ct(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`hk${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>Qt(n.fields))}async function ft(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`us${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>Ft(n.fields))}async function re(e,t){if(!t||t.length===0)return[];let r=t.map(n=>`jj${n}`);return(await e.getTencentQuote(r.join(","))).filter(n=>n.fields&&n.fields.length>0&&n.fields[0]!=="").map(n=>$t(n.fields))}async function oe(e,t){let r=e.getTimeout(),s=new AbortController,n=setTimeout(()=>s.abort(),r);try{let o=await fetch(`${Ct}?code=${t}`,{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?.[t];if(!a)return{code:t,date:"",data:[]};let l=a.data?.data||[],u=a.data?.date||"",c=!1;if(l.length>0){let p=l[0].split(" "),g=parseFloat(p[1])||0,y=parseInt(p[2],10)||0,C=parseFloat(p[3])||0;y>0&&g>0&&C/y>g*50&&(c=!0)}let f=l.map(p=>{let g=p.split(" "),y=g[0],C=`${y.slice(0,2)}:${y.slice(2,4)}`,T=parseInt(g[2],10)||0,w=parseFloat(g[3])||0,O=c?T*100:T,k=O>0?w/O:0;return{time:C,price:parseFloat(g[1])||0,volume:O,amount:w,avgPrice:Math.round(k*100)/100}});return{code:t,date:u,data:f}}finally{clearTimeout(n)}}async function se(e,t=!0){let r=e.getTimeout(),s=new AbortController,n=setTimeout(()=>s.abort(),r);try{let o=await fetch(Rt,{signal:s.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let a=(await o.json()).list||[];return t?a:a.map(l=>l.replace(/^(sh|sz|bj)/,""))}finally{clearTimeout(n)}}async function ie(e,t=!0){let r=e.getTimeout(),s=new AbortController,n=setTimeout(()=>s.abort(),r);try{let o=await fetch(bt,{signal:s.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let a=(await o.json()).list||[];return t?a:a.map(l=>l.replace(/^\d{3}\./,""))}finally{clearTimeout(n)}}async function ae(e){let t=e.getTimeout(),r=new AbortController,s=setTimeout(()=>r.abort(),t);try{let n=await fetch(St,{signal:r.signal});if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return(await n.json()).list||[]}finally{clearTimeout(s)}}async function le(e,t,r={}){let{batchSize:s=Q,concurrency:n=$,onProgress:o}=r;x(s,"batchSize"),x(n,"concurrency");let i=Math.min(s,F),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await ut(e,p);return u++,o&&o(u,l),g});return(await H(c,n)).flat()}async function ue(e,t,r={}){let{batchSize:s=Q,concurrency:n=$,onProgress:o}=r;x(s,"batchSize"),x(n,"concurrency");let i=Math.min(s,F),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await ct(e,p);return u++,o&&o(u,l),g});return(await H(c,n)).flat()}async function ce(e,t,r={}){let{batchSize:s=Q,concurrency:n=$,onProgress:o}=r;x(s,"batchSize"),x(n,"concurrency");let i=Math.min(s,F),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await ft(e,p);return u++,o&&o(u,l),g});return(await H(c,n)).flat()}async function fe(e){let t=await e.get(Zt);return!t||t.trim()===""?[]:t.trim().split(",").map(r=>r.trim()).filter(r=>r.length>0)}var pe="https://smartbox.gtimg.cn/s3/";function ve(e){return e.replace(/\\u([0-9a-fA-F]{4})/g,(t,r)=>String.fromCharCode(parseInt(r,16)))}function qe(e){return!e||e==="N"?[]:e.split("^").filter(Boolean).map(r=>{let s=r.split("~"),n=s[0]||"",o=s[1]||"",i=ve(s[2]||""),a=s[4]||"";return{code:n+o,name:i,market:n,type:a}})}function Ne(e){return new Promise((t,r)=>{let s=`${pe}?v=2&t=all&q=${encodeURIComponent(e)}`;window.v_hint="";let n=document.createElement("script");n.src=s,n.charset="utf-8",n.onload=()=>{let o=window.v_hint||"";document.body.removeChild(n),t(o)},n.onerror=()=>{document.body.removeChild(n),r(new Error("Network error calling Smartbox"))},document.body.appendChild(n)})}async function je(e,t){let r=`${pe}?v=2&t=all&q=${encodeURIComponent(t)}`,n=(await e.get(r)).match(/v_hint="([^"]*)"/);return n?n[1]:""}function Qe(){return typeof window<"u"&&typeof document<"u"}async function de(e,t){if(!t||!t.trim())return[];let r;return Qe()?r=await Ne(t):r=await je(e,t),qe(r)}var S={};ht(S,{getConceptConstituents:()=>we,getConceptKline:()=>Me,getConceptList:()=>Gt,getConceptMinuteKline:()=>Ke,getConceptSpot:()=>Te,getHKHistoryKline:()=>he,getHistoryKline:()=>me,getIndustryConstituents:()=>Re,getIndustryKline:()=>be,getIndustryList:()=>zt,getIndustryMinuteKline:()=>Se,getIndustrySpot:()=>Ce,getMinuteKline:()=>ge,getUSHistoryKline:()=>ye});async function v(e,t,r,s,n=100,o){let i=[],a=1,l=0;do{let u=new URLSearchParams({...r,pn:String(a),pz:String(n),fields:s}),c=`${t}?${u.toString()}`,p=(await e.get(c,{responseType:"json"}))?.data;if(!p||!Array.isArray(p.diff))break;a===1&&(l=p.total??0);let g=p.diff.map((y,C)=>o(y,i.length+C+1));i.push(...g),a++}while(i.length<l);return i}function L(e){let[t,r,s,n,o,i,a,l,u,c,f]=e.split(",");return{date:t,open:m(r),close:m(s),high:m(n),low:m(o),volume:m(i),amount:m(a),amplitude:m(l),changePercent:m(u),change:m(c),turnoverRate:m(f)}}async function E(e,t,r){let s=`${t}?${r.toString()}`,n=await e.get(s,{responseType:"json"});return{klines:n?.data?.klines||[],name:n?.data?.name,code:n?.data?.code}}async function me(e,t,r={}){let{period:s="daily",adjust:n="hfq",startDate:o="19700101",endDate:i="20500101"}=r;A(s),M(n);let a=t.replace(/^(sh|sz|bj)/,""),l=`${lt(t)}.${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:_(s),fqt:K(n),secid:l,beg:o,end:i}),c=st,{klines:f}=await E(e,c,u);return f.length===0?[]:f.map(p=>({...L(p),code:a}))}async function ge(e,t,r={}){let{period:s="1",adjust:n="hfq",startDate:o="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=r;B(s),M(n);let a=t.replace(/^(sh|sz|bj)/,""),l=`${lt(t)}.${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=`${Tt}?${u.toString()}`,p=(await e.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(p)||p.length===0)return[];let g=o.replace("T"," ").slice(0,16),y=i.replace("T"," ").slice(0,16);return p.map(C=>{let[T,w,O,k,q,Le,Ee,xe]=C.split(",");return{time:T,open:m(w),close:m(O),high:m(k),low:m(q),volume:m(Le),amount:m(Ee),avgPrice:m(xe)}}).filter(C=>C.time>=g&&C.time<=y)}else{let u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:s,fqt:K(n||""),secid:l,beg:"0",end:"20500000"}),c=st,{klines:f}=await E(e,c,u);if(f.length===0)return[];let p=o.replace("T"," ").slice(0,16),g=i.replace("T"," ").slice(0,16);return f.map(y=>{let C=L(y);return{...C,time:C.date}}).filter(y=>y.time>=p&&y.time<=g)}}async function he(e,t,r={}){let{period:s="daily",adjust:n="hfq",startDate:o="19700101",endDate:i="20500101"}=r;A(s),M(n);let a=t.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:_(s),fqt:K(n),secid:l,beg:o,end:i,lmt:"1000000"}),c=wt,{klines:f,name:p}=await E(e,c,u);return f.length===0?[]:f.map(g=>({...L(g),code:a,name:p||""}))}async function ye(e,t,r={}){let{period:s="daily",adjust:n="hfq",startDate:o="19700101",endDate:i="20500101"}=r;A(s),M(n);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:_(s),fqt:K(n),secid:t,beg:o,end:i,lmt:"1000000"}),l=Mt,{klines:u,name:c,code:f}=await E(e,l,a),p=f||t.split(".")[1]||t,g=c||"";return u.length===0?[]:u.map(y=>({...L(y),code:p,name:g}))}var Wt=null;async function pt(e,t){if(t.startsWith("BK"))return t;if(!Wt){let s=await zt(e);Wt=new Map(s.map(n=>[n.name,n.code]))}let r=Wt.get(t);if(!r)throw new Error(`\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757: ${t}`);return r}async function zt(e){let s=await v(e,Kt,{po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:"m:90 t:2 f:!50"},"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",100,(n,o)=>({rank:o,name:String(n.f14??""),code:String(n.f12??""),price:h(n.f2),change:h(n.f4),changePercent:h(n.f3),totalMarketCap:h(n.f20),turnoverRate:h(n.f8),riseCount:h(n.f104),fallCount:h(n.f105),leadingStock:n.f128?String(n.f128):null,leadingStockChangePercent:h(n.f136)}));return s.sort((n,o)=>(o.changePercent??0)-(n.changePercent??0)),s.forEach((n,o)=>{n.rank=o+1}),s}async function Ce(e,t){let r=await pt(e,t),s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${r}`}),n=`${At}?${s.toString()}`,i=(await e.get(n,{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 f=i[l],p=null;return typeof f=="number"&&!isNaN(f)&&(p=c?f/100:f),{item:u,value:p}}):[]}async function Re(e,t){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${await pt(e,t)} f:!50`};return v(e,_t,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:h(o.f2),changePercent:h(o.f3),change:h(o.f4),volume:h(o.f5),amount:h(o.f6),amplitude:h(o.f7),high:h(o.f15),low:h(o.f16),open:h(o.f17),prevClose:h(o.f18),turnoverRate:h(o.f8),pe:h(o.f9),pb:h(o.f23)}))}async function be(e,t,r={}){let{period:s="daily",adjust:n="",startDate:o="19700101",endDate:i="20500101"}=r;A(s),M(n);let a=await pt(e,t),l=new URLSearchParams({secid:`90.${a}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:_(s),fqt:K(n),beg:o,end:i,smplmt:"10000",lmt:"1000000"}),u=it,{klines:c}=await E(e,u,l);return c.length===0?[]:c.map(f=>({...L(f)}))}async function Se(e,t,r={}){let{period:s="5"}=r;B(s);let n=await pt(e,t);if(s==="1"){let o=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.${n}`}),i=`${Lt}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.trends;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),volume:m(C),amount:m(T),price:m(w)}})}else{let o=new URLSearchParams({secid:`90.${n}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:s,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),i=`${it}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.klines;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w,O,k,q]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),changePercent:m(O),change:m(k),volume:m(C),amount:m(T),amplitude:m(w),turnoverRate:m(q)}})}}var Vt=null;async function dt(e,t){if(t.startsWith("BK"))return t;if(!Vt){let s=await Gt(e);Vt=new Map(s.map(n=>[n.name,n.code]))}let r=Vt.get(t);if(!r)throw new Error(`\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757: ${t}`);return r}async function Gt(e){let s=await v(e,Et,{po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f12",fs:"m:90 t:3 f:!50"},"f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136",100,(n,o)=>({rank:o,name:String(n.f14??""),code:String(n.f12??""),price:h(n.f2),change:h(n.f4),changePercent:h(n.f3),totalMarketCap:h(n.f20),turnoverRate:h(n.f8),riseCount:h(n.f104),fallCount:h(n.f105),leadingStock:n.f128?String(n.f128):null,leadingStockChangePercent:h(n.f136)}));return s.sort((n,o)=>(o.changePercent??0)-(n.changePercent??0)),s.forEach((n,o)=>{n.rank=o+1}),s}async function Te(e,t){let r=await dt(e,t),s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${r}`}),n=`${xt}?${s.toString()}`,i=(await e.get(n,{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 f=i[l],p=null;return typeof f=="number"&&!isNaN(f)&&(p=c?f/100:f),{item:u,value:p}}):[]}async function we(e,t){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f12",fs:`b:${await dt(e,t)} f:!50`};return v(e,Ot,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:h(o.f2),changePercent:h(o.f3),change:h(o.f4),volume:h(o.f5),amount:h(o.f6),amplitude:h(o.f7),high:h(o.f15),low:h(o.f16),open:h(o.f17),prevClose:h(o.f18),turnoverRate:h(o.f8),pe:h(o.f9),pb:h(o.f23)}))}async function Me(e,t,r={}){let{period:s="daily",adjust:n="",startDate:o="19700101",endDate:i="20500101"}=r;A(s),M(n);let a=await dt(e,t),l=new URLSearchParams({secid:`90.${a}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:_(s),fqt:K(n),beg:o,end:i,smplmt:"10000",lmt:"1000000"}),u=at,{klines:c}=await E(e,u,l);return c.length===0?[]:c.map(f=>({...L(f)}))}async function Ke(e,t,r={}){let{period:s="5"}=r;B(s);let n=await dt(e,t);if(s==="1"){let o=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.${n}`}),i=`${Pt}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.trends;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),volume:m(C),amount:m(T),price:m(w)}})}else{let o=new URLSearchParams({secid:`90.${n}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:s,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),i=`${at}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.klines;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w,O,k,q]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),changePercent:m(O),change:m(k),volume:m(C),amount:m(T),amplitude:m(w),turnoverRate:m(q)}})}}function z(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function P(e,t){let r=[];for(let s=0;s<e.length;s++){if(s<t-1){r.push(null);continue}let n=0,o=0;for(let i=s-t+1;i<=s;i++)e[i]!==null&&(n+=e[i],o++);r.push(o===t?z(n/t):null)}return r}function I(e,t){let r=[],s=2/(t+1),n=null,o=!1;for(let i=0;i<e.length;i++){if(i<t-1){r.push(null);continue}if(!o){let l=0,u=0;for(let c=i-t+1;c<=i;c++)e[c]!==null&&(l+=e[c],u++);u===t&&(n=l/t,o=!0),r.push(n!==null?z(n):null);continue}let a=e[i];a===null?r.push(n!==null?z(n):null):(n=s*a+(1-s)*n,r.push(z(n)))}return r}function mt(e,t){let r=[],s=Array.from({length:t},(o,i)=>i+1),n=s.reduce((o,i)=>o+i,0);for(let o=0;o<e.length;o++){if(o<t-1){r.push(null);continue}let i=0,a=!0;for(let l=0;l<t;l++){let u=e[o-t+1+l];if(u===null){a=!1;break}i+=u*s[l]}r.push(a?z(i/n):null)}return r}function V(e,t={}){let{periods:r=[5,10,20,30,60,120,250],type:s="sma"}=t,n=s==="ema"?I:s==="wma"?mt:P,o={};for(let i of r)o[`ma${i}`]=n(e,i);return e.map((i,a)=>{let l={};for(let u of r)l[`ma${u}`]=o[`ma${u}`][a];return l})}function Ae(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function G(e,t={}){let{short:r=12,long:s=26,signal:n=9}=t,o=I(e,r),i=I(e,s),a=e.map((u,c)=>o[c]===null||i[c]===null?null:o[c]-i[c]),l=I(a,n);return e.map((u,c)=>({dif:a[c]!==null?Ae(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?Ae((a[c]-l[c])*2):null}))}function Jt(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function Fe(e,t,r){let s=[];for(let n=0;n<e.length;n++){if(n<t-1||r[n]===null){s.push(null);continue}let o=0,i=0;for(let a=n-t+1;a<=n;a++)e[a]!==null&&r[n]!==null&&(o+=Math.pow(e[a]-r[n],2),i++);s.push(i===t?Math.sqrt(o/t):null)}return s}function J(e,t={}){let{period:r=20,stdDev:s=2}=t,n=P(e,r),o=Fe(e,r,n);return e.map((i,a)=>{if(n[a]===null||o[a]===null)return{mid:null,upper:null,lower:null,bandwidth:null};let l=n[a]+s*o[a],u=n[a]-s*o[a],c=n[a]!==0?Jt((l-u)/n[a]*100):null;return{mid:n[a],upper:Jt(l),lower:Jt(u),bandwidth:c}})}function Yt(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function Y(e,t={}){let{period:r=9,kPeriod:s=3,dPeriod:n=3}=t,o=[],i=50,a=50;for(let l=0;l<e.length;l++){if(l<r-1){o.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,f=!0;for(let C=l-r+1;C<=l;C++){if(e[C].high===null||e[C].low===null){f=!1;break}u=Math.max(u,e[C].high),c=Math.min(c,e[C].low)}let p=e[l].close;if(!f||p===null||u===c){o.push({k:null,d:null,j:null});continue}let g=(p-c)/(u-c)*100;i=(s-1)/s*i+1/s*g,a=(n-1)/n*a+1/n*i;let y=3*i-2*a;o.push({k:Yt(i),d:Yt(a),j:Yt(y)})}return o}function $e(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function X(e,t={}){let{periods:r=[6,12,24]}=t,s=[null];for(let o=1;o<e.length;o++)e[o]===null||e[o-1]===null?s.push(null):s.push(e[o]-e[o-1]);let n={};for(let o of r){let i=[],a=0,l=0;for(let u=0;u<e.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,f=c>0?c:0,p=c<0?Math.abs(c):0;a=(a*(o-1)+f)/o,l=(l*(o-1)+p)/o}if(l===0)i.push(100);else if(a===0)i.push(0);else{let c=a/l;i.push($e(100-100/(1+c)))}}n[`rsi${o}`]=i}return e.map((o,i)=>{let a={};for(let l of r)a[`rsi${l}`]=n[`rsi${l}`][i];return a})}function We(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function Z(e,t={}){let{periods:r=[6,10]}=t,s={};for(let n of r){let o=[];for(let i=0;i<e.length;i++){if(i<n-1){o.push(null);continue}let a=-1/0,l=1/0,u=!0;for(let p=i-n+1;p<=i;p++){if(e[p].high===null||e[p].low===null){u=!1;break}a=Math.max(a,e[p].high),l=Math.min(l,e[p].low)}let c=e[i].close;if(!u||c===null||a===l){o.push(null);continue}let f=(a-c)/(a-l)*100;o.push(We(f))}s[`wr${n}`]=o}return e.map((n,o)=>{let i={};for(let a of r)i[`wr${a}`]=s[`wr${a}`][o];return i})}function ze(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function tt(e,t={}){let{periods:r=[6,12,24]}=t,s={};for(let n of r){let o=P(e,n),i=[];for(let a=0;a<e.length;a++)if(e[a]===null||o[a]===null||o[a]===0)i.push(null);else{let l=(e[a]-o[a])/o[a]*100;i.push(ze(l))}s[`bias${n}`]=i}return e.map((n,o)=>{let i={};for(let a of r)i[`bias${a}`]=s[`bias${a}`][o];return i})}function Ve(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function et(e,t={}){let{period:r=14}=t,s=[],n=e.map(o=>o.high===null||o.low===null||o.close===null?null:(o.high+o.low+o.close)/3);for(let o=0;o<e.length;o++){if(o<r-1){s.push({cci:null});continue}let i=0,a=0;for(let f=o-r+1;f<=o;f++)n[f]!==null&&(i+=n[f],a++);if(a!==r||n[o]===null){s.push({cci:null});continue}let l=i/r,u=0;for(let f=o-r+1;f<=o;f++)u+=Math.abs(n[f]-l);let c=u/r;if(c===0)s.push({cci:0});else{let f=(n[o]-l)/(.015*c);s.push({cci:Ve(f)})}}return s}function Xt(e,t=2){let r=Math.pow(10,t);return Math.round(e*r)/r}function nt(e,t={}){let{period:r=14}=t,s=[],n=[];for(let i=0;i<e.length;i++){let{high:a,low:l,close:u}=e[i];if(a===null||l===null||u===null){n.push(null);continue}if(i===0)n.push(a-l);else{let c=e[i-1].close;if(c===null)n.push(a-l);else{let f=a-l,p=Math.abs(a-c),g=Math.abs(l-c);n.push(Math.max(f,p,g))}}}let o=null;for(let i=0;i<e.length;i++){if(i<r-1){s.push({tr:n[i]!==null?Xt(n[i]):null,atr:null});continue}if(i===r-1){let a=0,l=0;for(let u=0;u<r;u++)n[u]!==null&&(a+=n[u],l++);l===r&&(o=a/r)}else o!==null&&n[i]!==null&&(o=(o*(r-1)+n[i])/r);s.push({tr:n[i]!==null?Xt(n[i]):null,atr:o!==null?Xt(o):null})}return s}function rt(e,t={}){if(e.length===0)return[];let r=e.map(g=>g.close),s=e.map(g=>({open:g.open,high:g.high,low:g.low,close:g.close,volume:g.volume})),n=t.ma?V(r,typeof t.ma=="object"?t.ma:{}):null,o=t.macd?G(r,typeof t.macd=="object"?t.macd:{}):null,i=t.boll?J(r,typeof t.boll=="object"?t.boll:{}):null,a=t.kdj?Y(s,typeof t.kdj=="object"?t.kdj:{}):null,l=t.rsi?X(r,typeof t.rsi=="object"?t.rsi:{}):null,u=t.wr?Z(s,typeof t.wr=="object"?t.wr:{}):null,c=t.bias?tt(r,typeof t.bias=="object"?t.bias:{}):null,f=t.cci?et(s,typeof t.cci=="object"?t.cci:{}):null,p=t.atr?nt(s,typeof t.atr=="object"?t.atr:{}):null;return e.map((g,y)=>({...g,...n&&{ma:n[y]},...o&&{macd:o[y]},...i&&{boll:i[y]},...a&&{kdj:a[y]},...l&&{rsi:l[y]},...u&&{wr:u[y]},...c&&{bias:c[y]},...f&&{cci:f[y]},...p&&{atr:p[y]}}))}var ot=class{constructor(t={}){this.client=new W(t)}getFullQuotes(t){return b.getFullQuotes(this.client,t)}getSimpleQuotes(t){return b.getSimpleQuotes(this.client,t)}getHKQuotes(t){return b.getHKQuotes(this.client,t)}getUSQuotes(t){return b.getUSQuotes(this.client,t)}getFundQuotes(t){return b.getFundQuotes(this.client,t)}getFundFlow(t){return b.getFundFlow(this.client,t)}getPanelLargeOrder(t){return b.getPanelLargeOrder(this.client,t)}getTodayTimeline(t){return b.getTodayTimeline(this.client,t)}getIndustryList(){return S.getIndustryList(this.client)}getIndustrySpot(t){return S.getIndustrySpot(this.client,t)}getIndustryConstituents(t){return S.getIndustryConstituents(this.client,t)}getIndustryKline(t,r){return S.getIndustryKline(this.client,t,r)}getIndustryMinuteKline(t,r){return S.getIndustryMinuteKline(this.client,t,r)}getConceptList(){return S.getConceptList(this.client)}getConceptSpot(t){return S.getConceptSpot(this.client,t)}getConceptConstituents(t){return S.getConceptConstituents(this.client,t)}getConceptKline(t,r){return S.getConceptKline(this.client,t,r)}getConceptMinuteKline(t,r){return S.getConceptMinuteKline(this.client,t,r)}getHistoryKline(t,r){return S.getHistoryKline(this.client,t,r)}getMinuteKline(t,r){return S.getMinuteKline(this.client,t,r)}getHKHistoryKline(t,r){return S.getHKHistoryKline(this.client,t,r)}getUSHistoryKline(t,r){return S.getUSHistoryKline(this.client,t,r)}search(t){return b.search(this.client,t)}getAShareCodeList(t=!0){return b.getAShareCodeList(this.client,t)}getUSCodeList(t=!0){return b.getUSCodeList(this.client,t)}getHKCodeList(){return b.getHKCodeList(this.client)}async getAllAShareQuotes(t={}){let r=await this.getAShareCodeList();return this.getAllQuotesByCodes(r,t)}async getAllHKShareQuotes(t={}){let r=await this.getHKCodeList();return b.getAllHKQuotesByCodes(this.client,r,t)}async getAllUSShareQuotes(t={}){let r=await this.getUSCodeList(!1);return b.getAllUSQuotesByCodes(this.client,r,t)}getAllQuotesByCodes(t,r={}){return b.getAllQuotesByCodes(this.client,t,r)}async batchRaw(t){return this.client.getTencentQuote(t)}getTradingCalendar(){return b.getTradingCalendar(this.client)}detectMarket(t){return/^\d{3}\.[A-Z]+$/i.test(t)?"US":/^\d{5}$/.test(t)?"HK":"A"}safeMax(t,r=0){return!t||t.length===0?r:Math.max(...t)}calcRequiredLookback(t){let r=0,s=!1;if(t.ma){let o=typeof t.ma=="object"?t.ma:{},i=o.periods??[5,10,20,30,60,120,250],a=o.type??"sma";r=Math.max(r,this.safeMax(i,20)),a==="ema"&&(s=!0)}if(t.macd){let o=typeof t.macd=="object"?t.macd:{},i=o.long??26,a=o.signal??9;r=Math.max(r,i*3+a),s=!0}if(t.boll){let o=typeof t.boll=="object"&&t.boll.period?t.boll.period:20;r=Math.max(r,o)}if(t.kdj){let o=typeof t.kdj=="object"&&t.kdj.period?t.kdj.period:9;r=Math.max(r,o)}if(t.rsi){let o=typeof t.rsi=="object"&&t.rsi.periods?t.rsi.periods:[6,12,24];r=Math.max(r,this.safeMax(o,14)+1)}if(t.wr){let o=typeof t.wr=="object"&&t.wr.periods?t.wr.periods:[6,10];r=Math.max(r,this.safeMax(o,10))}if(t.bias){let o=typeof t.bias=="object"&&t.bias.periods?t.bias.periods:[6,12,24];r=Math.max(r,this.safeMax(o,12))}if(t.cci){let o=typeof t.cci=="object"&&t.cci.period?t.cci.period:14;r=Math.max(r,o)}if(t.atr){let o=typeof t.atr=="object"&&t.atr.period?t.atr.period:14;r=Math.max(r,o)}return Math.ceil(r*(s?1.5:1.2))}calcActualStartDate(t,r,s=1.5){let n=Math.ceil(r*s),o=new Date(parseInt(t.slice(0,4)),parseInt(t.slice(4,6))-1,parseInt(t.slice(6,8)));o.setDate(o.getDate()-n);let i=o.getFullYear(),a=String(o.getMonth()+1).padStart(2,"0"),l=String(o.getDate()).padStart(2,"0");return`${i}${a}${l}`}dateToTimestamp(t){let r=t.includes("-")?t:`${t.slice(0,4)}-${t.slice(4,6)}-${t.slice(6,8)}`;return new Date(r).getTime()}async getKlineWithIndicators(t,r={}){let{startDate:s,endDate:n,indicators:o={}}=r,i=r.market??this.detectMarket(t),a=this.calcRequiredLookback(o),u={A:1.5,HK:1.46,US:1.45}[i],c=s?this.calcActualStartDate(s,a,u):void 0,f={period:r.period,adjust:r.adjust,startDate:c,endDate:r.endDate},p;switch(i){case"HK":p=await this.getHKHistoryKline(t,f);break;case"US":p=await this.getUSHistoryKline(t,f);break;default:p=await this.getHistoryKline(t,f)}if(s&&p.length<a)switch(i){case"HK":p=await this.getHKHistoryKline(t,{...f,startDate:void 0});break;case"US":p=await this.getUSHistoryKline(t,{...f,startDate:void 0});break;default:p=await this.getHistoryKline(t,{...f,startDate:void 0})}let g=rt(p,o);if(s){let y=this.dateToTimestamp(s),C=n?this.dateToTimestamp(n):1/0;return g.filter(T=>{let w=this.dateToTimestamp(T.date);return w>=y&&w<=C})}return g}},_e=ot;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 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});
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
declare class HttpError extends Error {
|
|
5
5
|
readonly status: number;
|
|
6
6
|
readonly statusText: string;
|
|
7
|
-
|
|
7
|
+
readonly url?: string | undefined;
|
|
8
|
+
readonly provider?: string | undefined;
|
|
9
|
+
constructor(status: number, statusText: string, url?: string | undefined, provider?: string | undefined);
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* 重试配置选项
|
|
@@ -34,6 +36,10 @@ interface RequestClientOptions {
|
|
|
34
36
|
baseUrl?: string;
|
|
35
37
|
timeout?: number;
|
|
36
38
|
retry?: RetryOptions;
|
|
39
|
+
/** 自定义请求头 */
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
/** 自定义 User-Agent(浏览器环境可能会被忽略) */
|
|
42
|
+
userAgent?: string;
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -704,10 +710,14 @@ interface USKlineOptions {
|
|
|
704
710
|
}
|
|
705
711
|
|
|
706
712
|
/**
|
|
707
|
-
* 东方财富 -
|
|
713
|
+
* 东方财富 - 板块通用逻辑
|
|
714
|
+
* 提取行业板块和概念板块的共享代码
|
|
708
715
|
*/
|
|
709
716
|
|
|
710
|
-
|
|
717
|
+
/**
|
|
718
|
+
* K 线选项
|
|
719
|
+
*/
|
|
720
|
+
interface BoardKlineOptions {
|
|
711
721
|
/** K 线周期 */
|
|
712
722
|
period?: 'daily' | 'weekly' | 'monthly';
|
|
713
723
|
/** 复权类型 */
|
|
@@ -717,29 +727,27 @@ interface IndustryBoardKlineOptions {
|
|
|
717
727
|
/** 结束日期 YYYYMMDD */
|
|
718
728
|
endDate?: string;
|
|
719
729
|
}
|
|
720
|
-
|
|
730
|
+
/**
|
|
731
|
+
* 分钟 K 线选项
|
|
732
|
+
*/
|
|
733
|
+
interface BoardMinuteKlineOptions {
|
|
721
734
|
/** K 线周期:1/5/15/30/60 分钟 */
|
|
722
735
|
period?: '1' | '5' | '15' | '30' | '60';
|
|
723
736
|
}
|
|
724
737
|
|
|
738
|
+
/**
|
|
739
|
+
* 东方财富 - 行业板块
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
type IndustryBoardKlineOptions = BoardKlineOptions;
|
|
743
|
+
type IndustryBoardMinuteKlineOptions = BoardMinuteKlineOptions;
|
|
744
|
+
|
|
725
745
|
/**
|
|
726
746
|
* 东方财富 - 概念板块
|
|
727
747
|
*/
|
|
728
748
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
period?: 'daily' | 'weekly' | 'monthly';
|
|
732
|
-
/** 复权类型 */
|
|
733
|
-
adjust?: '' | 'qfq' | 'hfq';
|
|
734
|
-
/** 开始日期 YYYYMMDD */
|
|
735
|
-
startDate?: string;
|
|
736
|
-
/** 结束日期 YYYYMMDD */
|
|
737
|
-
endDate?: string;
|
|
738
|
-
}
|
|
739
|
-
interface ConceptBoardMinuteKlineOptions {
|
|
740
|
-
/** K 线周期:1/5/15/30/60 分钟 */
|
|
741
|
-
period?: '1' | '5' | '15' | '30' | '60';
|
|
742
|
-
}
|
|
749
|
+
type ConceptBoardKlineOptions = BoardKlineOptions;
|
|
750
|
+
type ConceptBoardMinuteKlineOptions = BoardMinuteKlineOptions;
|
|
743
751
|
|
|
744
752
|
interface OHLCV {
|
|
745
753
|
open: number | null;
|
|
@@ -1146,6 +1154,18 @@ declare class StockSDK {
|
|
|
1146
1154
|
* 计算实际请求的开始日期
|
|
1147
1155
|
*/
|
|
1148
1156
|
private calcActualStartDate;
|
|
1157
|
+
/**
|
|
1158
|
+
* 计算实际请求的开始日期(交易日历)
|
|
1159
|
+
*/
|
|
1160
|
+
private calcActualStartDateByCalendar;
|
|
1161
|
+
/**
|
|
1162
|
+
* 统一日期格式为 YYYY-MM-DD
|
|
1163
|
+
*/
|
|
1164
|
+
private normalizeDate;
|
|
1165
|
+
/**
|
|
1166
|
+
* 压缩日期格式为 YYYYMMDD
|
|
1167
|
+
*/
|
|
1168
|
+
private toCompactDate;
|
|
1149
1169
|
/**
|
|
1150
1170
|
* 日期字符串转时间戳
|
|
1151
1171
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
declare class HttpError extends Error {
|
|
5
5
|
readonly status: number;
|
|
6
6
|
readonly statusText: string;
|
|
7
|
-
|
|
7
|
+
readonly url?: string | undefined;
|
|
8
|
+
readonly provider?: string | undefined;
|
|
9
|
+
constructor(status: number, statusText: string, url?: string | undefined, provider?: string | undefined);
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* 重试配置选项
|
|
@@ -34,6 +36,10 @@ interface RequestClientOptions {
|
|
|
34
36
|
baseUrl?: string;
|
|
35
37
|
timeout?: number;
|
|
36
38
|
retry?: RetryOptions;
|
|
39
|
+
/** 自定义请求头 */
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
/** 自定义 User-Agent(浏览器环境可能会被忽略) */
|
|
42
|
+
userAgent?: string;
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -704,10 +710,14 @@ interface USKlineOptions {
|
|
|
704
710
|
}
|
|
705
711
|
|
|
706
712
|
/**
|
|
707
|
-
* 东方财富 -
|
|
713
|
+
* 东方财富 - 板块通用逻辑
|
|
714
|
+
* 提取行业板块和概念板块的共享代码
|
|
708
715
|
*/
|
|
709
716
|
|
|
710
|
-
|
|
717
|
+
/**
|
|
718
|
+
* K 线选项
|
|
719
|
+
*/
|
|
720
|
+
interface BoardKlineOptions {
|
|
711
721
|
/** K 线周期 */
|
|
712
722
|
period?: 'daily' | 'weekly' | 'monthly';
|
|
713
723
|
/** 复权类型 */
|
|
@@ -717,29 +727,27 @@ interface IndustryBoardKlineOptions {
|
|
|
717
727
|
/** 结束日期 YYYYMMDD */
|
|
718
728
|
endDate?: string;
|
|
719
729
|
}
|
|
720
|
-
|
|
730
|
+
/**
|
|
731
|
+
* 分钟 K 线选项
|
|
732
|
+
*/
|
|
733
|
+
interface BoardMinuteKlineOptions {
|
|
721
734
|
/** K 线周期:1/5/15/30/60 分钟 */
|
|
722
735
|
period?: '1' | '5' | '15' | '30' | '60';
|
|
723
736
|
}
|
|
724
737
|
|
|
738
|
+
/**
|
|
739
|
+
* 东方财富 - 行业板块
|
|
740
|
+
*/
|
|
741
|
+
|
|
742
|
+
type IndustryBoardKlineOptions = BoardKlineOptions;
|
|
743
|
+
type IndustryBoardMinuteKlineOptions = BoardMinuteKlineOptions;
|
|
744
|
+
|
|
725
745
|
/**
|
|
726
746
|
* 东方财富 - 概念板块
|
|
727
747
|
*/
|
|
728
748
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
period?: 'daily' | 'weekly' | 'monthly';
|
|
732
|
-
/** 复权类型 */
|
|
733
|
-
adjust?: '' | 'qfq' | 'hfq';
|
|
734
|
-
/** 开始日期 YYYYMMDD */
|
|
735
|
-
startDate?: string;
|
|
736
|
-
/** 结束日期 YYYYMMDD */
|
|
737
|
-
endDate?: string;
|
|
738
|
-
}
|
|
739
|
-
interface ConceptBoardMinuteKlineOptions {
|
|
740
|
-
/** K 线周期:1/5/15/30/60 分钟 */
|
|
741
|
-
period?: '1' | '5' | '15' | '30' | '60';
|
|
742
|
-
}
|
|
749
|
+
type ConceptBoardKlineOptions = BoardKlineOptions;
|
|
750
|
+
type ConceptBoardMinuteKlineOptions = BoardMinuteKlineOptions;
|
|
743
751
|
|
|
744
752
|
interface OHLCV {
|
|
745
753
|
open: number | null;
|
|
@@ -1146,6 +1154,18 @@ declare class StockSDK {
|
|
|
1146
1154
|
* 计算实际请求的开始日期
|
|
1147
1155
|
*/
|
|
1148
1156
|
private calcActualStartDate;
|
|
1157
|
+
/**
|
|
1158
|
+
* 计算实际请求的开始日期(交易日历)
|
|
1159
|
+
*/
|
|
1160
|
+
private calcActualStartDateByCalendar;
|
|
1161
|
+
/**
|
|
1162
|
+
* 统一日期格式为 YYYY-MM-DD
|
|
1163
|
+
*/
|
|
1164
|
+
private normalizeDate;
|
|
1165
|
+
/**
|
|
1166
|
+
* 压缩日期格式为 YYYYMMDD
|
|
1167
|
+
*/
|
|
1168
|
+
private toCompactDate;
|
|
1149
1169
|
/**
|
|
1150
1170
|
* 日期字符串转时间戳
|
|
1151
1171
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ee=Object.defineProperty;var Yt=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})};function W(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 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 d(e){if(!e||e==="")return 0;let t=parseFloat(e);return Number.isNaN(t)?0:t}function R(e){if(!e||e==="")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function m(e){if(!e||e===""||e==="-")return null;let t=parseFloat(e);return Number.isNaN(t)?null:t}function h(e){return e==null?null:m(String(e))}var mt="https://qt.gtimg.cn",gt="https://web.ifzq.gtimg.cn/appstock/app/minute/query",ht="https://assets.linkdiary.cn/shares/zh_a_list.json",yt="https://assets.linkdiary.cn/shares/us_list.json",Ct="https://assets.linkdiary.cn/shares/hk_list.json",Xt="https://assets.linkdiary.cn/shares/trade-data-list.txt";var V="https://push2his.eastmoney.com/api/qt/stock/kline/get",Rt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",bt="https://33.push2his.eastmoney.com/api/qt/stock/kline/get",St="https://63.push2his.eastmoney.com/api/qt/stock/kline/get",Tt="https://17.push2.eastmoney.com/api/qt/clist/get",wt="https://91.push2.eastmoney.com/api/qt/stock/get",Mt="https://29.push2.eastmoney.com/api/qt/clist/get",G="https://7.push2his.eastmoney.com/api/qt/stock/kline/get",Kt="https://push2his.eastmoney.com/api/qt/stock/trends2/get",At="https://79.push2.eastmoney.com/api/qt/clist/get",_t="https://91.push2.eastmoney.com/api/qt/stock/get",Lt="https://29.push2.eastmoney.com/api/qt/clist/get",J="https://91.push2his.eastmoney.com/api/qt/stock/kline/get",Et="https://push2his.eastmoney.com/api/qt/stock/trends2/get",xt=3e4,N=500,j=500,Q=7,Ot=3,Pt=1e3,It=3e4,kt=2,Ut=[408,429,500,502,503,504];var B=class extends Error{constructor(n,s){super(`HTTP error! status: ${n}`);this.status=n;this.statusText=s;this.name="HttpError"}},F=class{constructor(t={}){this.baseUrl=t.baseUrl??mt,this.timeout=t.timeout??xt,this.retryOptions=this.resolveRetryOptions(t.retry)}resolveRetryOptions(t){return{maxRetries:t?.maxRetries??Ot,baseDelay:t?.baseDelay??Pt,maxDelay:t?.maxDelay??It,backoffMultiplier:t?.backoffMultiplier??kt,retryableStatusCodes:t?.retryableStatusCodes??Ut,retryOnNetworkError:t?.retryOnNetworkError??!0,retryOnTimeout:t?.retryOnTimeout??!0,onRetry:t?.onRetry}}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 B?this.retryOptions.retryableStatusCodes.includes(t.status):!1}async executeWithRetry(t,n=0){try{return await t()}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(t,n+1)}throw s}}async get(t,n={}){return this.executeWithRetry(async()=>{let s=new AbortController,r=setTimeout(()=>s.abort(),this.timeout);try{let o=await fetch(t,{signal:s.signal});if(!o.ok)throw new B(o.status,o.statusText);switch(n.responseType){case"json":return await o.json();case"arraybuffer":return await o.arrayBuffer();default:return await o.text()}}finally{clearTimeout(r)}})}async getTencentQuote(t){let n=`${this.baseUrl}/?q=${encodeURIComponent(t)}`,s=await this.get(n,{responseType:"arraybuffer"}),r=W(s);return z(r)}};var xe=new Set(["daily","weekly","monthly"]),Oe=new Set(["1","5","15","30","60"]),Pe=new Set(["","qfq","hfq"]);function x(e,t){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new RangeError(`${t} must be a positive integer`)}function A(e){if(!xe.has(e))throw new RangeError("period must be one of: daily, weekly, monthly")}function I(e){if(!Oe.has(e))throw new RangeError("period must be one of: 1, 5, 15, 30, 60")}function M(e){if(!Pe.has(e))throw new RangeError("adjust must be one of: '', 'qfq', 'hfq'")}function D(e,t){x(t,"chunkSize");let n=[];for(let s=0;s<e.length;s+=t)n.push(e.slice(s,s+t));return n}async function H(e,t){x(t,"concurrency");let n=[],s=[];for(let r of e){let o=Promise.resolve().then(()=>r()).then(i=>{n.push(i)});if(s.push(o),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 Y(e){return e.startsWith("sh")?"1":e.startsWith("sz")||e.startsWith("bj")?"0":e.startsWith("6")?"1":"0"}function _(e){return{daily:"101",weekly:"102",monthly:"103"}[e]}function K(e){return{"":"0",qfq:"1",hfq:"2"}[e]}var b={};Yt(b,{getAShareCodeList:()=>oe,getAllHKQuotesByCodes:()=>le,getAllQuotesByCodes:()=>ae,getAllUSQuotesByCodes:()=>ue,getFullQuotes:()=>X,getFundFlow:()=>te,getFundQuotes:()=>ne,getHKCodeList:()=>ie,getHKQuotes:()=>Z,getPanelLargeOrder:()=>ee,getSimpleQuotes:()=>Zt,getTodayTimeline:()=>re,getTradingCalendar:()=>ce,getUSCodeList:()=>se,getUSQuotes:()=>tt,parseFullQuote:()=>Bt,parseFundFlow:()=>Ht,parseFundQuote:()=>jt,parseHKQuote:()=>qt,parsePanelLargeOrder:()=>vt,parseSimpleQuote:()=>Dt,parseUSQuote:()=>Nt,search:()=>pe});function Bt(e){let t=[];for(let s=0;s<5;s++)t.push({price:d(e[9+s*2]),volume:d(e[10+s*2])});let n=[];for(let s=0;s<5;s++)n.push({price:d(e[19+s*2]),volume:d(e[20+s*2])});return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),outerVolume:d(e[7]),innerVolume:d(e[8]),bid:t,ask:n,time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),volume2:d(e[36]),amount:d(e[37]),turnoverRate:R(e[38]),pe:R(e[39]),amplitude:R(e[43]),circulatingMarketCap:R(e[44]),totalMarketCap:R(e[45]),pb:R(e[46]),limitUp:R(e[47]),limitDown:R(e[48]),volumeRatio:R(e[49]),avgPrice:R(e[51]),peStatic:R(e[52]),peDynamic:R(e[53]),high52w:R(e[67]),low52w:R(e[68]),circulatingShares:R(e[72]),totalShares:R(e[73]),raw:e}}function Dt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),change:d(e[4]),changePercent:d(e[5]),volume:d(e[6]),amount:d(e[7]),marketCap:R(e[9]),marketType:e[10]??"",raw:e}}function Ht(e){return{code:e[0]??"",mainInflow:d(e[1]),mainOutflow:d(e[2]),mainNet:d(e[3]),mainNetRatio:d(e[4]),retailInflow:d(e[5]),retailOutflow:d(e[6]),retailNet:d(e[7]),retailNetRatio:d(e[8]),totalFlow:d(e[9]),name:e[12]??"",date:e[13]??"",raw:e}}function vt(e){return{buyLargeRatio:d(e[0]),buySmallRatio:d(e[1]),sellLargeRatio:d(e[2]),sellSmallRatio:d(e[3]),raw:e}}function qt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),amount:d(e[37]),lotSize:R(e[40]),circulatingMarketCap:R(e[44]),totalMarketCap:R(e[45]),currency:e[e.length-3]??"",raw:e}}function Nt(e){return{marketId:e[0]??"",name:e[1]??"",code:e[2]??"",price:d(e[3]),prevClose:d(e[4]),open:d(e[5]),volume:d(e[6]),time:e[30]??"",change:d(e[31]),changePercent:d(e[32]),high:d(e[33]),low:d(e[34]),amount:d(e[37]),turnoverRate:R(e[38]),pe:R(e[39]),amplitude:R(e[43]),totalMarketCap:R(e[45]),pb:R(e[47]),high52w:R(e[48]),low52w:R(e[49]),raw:e}}function jt(e){return{code:e[0]??"",name:e[1]??"",nav:d(e[5]),accNav:d(e[6]),change:d(e[7]),navDate:e[8]??"",raw:e}}async function X(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=>Bt(s.fields))}async function Zt(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`s_${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Dt(r.fields))}async function te(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`ff_${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Ht(r.fields))}async function ee(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`s_pk${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>vt(r.fields))}async function Z(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`hk${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>qt(r.fields))}async function tt(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`us${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>Nt(r.fields))}async function ne(e,t){if(!t||t.length===0)return[];let n=t.map(r=>`jj${r}`);return(await e.getTencentQuote(n.join(","))).filter(r=>r.fields&&r.fields.length>0&&r.fields[0]!=="").map(r=>jt(r.fields))}async function re(e,t){let n=e.getTimeout(),s=new AbortController,r=setTimeout(()=>s.abort(),n);try{let o=await fetch(`${gt}?code=${t}`,{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?.[t];if(!a)return{code:t,date:"",data:[]};let l=a.data?.data||[],u=a.data?.date||"",c=!1;if(l.length>0){let p=l[0].split(" "),g=parseFloat(p[1])||0,y=parseInt(p[2],10)||0,C=parseFloat(p[3])||0;y>0&&g>0&&C/y>g*50&&(c=!0)}let f=l.map(p=>{let g=p.split(" "),y=g[0],C=`${y.slice(0,2)}:${y.slice(2,4)}`,T=parseInt(g[2],10)||0,w=parseFloat(g[3])||0,O=c?T*100:T,P=O>0?w/O:0;return{time:C,price:parseFloat(g[1])||0,volume:O,amount:w,avgPrice:Math.round(P*100)/100}});return{code:t,date:u,data:f}}finally{clearTimeout(r)}}async function oe(e,t=!0){let n=e.getTimeout(),s=new AbortController,r=setTimeout(()=>s.abort(),n);try{let o=await fetch(ht,{signal:s.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let a=(await o.json()).list||[];return t?a:a.map(l=>l.replace(/^(sh|sz|bj)/,""))}finally{clearTimeout(r)}}async function se(e,t=!0){let n=e.getTimeout(),s=new AbortController,r=setTimeout(()=>s.abort(),n);try{let o=await fetch(yt,{signal:s.signal});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let a=(await o.json()).list||[];return t?a:a.map(l=>l.replace(/^\d{3}\./,""))}finally{clearTimeout(r)}}async function ie(e){let t=e.getTimeout(),n=new AbortController,s=setTimeout(()=>n.abort(),t);try{let r=await fetch(Ct,{signal:n.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);return(await r.json()).list||[]}finally{clearTimeout(s)}}async function ae(e,t,n={}){let{batchSize:s=N,concurrency:r=Q,onProgress:o}=n;x(s,"batchSize"),x(r,"concurrency");let i=Math.min(s,j),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await X(e,p);return u++,o&&o(u,l),g});return(await H(c,r)).flat()}async function le(e,t,n={}){let{batchSize:s=N,concurrency:r=Q,onProgress:o}=n;x(s,"batchSize"),x(r,"concurrency");let i=Math.min(s,j),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await Z(e,p);return u++,o&&o(u,l),g});return(await H(c,r)).flat()}async function ue(e,t,n={}){let{batchSize:s=N,concurrency:r=Q,onProgress:o}=n;x(s,"batchSize"),x(r,"concurrency");let i=Math.min(s,j),a=D(t,i),l=a.length,u=0,c=a.map(p=>async()=>{let g=await tt(e,p);return u++,o&&o(u,l),g});return(await H(c,r)).flat()}async function ce(e){let t=await e.get(Xt);return!t||t.trim()===""?[]:t.trim().split(",").map(n=>n.trim()).filter(n=>n.length>0)}var fe="https://smartbox.gtimg.cn/s3/";function Ie(e){return e.replace(/\\u([0-9a-fA-F]{4})/g,(t,n)=>String.fromCharCode(parseInt(n,16)))}function ke(e){return!e||e==="N"?[]:e.split("^").filter(Boolean).map(n=>{let s=n.split("~"),r=s[0]||"",o=s[1]||"",i=Ie(s[2]||""),a=s[4]||"";return{code:r+o,name:i,market:r,type:a}})}function Ue(e){return new Promise((t,n)=>{let s=`${fe}?v=2&t=all&q=${encodeURIComponent(e)}`;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),t(o)},r.onerror=()=>{document.body.removeChild(r),n(new Error("Network error calling Smartbox"))},document.body.appendChild(r)})}async function Be(e,t){let n=`${fe}?v=2&t=all&q=${encodeURIComponent(t)}`,r=(await e.get(n)).match(/v_hint="([^"]*)"/);return r?r[1]:""}function De(){return typeof window<"u"&&typeof document<"u"}async function pe(e,t){if(!t||!t.trim())return[];let n;return De()?n=await Ue(t):n=await Be(e,t),ke(n)}var S={};Yt(S,{getConceptConstituents:()=>Te,getConceptKline:()=>we,getConceptList:()=>Wt,getConceptMinuteKline:()=>Me,getConceptSpot:()=>Se,getHKHistoryKline:()=>ge,getHistoryKline:()=>de,getIndustryConstituents:()=>Ce,getIndustryKline:()=>Re,getIndustryList:()=>Ft,getIndustryMinuteKline:()=>be,getIndustrySpot:()=>ye,getMinuteKline:()=>me,getUSHistoryKline:()=>he});async function v(e,t,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=`${t}?${u.toString()}`,p=(await e.get(c,{responseType:"json"}))?.data;if(!p||!Array.isArray(p.diff))break;a===1&&(l=p.total??0);let g=p.diff.map((y,C)=>o(y,i.length+C+1));i.push(...g),a++}while(i.length<l);return i}function L(e){let[t,n,s,r,o,i,a,l,u,c,f]=e.split(",");return{date:t,open:m(n),close:m(s),high:m(r),low:m(o),volume:m(i),amount:m(a),amplitude:m(l),changePercent:m(u),change:m(c),turnoverRate:m(f)}}async function E(e,t,n){let s=`${t}?${n.toString()}`,r=await e.get(s,{responseType:"json"});return{klines:r?.data?.klines||[],name:r?.data?.name,code:r?.data?.code}}async function de(e,t,n={}){let{period:s="daily",adjust:r="hfq",startDate:o="19700101",endDate:i="20500101"}=n;A(s),M(r);let a=t.replace(/^(sh|sz|bj)/,""),l=`${Y(t)}.${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:_(s),fqt:K(r),secid:l,beg:o,end:i}),c=V,{klines:f}=await E(e,c,u);return f.length===0?[]:f.map(p=>({...L(p),code:a}))}async function me(e,t,n={}){let{period:s="1",adjust:r="hfq",startDate:o="1979-09-01 09:32:00",endDate:i="2222-01-01 09:32:00"}=n;I(s),M(r);let a=t.replace(/^(sh|sz|bj)/,""),l=`${Y(t)}.${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=`${Rt}?${u.toString()}`,p=(await e.get(c,{responseType:"json"}))?.data?.trends;if(!Array.isArray(p)||p.length===0)return[];let g=o.replace("T"," ").slice(0,16),y=i.replace("T"," ").slice(0,16);return p.map(C=>{let[T,w,O,P,q,Ae,_e,Le]=C.split(",");return{time:T,open:m(w),close:m(O),high:m(P),low:m(q),volume:m(Ae),amount:m(_e),avgPrice:m(Le)}}).filter(C=>C.time>=g&&C.time<=y)}else{let u=new URLSearchParams({fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",ut:"7eea3edcaed734bea9cbfc24409ed989",klt:s,fqt:K(r||""),secid:l,beg:"0",end:"20500000"}),c=V,{klines:f}=await E(e,c,u);if(f.length===0)return[];let p=o.replace("T"," ").slice(0,16),g=i.replace("T"," ").slice(0,16);return f.map(y=>{let C=L(y);return{...C,time:C.date}}).filter(y=>y.time>=p&&y.time<=g)}}async function ge(e,t,n={}){let{period:s="daily",adjust:r="hfq",startDate:o="19700101",endDate:i="20500101"}=n;A(s),M(r);let a=t.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:_(s),fqt:K(r),secid:l,beg:o,end:i,lmt:"1000000"}),c=bt,{klines:f,name:p}=await E(e,c,u);return f.length===0?[]:f.map(g=>({...L(g),code:a,name:p||""}))}async function he(e,t,n={}){let{period:s="daily",adjust:r="hfq",startDate:o="19700101",endDate:i="20500101"}=n;A(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:_(s),fqt:K(r),secid:t,beg:o,end:i,lmt:"1000000"}),l=St,{klines:u,name:c,code:f}=await E(e,l,a),p=f||t.split(".")[1]||t,g=c||"";return u.length===0?[]:u.map(y=>({...L(y),code:p,name:g}))}var Qt=null;async function et(e,t){if(t.startsWith("BK"))return t;if(!Qt){let s=await Ft(e);Qt=new Map(s.map(r=>[r.name,r.code]))}let n=Qt.get(t);if(!n)throw new Error(`\u672A\u627E\u5230\u884C\u4E1A\u677F\u5757: ${t}`);return n}async function Ft(e){let s=await v(e,Tt,{po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:"m:90 t:2 f:!50"},"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",100,(r,o)=>({rank:o,name:String(r.f14??""),code:String(r.f12??""),price:h(r.f2),change:h(r.f4),changePercent:h(r.f3),totalMarketCap:h(r.f20),turnoverRate:h(r.f8),riseCount:h(r.f104),fallCount:h(r.f105),leadingStock:r.f128?String(r.f128):null,leadingStockChangePercent:h(r.f136)}));return s.sort((r,o)=>(o.changePercent??0)-(r.changePercent??0)),s.forEach((r,o)=>{r.rank=o+1}),s}async function ye(e,t){let n=await et(e,t),s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${n}`}),r=`${wt}?${s.toString()}`,i=(await e.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 f=i[l],p=null;return typeof f=="number"&&!isNaN(f)&&(p=c?f/100:f),{item:u,value:p}}):[]}async function Ce(e,t){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f3",fs:`b:${await et(e,t)} f:!50`};return v(e,Mt,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:h(o.f2),changePercent:h(o.f3),change:h(o.f4),volume:h(o.f5),amount:h(o.f6),amplitude:h(o.f7),high:h(o.f15),low:h(o.f16),open:h(o.f17),prevClose:h(o.f18),turnoverRate:h(o.f8),pe:h(o.f9),pb:h(o.f23)}))}async function Re(e,t,n={}){let{period:s="daily",adjust:r="",startDate:o="19700101",endDate:i="20500101"}=n;A(s),M(r);let a=await et(e,t),l=new URLSearchParams({secid:`90.${a}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:_(s),fqt:K(r),beg:o,end:i,smplmt:"10000",lmt:"1000000"}),u=G,{klines:c}=await E(e,u,l);return c.length===0?[]:c.map(f=>({...L(f)}))}async function be(e,t,n={}){let{period:s="5"}=n;I(s);let r=await et(e,t);if(s==="1"){let o=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.${r}`}),i=`${Kt}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.trends;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),volume:m(C),amount:m(T),price:m(w)}})}else{let o=new URLSearchParams({secid:`90.${r}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:s,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),i=`${G}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.klines;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w,O,P,q]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),changePercent:m(O),change:m(P),volume:m(C),amount:m(T),amplitude:m(w),turnoverRate:m(q)}})}}var $t=null;async function nt(e,t){if(t.startsWith("BK"))return t;if(!$t){let s=await Wt(e);$t=new Map(s.map(r=>[r.name,r.code]))}let n=$t.get(t);if(!n)throw new Error(`\u672A\u627E\u5230\u6982\u5FF5\u677F\u5757: ${t}`);return n}async function Wt(e){let s=await v(e,At,{po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f12",fs:"m:90 t:3 f:!50"},"f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136",100,(r,o)=>({rank:o,name:String(r.f14??""),code:String(r.f12??""),price:h(r.f2),change:h(r.f4),changePercent:h(r.f3),totalMarketCap:h(r.f20),turnoverRate:h(r.f8),riseCount:h(r.f104),fallCount:h(r.f105),leadingStock:r.f128?String(r.f128):null,leadingStockChangePercent:h(r.f136)}));return s.sort((r,o)=>(o.changePercent??0)-(r.changePercent??0)),s.forEach((r,o)=>{r.rank=o+1}),s}async function Se(e,t){let n=await nt(e,t),s=new URLSearchParams({fields:"f43,f44,f45,f46,f47,f48,f170,f171,f168,f169",mpi:"1000",invt:"2",fltt:"1",secid:`90.${n}`}),r=`${_t}?${s.toString()}`,i=(await e.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 f=i[l],p=null;return typeof f=="number"&&!isNaN(f)&&(p=c?f/100:f),{item:u,value:p}}):[]}async function Te(e,t){let s={po:"1",np:"1",ut:"bd1d9ddb04089700cf9c27f6f7426281",fltt:"2",invt:"2",fid:"f12",fs:`b:${await nt(e,t)} f:!50`};return v(e,Lt,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:h(o.f2),changePercent:h(o.f3),change:h(o.f4),volume:h(o.f5),amount:h(o.f6),amplitude:h(o.f7),high:h(o.f15),low:h(o.f16),open:h(o.f17),prevClose:h(o.f18),turnoverRate:h(o.f8),pe:h(o.f9),pb:h(o.f23)}))}async function we(e,t,n={}){let{period:s="daily",adjust:r="",startDate:o="19700101",endDate:i="20500101"}=n;A(s),M(r);let a=await nt(e,t),l=new URLSearchParams({secid:`90.${a}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:_(s),fqt:K(r),beg:o,end:i,smplmt:"10000",lmt:"1000000"}),u=J,{klines:c}=await E(e,u,l);return c.length===0?[]:c.map(f=>({...L(f)}))}async function Me(e,t,n={}){let{period:s="5"}=n;I(s);let r=await nt(e,t);if(s==="1"){let o=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.${r}`}),i=`${Et}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.trends;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),volume:m(C),amount:m(T),price:m(w)}})}else{let o=new URLSearchParams({secid:`90.${r}`,fields1:"f1,f2,f3,f4,f5,f6",fields2:"f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",klt:s,fqt:"1",beg:"0",end:"20500101",smplmt:"10000",lmt:"1000000"}),i=`${J}?${o.toString()}`,l=(await e.get(i,{responseType:"json"}))?.data?.klines;return!Array.isArray(l)||l.length===0?[]:l.map(u=>{let[c,f,p,g,y,C,T,w,O,P,q]=u.split(",");return{time:c,open:m(f),close:m(p),high:m(g),low:m(y),changePercent:m(O),change:m(P),volume:m(C),amount:m(T),amplitude:m(w),turnoverRate:m(q)}})}}function $(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function k(e,t){let n=[];for(let s=0;s<e.length;s++){if(s<t-1){n.push(null);continue}let r=0,o=0;for(let i=s-t+1;i<=s;i++)e[i]!==null&&(r+=e[i],o++);n.push(o===t?$(r/t):null)}return n}function U(e,t){let n=[],s=2/(t+1),r=null,o=!1;for(let i=0;i<e.length;i++){if(i<t-1){n.push(null);continue}if(!o){let l=0,u=0;for(let c=i-t+1;c<=i;c++)e[c]!==null&&(l+=e[c],u++);u===t&&(r=l/t,o=!0),n.push(r!==null?$(r):null);continue}let a=e[i];a===null?n.push(r!==null?$(r):null):(r=s*a+(1-s)*r,n.push($(r)))}return n}function zt(e,t){let n=[],s=Array.from({length:t},(o,i)=>i+1),r=s.reduce((o,i)=>o+i,0);for(let o=0;o<e.length;o++){if(o<t-1){n.push(null);continue}let i=0,a=!0;for(let l=0;l<t;l++){let u=e[o-t+1+l];if(u===null){a=!1;break}i+=u*s[l]}n.push(a?$(i/r):null)}return n}function rt(e,t={}){let{periods:n=[5,10,20,30,60,120,250],type:s="sma"}=t,r=s==="ema"?U:s==="wma"?zt:k,o={};for(let i of n)o[`ma${i}`]=r(e,i);return e.map((i,a)=>{let l={};for(let u of n)l[`ma${u}`]=o[`ma${u}`][a];return l})}function Ke(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function ot(e,t={}){let{short:n=12,long:s=26,signal:r=9}=t,o=U(e,n),i=U(e,s),a=e.map((u,c)=>o[c]===null||i[c]===null?null:o[c]-i[c]),l=U(a,r);return e.map((u,c)=>({dif:a[c]!==null?Ke(a[c]):null,dea:l[c],macd:a[c]!==null&&l[c]!==null?Ke((a[c]-l[c])*2):null}))}function Vt(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function He(e,t,n){let s=[];for(let r=0;r<e.length;r++){if(r<t-1||n[r]===null){s.push(null);continue}let o=0,i=0;for(let a=r-t+1;a<=r;a++)e[a]!==null&&n[r]!==null&&(o+=Math.pow(e[a]-n[r],2),i++);s.push(i===t?Math.sqrt(o/t):null)}return s}function st(e,t={}){let{period:n=20,stdDev:s=2}=t,r=k(e,n),o=He(e,n,r);return e.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?Vt((l-u)/r[a]*100):null;return{mid:r[a],upper:Vt(l),lower:Vt(u),bandwidth:c}})}function Gt(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function it(e,t={}){let{period:n=9,kPeriod:s=3,dPeriod:r=3}=t,o=[],i=50,a=50;for(let l=0;l<e.length;l++){if(l<n-1){o.push({k:null,d:null,j:null});continue}let u=-1/0,c=1/0,f=!0;for(let C=l-n+1;C<=l;C++){if(e[C].high===null||e[C].low===null){f=!1;break}u=Math.max(u,e[C].high),c=Math.min(c,e[C].low)}let p=e[l].close;if(!f||p===null||u===c){o.push({k:null,d:null,j:null});continue}let g=(p-c)/(u-c)*100;i=(s-1)/s*i+1/s*g,a=(r-1)/r*a+1/r*i;let y=3*i-2*a;o.push({k:Gt(i),d:Gt(a),j:Gt(y)})}return o}function ve(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function at(e,t={}){let{periods:n=[6,12,24]}=t,s=[null];for(let o=1;o<e.length;o++)e[o]===null||e[o-1]===null?s.push(null):s.push(e[o]-e[o-1]);let r={};for(let o of n){let i=[],a=0,l=0;for(let u=0;u<e.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,f=c>0?c:0,p=c<0?Math.abs(c):0;a=(a*(o-1)+f)/o,l=(l*(o-1)+p)/o}if(l===0)i.push(100);else if(a===0)i.push(0);else{let c=a/l;i.push(ve(100-100/(1+c)))}}r[`rsi${o}`]=i}return e.map((o,i)=>{let a={};for(let l of n)a[`rsi${l}`]=r[`rsi${l}`][i];return a})}function qe(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function lt(e,t={}){let{periods:n=[6,10]}=t,s={};for(let r of n){let o=[];for(let i=0;i<e.length;i++){if(i<r-1){o.push(null);continue}let a=-1/0,l=1/0,u=!0;for(let p=i-r+1;p<=i;p++){if(e[p].high===null||e[p].low===null){u=!1;break}a=Math.max(a,e[p].high),l=Math.min(l,e[p].low)}let c=e[i].close;if(!u||c===null||a===l){o.push(null);continue}let f=(a-c)/(a-l)*100;o.push(qe(f))}s[`wr${r}`]=o}return e.map((r,o)=>{let i={};for(let a of n)i[`wr${a}`]=s[`wr${a}`][o];return i})}function Ne(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function ut(e,t={}){let{periods:n=[6,12,24]}=t,s={};for(let r of n){let o=k(e,r),i=[];for(let a=0;a<e.length;a++)if(e[a]===null||o[a]===null||o[a]===0)i.push(null);else{let l=(e[a]-o[a])/o[a]*100;i.push(Ne(l))}s[`bias${r}`]=i}return e.map((r,o)=>{let i={};for(let a of n)i[`bias${a}`]=s[`bias${a}`][o];return i})}function je(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function ct(e,t={}){let{period:n=14}=t,s=[],r=e.map(o=>o.high===null||o.low===null||o.close===null?null:(o.high+o.low+o.close)/3);for(let o=0;o<e.length;o++){if(o<n-1){s.push({cci:null});continue}let i=0,a=0;for(let f=o-n+1;f<=o;f++)r[f]!==null&&(i+=r[f],a++);if(a!==n||r[o]===null){s.push({cci:null});continue}let l=i/n,u=0;for(let f=o-n+1;f<=o;f++)u+=Math.abs(r[f]-l);let c=u/n;if(c===0)s.push({cci:0});else{let f=(r[o]-l)/(.015*c);s.push({cci:je(f)})}}return s}function Jt(e,t=2){let n=Math.pow(10,t);return Math.round(e*n)/n}function ft(e,t={}){let{period:n=14}=t,s=[],r=[];for(let i=0;i<e.length;i++){let{high:a,low:l,close:u}=e[i];if(a===null||l===null||u===null){r.push(null);continue}if(i===0)r.push(a-l);else{let c=e[i-1].close;if(c===null)r.push(a-l);else{let f=a-l,p=Math.abs(a-c),g=Math.abs(l-c);r.push(Math.max(f,p,g))}}}let o=null;for(let i=0;i<e.length;i++){if(i<n-1){s.push({tr:r[i]!==null?Jt(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?Jt(r[i]):null,atr:o!==null?Jt(o):null})}return s}function pt(e,t={}){if(e.length===0)return[];let n=e.map(g=>g.close),s=e.map(g=>({open:g.open,high:g.high,low:g.low,close:g.close,volume:g.volume})),r=t.ma?rt(n,typeof t.ma=="object"?t.ma:{}):null,o=t.macd?ot(n,typeof t.macd=="object"?t.macd:{}):null,i=t.boll?st(n,typeof t.boll=="object"?t.boll:{}):null,a=t.kdj?it(s,typeof t.kdj=="object"?t.kdj:{}):null,l=t.rsi?at(n,typeof t.rsi=="object"?t.rsi:{}):null,u=t.wr?lt(s,typeof t.wr=="object"?t.wr:{}):null,c=t.bias?ut(n,typeof t.bias=="object"?t.bias:{}):null,f=t.cci?ct(s,typeof t.cci=="object"?t.cci:{}):null,p=t.atr?ft(s,typeof t.atr=="object"?t.atr:{}):null;return e.map((g,y)=>({...g,...r&&{ma:r[y]},...o&&{macd:o[y]},...i&&{boll:i[y]},...a&&{kdj:a[y]},...l&&{rsi:l[y]},...u&&{wr:u[y]},...c&&{bias:c[y]},...f&&{cci:f[y]},...p&&{atr:p[y]}}))}var dt=class{constructor(t={}){this.client=new F(t)}getFullQuotes(t){return b.getFullQuotes(this.client,t)}getSimpleQuotes(t){return b.getSimpleQuotes(this.client,t)}getHKQuotes(t){return b.getHKQuotes(this.client,t)}getUSQuotes(t){return b.getUSQuotes(this.client,t)}getFundQuotes(t){return b.getFundQuotes(this.client,t)}getFundFlow(t){return b.getFundFlow(this.client,t)}getPanelLargeOrder(t){return b.getPanelLargeOrder(this.client,t)}getTodayTimeline(t){return b.getTodayTimeline(this.client,t)}getIndustryList(){return S.getIndustryList(this.client)}getIndustrySpot(t){return S.getIndustrySpot(this.client,t)}getIndustryConstituents(t){return S.getIndustryConstituents(this.client,t)}getIndustryKline(t,n){return S.getIndustryKline(this.client,t,n)}getIndustryMinuteKline(t,n){return S.getIndustryMinuteKline(this.client,t,n)}getConceptList(){return S.getConceptList(this.client)}getConceptSpot(t){return S.getConceptSpot(this.client,t)}getConceptConstituents(t){return S.getConceptConstituents(this.client,t)}getConceptKline(t,n){return S.getConceptKline(this.client,t,n)}getConceptMinuteKline(t,n){return S.getConceptMinuteKline(this.client,t,n)}getHistoryKline(t,n){return S.getHistoryKline(this.client,t,n)}getMinuteKline(t,n){return S.getMinuteKline(this.client,t,n)}getHKHistoryKline(t,n){return S.getHKHistoryKline(this.client,t,n)}getUSHistoryKline(t,n){return S.getUSHistoryKline(this.client,t,n)}search(t){return b.search(this.client,t)}getAShareCodeList(t=!0){return b.getAShareCodeList(this.client,t)}getUSCodeList(t=!0){return b.getUSCodeList(this.client,t)}getHKCodeList(){return b.getHKCodeList(this.client)}async getAllAShareQuotes(t={}){let n=await this.getAShareCodeList();return this.getAllQuotesByCodes(n,t)}async getAllHKShareQuotes(t={}){let n=await this.getHKCodeList();return b.getAllHKQuotesByCodes(this.client,n,t)}async getAllUSShareQuotes(t={}){let n=await this.getUSCodeList(!1);return b.getAllUSQuotesByCodes(this.client,n,t)}getAllQuotesByCodes(t,n={}){return b.getAllQuotesByCodes(this.client,t,n)}async batchRaw(t){return this.client.getTencentQuote(t)}getTradingCalendar(){return b.getTradingCalendar(this.client)}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 o=typeof t.ma=="object"?t.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(t.macd){let o=typeof t.macd=="object"?t.macd:{},i=o.long??26,a=o.signal??9;n=Math.max(n,i*3+a),s=!0}if(t.boll){let o=typeof t.boll=="object"&&t.boll.period?t.boll.period:20;n=Math.max(n,o)}if(t.kdj){let o=typeof t.kdj=="object"&&t.kdj.period?t.kdj.period:9;n=Math.max(n,o)}if(t.rsi){let o=typeof t.rsi=="object"&&t.rsi.periods?t.rsi.periods:[6,12,24];n=Math.max(n,this.safeMax(o,14)+1)}if(t.wr){let o=typeof t.wr=="object"&&t.wr.periods?t.wr.periods:[6,10];n=Math.max(n,this.safeMax(o,10))}if(t.bias){let o=typeof t.bias=="object"&&t.bias.periods?t.bias.periods:[6,12,24];n=Math.max(n,this.safeMax(o,12))}if(t.cci){let o=typeof t.cci=="object"&&t.cci.period?t.cci.period:14;n=Math.max(n,o)}if(t.atr){let o=typeof t.atr=="object"&&t.atr.period?t.atr.period:14;n=Math.max(n,o)}return Math.ceil(n*(s?1.5:1.2))}calcActualStartDate(t,n,s=1.5){let r=Math.ceil(n*s),o=new Date(parseInt(t.slice(0,4)),parseInt(t.slice(4,6))-1,parseInt(t.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}`}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:r,indicators:o={}}=n,i=n.market??this.detectMarket(t),a=this.calcRequiredLookback(o),u={A:1.5,HK:1.46,US:1.45}[i],c=s?this.calcActualStartDate(s,a,u):void 0,f={period:n.period,adjust:n.adjust,startDate:c,endDate:n.endDate},p;switch(i){case"HK":p=await this.getHKHistoryKline(t,f);break;case"US":p=await this.getUSHistoryKline(t,f);break;default:p=await this.getHistoryKline(t,f)}if(s&&p.length<a)switch(i){case"HK":p=await this.getHKHistoryKline(t,{...f,startDate:void 0});break;case"US":p=await this.getUSHistoryKline(t,{...f,startDate:void 0});break;default:p=await this.getHistoryKline(t,{...f,startDate:void 0})}let g=pt(p,o);if(s){let y=this.dateToTimestamp(s),C=r?this.dateToTimestamp(r):1/0;return g.filter(T=>{let w=this.dateToTimestamp(T.date);return w>=y&&w<=C})}return g}},Qe=dt;export{B as HttpError,dt as StockSDK,pt as addIndicators,H as asyncPool,ft as calcATR,ut as calcBIAS,st as calcBOLL,ct as calcCCI,U as calcEMA,it as calcKDJ,rt as calcMA,ot as calcMACD,at as calcRSI,k as calcSMA,zt as calcWMA,lt as calcWR,D as chunkArray,W as decodeGBK,Qe as default,z as parseResponse,d as safeNumber,R as safeNumberOrNull};
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stock-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
"build:pages": "DOCS_BASE=/stock-sdk/ vitepress build website"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
|
+
"JavaScript",
|
|
36
|
+
"TypeScript",
|
|
35
37
|
"stock",
|
|
36
38
|
"sdk",
|
|
37
39
|
"browser",
|
|
@@ -57,6 +59,9 @@
|
|
|
57
59
|
"node": ">=18.0.0"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
62
|
+
"@grafana/faro-rollup-plugin": "^0.7.1",
|
|
63
|
+
"@grafana/faro-web-sdk": "^2.1.0",
|
|
64
|
+
"@grafana/faro-web-tracing": "^2.1.0",
|
|
60
65
|
"@iconify/vue": "^5.0.0",
|
|
61
66
|
"@types/node": "^24.10.2",
|
|
62
67
|
"@vitest/coverage-v8": "^4.0.16",
|