rquote 0.3.5__py3-none-any.whl → 0.3.8__py3-none-any.whl
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/__init__.py +35 -1
- rquote/api/lists.py +1 -1
- rquote/api/price.py +6 -0
- rquote/api/stock_info.py +2 -0
- rquote/data_sources/sina.py +6 -0
- rquote/data_sources/tencent.py +7 -4
- rquote/markets/cn_stock.py +1 -1
- rquote/utils/web.py +5 -0
- {rquote-0.3.5.dist-info → rquote-0.3.8.dist-info}/METADATA +2 -2
- {rquote-0.3.5.dist-info → rquote-0.3.8.dist-info}/RECORD +12 -12
- {rquote-0.3.5.dist-info → rquote-0.3.8.dist-info}/WHEEL +0 -0
- {rquote-0.3.5.dist-info → rquote-0.3.8.dist-info}/top_level.txt +0 -0
rquote/__init__.py
CHANGED
|
@@ -7,6 +7,9 @@ Copyright (c) 2021 Roi ZHAO
|
|
|
7
7
|
|
|
8
8
|
'''
|
|
9
9
|
|
|
10
|
+
import re
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
10
13
|
# API函数
|
|
11
14
|
from .api import (
|
|
12
15
|
get_price,
|
|
@@ -34,7 +37,38 @@ from . import exceptions
|
|
|
34
37
|
from .cache import MemoryCache, Cache
|
|
35
38
|
from .utils.http import HTTPClient
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
|
|
41
|
+
def _get_version():
|
|
42
|
+
"""从 pyproject.toml 读取版本号"""
|
|
43
|
+
# 优先尝试从已安装的包中读取版本
|
|
44
|
+
try:
|
|
45
|
+
from importlib import metadata
|
|
46
|
+
return metadata.version("rquote")
|
|
47
|
+
except Exception:
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
# 如果包未安装,从 pyproject.toml 读取
|
|
51
|
+
try:
|
|
52
|
+
# 获取项目根目录(__init__.py 的父目录的父目录)
|
|
53
|
+
current_file = Path(__file__).resolve()
|
|
54
|
+
project_root = current_file.parent.parent
|
|
55
|
+
pyproject_path = project_root / "pyproject.toml"
|
|
56
|
+
|
|
57
|
+
if pyproject_path.exists():
|
|
58
|
+
with open(pyproject_path, 'r', encoding='utf-8') as f:
|
|
59
|
+
content = f.read()
|
|
60
|
+
# 使用正则表达式匹配 version = "x.x.x"
|
|
61
|
+
match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)
|
|
62
|
+
if match:
|
|
63
|
+
return match.group(1)
|
|
64
|
+
except Exception:
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
# 如果都失败了,返回默认版本
|
|
68
|
+
return "0.0.0"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
__version__ = _get_version()
|
|
38
72
|
|
|
39
73
|
__all__ = [
|
|
40
74
|
# API函数
|
rquote/api/lists.py
CHANGED
rquote/api/price.py
CHANGED
|
@@ -20,6 +20,7 @@ def get_price(i: str, sdate: str = '', edate: str = '', freq: str = 'day',
|
|
|
20
20
|
i: 股票代码
|
|
21
21
|
sdate: 开始日期
|
|
22
22
|
edate: 结束日期
|
|
23
|
+
freq: 频率,默认'day' (日线),可选:'week', 'month', 'min'
|
|
23
24
|
dd: data dictionary或Cache对象,任何有get/put方法的本地缓存
|
|
24
25
|
days: 获取天数,覆盖sdate
|
|
25
26
|
fq: 复权方式,qfq为前复权
|
|
@@ -71,3 +72,8 @@ def get_price_longer(i: str, l: int = 2, dd=None) -> Tuple[str, str, pd.DataFram
|
|
|
71
72
|
d1 = d0
|
|
72
73
|
return i, name, a
|
|
73
74
|
|
|
75
|
+
|
|
76
|
+
if __name__ == '__main__':
|
|
77
|
+
i = 'usTSLA.N'
|
|
78
|
+
a = get_price(i, freq='min')
|
|
79
|
+
print(a)
|
rquote/api/stock_info.py
CHANGED
|
@@ -18,6 +18,7 @@ def get_stock_concepts(i: str) -> List[str]:
|
|
|
18
18
|
Returns:
|
|
19
19
|
概念代码列表
|
|
20
20
|
"""
|
|
21
|
+
i = {'6': 'sh', '0': 'sz', '3': 'sz'}.get(i[0], '') + i if i[0] in ['6', '0', '3'] else i
|
|
21
22
|
url = f'https://proxy.finance.qq.com/ifzqgtimg/appstock/app/stockinfo/plateNew?code={i}&app=wzq&zdf=1'
|
|
22
23
|
a = hget(url)
|
|
23
24
|
if not a:
|
|
@@ -38,6 +39,7 @@ def get_stock_industry(i: str) -> List[str]:
|
|
|
38
39
|
Returns:
|
|
39
40
|
行业代码列表
|
|
40
41
|
"""
|
|
42
|
+
i = {'6': 'sh', '0': 'sz', '3': 'sz'}.get(i[0], '') + i if i[0] in ['6', '0', '3'] else i
|
|
41
43
|
url = f'https://proxy.finance.qq.com/ifzqgtimg/appstock/app/stockinfo/plateNew?code={i}&app=wzq&zdf=1'
|
|
42
44
|
a = hget(url)
|
|
43
45
|
if not a:
|
rquote/data_sources/sina.py
CHANGED
|
@@ -57,6 +57,9 @@ class SinaDataSource(DataSource):
|
|
|
57
57
|
return {'data': data}
|
|
58
58
|
except json.JSONDecodeError as e:
|
|
59
59
|
raise ParseError(f"Parse error: {e}")
|
|
60
|
+
finally:
|
|
61
|
+
# 确保响应对象被关闭,释放SSL连接
|
|
62
|
+
response.close()
|
|
60
63
|
|
|
61
64
|
def fetch_tick(self, symbols: List[str]) -> Dict[str, Any]:
|
|
62
65
|
"""
|
|
@@ -89,4 +92,7 @@ class SinaDataSource(DataSource):
|
|
|
89
92
|
return {'data': result}
|
|
90
93
|
except Exception as e:
|
|
91
94
|
raise ParseError(f"Parse tick error: {e}")
|
|
95
|
+
finally:
|
|
96
|
+
# 确保响应对象被关闭,释放SSL连接
|
|
97
|
+
response.close()
|
|
92
98
|
|
rquote/data_sources/tencent.py
CHANGED
|
@@ -12,9 +12,9 @@ from ..exceptions import DataSourceError, ParseError
|
|
|
12
12
|
class TencentDataSource(DataSource):
|
|
13
13
|
"""腾讯数据源"""
|
|
14
14
|
|
|
15
|
-
BASE_URL = "
|
|
16
|
-
BASE_URL_HK = "
|
|
17
|
-
BASE_URL_US = "
|
|
15
|
+
BASE_URL = "https://web.ifzq.gtimg.cn/appstock/app/newfqkline/get"
|
|
16
|
+
BASE_URL_HK = "https://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get"
|
|
17
|
+
BASE_URL_US = "https://web.ifzq.gtimg.cn/appstock/app/usfqkline/get"
|
|
18
18
|
|
|
19
19
|
def __init__(self, http_client: HTTPClient = None):
|
|
20
20
|
"""
|
|
@@ -56,7 +56,7 @@ class TencentDataSource(DataSource):
|
|
|
56
56
|
if not response:
|
|
57
57
|
raise DataSourceError(f"Failed to fetch from Tencent: {symbol}")
|
|
58
58
|
|
|
59
|
-
#
|
|
59
|
+
# 解析响应,确保响应对象被正确关闭
|
|
60
60
|
try:
|
|
61
61
|
text = response.text
|
|
62
62
|
# 处理不同的响应格式
|
|
@@ -83,6 +83,9 @@ class TencentDataSource(DataSource):
|
|
|
83
83
|
return data
|
|
84
84
|
except json.JSONDecodeError as e:
|
|
85
85
|
raise ParseError(f"Parse error: {e}")
|
|
86
|
+
finally:
|
|
87
|
+
# 确保响应对象被关闭,释放SSL连接
|
|
88
|
+
response.close()
|
|
86
89
|
|
|
87
90
|
def fetch_tick(self, symbols: List[str]) -> Dict[str, Any]:
|
|
88
91
|
"""获取实时行情(暂未实现)"""
|
rquote/markets/cn_stock.py
CHANGED
|
@@ -159,7 +159,7 @@ class CNStockMarket(Market):
|
|
|
159
159
|
from ..utils import hget
|
|
160
160
|
import json
|
|
161
161
|
|
|
162
|
-
url = f'
|
|
162
|
+
url = f'https://web.ifzq.gtimg.cn/appstock/app/newfqkline/get?param={symbol},{freq},{sdate},{edate},{days},{fq}'
|
|
163
163
|
response = hget(url)
|
|
164
164
|
if not response:
|
|
165
165
|
raise DataSourceError(f'Failed to fetch data for {symbol}')
|
rquote/utils/web.py
CHANGED
|
@@ -91,6 +91,7 @@ class hget:
|
|
|
91
91
|
"""
|
|
92
92
|
def __init__(self, url, *args, **kwargs):
|
|
93
93
|
self.url = url
|
|
94
|
+
r = None
|
|
94
95
|
try:
|
|
95
96
|
r = httpx.get(
|
|
96
97
|
self.url, follow_redirects=True, headers=WebUtils.headers(),
|
|
@@ -101,4 +102,8 @@ class hget:
|
|
|
101
102
|
logger.error(f'fetch {self.url} err: {e}')
|
|
102
103
|
self.text = ''
|
|
103
104
|
self.content = b''
|
|
105
|
+
finally:
|
|
106
|
+
# 确保响应对象被关闭,释放SSL连接
|
|
107
|
+
if r is not None:
|
|
108
|
+
r.close()
|
|
104
109
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rquote
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
|
|
5
5
|
Requires-Python: >=3.6.1
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -83,7 +83,7 @@ sid, name, df = get_price('sh000001', dd=cache_dict)
|
|
|
83
83
|
- `i`: 股票代码,使用新浪/腾讯的id形式
|
|
84
84
|
- `sdate`: 开始日期 (可选,格式:YYYY-MM-DD)
|
|
85
85
|
- `edate`: 结束日期 (可选,格式:YYYY-MM-DD)
|
|
86
|
-
- `freq`: 频率,默认'day' (日线),可选:'week', 'month', 'min'
|
|
86
|
+
- `freq`: 频率,默认'day' (日线),可选:(港A)'week', 'month', (美股)'min'
|
|
87
87
|
- `days`: 获取天数,默认320天
|
|
88
88
|
- `fq`: 复权方式,默认'qfq' (前复权),可选:'hfq' (后复权)
|
|
89
89
|
- `dd`: 本地缓存字典 (可选,已废弃,建议使用MemoryCache)
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
rquote/__init__.py,sha256
|
|
1
|
+
rquote/__init__.py,sha256=-U5Uq4eT3Hhl2EkVmBgr5TAfU-ZfFzpOaGeJafnhyos,2208
|
|
2
2
|
rquote/config.py,sha256=noep_VzY_nJehnkPQb4mkwzpeYLwkU1riqofQJ6Hhw0,1108
|
|
3
3
|
rquote/exceptions.py,sha256=lJH2GC5dDhMoW_OtlBc03wlUn684-7jNPyF1NjmfVIE,569
|
|
4
4
|
rquote/plots.py,sha256=UQn4sjhIzVwagfhUDM738b2HHjKo4tRdU2UCs_1-FbY,2341
|
|
5
5
|
rquote/utils.py,sha256=bH0ZFIo-ZelNztzPS6BXFShXE3yGA9USI_P9INN0Y-s,310
|
|
6
6
|
rquote/api/__init__.py,sha256=ptizO--im80HaxlzxkJo9BKdJPEnbu00R9UDgcoA0mU,656
|
|
7
|
-
rquote/api/lists.py,sha256=
|
|
8
|
-
rquote/api/price.py,sha256=
|
|
9
|
-
rquote/api/stock_info.py,sha256=
|
|
7
|
+
rquote/api/lists.py,sha256=fRebS02Fi0qe6KpWBA-9W1UG0It6__DmRlNimtMa7L8,5331
|
|
8
|
+
rquote/api/price.py,sha256=hVmQN_kHIisr38RlAB43UCGtEqdxLmj6tsiog0jaa3w,2262
|
|
9
|
+
rquote/api/stock_info.py,sha256=912ICdIBr8z2lKWDbq3gG0E94czTPvbx9aXsKUi-QkE,1537
|
|
10
10
|
rquote/api/tick.py,sha256=nEcjuAjtBHUaD8KPRLg643piVa21PhKDQvkVWNwvvME,1431
|
|
11
11
|
rquote/cache/__init__.py,sha256=IXGSRpvSgBlcM6twLuJEOEockbb09_VqORXdQpfwpCA,138
|
|
12
12
|
rquote/cache/base.py,sha256=orzG4Yo-6gzVG027j1-LTZPT718JohnCdLDnOLoLUQ4,515
|
|
13
13
|
rquote/cache/memory.py,sha256=7z4keb3q91pzI4ASQWy1MU8T5nbWLCEUjJcStv_3hvk,1933
|
|
14
14
|
rquote/data_sources/__init__.py,sha256=WCe1aam4677jM5G6wP4a-dQFTeBzcU5PJqsKieAVMBo,215
|
|
15
15
|
rquote/data_sources/base.py,sha256=JuKsTMxH7y8yRxHg3JbLzQwXPr43rS4pnwc5625u2U4,443
|
|
16
|
-
rquote/data_sources/sina.py,sha256=
|
|
17
|
-
rquote/data_sources/tencent.py,sha256=
|
|
16
|
+
rquote/data_sources/sina.py,sha256=T_3Dl0Mwlhx8CKRJll_UKobYecRWltGaIOiGkpHS43Q,3300
|
|
17
|
+
rquote/data_sources/tencent.py,sha256=ayt1O85pheLwzX3z5c6Qij1NrmUywcsz6YcSVzdDoME,3370
|
|
18
18
|
rquote/factors/__init__.py,sha256=_ZbH2XxYtXwCJpvRVdNvGncoPSpMqrtlYmf1_fMGIjM,116
|
|
19
19
|
rquote/factors/technical.py,sha256=dPDs3pDEDRV9iQJBrSoKpGFLQMjOqyoBdN2rUntpOUU,4235
|
|
20
20
|
rquote/markets/__init__.py,sha256=k4F8cZgb-phqemMqhZXFPdOKsR4P--DD3d5i21vKhbg,365
|
|
21
21
|
rquote/markets/base.py,sha256=DjvxRcJqwUsBTxnsE28Gd-zJLFsCGwdQpezLRAZ_9sQ,1347
|
|
22
|
-
rquote/markets/cn_stock.py,sha256=
|
|
22
|
+
rquote/markets/cn_stock.py,sha256=xf-uXDvkdPBPuc-4-VhEsX0OrxSsaMVsCl1wmSqnVl0,8064
|
|
23
23
|
rquote/markets/factory.py,sha256=4Txpuok0LBOLT_vAiIU-NslwVnYF7sKHCdlacAboxpo,2875
|
|
24
24
|
rquote/markets/future.py,sha256=AbA-gpmBhbyrRJn8Vu-ouQLCd-TlacXSVZQ2VHYn2pg,3907
|
|
25
25
|
rquote/markets/hk_stock.py,sha256=iz0BriBDNGLkUCPExcCbe2jmuoqJinxx_cbDtKblABc,1445
|
|
@@ -31,8 +31,8 @@ rquote/utils/date.py,sha256=nhK3xQ2kFvKhdkPw-2HR2V0PSzBfXmX8L7laG7VmG2E,913
|
|
|
31
31
|
rquote/utils/helpers.py,sha256=V07n9BtRS8bEJH023Kca78-unk7iD3B9hn2UjELetYs,354
|
|
32
32
|
rquote/utils/http.py,sha256=X0Alhnu0CNqyQeOt6ivUWmh2XwrWxXd2lSpQOKDdnzw,3249
|
|
33
33
|
rquote/utils/logging.py,sha256=cbeRH4ODazn7iyQmGoEBT2lH5LX4Ca3zDfs_20J1T28,566
|
|
34
|
-
rquote/utils/web.py,sha256=
|
|
35
|
-
rquote-0.3.
|
|
36
|
-
rquote-0.3.
|
|
37
|
-
rquote-0.3.
|
|
38
|
-
rquote-0.3.
|
|
34
|
+
rquote/utils/web.py,sha256=I8_pcThW6VUvahuRHdtp32iZwr85hEt1hB6TgznMy_U,3854
|
|
35
|
+
rquote-0.3.8.dist-info/METADATA,sha256=33b2tfuTz_P71F71EHnUZk8CHWXcrkp-blmF0al4YQs,11262
|
|
36
|
+
rquote-0.3.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
37
|
+
rquote-0.3.8.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
|
|
38
|
+
rquote-0.3.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|