stock-sdk 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  基于腾讯财经 `qt.gtimg.cn` 非官方接口封装的 TypeScript SDK,支持 A 股、港股、美股、公募基金实时行情查询。
4
4
 
5
+ **同时支持浏览器端和 Node.js 端使用。**
6
+
7
+ ## 特性
8
+
9
+ - ✅ 零依赖,轻量级(使用原生 fetch 和 TextDecoder)
10
+ - ✅ 支持浏览器和 Node.js 18+ 双端运行
11
+ - ✅ 同时提供 ESM 和 CommonJS 两种模块格式
12
+ - ✅ 完整的 TypeScript 类型定义
13
+ - ✅ A 股、港股、美股、公募基金实时行情
14
+ - ✅ 资金流向、盘口大单等扩展数据
15
+ - ✅ 内置全部 A 股代码列表(5000+)
16
+ - ✅ 支持批量获取全市场行情(并发控制)
17
+
5
18
  ## 安装
6
19
 
7
20
  ```bash
@@ -13,7 +26,11 @@ yarn add stock-sdk
13
26
  ## 快速开始
14
27
 
15
28
  ```typescript
16
- import StockSDK from 'stock-sdk';
29
+ // ESM (浏览器 / Node.js)
30
+ import { StockSDK } from 'stock-sdk';
31
+
32
+ // CommonJS (Node.js)
33
+ // const { StockSDK } = require('stock-sdk');
17
34
 
18
35
  const sdk = new StockSDK();
19
36
 
@@ -21,8 +38,8 @@ const sdk = new StockSDK();
21
38
  const fullQuotes = await sdk.getFullQuotes(['sz000858', 'sh600000']);
22
39
  console.log(fullQuotes);
23
40
 
24
- // 简要行情
25
- const simpleQuotes = await sdk.getSimpleQuotes(['s_sz000858', 's_sh000001']);
41
+ // 简要行情(参数格式与 getFullQuotes 相同)
42
+ const simpleQuotes = await sdk.getSimpleQuotes(['sz000858', 'sh000001']);
26
43
  console.log(simpleQuotes);
27
44
  ```
28
45
 
@@ -59,12 +76,21 @@ interface FullQuote {
59
76
  volume2: number; // 成交量(手)
60
77
  amount: number; // 成交额(万)
61
78
  turnoverRate: number | null; // 换手率%
62
- pe: number | null; // 市盈率
79
+ pe: number | null; // 市盈率(TTM)
80
+ amplitude: number | null; // 振幅%
63
81
  circulatingMarketCap: number | null; // 流通市值(亿)
64
82
  totalMarketCap: number | null; // 总市值(亿)
65
83
  pb: number | null; // 市净率
66
84
  limitUp: number | null; // 涨停价
67
85
  limitDown: number | null; // 跌停价
86
+ volumeRatio: number | null; // 量比
87
+ avgPrice: number | null; // 均价
88
+ peStatic: number | null; // 市盈率(静)
89
+ peDynamic: number | null; // 市盈率(动)
90
+ high52w: number | null; // 52周最高价
91
+ low52w: number | null; // 52周最低价
92
+ circulatingShares: number | null; // 流通股本(股)
93
+ totalShares: number | null; // 总股本(股)
68
94
  raw: string[]; // 原始字段数组
69
95
  }
70
96
  ```
@@ -79,13 +105,68 @@ console.log(quotes[0].price); // 111.70
79
105
 
80
106
  ---
81
107
 
