rquote 0.3.9__tar.gz → 0.4.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.
- {rquote-0.3.9/rquote.egg-info → rquote-0.4.1}/PKG-INFO +60 -8
- rquote-0.3.9/PKG-INFO → rquote-0.4.1/README.md +56 -18
- {rquote-0.3.9 → rquote-0.4.1}/pyproject.toml +5 -2
- {rquote-0.3.9 → rquote-0.4.1}/rquote/__init__.py +6 -0
- rquote-0.4.1/rquote/cache/__init__.py +14 -0
- rquote-0.4.1/rquote/cache/persistent.py +507 -0
- rquote-0.4.1/rquote/markets/base.py +242 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/cn_stock.py +9 -12
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/future.py +8 -9
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/hk_stock.py +4 -13
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/us_stock.py +8 -9
- rquote-0.3.9/README.md → rquote-0.4.1/rquote.egg-info/PKG-INFO +70 -6
- {rquote-0.3.9 → rquote-0.4.1}/rquote.egg-info/SOURCES.txt +1 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote.egg-info/requires.txt +3 -0
- rquote-0.4.1/tests/test_cache.py +357 -0
- rquote-0.3.9/rquote/cache/__init__.py +0 -9
- rquote-0.3.9/rquote/markets/base.py +0 -49
- rquote-0.3.9/tests/test_cache.py +0 -71
- {rquote-0.3.9 → rquote-0.4.1}/rquote/api/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/api/lists.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/api/price.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/api/stock_info.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/api/tick.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/cache/base.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/cache/memory.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/config.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/data_sources/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/data_sources/base.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/data_sources/sina.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/data_sources/tencent.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/exceptions.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/factors/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/factors/technical.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/markets/factory.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/parsers/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/parsers/kline.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/plots.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/__init__.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/date.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/helpers.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/http.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/logging.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils/web.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote/utils.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote.egg-info/dependency_links.txt +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/rquote.egg-info/top_level.txt +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/setup.cfg +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/tests/test_api.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/tests/test_config.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/tests/test_exceptions.py +0 -0
- {rquote-0.3.9 → rquote-0.4.1}/tests/test_utils.py +0 -0
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rquote
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
|
|
5
|
-
Requires-Python: >=3.
|
|
5
|
+
Requires-Python: >=3.9.0
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
7
|
Requires-Dist: build>=0.9.0
|
|
8
8
|
Requires-Dist: httpx>=0.20.0
|
|
9
9
|
Requires-Dist: pandas>=1.0.0
|
|
10
10
|
Requires-Dist: setuptools>=42
|
|
11
11
|
Requires-Dist: twine>=3.8.0
|
|
12
|
+
Provides-Extra: persistent
|
|
13
|
+
Requires-Dist: duckdb>=0.9.0; extra == "persistent"
|
|
12
14
|
|
|
13
15
|
# rquote
|
|
14
16
|
|
|
@@ -16,7 +18,7 @@ Requires-Dist: twine>=3.8.0
|
|
|
16
18
|
|
|
17
19
|
## 版本信息
|
|
18
20
|
|
|
19
|
-
当前版本:**0.
|
|
21
|
+
当前版本:**0.4.1**
|
|
20
22
|
|
|
21
23
|
## 主要特性
|
|
22
24
|
|
|
@@ -60,17 +62,67 @@ sid, name, df = get_price('sz000001', sdate='2024-01-01', edate='2024-02-01')
|
|
|
60
62
|
|
|
61
63
|
### 使用缓存
|
|
62
64
|
|
|
65
|
+
#### 内存缓存(MemoryCache)
|
|
66
|
+
|
|
63
67
|
```python
|
|
64
68
|
from rquote import get_price, MemoryCache
|
|
65
69
|
|
|
66
70
|
# 创建缓存实例
|
|
67
71
|
cache = MemoryCache(ttl=3600) # 缓存1小时
|
|
68
72
|
|
|
69
|
-
# 使用缓存(通过dd
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
# 使用缓存(通过dd参数传递MemoryCache实例)
|
|
74
|
+
sid, name, df = get_price('sh000001', dd=cache)
|
|
75
|
+
|
|
76
|
+
# 注意:MemoryCache 是内存缓存,数据仅在当前进程运行期间有效
|
|
77
|
+
# 脚本运行结束后,缓存数据会丢失
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**缓存生命周期说明:**
|
|
81
|
+
- `MemoryCache` 是纯内存缓存,数据存储在进程内存中
|
|
82
|
+
- 缓存数据仅在当前脚本运行期间有效
|
|
83
|
+
- 脚本运行结束后,所有缓存数据会丢失
|
|
84
|
+
|
|
85
|
+
#### 持久化缓存(PersistentCache)
|
|
86
|
+
|
|
87
|
+
持久化缓存支持跨进程/跨运行的缓存持久化,数据会保存到本地文件。
|
|
88
|
+
|
|
89
|
+
**安装可选依赖:**
|
|
90
|
+
```bash
|
|
91
|
+
pip install rquote[persistent]
|
|
92
|
+
# 或
|
|
93
|
+
uv pip install "rquote[persistent]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**使用持久化缓存:**
|
|
97
|
+
```python
|
|
98
|
+
from rquote import get_price, PersistentCache
|
|
99
|
+
|
|
100
|
+
# 创建持久化缓存实例
|
|
101
|
+
# 默认使用 duckdb(如果已安装),否则使用 pickle 文件
|
|
102
|
+
cache = PersistentCache(ttl=86400) # 缓存24小时,默认路径:~/.rquote/cache.db
|
|
103
|
+
|
|
104
|
+
# 或指定自定义路径
|
|
105
|
+
cache = PersistentCache(db_path='./my_cache.db', use_duckdb=True)
|
|
106
|
+
|
|
107
|
+
# 使用缓存
|
|
108
|
+
sid, name, df = get_price('sh000001', dd=cache)
|
|
109
|
+
|
|
110
|
+
# 持久化缓存支持智能扩展:
|
|
111
|
+
# - 当请求的结束日期不在缓存中时,会自动从缓存的最新日期向前扩展
|
|
112
|
+
# - 当请求的开始日期不在缓存中时,会自动从缓存的最早日期向后扩展
|
|
113
|
+
# - 数据会自动合并,避免重复请求
|
|
114
|
+
|
|
115
|
+
# 关闭缓存(可选,程序退出时会自动保存)
|
|
116
|
+
cache.close()
|
|
72
117
|
```
|
|
73
118
|
|
|
119
|
+
**持久化缓存特性:**
|
|
120
|
+
- ✅ 跨进程/跨运行持久化:数据保存在本地文件,下次运行仍可使用
|
|
121
|
+
- ✅ 智能数据合并:相同股票的数据会自动合并,key 不包含日期范围
|
|
122
|
+
- ✅ 智能扩展:当请求的日期范围超出缓存时,自动扩展并合并数据
|
|
123
|
+
- ✅ 支持 TTL:可设置缓存过期时间
|
|
124
|
+
- ✅ 可选 duckdb:如果安装了 duckdb,使用 duckdb 存储(性能更好),否则使用 pickle 文件
|
|
125
|
+
|
|
74
126
|
## 主要功能
|
|
75
127
|
|
|
76
128
|
### 历史价格数据获取
|
|
@@ -147,13 +199,13 @@ stocks = get_cn_stock_list(money_min=5e8)
|
|
|
147
199
|
|
|
148
200
|
#### `get_hk_stocks_500()`
|
|
149
201
|
|
|
150
|
-
获取港股前500只股票列表
|
|
202
|
+
获取港股前500只股票列表(按当日成交额排序)
|
|
151
203
|
|
|
152
204
|
```python
|
|
153
205
|
from rquote import get_hk_stocks_500
|
|
154
206
|
|
|
155
207
|
stocks = get_hk_stocks_500()
|
|
156
|
-
# 返回格式: [[code, name, price, turnover, ...], ...]
|
|
208
|
+
# 返回格式: [[code, name, price, -, -, -, -, volume, turnover, ...], ...]
|
|
157
209
|
```
|
|
158
210
|
|
|
159
211
|
#### `get_us_stocks(k=100)`
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: rquote
|
|
3
|
-
Version: 0.3.9
|
|
4
|
-
Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
|
|
5
|
-
Requires-Python: >=3.6.1
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
Requires-Dist: build>=0.9.0
|
|
8
|
-
Requires-Dist: httpx>=0.20.0
|
|
9
|
-
Requires-Dist: pandas>=1.0.0
|
|
10
|
-
Requires-Dist: setuptools>=42
|
|
11
|
-
Requires-Dist: twine>=3.8.0
|
|
12
|
-
|
|
13
1
|
# rquote
|
|
14
2
|
|
|
15
3
|
`rquote` 是一个提供 A股/港股/美股/ETF基金/期货 历史数据获取的Python库
|
|
16
4
|
|
|
17
5
|
## 版本信息
|
|
18
6
|
|
|
19
|
-
当前版本:**0.
|
|
7
|
+
当前版本:**0.4.1**
|
|
20
8
|
|
|
21
9
|
## 主要特性
|
|
22
10
|
|
|
@@ -60,17 +48,67 @@ sid, name, df = get_price('sz000001', sdate='2024-01-01', edate='2024-02-01')
|
|
|
60
48
|
|
|
61
49
|
### 使用缓存
|
|
62
50
|
|
|
51
|
+
#### 内存缓存(MemoryCache)
|
|
52
|
+
|
|
63
53
|
```python
|
|
64
54
|
from rquote import get_price, MemoryCache
|
|
65
55
|
|
|
66
56
|
# 创建缓存实例
|
|
67
57
|
cache = MemoryCache(ttl=3600) # 缓存1小时
|
|
68
58
|
|
|
69
|
-
# 使用缓存(通过dd
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
# 使用缓存(通过dd参数传递MemoryCache实例)
|
|
60
|
+
sid, name, df = get_price('sh000001', dd=cache)
|
|
61
|
+
|
|
62
|
+
# 注意:MemoryCache 是内存缓存,数据仅在当前进程运行期间有效
|
|
63
|
+
# 脚本运行结束后,缓存数据会丢失
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**缓存生命周期说明:**
|
|
67
|
+
- `MemoryCache` 是纯内存缓存,数据存储在进程内存中
|
|
68
|
+
- 缓存数据仅在当前脚本运行期间有效
|
|
69
|
+
- 脚本运行结束后,所有缓存数据会丢失
|
|
70
|
+
|
|
71
|
+
#### 持久化缓存(PersistentCache)
|
|
72
|
+
|
|
73
|
+
持久化缓存支持跨进程/跨运行的缓存持久化,数据会保存到本地文件。
|
|
74
|
+
|
|
75
|
+
**安装可选依赖:**
|
|
76
|
+
```bash
|
|
77
|
+
pip install rquote[persistent]
|
|
78
|
+
# 或
|
|
79
|
+
uv pip install "rquote[persistent]"
|
|
72
80
|
```
|
|
73
81
|
|
|
82
|
+
**使用持久化缓存:**
|
|
83
|
+
```python
|
|
84
|
+
from rquote import get_price, PersistentCache
|
|
85
|
+
|
|
86
|
+
# 创建持久化缓存实例
|
|
87
|
+
# 默认使用 duckdb(如果已安装),否则使用 pickle 文件
|
|
88
|
+
cache = PersistentCache(ttl=86400) # 缓存24小时,默认路径:~/.rquote/cache.db
|
|
89
|
+
|
|
90
|
+
# 或指定自定义路径
|
|
91
|
+
cache = PersistentCache(db_path='./my_cache.db', use_duckdb=True)
|
|
92
|
+
|
|
93
|
+
# 使用缓存
|
|
94
|
+
sid, name, df = get_price('sh000001', dd=cache)
|
|
95
|
+
|
|
96
|
+
# 持久化缓存支持智能扩展:
|
|
97
|
+
# - 当请求的结束日期不在缓存中时,会自动从缓存的最新日期向前扩展
|
|
98
|
+
# - 当请求的开始日期不在缓存中时,会自动从缓存的最早日期向后扩展
|
|
99
|
+
# - 数据会自动合并,避免重复请求
|
|
100
|
+
|
|
101
|
+
# 关闭缓存(可选,程序退出时会自动保存)
|
|
102
|
+
cache.close()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**持久化缓存特性:**
|
|
106
|
+
- ✅ 跨进程/跨运行持久化:数据保存在本地文件,下次运行仍可使用
|
|
107
|
+
- ✅ 智能数据合并:相同股票的数据会自动合并,key 不包含日期范围
|
|
108
|
+
- ✅ 智能扩展:当请求的日期范围超出缓存时,自动扩展并合并数据
|
|
109
|
+
- ✅ 支持 TTL:可设置缓存过期时间
|
|
110
|
+
- ✅ 可选 duckdb:如果安装了 duckdb,使用 duckdb 存储(性能更好),否则使用 pickle 文件
|
|
111
|
+
|
|
74
112
|
## 主要功能
|
|
75
113
|
|
|
76
114
|
### 历史价格数据获取
|
|
@@ -147,13 +185,13 @@ stocks = get_cn_stock_list(money_min=5e8)
|
|
|
147
185
|
|
|
148
186
|
#### `get_hk_stocks_500()`
|
|
149
187
|
|
|
150
|
-
获取港股前500只股票列表
|
|
188
|
+
获取港股前500只股票列表(按当日成交额排序)
|
|
151
189
|
|
|
152
190
|
```python
|
|
153
191
|
from rquote import get_hk_stocks_500
|
|
154
192
|
|
|
155
193
|
stocks = get_hk_stocks_500()
|
|
156
|
-
# 返回格式: [[code, name, price, turnover, ...], ...]
|
|
194
|
+
# 返回格式: [[code, name, price, -, -, -, -, volume, turnover, ...], ...]
|
|
157
195
|
```
|
|
158
196
|
|
|
159
197
|
#### `get_us_stocks(k=100)`
|
|
@@ -4,10 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "rquote"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.1"
|
|
8
8
|
description = "Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.6.1"
|
|
10
|
+
# requires-python = ">=3.6.1" # duckdb requires higher python version
|
|
11
|
+
requires-python = ">=3.9.0"
|
|
11
12
|
dependencies = [
|
|
12
13
|
"build>=0.9.0",
|
|
13
14
|
"httpx>=0.20.0",
|
|
@@ -15,3 +16,5 @@ dependencies = [
|
|
|
15
16
|
"setuptools>=42",
|
|
16
17
|
"twine>=3.8.0",
|
|
17
18
|
]
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
persistent = ["duckdb>=0.9.0"]
|
|
@@ -35,6 +35,11 @@ from .plots import PlotUtils
|
|
|
35
35
|
from . import config
|
|
36
36
|
from . import exceptions
|
|
37
37
|
from .cache import MemoryCache, Cache
|
|
38
|
+
# 尝试导入持久化缓存(可选依赖)
|
|
39
|
+
try:
|
|
40
|
+
from .cache import PersistentCache
|
|
41
|
+
except ImportError:
|
|
42
|
+
PersistentCache = None
|
|
38
43
|
from .utils.http import HTTPClient
|
|
39
44
|
|
|
40
45
|
|
|
@@ -93,5 +98,6 @@ __all__ = [
|
|
|
93
98
|
'exceptions',
|
|
94
99
|
'MemoryCache',
|
|
95
100
|
'Cache',
|
|
101
|
+
'PersistentCache',
|
|
96
102
|
'HTTPClient',
|
|
97
103
|
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
缓存模块
|
|
4
|
+
"""
|
|
5
|
+
from .base import Cache
|
|
6
|
+
from .memory import MemoryCache
|
|
7
|
+
|
|
8
|
+
# 尝试导入持久化缓存(可选依赖)
|
|
9
|
+
try:
|
|
10
|
+
from .persistent import PersistentCache
|
|
11
|
+
__all__ = ['Cache', 'MemoryCache', 'PersistentCache']
|
|
12
|
+
except ImportError:
|
|
13
|
+
__all__ = ['Cache', 'MemoryCache']
|
|
14
|
+
|