panda-data 0.0.1__tar.gz
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.
- panda_data-0.0.1/PKG-INFO +438 -0
- panda_data-0.0.1/README.md +418 -0
- panda_data-0.0.1/panda_data/__init__.py +68 -0
- panda_data-0.0.1/panda_data/client.py +372 -0
- panda_data-0.0.1/panda_data/config/__init__.py +177 -0
- panda_data-0.0.1/panda_data/core/__init__.py +2 -0
- panda_data-0.0.1/panda_data/core/service.py +49 -0
- panda_data-0.0.1/panda_data/exceptions.py +140 -0
- panda_data-0.0.1/panda_data/readers/__init__.py +1 -0
- panda_data-0.0.1/panda_data/readers/financial_and_factors_reader.py +852 -0
- panda_data-0.0.1/panda_data/readers/future_reader.py +206 -0
- panda_data-0.0.1/panda_data/readers/init_token.py +121 -0
- panda_data-0.0.1/panda_data/readers/market_reader.py +512 -0
- panda_data-0.0.1/panda_data/readers/market_reference_reader.py +1455 -0
- panda_data-0.0.1/panda_data/readers/trading_tools_reader.py +242 -0
- panda_data-0.0.1/panda_data/test.py +32 -0
- panda_data-0.0.1/panda_data/transport/__init__.py +6 -0
- panda_data-0.0.1/panda_data/transport/http.py +1155 -0
- panda_data-0.0.1/panda_data/utils/common_utils.py +49 -0
- panda_data-0.0.1/panda_data/utils/param_check_utils.py +1409 -0
- panda_data-0.0.1/panda_data.egg-info/PKG-INFO +438 -0
- panda_data-0.0.1/panda_data.egg-info/SOURCES.txt +25 -0
- panda_data-0.0.1/panda_data.egg-info/dependency_links.txt +1 -0
- panda_data-0.0.1/panda_data.egg-info/requires.txt +14 -0
- panda_data-0.0.1/panda_data.egg-info/top_level.txt +1 -0
- panda_data-0.0.1/pyproject.toml +41 -0
- panda_data-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: panda_data
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: PandaAI DataQuant
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pandas>=2.0.0
|
|
8
|
+
Requires-Dist: numpy<2.0,>=1.22
|
|
9
|
+
Requires-Dist: python-snappy>=0.7.3
|
|
10
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
11
|
+
Requires-Dist: PyYAML>=6.0
|
|
12
|
+
Requires-Dist: zstandard>=0.22.0
|
|
13
|
+
Requires-Dist: duckdb
|
|
14
|
+
Requires-Dist: pyarrow
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
|
17
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
18
|
+
Requires-Dist: httpx; extra == "dev"
|
|
19
|
+
Requires-Dist: jupyterlab>=3.5.0; extra == "dev"
|
|
20
|
+
|
|
21
|
+
# panda_data Python SDK 使用文档
|
|
22
|
+
|
|
23
|
+
> **项目状态**: 🟢 生产环境
|
|
24
|
+
> **版本**: v0.1.0
|
|
25
|
+
> **Python 版本**: >= 3.12
|
|
26
|
+
> **最后更新**: 2024-XX-XX
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📋 项目概述
|
|
31
|
+
|
|
32
|
+
`panda_data` 是公司内部金融数据服务的 Python SDK,提供统一的 Python API 接口访问各类金融数据,所有接口返回 `pandas.DataFrame` 格式,便于数据分析和处理。
|
|
33
|
+
|
|
34
|
+
### 核心特性
|
|
35
|
+
|
|
36
|
+
- ✅ 统一返回 `pandas.DataFrame` 格式,无需数据转换
|
|
37
|
+
- ✅ 支持股票、基金、指数、行业、概念、财务、期货等多种数据类型
|
|
38
|
+
- ✅ 完善的错误处理和自动重试机制
|
|
39
|
+
- ✅ 支持代码配置和环境变量配置
|
|
40
|
+
- ✅ 支持代理、SSL 验证、Gzip 压缩等企业级特性
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 📑 快速导航
|
|
45
|
+
|
|
46
|
+
- [快速开始](#快速开始)
|
|
47
|
+
- [配置说明](#配置说明)
|
|
48
|
+
- [API 接口](#api-接口)
|
|
49
|
+
- [使用示例](#使用示例)
|
|
50
|
+
- [常见问题](#常见问题)
|
|
51
|
+
- [技术支持](#技术支持)
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🚀 快速开始
|
|
56
|
+
|
|
57
|
+
### 安装
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install panda_data
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 依赖要求
|
|
64
|
+
|
|
65
|
+
| 依赖包 | 版本要求 |
|
|
66
|
+
|--------|---------|
|
|
67
|
+
| Python | >= 3.12 |
|
|
68
|
+
| pandas | >= 2.0.0 |
|
|
69
|
+
| numpy | >= 1.22, < 2.0 |
|
|
70
|
+
|
|
71
|
+
### 基本使用
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import panda_data
|
|
75
|
+
|
|
76
|
+
# 初始化连接
|
|
77
|
+
panda_data.init(
|
|
78
|
+
username="your_username",
|
|
79
|
+
password="your_password",
|
|
80
|
+
base_url="http://java-service-host:8080",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# 获取数据
|
|
84
|
+
df = panda_data.get_market_data(
|
|
85
|
+
symbol=["000001.SZ"],
|
|
86
|
+
start_date="2024-01-01",
|
|
87
|
+
end_date="2024-01-31"
|
|
88
|
+
)
|
|
89
|
+
print(df.head())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Token 初始化(推荐)
|
|
93
|
+
|
|
94
|
+
使用 Token 方式可以避免在代码中硬编码密码,更安全:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import panda_data
|
|
98
|
+
|
|
99
|
+
# 使用 token 文件初始化
|
|
100
|
+
panda_data.init_token()
|
|
101
|
+
|
|
102
|
+
# 调用接口
|
|
103
|
+
df = panda_data.get_abnormal(symbol=["000001.SZ"])
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## ⚙️ 配置说明
|
|
109
|
+
|
|
110
|
+
### 代码配置
|
|
111
|
+
|
|
112
|
+
在 `init()` 函数中传入配置参数:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
panda_data.init(
|
|
116
|
+
username="user",
|
|
117
|
+
password="pass",
|
|
118
|
+
base_url="http://service.example.com:8080",
|
|
119
|
+
timeout=60.0, # 请求超时时间(秒)
|
|
120
|
+
max_retries=5, # 最大重试次数
|
|
121
|
+
verify_ssl=True, # 是否验证 SSL 证书
|
|
122
|
+
use_gzip=True, # 是否使用 Gzip 压缩
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 环境变量配置
|
|
127
|
+
|
|
128
|
+
支持通过环境变量配置,**环境变量优先级高于代码配置**:
|
|
129
|
+
|
|
130
|
+
| 环境变量 | 说明 | 默认值 |
|
|
131
|
+
|---------|------|--------|
|
|
132
|
+
| `HTTP_SERVICE_BASE_URL` | 服务基础 URL | `http://localhost:8080` |
|
|
133
|
+
| `HTTP_TIMEOUT` | 请求超时时间(秒) | `30` |
|
|
134
|
+
| `HTTP_MAX_RETRIES` | 自动重试次数 | `3` |
|
|
135
|
+
| `HTTP_VERIFY_SSL` | 是否验证 SSL 证书 | `true` |
|
|
136
|
+
| `HTTP_PROXY_TYPE` | 代理类型("http" 或 "https") | `None` |
|
|
137
|
+
| `HTTP_PROXY_HOST` | 代理主机 | `None` |
|
|
138
|
+
| `HTTP_PROXY_PORT` | 代理端口 | `None` |
|
|
139
|
+
| `HTTP_USE_GZIP` | 是否使用 Gzip 压缩 | `false` |
|
|
140
|
+
|
|
141
|
+
### 代理配置
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
panda_data.init(
|
|
145
|
+
username="user",
|
|
146
|
+
password="pass",
|
|
147
|
+
base_url="http://service.example.com:8080",
|
|
148
|
+
proxy_type="http",
|
|
149
|
+
proxy_host="proxy.example.com",
|
|
150
|
+
proxy_port=8080,
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 📚 API 接口
|
|
157
|
+
|
|
158
|
+
### 股票数据
|
|
159
|
+
|
|
160
|
+
| 接口 | 说明 |
|
|
161
|
+
|------|------|
|
|
162
|
+
| `get_stock_detail(symbol, fields=None)` | 获取股票详情 |
|
|
163
|
+
| `get_all_symbols(market="cn")` | 获取所有股票代码 |
|
|
164
|
+
| `get_market_data(symbol, start_date, end_date, ...)` | 获取行情数据(日线) |
|
|
165
|
+
| `get_market_min_data(symbol, start_date, end_date, ...)` | 获取分钟行情数据 |
|
|
166
|
+
| `get_stock_flow(symbol)` | 获取资金流向 |
|
|
167
|
+
| `get_main_shareholder(symbol)` | 获取主要股东信息 |
|
|
168
|
+
|
|
169
|
+
**示例:**
|
|
170
|
+
```python
|
|
171
|
+
# 获取行情数据
|
|
172
|
+
df = panda_data.get_market_data(
|
|
173
|
+
symbol=["000001.SZ", "000002.SZ"],
|
|
174
|
+
start_date="2024-01-01",
|
|
175
|
+
end_date="2024-01-31"
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 异常数据(龙虎榜)
|
|
180
|
+
|
|
181
|
+
| 接口 | 说明 |
|
|
182
|
+
|------|------|
|
|
183
|
+
| `get_abnormal(symbol, type, start_date, end_date, ...)` | 获取异常数据 |
|
|
184
|
+
| `get_abnormal_detail(symbol, type, start_date, end_date, ...)` | 获取异常明细 |
|
|
185
|
+
| `get_abnormal_types()` | 获取异常类型列表 |
|
|
186
|
+
| `get_abnormal_stocks(date, type=None)` | 获取指定日期的异常股票 |
|
|
187
|
+
|
|
188
|
+
**示例:**
|
|
189
|
+
```python
|
|
190
|
+
df = panda_data.get_abnormal(
|
|
191
|
+
symbol=["000001.SZ"],
|
|
192
|
+
start_date="2024-01-01",
|
|
193
|
+
end_date="2024-01-31"
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 基金数据
|
|
198
|
+
|
|
199
|
+
| 接口 | 说明 |
|
|
200
|
+
|------|------|
|
|
201
|
+
| `get_all_funds()` | 获取所有基金列表 |
|
|
202
|
+
| `get_fund_pro(symbol)` | 获取基金持仓 |
|
|
203
|
+
| `get_fund_nav(symbol)` | 获取基金净值 |
|
|
204
|
+
|
|
205
|
+
### 指数数据
|
|
206
|
+
|
|
207
|
+
| 接口 | 说明 |
|
|
208
|
+
|------|------|
|
|
209
|
+
| `get_index_symbol()` | 获取指数代码列表 |
|
|
210
|
+
| `get_index_indicator(symbol)` | 获取指数指标 |
|
|
211
|
+
| `get_index_weights(symbol)` | 获取指数权重 |
|
|
212
|
+
| `get_index_stock(symbol)` | 获取指数成分股 |
|
|
213
|
+
| `get_index_1m_market(symbol)` | 获取指数分钟行情 |
|
|
214
|
+
|
|
215
|
+
### 行业数据
|
|
216
|
+
|
|
217
|
+
| 接口 | 说明 |
|
|
218
|
+
|------|------|
|
|
219
|
+
| `get_industry_list()` | 获取行业列表 |
|
|
220
|
+
| `get_industry_stock(industry)` | 获取行业股票 |
|
|
221
|
+
| `get_stock_industry(symbol)` | 获取股票所属行业 |
|
|
222
|
+
|
|
223
|
+
### 概念数据
|
|
224
|
+
|
|
225
|
+
| 接口 | 说明 |
|
|
226
|
+
|------|------|
|
|
227
|
+
| `get_concept_list()` | 获取概念列表 |
|
|
228
|
+
| `get_concept_stock(concept)` | 获取概念股票 |
|
|
229
|
+
|
|
230
|
+
### 财务数据
|
|
231
|
+
|
|
232
|
+
| 接口 | 说明 |
|
|
233
|
+
|------|------|
|
|
234
|
+
| `get_financial_ex(symbol)` | 获取财务数据 |
|
|
235
|
+
| `get_financial_forecast(symbol)` | 获取业绩预告 |
|
|
236
|
+
| `get_financial_performance(symbol)` | 获取业绩快报 |
|
|
237
|
+
|
|
238
|
+
### 交易日历
|
|
239
|
+
|
|
240
|
+
| 接口 | 说明 | 返回类型 |
|
|
241
|
+
|------|------|---------|
|
|
242
|
+
| `get_trading_calendar(start_date, end_date)` | 获取交易日历 | DataFrame |
|
|
243
|
+
| `get_trading_days(start_date, end_date)` | 获取交易日列表 | DataFrame |
|
|
244
|
+
| `is_trading_day(date)` | 判断是否为交易日 | bool |
|
|
245
|
+
| `get_previous_trading_date(date)` | 获取前一个交易日 | str |
|
|
246
|
+
| `get_next_trading_date(date)` | 获取下一个交易日 | str |
|
|
247
|
+
| `get_latest_trading_date()` | 获取最新交易日 | str |
|
|
248
|
+
|
|
249
|
+
### 其他数据
|
|
250
|
+
|
|
251
|
+
| 接口 | 说明 |
|
|
252
|
+
|------|------|
|
|
253
|
+
| `get_buy_back(symbol)` | 获取回购数据 |
|
|
254
|
+
| `get_securities_margin(symbol)` | 获取融资融券数据 |
|
|
255
|
+
| `get_future_list()` | 获取期货列表 |
|
|
256
|
+
| `get_future_factor_post(symbol)` | 获取期货因子数据 |
|
|
257
|
+
| `get_consensus_report(symbol)` | 获取一致预期 |
|
|
258
|
+
| `get_stock_connect(symbol)` | 获取沪港通数据 |
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 💡 使用示例
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
import panda_data
|
|
266
|
+
import pandas as pd
|
|
267
|
+
|
|
268
|
+
# 初始化
|
|
269
|
+
panda_data.init(
|
|
270
|
+
username="your_username",
|
|
271
|
+
password="your_password",
|
|
272
|
+
base_url="http://service.example.com:8080",
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
# 获取股票行情数据
|
|
276
|
+
df = panda_data.get_market_data(
|
|
277
|
+
symbol=["000001.SZ", "000002.SZ"],
|
|
278
|
+
start_date="2024-01-01",
|
|
279
|
+
end_date="2024-01-31",
|
|
280
|
+
fields=["open", "high", "low", "close", "volume"]
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
# 数据分析
|
|
284
|
+
print(f"共获取 {len(df)} 条数据")
|
|
285
|
+
print(df.groupby("symbol")["close"].mean())
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## ❓ 常见问题
|
|
291
|
+
|
|
292
|
+
### Q1: 如何设置代理?
|
|
293
|
+
|
|
294
|
+
**A:** 通过代码或环境变量设置:
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
panda_data.init(
|
|
298
|
+
username="user",
|
|
299
|
+
password="pass",
|
|
300
|
+
base_url="http://service.example.com:8080",
|
|
301
|
+
proxy_type="http",
|
|
302
|
+
proxy_host="proxy.example.com",
|
|
303
|
+
proxy_port=8080,
|
|
304
|
+
)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Q2: 如何启用 Gzip 压缩?
|
|
308
|
+
|
|
309
|
+
**A:** 设置 `use_gzip=True`:
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
panda_data.init(
|
|
313
|
+
username="user",
|
|
314
|
+
password="pass",
|
|
315
|
+
base_url="http://service.example.com:8080",
|
|
316
|
+
use_gzip=True,
|
|
317
|
+
)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Q3: 如何处理超时?
|
|
321
|
+
|
|
322
|
+
**A:** 设置 `timeout` 参数:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
panda_data.init(
|
|
326
|
+
username="user",
|
|
327
|
+
password="pass",
|
|
328
|
+
base_url="http://service.example.com:8080",
|
|
329
|
+
timeout=60.0, # 60 秒超时
|
|
330
|
+
)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Q4: 返回的 DataFrame 为空怎么办?
|
|
334
|
+
|
|
335
|
+
**A:** 检查以下几点:
|
|
336
|
+
1. 确认参数是否正确(股票代码、日期格式等)
|
|
337
|
+
2. 确认请求的时间范围内是否有数据
|
|
338
|
+
3. 确认账号是否有权限访问该数据
|
|
339
|
+
4. 查看异常信息排查问题
|
|
340
|
+
|
|
341
|
+
```python
|
|
342
|
+
try:
|
|
343
|
+
df = panda_data.get_market_data(
|
|
344
|
+
symbol=["000001.SZ"],
|
|
345
|
+
start_date="2024-01-01",
|
|
346
|
+
end_date="2024-01-31"
|
|
347
|
+
)
|
|
348
|
+
if df.empty:
|
|
349
|
+
print("未找到数据,请检查参数")
|
|
350
|
+
except Exception as e:
|
|
351
|
+
print(f"错误: {e}")
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## 🛠️ 错误处理
|
|
357
|
+
|
|
358
|
+
SDK 提供了完善的异常处理机制:
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
from panda_data.exceptions import (
|
|
362
|
+
ClientNotInitializedError, # 客户端未初始化
|
|
363
|
+
AuthenticationError, # 认证失败
|
|
364
|
+
ServiceError, # 服务端错误
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
try:
|
|
368
|
+
df = panda_data.get_abnormal(symbol=["000001.SZ"])
|
|
369
|
+
except ClientNotInitializedError:
|
|
370
|
+
print("请先调用 panda_data.init() 初始化客户端")
|
|
371
|
+
except AuthenticationError:
|
|
372
|
+
print("认证失败,请检查用户名和密码")
|
|
373
|
+
except ServiceError as e:
|
|
374
|
+
print(f"服务端错误: {e}")
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### 异常类型说明
|
|
378
|
+
|
|
379
|
+
| 异常类型 | 说明 | 解决方案 |
|
|
380
|
+
|---------|------|---------|
|
|
381
|
+
| `ClientNotInitializedError` | 客户端未初始化 | 调用 `panda_data.init()` 或 `panda_data.init_token()` |
|
|
382
|
+
| `AuthenticationError` | 认证失败 | 检查用户名和密码是否正确 |
|
|
383
|
+
| `ServiceError` | 服务端错误 | 检查服务端状态和请求参数 |
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 🏗️ 架构说明
|
|
388
|
+
|
|
389
|
+
### 模块结构
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
panda_data/
|
|
393
|
+
├── client.py # 客户端入口与连接管理
|
|
394
|
+
├── config/ # 配置加载与环境变量解析
|
|
395
|
+
├── core/ # 面向业务的服务封装
|
|
396
|
+
├── transport/ # HTTP 底层通信实现
|
|
397
|
+
├── readers/ # 各类数据 Reader
|
|
398
|
+
│ ├── abnormal_reader.py # 异常数据
|
|
399
|
+
│ ├── kline_reader.py # K线数据
|
|
400
|
+
│ ├── stock_reader.py # 股票数据
|
|
401
|
+
│ └── ...
|
|
402
|
+
└── exceptions.py # 异常定义
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### 核心组件
|
|
406
|
+
|
|
407
|
+
- **`PandaServiceClient`**: 封装与 Java 服务的 HTTP 通信逻辑
|
|
408
|
+
- **`HTTPClient`**: 底层 HTTP 客户端,处理请求、响应、重试、代理等
|
|
409
|
+
- **`ClientFactory`**: 工厂模式管理各类 Reader
|
|
410
|
+
- **`Reader`**: 各类数据 Reader,封装特定数据接口的调用逻辑
|
|
411
|
+
|
|
412
|
+
### 通信协议
|
|
413
|
+
|
|
414
|
+
- **请求方法**: POST
|
|
415
|
+
- **请求格式**: JSON
|
|
416
|
+
- **响应格式**: JSON
|
|
417
|
+
- **认证方式**: HTTP Basic Authentication
|
|
418
|
+
- **压缩支持**: 可选 Gzip 压缩
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## 📞 技术支持
|
|
423
|
+
|
|
424
|
+
### 获取帮助
|
|
425
|
+
|
|
426
|
+
- 📧 **技术支持**: [待补充]
|
|
427
|
+
- 📝 **问题反馈**: [待补充]
|
|
428
|
+
- 📚 **更多文档**: [待补充]
|
|
429
|
+
|
|
430
|
+
### 相关资源
|
|
431
|
+
|
|
432
|
+
- 项目仓库: [待补充]
|
|
433
|
+
- 更新日志: [待补充]
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
**文档维护**: 数据团队
|
|
438
|
+
**最后更新**: 2024-XX-XX
|