108
+ ### `getAllAShareQuotes(options?): Promise<FullQuote[]>`
109
+
110
+ 获取全部 A 股实时行情(使用内置股票代码列表,包含 5000+ 只股票)。
111
+
112
+ 返回的每只股票数据格式与 `getFullQuotes` 相同。
113
+
114
+ **参数**
115
+
116
+ - `options` — 可选配置对象
117
+ - `batchSize` — 单次请求的股票数量,默认 `800`
118
+ - `concurrency` — 最大并发请求数,默认 `5`
119
+ - `onProgress` — 进度回调函数 `(completed: number, total: number) => void`
120
+
121
+ **示例**
122
+
123
+ ```typescript
124
+ // 获取全部 A 股行情
125
+ const allQuotes = await sdk.getAllAShareQuotes();
126
+ console.log(`共获取 ${allQuotes.length} 只股票行情`);
127
+
128
+ // 自定义配置
129
+ const allQuotes = await sdk.getAllAShareQuotes({
130
+ batchSize: 500, // 每次请求 500 只
131
+ concurrency: 3, // 最多 3 个并发
132
+ onProgress: (completed, total) => {
133
+ console.log(`进度: ${completed}/${total}`);
134
+ },
135
+ });
136
+ ```
137
+
138
+ ---
139
+
140
+ ### `getAllQuotesByCodes(codes, options?): Promise<FullQuote[]>`
141
+
142
+ 批量获取指定股票的全量行情(支持自定义股票列表)。
143
+
144
+ 返回的每只股票数据格式与 `getFullQuotes` 相同。
145
+
146
+ **参数**
147
+
148
+ - `codes` — 股票代码数组
149
+ - `options` — 可选配置对象(同 `getAllAShareQuotes`)
150
+
151
+ **示例**
152
+
153
+ ```typescript
154
+ const codes = ['sz000858', 'sh600000', 'sh600519', /* ... */];
155
+ const quotes = await sdk.getAllQuotesByCodes(codes, {
156
+ batchSize: 100,
157
+ concurrency: 2,
158
+ });
159
+ ```
160
+
161
+ ---
162
+
82
163
  ### `getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>`
83
164
 
84
165
  获取简要行情(股票 / 指数)。
85
166
 
86
167
  **参数**
87
168
 
88
- - `codes` — 代码数组,格式 `s_<market><code>`,如 `['s_sz000858', 's_sh000001']`
169
+ - `codes` — 代码数组,格式与 `getFullQuotes` 相同,如 `['sz000858', 'sh000001']`
89
170
 
90
171
  **返回**
91
172
 
@@ -108,7 +189,7 @@ interface SimpleQuote {
108
189
  **示例**
109
190
 
110
191
  ```typescript
111
- const quotes = await sdk.getSimpleQuotes(['s_sh000001']);
192
+ const quotes = await sdk.getSimpleQuotes(['sh000001']);
112
193
  console.log(quotes[0].name); // 上证指数
113
194
  ```
114
195
 
@@ -311,20 +392,48 @@ console.log(raw[0].fields); // ['51', '五 粮 液', '000858', ...]
311
392
 
312
393
  ---
313
394
 
395
+ ### `codeList`
396
+
397
+ 导出的全部 A 股代码列表(包含沪市、深市、北交所)。
398
+
399
+ ```typescript
400
+ import { codeList } from 'stock-sdk';
401
+
402
+ console.log(codeList.length); // 5000+
403
+ console.log(codeList[0]); // 'bj920000'
404
+ ```
405
+
406
+ ---
407
+
408
+ ## 浏览器使用说明
409
+
410
+ 在浏览器端使用时,SDK 会自动使用浏览器原生的 `TextDecoder` 来解码 GBK 编码的响应数据,无需额外的 polyfill。
411
+
412
+ ```html
413
+ <script type="module">
414
+ import { StockSDK } from 'https://unpkg.com/stock-sdk/dist/index.js';
415
+
416
+ const sdk = new StockSDK();
417
+ const quotes = await sdk.getFullQuotes(['sz000858']);
418
+ console.log(quotes[0].name, quotes[0].price);
419
+ </script>
420
+ ```
421
+
422
+ > **注意**:由于 `qt.gtimg.cn` 接口不支持 CORS,在浏览器端使用时需要配置代理服务器。
423
+
314
424
  ## 开发
315
425
 
316
426
  ```bash
317
427
  # 安装依赖
318
- npm install
428
+ yarn install
319
429
 
320
430
  # 运行测试
321
- npm test
431
+ yarn test
322
432
 
323
433
  # 构建
324
- npm run build
434
+ yarn build
325
435
  ```
326
436
 
327
437
  ## 许可证
328
438
 
329
439
  ISC
330
-