stock-sdk 1.1.1 → 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/LICENSE +12 -19
- package/README.md +323 -227
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +156 -11
- package/dist/index.d.ts +156 -11
- package/dist/index.js +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/stock-sdk)
|
|
4
4
|
[](https://www.npmjs.com/package/stock-sdk)
|
|
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,154 +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
|
-
|
|
92
|
+
获取 A 股/指数全量行情数据。
|
|
119
93
|
|
|
120
94
|
**参数**
|
|
121
95
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- `onProgress` — 进度回调函数 `(completed: number, total: number) => void`
|
|
96
|
+
| 参数 | 类型 | 说明 |
|
|
97
|
+
|------|------|------|
|
|
98
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858', 'sh600519']` |
|
|
126
99
|
|
|
127
|
-
|
|
100
|
+
**返回类型**
|
|
128
101
|
|
|
129
102
|
```typescript
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
}
|
|
142
128
|
```
|
|
143
129
|
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
### `getAllQuotesByCodes(codes, options?): Promise<FullQuote[]>`
|
|
147
|
-
|
|
148
|
-
批量获取指定股票的全量行情(支持自定义股票列表)。
|
|
149
|
-
|
|
150
|
-
返回的每只股票数据格式与 `getFullQuotes` 相同。
|
|
151
|
-
|
|
152
|
-
**参数**
|
|
153
|
-
|
|
154
|
-
- `codes` — 股票代码数组
|
|
155
|
-
- `options` — 可选配置对象(同 `getAllAShareQuotes`)
|
|
156
|
-
|
|
157
130
|
**示例**
|
|
158
131
|
|
|
159
132
|
```typescript
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
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
|
|
165
137
|
```
|
|
166
138
|
|
|
167
139
|
---
|
|
168
140
|
|
|
169
|
-
### `getSimpleQuotes(codes
|
|
141
|
+
### `getSimpleQuotes(codes): Promise<SimpleQuote[]>`
|
|
170
142
|
|
|
171
|
-
|
|
143
|
+
获取简要行情(股票/指数)。
|
|
172
144
|
|
|
173
145
|
**参数**
|
|
174
146
|
|
|
175
|
-
|
|
147
|
+
| 参数 | 类型 | 说明 |
|
|
148
|
+
|------|------|------|
|
|
149
|
+
| `codes` | `string[]` | 代码数组,如 `['sz000858', 'sh000001']` |
|
|
176
150
|
|
|
177
|
-
|
|
151
|
+
**返回类型**
|
|
178
152
|
|
|
179
153
|
```typescript
|
|
180
154
|
interface SimpleQuote {
|
|
@@ -186,9 +160,8 @@ interface SimpleQuote {
|
|
|
186
160
|
changePercent: number;
|
|
187
161
|
volume: number;
|
|
188
162
|
amount: number;
|
|
189
|
-
marketCap: number | null;
|
|
190
|
-
marketType: string;
|
|
191
|
-
raw: string[];
|
|
163
|
+
marketCap: number | null;
|
|
164
|
+
marketType: string;
|
|
192
165
|
}
|
|
193
166
|
```
|
|
194
167
|
|
|
@@ -201,230 +174,343 @@ console.log(quotes[0].name); // 上证指数
|
|
|
201
174
|
|
|
202
175
|
---
|
|
203
176
|
|
|
204
|
-
### `
|
|
177
|
+
### `getHistoryKline(symbol, options?): Promise<HistoryKline[]>`
|
|
205
178
|
|
|
206
|
-
|
|
179
|
+
获取 A 股历史 K 线(日/周/月),数据来源:东方财富。
|
|
207
180
|
|
|
208
181
|
**参数**
|
|
209
182
|
|
|
210
|
-
|
|
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` |
|
|
211
190
|
|
|
212
|
-
|
|
191
|
+
**返回类型**
|
|
213
192
|
|
|
214
193
|
```typescript
|
|
215
|
-
interface
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
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; // 换手率 %
|
|
229
207
|
}
|
|
230
208
|
```
|
|
231
209
|
|
|
232
210
|
**示例**
|
|
233
211
|
|
|
234
212
|
```typescript
|
|
235
|
-
|
|
236
|
-
|
|
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
|
+
});
|
|
237
223
|
```
|
|
238
224
|
|
|
239
225
|
---
|
|
240
226
|
|
|
241
|
-
### `
|
|
227
|
+
### `getMinuteKline(symbol, options?): Promise<MinuteTimeline[] | MinuteKline[]>`
|
|
242
228
|
|
|
243
|
-
|
|
229
|
+
获取 A 股分钟 K 线或分时数据,数据来源:东方财富。
|
|
244
230
|
|
|
245
|
-
|
|
231
|
+
> **注意**:`period='1'` 分时数据仅返回近 5 个交易日数据。
|
|
246
232
|
|
|
247
|
-
|
|
233
|
+
**参数**
|
|
248
234
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
sellSmallRatio: number; // 卖盘小单占比
|
|
257
|
-
raw: string[];
|
|
258
|
-
}
|
|
259
|
-
```
|
|
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` |
|
|
260
242
|
|
|
261
243
|
**示例**
|
|
262
244
|
|
|
263
245
|
```typescript
|
|
264
|
-
|
|
265
|
-
|
|
246
|
+
// 获取分时数据
|
|
247
|
+
const timeline = await sdk.getMinuteKline('000001');
|
|
248
|
+
|
|
249
|
+
// 获取 5 分钟 K 线
|
|
250
|
+
const kline5m = await sdk.getMinuteKline('sz000858', { period: '5' });
|
|
266
251
|
```
|
|
267
252
|
|
|
268
253
|
---
|
|
269
254
|
|
|
270
|
-
### `
|
|
255
|
+
### `getTodayTimeline(code): Promise<TodayTimelineResponse>`
|
|
271
256
|
|
|
272
|
-
|
|
257
|
+
获取当日分时走势数据,数据来源:腾讯财经。
|
|
258
|
+
|
|
259
|
+
> **注意**:仅返回当日交易时段数据,成交量和成交额为累计值。
|
|
273
260
|
|
|
274
261
|
**参数**
|
|
275
262
|
|
|
276
|
-
|
|
263
|
+
| 参数 | 类型 | 说明 |
|
|
264
|
+
|------|------|------|
|
|
265
|
+
| `code` | `string` | 股票代码,如 `'sz000001'` |
|
|
277
266
|
|
|
278
|
-
|
|
267
|
+
**返回类型**
|
|
279
268
|
|
|
280
269
|
```typescript
|
|
281
|
-
interface
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
low: number;
|
|
294
|
-
amount: number;
|
|
295
|
-
lotSize: number | null;
|
|
296
|
-
circulatingMarketCap: number | null;
|
|
297
|
-
totalMarketCap: number | null;
|
|
298
|
-
currency: string;
|
|
299
|
-
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; // 当日均价
|
|
300
282
|
}
|
|
301
283
|
```
|
|
302
284
|
|
|
303
285
|
**示例**
|
|
304
286
|
|
|
305
287
|
```typescript
|
|
306
|
-
const
|
|
307
|
-
console.log(
|
|
288
|
+
const timeline = await sdk.getTodayTimeline('sz000001');
|
|
289
|
+
console.log(timeline.date); // '20241218'
|
|
290
|
+
console.log(timeline.data[0].avgPrice); // 当日均价
|
|
308
291
|
```
|
|
309
292
|
|
|
310
293
|
---
|
|
311
294
|
|
|
312
|
-
### `
|
|
295
|
+
### `getAShareCodeList(includeExchange?): Promise<string[]>`
|
|
313
296
|
|
|
314
|
-
|
|
297
|
+
获取全部 A 股代码列表(沪市、深市、北交所 5000+ 只股票)。
|
|
315
298
|
|
|
316
299
|
**参数**
|
|
317
300
|
|
|
318
|
-
|
|
301
|
+
| 参数 | 类型 | 说明 |
|
|
302
|
+
|------|------|------|
|
|
303
|
+
| `includeExchange` | `boolean` | 是否包含交易所前缀,默认 `true` |
|
|
319
304
|
|
|
320
|
-
|
|
305
|
+
**示例**
|
|
321
306
|
|
|
322
307
|
```typescript
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
volume: number;
|
|
331
|
-
amount: number;
|
|
332
|
-
marketCap: number | null;
|
|
333
|
-
raw: string[];
|
|
334
|
-
}
|
|
308
|
+
// 包含交易所前缀
|
|
309
|
+
const codes = await sdk.getAShareCodeList();
|
|
310
|
+
// ['sh600000', 'sz000001', 'bj430047', ...]
|
|
311
|
+
|
|
312
|
+
// 不包含交易所前缀
|
|
313
|
+
const pureCodes = await sdk.getAShareCodeList(false);
|
|
314
|
+
// ['600000', '000001', '430047', ...]
|
|
335
315
|
```
|
|
336
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
|
+
|
|
337
333
|
**示例**
|
|
338
334
|
|
|
339
335
|
```typescript
|
|
340
|
-
const
|
|
341
|
-
|
|
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} 只股票`);
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
---
|
|
345
347
|
|
|
346
|
-
### `
|
|
348
|
+
### `getAllQuotesByCodes(codes, options?): Promise<FullQuote[]>`
|
|
347
349
|
|
|
348
|
-
|
|
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
|
+
获取资金流向数据。
|
|
349
364
|
|
|
350
365
|
**参数**
|
|
351
366
|
|
|
352
|
-
|
|
367
|
+
| 参数 | 类型 | 说明 |
|
|
368
|
+
|------|------|------|
|
|
369
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858']` |
|
|
353
370
|
|
|
354
|
-
|
|
371
|
+
**返回类型**
|
|
355
372
|
|
|
356
373
|
```typescript
|
|
357
|
-
interface
|
|
374
|
+
interface FundFlow {
|
|
358
375
|
code: string;
|
|
359
376
|
name: string;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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;
|
|
365
387
|
}
|
|
366
388
|
```
|
|
367
389
|
|
|
368
|
-
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
### `getPanelLargeOrder(codes): Promise<PanelLargeOrder[]>`
|
|
393
|
+
|
|
394
|
+
获取盘口大单占比。
|
|
395
|
+
|
|
396
|
+
**参数**
|
|
397
|
+
|
|
398
|
+
| 参数 | 类型 | 说明 |
|
|
399
|
+
|------|------|------|
|
|
400
|
+
| `codes` | `string[]` | 股票代码数组,如 `['sz000858']` |
|
|
401
|
+
|
|
402
|
+
**返回类型**
|
|
369
403
|
|
|
370
404
|
```typescript
|
|
371
|
-
|
|
372
|
-
|
|
405
|
+
interface PanelLargeOrder {
|
|
406
|
+
buyLargeRatio: number; // 买盘大单占比
|
|
407
|
+
buySmallRatio: number; // 买盘小单占比
|
|
408
|
+
sellLargeRatio: number; // 卖盘大单占比
|
|
409
|
+
sellSmallRatio: number; // 卖盘小单占比
|
|
410
|
+
}
|
|
373
411
|
```
|
|
374
412
|
|
|
375
413
|
---
|
|
376
414
|
|
|
377
|
-
### `
|
|
415
|
+
### `getHKQuotes(codes): Promise<HKQuote[]>`
|
|
378
416
|
|
|
379
|
-
|
|
417
|
+
获取港股行情。
|
|
380
418
|
|
|
381
419
|
**参数**
|
|
382
420
|
|
|
383
|
-
|
|
421
|
+
| 参数 | 类型 | 说明 |
|
|
422
|
+
|------|------|------|
|
|
423
|
+
| `codes` | `string[]` | 港股代码数组,如 `['09988', '00700']` |
|
|
384
424
|
|
|
385
|
-
|
|
425
|
+
**示例**
|
|
386
426
|
|
|
387
427
|
```typescript
|
|
388
|
-
|
|
428
|
+
const quotes = await sdk.getHKQuotes(['09988']);
|
|
429
|
+
console.log(quotes[0].name); // 阿里巴巴-W
|
|
389
430
|
```
|
|
390
431
|
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
### `getUSQuotes(codes): Promise<USQuote[]>`
|
|
435
|
+
|
|
436
|
+
获取美股行情。
|
|
437
|
+
|
|
438
|
+
**参数**
|
|
439
|
+
|
|
440
|
+
| 参数 | 类型 | 说明 |
|
|
441
|
+
|------|------|------|
|
|
442
|
+
| `codes` | `string[]` | 美股代码数组,如 `['BABA', 'AAPL']` |
|
|
443
|
+
|
|
391
444
|
**示例**
|
|
392
445
|
|
|
393
446
|
```typescript
|
|
394
|
-
const
|
|
395
|
-
console.log(
|
|
396
|
-
console.log(raw[0].fields); // ['51', '五 粮 液', '000858', ...]
|
|
447
|
+
const quotes = await sdk.getUSQuotes(['BABA', 'AAPL']);
|
|
448
|
+
console.log(quotes[0].code); // BABA.N
|
|
397
449
|
```
|
|
398
450
|
|
|
399
451
|
---
|
|
400
452
|
|
|
401
|
-
### `
|
|
453
|
+
### `getFundQuotes(codes): Promise<FundQuote[]>`
|
|
402
454
|
|
|
403
|
-
|
|
455
|
+
获取公募基金行情。
|
|
456
|
+
|
|
457
|
+
**参数**
|
|
458
|
+
|
|
459
|
+
| 参数 | 类型 | 说明 |
|
|
460
|
+
|------|------|------|
|
|
461
|
+
| `codes` | `string[]` | 基金代码数组,如 `['000001', '110011']` |
|
|
462
|
+
|
|
463
|
+
**返回类型**
|
|
404
464
|
|
|
405
465
|
```typescript
|
|
406
|
-
|
|
466
|
+
interface FundQuote {
|
|
467
|
+
code: string;
|
|
468
|
+
name: string;
|
|
469
|
+
nav: number; // 最新单位净值
|
|
470
|
+
accNav: number; // 累计净值
|
|
471
|
+
change: number; // 当日涨跌额
|
|
472
|
+
navDate: string; // 净值日期
|
|
473
|
+
}
|
|
474
|
+
```
|
|
407
475
|
|
|
408
|
-
|
|
409
|
-
|
|
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
|
+
**示例**
|
|
489
|
+
|
|
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', ...]
|
|
410
494
|
```
|
|
411
495
|
|
|
412
496
|
---
|
|
413
497
|
|
|
414
|
-
##
|
|
498
|
+
## 浏览器使用
|
|
415
499
|
|
|
416
|
-
|
|
500
|
+
SDK 使用原生 `TextDecoder` 解码 GBK 编码数据,无需额外 polyfill。
|
|
417
501
|
|
|
418
502
|
```html
|
|
419
503
|
<script type="module">
|
|
420
504
|
import { StockSDK } from 'https://unpkg.com/stock-sdk/dist/index.js';
|
|
421
|
-
|
|
505
|
+
|
|
422
506
|
const sdk = new StockSDK();
|
|
423
507
|
const quotes = await sdk.getFullQuotes(['sz000858']);
|
|
424
508
|
console.log(quotes[0].name, quotes[0].price);
|
|
425
509
|
</script>
|
|
426
510
|
```
|
|
427
511
|
|
|
512
|
+
---
|
|
513
|
+
|
|
428
514
|
## 开发
|
|
429
515
|
|
|
430
516
|
```bash
|
|
@@ -434,10 +520,20 @@ yarn install
|
|
|
434
520
|
# 运行测试
|
|
435
521
|
yarn test
|
|
436
522
|
|
|
523
|
+
# 查看覆盖率
|
|
524
|
+
yarn test --coverage
|
|
525
|
+
|
|
437
526
|
# 构建
|
|
438
527
|
yarn build
|
|
528
|
+
|
|
529
|
+
# 启动调试页面
|
|
530
|
+
yarn dev
|
|
439
531
|
```
|
|
440
532
|
|
|
441
533
|
## 许可证
|
|
442
534
|
|
|
443
|
-
|
|
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)
|