stock-sdk 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +322 -228
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +154 -9
- package/dist/index.d.ts +154 -9
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/stock-sdk)
|
|
4
4
|
[](https://www.npmjs.com/package/stock-sdk)
|
|
5
5
|
[](https://github.com/chengzuopeng/stock-sdk/blob/master/LICENSE)
|
|
6
|
+
[](https://github.com/chengzuopeng/stock-sdk)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
轻量级股票行情 SDK,基于腾讯财经 `qt.gtimg.cn` 和东方财富等数据源,支持 A 股、港股、美股、公募基金实时行情及历史 K 线查询。
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
**✨ 零依赖 | 🌐 浏览器 + Node.js 双端支持 | 📦 ESM + CommonJS**
|
|
10
11
|
|
|
11
|
-
📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk)
|
|
12
|
+
📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk) | 🎮 [在线演示](https://chengzuopeng.github.io/stock-sdk/)
|
|
12
13
|
|
|
13
14
|
## 特性
|
|
14
15
|
|
|
15
|
-
- ✅
|
|
16
|
-
- ✅
|
|
17
|
-
- ✅ 同时提供 ESM 和 CommonJS 两种模块格式
|
|
18
|
-
- ✅ 完整的 TypeScript
|
|
19
|
-
- ✅ A
|
|
20
|
-
- ✅
|
|
21
|
-
- ✅
|
|
22
|
-
- ✅
|
|
16
|
+
- ✅ **零依赖**,轻量级(压缩后 < 10KB)
|
|
17
|
+
- ✅ 支持 **浏览器** 和 **Node.js 18+** 双端运行
|
|
18
|
+
- ✅ 同时提供 **ESM** 和 **CommonJS** 两种模块格式
|
|
19
|
+
- ✅ 完整的 **TypeScript** 类型定义的单元测试覆盖
|
|
20
|
+
- ✅ **A 股、港股、美股、公募基金**实时行情
|
|
21
|
+
- ✅ **历史 K 线**(日/周/月)、**分钟 K 线**(1/5/15/30/60 分钟)和**当日分时走势**数据
|
|
22
|
+
- ✅ **资金流向**、**盘口大单**等扩展数据
|
|
23
|
+
- ✅ 获取全部 **A 股代码列表**(5000+ 只股票)和批量获取**全市场行情**(内置并发控制)
|
|
23
24
|
|
|
24
25
|
## 安装
|
|
25
26
|
|
|
@@ -27,156 +28,127 @@
|
|
|
27
28
|
npm install stock-sdk
|
|
28
29
|
# 或
|
|
29
30
|
yarn add stock-sdk
|
|
31
|
+
# 或
|
|
32
|
+
pnpm add stock-sdk
|
|
30
33
|
```
|
|
31
34
|
|
|
32
35
|
## 快速开始
|
|
33
36
|
|
|
34
37
|
```typescript
|
|
35
|
-
// ESM (浏览器 / Node.js)
|
|
36
38
|
import { StockSDK } from 'stock-sdk';
|
|
37
39
|
|
|
38
|
-
// CommonJS (Node.js)
|
|
39
|
-
// const { StockSDK } = require('stock-sdk');
|
|
40
|
-
|
|
41
40
|
const sdk = new StockSDK();
|
|
42
41
|
|
|
43
42
|
// A 股全量行情
|
|
44
|
-
const
|
|
45
|
-
console.log(
|
|
43
|
+
const quotes = await sdk.getFullQuotes(['sz000858', 'sh600519']);
|
|
44
|
+
console.log(quotes[0].name, quotes[0].price);
|
|
45
|
+
|
|
46
|
+
// 历史 K 线
|
|
47
|
+
const klines = await sdk.getHistoryKline('000001', { period: 'daily' });
|
|
46
48
|
|
|
47
|
-
//
|
|
48
|
-
const
|
|
49
|
-
console.log(simpleQuotes);
|
|
49
|
+
// 当日分时
|
|
50
|
+
const timeline = await sdk.getTodayTimeline('sz000001');
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
## API 文档
|
|
53
54
|
|
|
54
|
-
###
|
|
55
|
+
### 实时行情
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
| 方法 | 说明 |
|
|
58
|
+
|------|------|
|
|
59
|
+
| [`getFullQuotes`](#getfullquotescodes-promisefullquote) | A 股/指数全量行情 |
|
|
60
|
+
| [`getSimpleQuotes`](#getsimplequotescodes-promisesimplequote) | A 股/指数简要行情 |
|
|
61
|
+
| [`getHKQuotes`](#gethkquotescodes-promisehkquote) | 港股行情 |
|
|
62
|
+
| [`getUSQuotes`](#getusquotescodes-promiseusquote) | 美股行情 |
|
|
63
|
+
| [`getFundQuotes`](#getfundquotescodes-promisefundquote) | 公募基金行情 |
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
### K 线数据
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
| 方法 | 说明 |
|
|
68
|
+
|------|------|
|
|
69
|
+
| [`getHistoryKline`](#gethistoryklinesymbol-options-promisehistorykline) | 历史 K 线(日/周/月) |
|
|
70
|
+
| [`getMinuteKline`](#getminuteklinesymbol-options-promiseminutetimeline--minutekline) | 分钟 K 线(1/5/15/30/60 分钟) |
|
|
71
|
+
| [`getTodayTimeline`](#gettodaytimelinecode-promisetodaytimelineresponse) | 当日分时走势 |
|
|
61
72
|
|
|
62
|
-
|
|
73
|
+
### 扩展数据
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
code: string; // 股票代码
|
|
69
|
-
price: number; // 最新价
|
|
70
|
-
prevClose: number; // 昨收
|
|
71
|
-
open: number; // 今开
|
|
72
|
-
volume: number; // 成交量(手)
|
|
73
|
-
outerVolume: number; // 外盘
|
|
74
|
-
innerVolume: number; // 内盘
|
|
75
|
-
bid: { price: number; volume: number }[]; // 买一~买五
|
|
76
|
-
ask: { price: number; volume: number }[]; // 卖一~卖五
|
|
77
|
-
time: string; // 时间戳 yyyyMMddHHmmss
|
|
78
|
-
change: number; // 涨跌额
|
|
79
|
-
changePercent: number; // 涨跌幅%
|
|
80
|
-
high: number; // 最高
|
|
81
|
-
low: number; // 最低
|
|
82
|
-
volume2: number; // 成交量(手)
|
|
83
|
-
amount: number; // 成交额(万)
|
|
84
|
-
turnoverRate: number | null; // 换手率%
|
|
85
|
-
pe: number | null; // 市盈率(TTM)
|
|
86
|
-
amplitude: number | null; // 振幅%
|
|
87
|
-
circulatingMarketCap: number | null; // 流通市值(亿)
|
|
88
|
-
totalMarketCap: number | null; // 总市值(亿)
|
|
89
|
-
pb: number | null; // 市净率
|
|
90
|
-
limitUp: number | null; // 涨停价
|
|
91
|
-
limitDown: number | null; // 跌停价
|
|
92
|
-
volumeRatio: number | null; // 量比
|
|
93
|
-
avgPrice: number | null; // 均价
|
|
94
|
-
peStatic: number | null; // 市盈率(静)
|
|
95
|
-
peDynamic: number | null; // 市盈率(动)
|
|
96
|
-
high52w: number | null; // 52周最高价
|
|
97
|
-
low52w: number | null; // 52周最低价
|
|
98
|
-
circulatingShares: number | null; // 流通股本(股)
|
|
99
|
-
totalShares: number | null; // 总股本(股)
|
|
100
|
-
raw: string[]; // 原始字段数组
|
|
101
|
-
}
|
|
102
|
-
```
|
|
75
|
+
| 方法 | 说明 |
|
|
76
|
+
|------|------|
|
|
77
|
+
| [`getFundFlow`](#getfundflowcodes-promisefundflow) | 资金流向 |
|
|
78
|
+
| [`getPanelLargeOrder`](#getpanellargeordercodes-promisepanellargeorder) | 盘口大单占比 |
|
|
103
79
|
|
|
104
|
-
|
|
80
|
+
### 批量查询
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
82
|
+
| 方法 | 说明 |
|
|
83
|
+
|------|------|
|
|
84
|
+
| [`getAShareCodeList`](#getasharecodellistincludeexchange-promisestring) | 获取全部 A 股代码 |
|
|
85
|
+
| [`getAllAShareQuotes`](#getallasharequotesoptions-promisefullquote) | 获取全市场 A 股行情 |
|
|
86
|
+
| [`getAllQuotesByCodes`](#getallquotesbycodescodes-options-promisefullquote) | 批量获取指定股票行情 |
|
|
111
87
|
|
|
112
88
|
---
|
|
113
89
|
|
|
114
|
-
### `
|
|
115
|
-
|
|
116
|
-
获取全部 A 股实时行情(使用内置股票代码列表,包含 5000+ 只股票)。
|
|
90
|
+
### `getFullQuotes(codes): Promise<FullQuote[]>`
|
|
117
91
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
> ⚠️ **提示**:如果请求过程中遇到超时或报错,请尝试将 `batchSize` 设置得更小,例如 `100`。
|
|
92
|
+
获取 A 股/指数全量行情数据。
|
|
121
93
|
|
|
122
94
|
**参数**
|
|
123
95
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- `onProgress` — 进度回调函数 `(completed: number, total: number) => void`
|
|
96
|
+
| 参数 | 类型 | 说明 |
|
|
97
|
+
|------|------|------|
|
|
98
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858', 'sh600519']` |
|
|
128
99
|
|
|
129
|
-
|
|
100
|
+
**返回类型**
|
|
130
101
|
|
|
131
102
|
```typescript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
103
|
+
interface FullQuote {
|
|
104
|
+
marketId: string; // 市场标识
|
|
105
|
+
name: string; // 名称
|
|
106
|
+
code: string; // 股票代码
|
|
107
|
+
price: number; // 最新价
|
|
108
|
+
prevClose: number; // 昨收
|
|
109
|
+
open: number; // 今开
|
|
110
|
+
high: number; // 最高
|
|
111
|
+
low: number; // 最低
|
|
112
|
+
volume: number; // 成交量(手)
|
|
113
|
+
amount: number; // 成交额(万)
|
|
114
|
+
change: number; // 涨跌额
|
|
115
|
+
changePercent: number; // 涨跌幅 %
|
|
116
|
+
bid: { price: number; volume: number }[]; // 买一~买五
|
|
117
|
+
ask: { price: number; volume: number }[]; // 卖一~卖五
|
|
118
|
+
turnoverRate: number | null; // 换手率 %
|
|
119
|
+
pe: number | null; // 市盈率(TTM)
|
|
120
|
+
pb: number | null; // 市净率
|
|
121
|
+
totalMarketCap: number | null; // 总市值(亿)
|
|
122
|
+
circulatingMarketCap: number | null; // 流通市值(亿)
|
|
123
|
+
volumeRatio: number | null; // 量比
|
|
124
|
+
limitUp: number | null; // 涨停价
|
|
125
|
+
limitDown: number | null; // 跌停价
|
|
126
|
+
// ... 更多字段见类型定义
|
|
127
|
+
}
|
|
144
128
|
```
|
|
145
129
|
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
### `getAllQuotesByCodes(codes, options?): Promise<FullQuote[]>`
|
|
149
|
-
|
|
150
|
-
批量获取指定股票的全量行情(支持自定义股票列表)。
|
|
151
|
-
|
|
152
|
-
返回的每只股票数据格式与 `getFullQuotes` 相同。
|
|
153
|
-
|
|
154
|
-
**参数**
|
|
155
|
-
|
|
156
|
-
- `codes` — 股票代码数组
|
|
157
|
-
- `options` — 可选配置对象(同 `getAllAShareQuotes`)
|
|
158
|
-
|
|
159
130
|
**示例**
|
|
160
131
|
|
|
161
132
|
```typescript
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
133
|
+
const quotes = await sdk.getFullQuotes(['sz000858']);
|
|
134
|
+
console.log(quotes[0].name); // 五 粮 液
|
|
135
|
+
console.log(quotes[0].price); // 111.70
|
|
136
|
+
console.log(quotes[0].changePercent); // 2.35
|
|
167
137
|
```
|
|
168
138
|
|
|
169
139
|
---
|
|
170
140
|
|
|
171
|
-
### `getSimpleQuotes(codes
|
|
141
|
+
### `getSimpleQuotes(codes): Promise<SimpleQuote[]>`
|
|
172
142
|
|
|
173
|
-
|
|
143
|
+
获取简要行情(股票/指数)。
|
|
174
144
|
|
|
175
145
|
**参数**
|
|
176
146
|
|
|
177
|
-
|
|
147
|
+
| 参数 | 类型 | 说明 |
|
|
148
|
+
|------|------|------|
|
|
149
|
+
| `codes` | `string[]` | 代码数组,如 `['sz000858', 'sh000001']` |
|
|
178
150
|
|
|
179
|
-
|
|
151
|
+
**返回类型**
|
|
180
152
|
|
|
181
153
|
```typescript
|
|
182
154
|
interface SimpleQuote {
|
|
@@ -188,9 +160,8 @@ interface SimpleQuote {
|
|
|
188
160
|
changePercent: number;
|
|
189
161
|
volume: number;
|
|
190
162
|
amount: number;
|
|
191
|
-
marketCap: number | null;
|
|
192
|
-
marketType: string;
|
|
193
|
-
raw: string[];
|
|
163
|
+
marketCap: number | null;
|
|
164
|
+
marketType: string;
|
|
194
165
|
}
|
|
195
166
|
```
|
|
196
167
|
|
|
@@ -203,230 +174,343 @@ console.log(quotes[0].name); // 上证指数
|
|
|
203
174
|
|
|
204
175
|
---
|
|
205
176
|
|
|
206
|
-
### `
|
|
177
|
+
### `getHistoryKline(symbol, options?): Promise<HistoryKline[]>`
|
|
207
178
|
|
|
208
|
-
|
|
179
|
+
获取 A 股历史 K 线(日/周/月),数据来源:东方财富。
|
|
209
180
|
|
|
210
181
|
**参数**
|
|
211
182
|
|
|
212
|
-
|
|
183
|
+
| 参数 | 类型 | 说明 |
|
|
184
|
+
|------|------|------|
|
|
185
|
+
| `symbol` | `string` | 股票代码,如 `'000001'` 或 `'sz000001'` |
|
|
186
|
+
| `options.period` | `'daily' \| 'weekly' \| 'monthly'` | K 线周期,默认 `'daily'` |
|
|
187
|
+
| `options.adjust` | `'' \| 'qfq' \| 'hfq'` | 复权类型,默认 `'hfq'`(后复权) |
|
|
188
|
+
| `options.startDate` | `string` | 开始日期 `YYYYMMDD` |
|
|
189
|
+
| `options.endDate` | `string` | 结束日期 `YYYYMMDD` |
|
|
213
190
|
|
|
214
|
-
|
|
191
|
+
**返回类型**
|
|
215
192
|
|
|
216
193
|
```typescript
|
|
217
|
-
interface
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
raw: string[];
|
|
194
|
+
interface HistoryKline {
|
|
195
|
+
date: string; // 日期 YYYY-MM-DD
|
|
196
|
+
code: string; // 股票代码
|
|
197
|
+
open: number | null; // 开盘价
|
|
198
|
+
close: number | null; // 收盘价
|
|
199
|
+
high: number | null; // 最高价
|
|
200
|
+
low: number | null; // 最低价
|
|
201
|
+
volume: number | null; // 成交量
|
|
202
|
+
amount: number | null; // 成交额
|
|
203
|
+
changePercent: number | null; // 涨跌幅 %
|
|
204
|
+
change: number | null; // 涨跌额
|
|
205
|
+
amplitude: number | null; // 振幅 %
|
|
206
|
+
turnoverRate: number | null; // 换手率 %
|
|
231
207
|
}
|
|
232
208
|
```
|
|
233
209
|
|
|
234
210
|
**示例**
|
|
235
211
|
|
|
236
212
|
```typescript
|
|
237
|
-
|
|
238
|
-
|
|
213
|
+
// 获取日线(默认后复权)
|
|
214
|
+
const dailyKlines = await sdk.getHistoryKline('000001');
|
|
215
|
+
|
|
216
|
+
// 获取周线,前复权,指定日期范围
|
|
217
|
+
const weeklyKlines = await sdk.getHistoryKline('sz000858', {
|
|
218
|
+
period: 'weekly',
|
|
219
|
+
adjust: 'qfq',
|
|
220
|
+
startDate: '20240101',
|
|
221
|
+
endDate: '20241231',
|
|
222
|
+
});
|
|
239
223
|
```
|
|
240
224
|
|
|
241
225
|
---
|
|
242
226
|
|
|
243
|
-
### `
|
|
227
|
+
### `getMinuteKline(symbol, options?): Promise<MinuteTimeline[] | MinuteKline[]>`
|
|
244
228
|
|
|
245
|
-
|
|
229
|
+
获取 A 股分钟 K 线或分时数据,数据来源:东方财富。
|
|
246
230
|
|
|
247
|
-
|
|
231
|
+
> **注意**:`period='1'` 分时数据仅返回近 5 个交易日数据。
|
|
248
232
|
|
|
249
|
-
|
|
233
|
+
**参数**
|
|
250
234
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
sellSmallRatio: number; // 卖盘小单占比
|
|
259
|
-
raw: string[];
|
|
260
|
-
}
|
|
261
|
-
```
|
|
235
|
+
| 参数 | 类型 | 说明 |
|
|
236
|
+
|------|------|------|
|
|
237
|
+
| `symbol` | `string` | 股票代码,如 `'000001'` 或 `'sz000001'` |
|
|
238
|
+
| `options.period` | `'1' \| '5' \| '15' \| '30' \| '60'` | K 线周期,默认 `'1'`(分时) |
|
|
239
|
+
| `options.adjust` | `'' \| 'qfq' \| 'hfq'` | 复权类型(仅 5/15/30/60 有效),默认 `'hfq'` |
|
|
240
|
+
| `options.startDate` | `string` | 开始时间 `YYYY-MM-DD HH:mm:ss` |
|
|
241
|
+
| `options.endDate` | `string` | 结束时间 `YYYY-MM-DD HH:mm:ss` |
|
|
262
242
|
|
|
263
243
|
**示例**
|
|
264
244
|
|
|
265
245
|
```typescript
|
|
266
|
-
|
|
267
|
-
|
|
246
|
+
// 获取分时数据
|
|
247
|
+
const timeline = await sdk.getMinuteKline('000001');
|
|
248
|
+
|
|
249
|
+
// 获取 5 分钟 K 线
|
|
250
|
+
const kline5m = await sdk.getMinuteKline('sz000858', { period: '5' });
|
|
268
251
|
```
|
|
269
252
|
|
|
270
253
|
---
|
|
271
254
|
|
|
272
|
-
### `
|
|
255
|
+
### `getTodayTimeline(code): Promise<TodayTimelineResponse>`
|
|
256
|
+
|
|
257
|
+
获取当日分时走势数据,数据来源:腾讯财经。
|
|
273
258
|
|
|
274
|
-
|
|
259
|
+
> **注意**:仅返回当日交易时段数据,成交量和成交额为累计值。
|
|
275
260
|
|
|
276
261
|
**参数**
|
|
277
262
|
|
|
278
|
-
|
|
263
|
+
| 参数 | 类型 | 说明 |
|
|
264
|
+
|------|------|------|
|
|
265
|
+
| `code` | `string` | 股票代码,如 `'sz000001'` |
|
|
279
266
|
|
|
280
|
-
|
|
267
|
+
**返回类型**
|
|
281
268
|
|
|
282
269
|
```typescript
|
|
283
|
-
interface
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
low: number;
|
|
296
|
-
amount: number;
|
|
297
|
-
lotSize: number | null;
|
|
298
|
-
circulatingMarketCap: number | null;
|
|
299
|
-
totalMarketCap: number | null;
|
|
300
|
-
currency: string;
|
|
301
|
-
raw: string[];
|
|
270
|
+
interface TodayTimelineResponse {
|
|
271
|
+
code: string; // 股票代码
|
|
272
|
+
date: string; // 交易日期 YYYYMMDD
|
|
273
|
+
data: TodayTimeline[]; // 分时数据列表
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
interface TodayTimeline {
|
|
277
|
+
time: string; // 时间 HH:mm
|
|
278
|
+
price: number; // 成交价
|
|
279
|
+
volume: number; // 累计成交量(手)
|
|
280
|
+
amount: number; // 累计成交额(元)
|
|
281
|
+
avgPrice: number; // 当日均价
|
|
302
282
|
}
|
|
303
283
|
```
|
|
304
284
|
|
|
305
285
|
**示例**
|
|
306
286
|
|
|
307
287
|
```typescript
|
|
308
|
-
const
|
|
309
|
-
console.log(
|
|
288
|
+
const timeline = await sdk.getTodayTimeline('sz000001');
|
|
289
|
+
console.log(timeline.date); // '20241218'
|
|
290
|
+
console.log(timeline.data[0].avgPrice); // 当日均价
|
|
310
291
|
```
|
|
311
292
|
|
|
312
293
|
---
|
|
313
294
|
|
|
314
|
-
### `
|
|
295
|
+
### `getAShareCodeList(includeExchange?): Promise<string[]>`
|
|
315
296
|
|
|
316
|
-
|
|
297
|
+
获取全部 A 股代码列表(沪市、深市、北交所 5000+ 只股票)。
|
|
317
298
|
|
|
318
299
|
**参数**
|
|
319
300
|
|
|
320
|
-
|
|
301
|
+
| 参数 | 类型 | 说明 |
|
|
302
|
+
|------|------|------|
|
|
303
|
+
| `includeExchange` | `boolean` | 是否包含交易所前缀,默认 `true` |
|
|
321
304
|
|
|
322
|
-
|
|
305
|
+
**示例**
|
|
323
306
|
|
|
324
307
|
```typescript
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
volume: number;
|
|
333
|
-
amount: number;
|
|
334
|
-
marketCap: number | null;
|
|
335
|
-
raw: string[];
|
|
336
|
-
}
|
|
308
|
+
// 包含交易所前缀
|
|
309
|
+
const codes = await sdk.getAShareCodeList();
|
|
310
|
+
// ['sh600000', 'sz000001', 'bj430047', ...]
|
|
311
|
+
|
|
312
|
+
// 不包含交易所前缀
|
|
313
|
+
const pureCodes = await sdk.getAShareCodeList(false);
|
|
314
|
+
// ['600000', '000001', '430047', ...]
|
|
337
315
|
```
|
|
338
316
|
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
### `getAllAShareQuotes(options?): Promise<FullQuote[]>`
|
|
320
|
+
|
|
321
|
+
获取全市场 A 股实时行情(5000+ 只股票),返回格式同 `getFullQuotes`。
|
|
322
|
+
|
|
323
|
+
> ⚠️ 如遇超时或报错,可尝试减小 `batchSize`(如设为 `100`)。
|
|
324
|
+
|
|
325
|
+
**参数**
|
|
326
|
+
|
|
327
|
+
| 参数 | 类型 | 说明 |
|
|
328
|
+
|------|------|------|
|
|
329
|
+
| `options.batchSize` | `number` | 单次请求股票数量,默认 `500` |
|
|
330
|
+
| `options.concurrency` | `number` | 最大并发数,默认 `7` |
|
|
331
|
+
| `options.onProgress` | `(completed, total) => void` | 进度回调 |
|
|
332
|
+
|
|
339
333
|
**示例**
|
|
340
334
|
|
|
341
335
|
```typescript
|
|
342
|
-
const
|
|
343
|
-
|
|
336
|
+
const allQuotes = await sdk.getAllAShareQuotes({
|
|
337
|
+
batchSize: 300,
|
|
338
|
+
concurrency: 3,
|
|
339
|
+
onProgress: (completed, total) => {
|
|
340
|
+
console.log(`进度: ${completed}/${total}`);
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
console.log(`共获取 ${allQuotes.length} 只股票`);
|
|
344
344
|
```
|
|
345
345
|
|
|
346
346
|
---
|
|
347
347
|
|
|
348
|
-
### `
|
|
348
|
+
### `getAllQuotesByCodes(codes, options?): Promise<FullQuote[]>`
|
|
349
349
|
|
|
350
|
-
|
|
350
|
+
批量获取指定股票的全量行情,参数同 `getAllAShareQuotes`。
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
const quotes = await sdk.getAllQuotesByCodes(
|
|
354
|
+
['sz000858', 'sh600519', 'sh600000'],
|
|
355
|
+
{ batchSize: 100, concurrency: 2 }
|
|
356
|
+
);
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
### `getFundFlow(codes): Promise<FundFlow[]>`
|
|
362
|
+
|
|
363
|
+
获取资金流向数据。
|
|
351
364
|
|
|
352
365
|
**参数**
|
|
353
366
|
|
|
354
|
-
|
|
367
|
+
| 参数 | 类型 | 说明 |
|
|
368
|
+
|------|------|------|
|
|
369
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858']` |
|
|
355
370
|
|
|
356
|
-
|
|
371
|
+
**返回类型**
|
|
357
372
|
|
|
358
373
|
```typescript
|
|
359
|
-
interface
|
|
374
|
+
interface FundFlow {
|
|
360
375
|
code: string;
|
|
361
376
|
name: string;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
377
|
+
mainInflow: number; // 主力流入
|
|
378
|
+
mainOutflow: number; // 主力流出
|
|
379
|
+
mainNet: number; // 主力净流入
|
|
380
|
+
mainNetRatio: number; // 主力净流入占比
|
|
381
|
+
retailInflow: number; // 散户流入
|
|
382
|
+
retailOutflow: number; // 散户流出
|
|
383
|
+
retailNet: number; // 散户净流入
|
|
384
|
+
retailNetRatio: number; // 散户净流入占比
|
|
385
|
+
totalFlow: number; // 总资金流
|
|
386
|
+
date: string;
|
|
367
387
|
}
|
|
368
388
|
```
|
|
369
389
|
|
|
370
|
-
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
### `getPanelLargeOrder(codes): Promise<PanelLargeOrder[]>`
|
|
393
|
+
|
|
394
|
+
获取盘口大单占比。
|
|
395
|
+
|
|
396
|
+
**参数**
|
|
397
|
+
|
|
398
|
+
| 参数 | 类型 | 说明 |
|
|
399
|
+
|------|------|------|
|
|
400
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858']` |
|
|
401
|
+
|
|
402
|
+
**返回类型**
|
|
371
403
|
|
|
372
404
|
```typescript
|
|
373
|
-
|
|
374
|
-
|
|
405
|
+
interface PanelLargeOrder {
|
|
406
|
+
buyLargeRatio: number; // 买盘大单占比
|
|
407
|
+
buySmallRatio: number; // 买盘小单占比
|
|
408
|
+
sellLargeRatio: number; // 卖盘大单占比
|
|
409
|
+
sellSmallRatio: number; // 卖盘小单占比
|
|
410
|
+
}
|
|
375
411
|
```
|
|
376
412
|
|
|
377
413
|
---
|
|
378
414
|
|
|
379
|
-
### `
|
|
415
|
+
### `getHKQuotes(codes): Promise<HKQuote[]>`
|
|
380
416
|
|
|
381
|
-
|
|
417
|
+
获取港股行情。
|
|
382
418
|
|
|
383
419
|
**参数**
|
|
384
420
|
|
|
385
|
-
|
|
421
|
+
| 参数 | 类型 | 说明 |
|
|
422
|
+
|------|------|------|
|
|
423
|
+
| `codes` | `string[]` | 港股代码数组,如 `['09988', '00700']` |
|
|
386
424
|
|
|
387
|
-
|
|
425
|
+
**示例**
|
|
388
426
|
|
|
389
427
|
```typescript
|
|
390
|
-
|
|
428
|
+
const quotes = await sdk.getHKQuotes(['09988']);
|
|
429
|
+
console.log(quotes[0].name); // 阿里巴巴-W
|
|
391
430
|
```
|
|
392
431
|
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
### `getUSQuotes(codes): Promise<USQuote[]>`
|
|
435
|
+
|
|
436
|
+
获取美股行情。
|
|
437
|
+
|
|
438
|
+
**参数**
|
|
439
|
+
|
|
440
|
+
| 参数 | 类型 | 说明 |
|
|
441
|
+
|------|------|------|
|
|
442
|
+
| `codes` | `string[]` | 美股代码数组,如 `['BABA', 'AAPL']` |
|
|
443
|
+
|
|
393
444
|
**示例**
|
|
394
445
|
|
|
395
446
|
```typescript
|
|
396
|
-
const
|
|
397
|
-
console.log(
|
|
398
|
-
console.log(raw[0].fields); // ['51', '五 粮 液', '000858', ...]
|
|
447
|
+
const quotes = await sdk.getUSQuotes(['BABA', 'AAPL']);
|
|
448
|
+
console.log(quotes[0].code); // BABA.N
|
|
399
449
|
```
|
|
400
450
|
|
|
401
451
|
---
|
|
402
452
|
|
|
403
|
-
### `
|
|
453
|
+
### `getFundQuotes(codes): Promise<FundQuote[]>`
|
|
454
|
+
|
|
455
|
+
获取公募基金行情。
|
|
456
|
+
|
|
457
|
+
**参数**
|
|
458
|
+
|
|
459
|
+
| 参数 | 类型 | 说明 |
|
|
460
|
+
|------|------|------|
|
|
461
|
+
| `codes` | `string[]` | 基金代码数组,如 `['000001', '110011']` |
|
|
404
462
|
|
|
405
|
-
|
|
463
|
+
**返回类型**
|
|
406
464
|
|
|
407
465
|
```typescript
|
|
408
|
-
|
|
466
|
+
interface FundQuote {
|
|
467
|
+
code: string;
|
|
468
|
+
name: string;
|
|
469
|
+
nav: number; // 最新单位净值
|
|
470
|
+
accNav: number; // 累计净值
|
|
471
|
+
change: number; // 当日涨跌额
|
|
472
|
+
navDate: string; // 净值日期
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
### `batchRaw(params): Promise<{ key: string; fields: string[] }[]>`
|
|
479
|
+
|
|
480
|
+
批量混合查询,返回原始解析结果。
|
|
481
|
+
|
|
482
|
+
**参数**
|
|
483
|
+
|
|
484
|
+
| 参数 | 类型 | 说明 |
|
|
485
|
+
|------|------|------|
|
|
486
|
+
| `params` | `string` | 逗号分隔的查询参数,如 `'sz000858,s_sh000001'` |
|
|
487
|
+
|
|
488
|
+
**示例**
|
|
409
489
|
|
|
410
|
-
|
|
411
|
-
|
|
490
|
+
```typescript
|
|
491
|
+
const raw = await sdk.batchRaw('sz000858,s_sh000001');
|
|
492
|
+
console.log(raw[0].key); // sz000858
|
|
493
|
+
console.log(raw[0].fields); // ['51', '五 粮 液', '000858', ...]
|
|
412
494
|
```
|
|
413
495
|
|
|
414
496
|
---
|
|
415
497
|
|
|
416
|
-
##
|
|
498
|
+
## 浏览器使用
|
|
417
499
|
|
|
418
|
-
|
|
500
|
+
SDK 使用原生 `TextDecoder` 解码 GBK 编码数据,无需额外 polyfill。
|
|
419
501
|
|
|
420
502
|
```html
|
|
421
503
|
<script type="module">
|
|
422
504
|
import { StockSDK } from 'https://unpkg.com/stock-sdk/dist/index.js';
|
|
423
|
-
|
|
505
|
+
|
|
424
506
|
const sdk = new StockSDK();
|
|
425
507
|
const quotes = await sdk.getFullQuotes(['sz000858']);
|
|
426
508
|
console.log(quotes[0].name, quotes[0].price);
|
|
427
509
|
</script>
|
|
428
510
|
```
|
|
429
511
|
|
|
512
|
+
---
|
|
513
|
+
|
|
430
514
|
## 开发
|
|
431
515
|
|
|
432
516
|
```bash
|
|
@@ -436,10 +520,20 @@ yarn install
|
|
|
436
520
|
# 运行测试
|
|
437
521
|
yarn test
|
|
438
522
|
|
|
523
|
+
# 查看覆盖率
|
|
524
|
+
yarn test --coverage
|
|
525
|
+
|
|
439
526
|
# 构建
|
|
440
527
|
yarn build
|
|
528
|
+
|
|
529
|
+
# 启动调试页面
|
|
530
|
+
yarn dev
|
|
441
531
|
```
|
|
442
532
|
|
|
443
533
|
## 许可证
|
|
444
534
|
|
|
445
|
-
ISC
|
|
535
|
+
[ISC](./LICENSE)
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
📦 [NPM](https://www.npmjs.com/package/stock-sdk) | 📖 [GitHub](https://github.com/chengzuopeng/stock-sdk) | 🎮 [在线演示](https://chengzuopeng.github.io/stock-sdk/) | 🐛 [Issues](https://github.com/chengzuopeng/stock-sdk/issues)
|