stock-sdk 1.0.2 → 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 +81 -11
- package/dist/index.cjs +5581 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -6
- package/dist/index.d.ts +38 -6
- package/dist/index.js +5578 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
## 特性
|
|
8
8
|
|
|
9
|
-
- ✅
|
|
9
|
+
- ✅ 零依赖,轻量级(使用原生 fetch 和 TextDecoder)
|
|
10
|
+
- ✅ 支持浏览器和 Node.js 18+ 双端运行
|
|
10
11
|
- ✅ 同时提供 ESM 和 CommonJS 两种模块格式
|
|
11
12
|
- ✅ 完整的 TypeScript 类型定义
|
|
12
13
|
- ✅ A 股、港股、美股、公募基金实时行情
|
|
13
14
|
- ✅ 资金流向、盘口大单等扩展数据
|
|
15
|
+
- ✅ 内置全部 A 股代码列表(5000+)
|
|
16
|
+
- ✅ 支持批量获取全市场行情(并发控制)
|
|
14
17
|
|
|
15
18
|
## 安装
|
|
16
19
|
|
|
@@ -24,19 +27,19 @@ yarn add stock-sdk
|
|
|
24
27
|
|
|
25
28
|
```typescript
|
|
26
29
|
// ESM (浏览器 / Node.js)
|
|
27
|
-
import {
|
|
30
|
+
import { StockSDK } from 'stock-sdk';
|
|
28
31
|
|
|
29
32
|
// CommonJS (Node.js)
|
|
30
|
-
// const {
|
|
33
|
+
// const { StockSDK } = require('stock-sdk');
|
|
31
34
|
|
|
32
|
-
const sdk = new
|
|
35
|
+
const sdk = new StockSDK();
|
|
33
36
|
|
|
34
37
|
// A 股全量行情
|
|
35
38
|
const fullQuotes = await sdk.getFullQuotes(['sz000858', 'sh600000']);
|
|
36
39
|
console.log(fullQuotes);
|
|
37
40
|
|
|
38
|
-
//
|
|
39
|
-
const simpleQuotes = await sdk.getSimpleQuotes(['
|
|
41
|
+
// 简要行情(参数格式与 getFullQuotes 相同)
|
|
42
|
+
const simpleQuotes = await sdk.getSimpleQuotes(['sz000858', 'sh000001']);
|
|
40
43
|
console.log(simpleQuotes);
|
|
41
44
|
```
|
|
42
45
|
|
|
@@ -102,13 +105,68 @@ console.log(quotes[0].price); // 111.70
|
|
|
102
105
|
|
|
103
106
|
---
|
|
104
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
|
+
|
|
105
163
|
### `getSimpleQuotes(codes: string[]): Promise<SimpleQuote[]>`
|
|
106
164
|
|
|
107
165
|
获取简要行情(股票 / 指数)。
|
|
108
166
|
|
|
109
167
|
**参数**
|
|
110
168
|
|
|
111
|
-
- `codes` —
|
|
169
|
+
- `codes` — 代码数组,格式与 `getFullQuotes` 相同,如 `['sz000858', 'sh000001']`
|
|
112
170
|
|
|
113
171
|
**返回**
|
|
114
172
|
|
|
@@ -131,7 +189,7 @@ interface SimpleQuote {
|
|
|
131
189
|
**示例**
|
|
132
190
|
|
|
133
191
|
```typescript
|
|
134
|
-
const quotes = await sdk.getSimpleQuotes(['
|
|
192
|
+
const quotes = await sdk.getSimpleQuotes(['sh000001']);
|
|
135
193
|
console.log(quotes[0].name); // 上证指数
|
|
136
194
|
```
|
|
137
195
|
|
|
@@ -334,15 +392,28 @@ console.log(raw[0].fields); // ['51', '五 粮 液', '000858', ...]
|
|
|
334
392
|
|
|
335
393
|
---
|
|
336
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
|
+
|
|
337
408
|
## 浏览器使用说明
|
|
338
409
|
|
|
339
410
|
在浏览器端使用时,SDK 会自动使用浏览器原生的 `TextDecoder` 来解码 GBK 编码的响应数据,无需额外的 polyfill。
|
|
340
411
|
|
|
341
412
|
```html
|
|
342
413
|
<script type="module">
|
|
343
|
-
import {
|
|
414
|
+
import { StockSDK } from 'https://unpkg.com/stock-sdk/dist/index.js';
|
|
344
415
|
|
|
345
|
-
const sdk = new
|
|
416
|
+
const sdk = new StockSDK();
|
|
346
417
|
const quotes = await sdk.getFullQuotes(['sz000858']);
|
|
347
418
|
console.log(quotes[0].name, quotes[0].price);
|
|
348
419
|
</script>
|
|
@@ -366,4 +437,3 @@ yarn build
|
|
|
366
437
|
## 许可证
|
|
367
438
|
|
|
368
439
|
ISC
|
|
369
|
-
|