rquote 0.3.3__tar.gz → 0.3.5__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.
Files changed (55) hide show
  1. rquote-0.3.5/PKG-INFO +486 -0
  2. rquote-0.3.5/README.md +474 -0
  3. {rquote-0.3.3 → rquote-0.3.5}/pyproject.toml +1 -1
  4. rquote-0.3.5/rquote/__init__.py +63 -0
  5. rquote-0.3.5/rquote/api/__init__.py +32 -0
  6. rquote-0.3.5/rquote/api/lists.py +175 -0
  7. rquote-0.3.5/rquote/api/price.py +73 -0
  8. rquote-0.3.5/rquote/api/stock_info.py +49 -0
  9. rquote-0.3.5/rquote/api/tick.py +47 -0
  10. rquote-0.3.5/rquote/cache/__init__.py +9 -0
  11. rquote-0.3.5/rquote/cache/base.py +26 -0
  12. rquote-0.3.5/rquote/cache/memory.py +77 -0
  13. rquote-0.3.5/rquote/config.py +42 -0
  14. rquote-0.3.5/rquote/data_sources/__init__.py +10 -0
  15. rquote-0.3.5/rquote/data_sources/base.py +21 -0
  16. rquote-0.3.5/rquote/data_sources/sina.py +92 -0
  17. rquote-0.3.5/rquote/data_sources/tencent.py +90 -0
  18. rquote-0.3.5/rquote/exceptions.py +40 -0
  19. rquote-0.3.5/rquote/factors/__init__.py +8 -0
  20. rquote-0.3.5/rquote/factors/technical.py +150 -0
  21. rquote-0.3.5/rquote/markets/__init__.py +14 -0
  22. rquote-0.3.5/rquote/markets/base.py +49 -0
  23. rquote-0.3.5/rquote/markets/cn_stock.py +186 -0
  24. rquote-0.3.5/rquote/markets/factory.py +82 -0
  25. rquote-0.3.5/rquote/markets/future.py +92 -0
  26. rquote-0.3.5/rquote/markets/hk_stock.py +46 -0
  27. rquote-0.3.5/rquote/markets/us_stock.py +69 -0
  28. rquote-0.3.5/rquote/parsers/__init__.py +8 -0
  29. rquote-0.3.5/rquote/parsers/kline.py +104 -0
  30. {rquote-0.3.3 → rquote-0.3.5}/rquote/plots.py +1 -1
  31. rquote-0.3.5/rquote/utils/__init__.py +13 -0
  32. rquote-0.3.5/rquote/utils/date.py +40 -0
  33. rquote-0.3.5/rquote/utils/helpers.py +23 -0
  34. rquote-0.3.5/rquote/utils/http.py +112 -0
  35. rquote-0.3.5/rquote/utils/logging.py +25 -0
  36. rquote-0.3.5/rquote/utils/web.py +104 -0
  37. rquote-0.3.5/rquote/utils.py +11 -0
  38. rquote-0.3.5/rquote.egg-info/PKG-INFO +486 -0
  39. rquote-0.3.5/rquote.egg-info/SOURCES.txt +46 -0
  40. rquote-0.3.5/tests/test_api.py +56 -0
  41. rquote-0.3.5/tests/test_cache.py +71 -0
  42. rquote-0.3.5/tests/test_config.py +47 -0
  43. rquote-0.3.5/tests/test_exceptions.py +65 -0
  44. rquote-0.3.5/tests/test_utils.py +102 -0
  45. rquote-0.3.3/PKG-INFO +0 -286
  46. rquote-0.3.3/README.md +0 -274
  47. rquote-0.3.3/rquote/__init__.py +0 -15
  48. rquote-0.3.3/rquote/main.py +0 -497
  49. rquote-0.3.3/rquote/utils.py +0 -197
  50. rquote-0.3.3/rquote.egg-info/PKG-INFO +0 -286
  51. rquote-0.3.3/rquote.egg-info/SOURCES.txt +0 -11
  52. {rquote-0.3.3 → rquote-0.3.5}/rquote.egg-info/dependency_links.txt +0 -0
  53. {rquote-0.3.3 → rquote-0.3.5}/rquote.egg-info/requires.txt +0 -0
  54. {rquote-0.3.3 → rquote-0.3.5}/rquote.egg-info/top_level.txt +0 -0
  55. {rquote-0.3.3 → rquote-0.3.5}/setup.cfg +0 -0
rquote-0.3.5/PKG-INFO ADDED
@@ -0,0 +1,486 @@
1
+ Metadata-Version: 2.4
2
+ Name: rquote
3
+ Version: 0.3.5
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
+ # rquote
14
+
15
+ `rquote` 是一个提供 A股/港股/美股/ETF基金/期货 历史数据获取的Python库
16
+
17
+ ## 版本信息
18
+
19
+ 当前版本:**0.3.5**
20
+
21
+ ## 主要特性
22
+
23
+ - ✅ 支持多市场数据获取(A股、港股、美股、期货、基金)
24
+ - ✅ 统一的API接口,使用简单
25
+ - ✅ 内置缓存机制,提升性能
26
+ - ✅ 完善的错误处理和异常体系
27
+ - ✅ 可配置的HTTP客户端(超时、重试等)
28
+ - ✅ 模块化设计,易于扩展
29
+
30
+ ## 安装
31
+
32
+ ```bash
33
+ pip install rquote
34
+ ```
35
+
36
+ 或使用 uv:
37
+
38
+ ```bash
39
+ uv pip install rquote
40
+ ```
41
+
42
+ ## 快速开始
43
+
44
+ ### 基本使用
45
+
46
+ ```python
47
+ from rquote import get_price
48
+
49
+ # 获取上证指数数据
50
+ sid, name, df = get_price('sh000001')
51
+ print(df.head()) # 数据为pandas DataFrame
52
+ ```
53
+
54
+ ### 获取指定日期范围的数据
55
+
56
+ ```python
57
+ # 获取指定日期范围的数据
58
+ sid, name, df = get_price('sz000001', sdate='2024-01-01', edate='2024-02-01')
59
+ ```
60
+
61
+ ### 使用缓存
62
+
63
+ ```python
64
+ from rquote import get_price, MemoryCache
65
+
66
+ # 创建缓存实例
67
+ cache = MemoryCache(ttl=3600) # 缓存1小时
68
+
69
+ # 使用缓存(通过dd参数,向后兼容)
70
+ cache_dict = {}
71
+ sid, name, df = get_price('sh000001', dd=cache_dict)
72
+ ```
73
+
74
+ ## 主要功能
75
+
76
+ ### 历史价格数据获取
77
+
78
+ #### `get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq', dd=None)`
79
+
80
+ 获取股票、基金、期货的历史价格数据
81
+
82
+ **参数:**
83
+ - `i`: 股票代码,使用新浪/腾讯的id形式
84
+ - `sdate`: 开始日期 (可选,格式:YYYY-MM-DD)
85
+ - `edate`: 结束日期 (可选,格式:YYYY-MM-DD)
86
+ - `freq`: 频率,默认'day' (日线),可选:'week', 'month', 'min'
87
+ - `days`: 获取天数,默认320天
88
+ - `fq`: 复权方式,默认'qfq' (前复权),可选:'hfq' (后复权)
89
+ - `dd`: 本地缓存字典 (可选,已废弃,建议使用MemoryCache)
90
+
91
+ **代码格式说明:**
92
+ - A股: `sh000001`表示上证指数,`sz000001`表示深市000001股票`平安银行`
93
+ - ETF: `sh510050`表示上证50指数ETF
94
+ - 港股: `hk00700`表示港股腾讯
95
+ - 期货: 需加`fu`前缀,如`fuAP2110`,`fuBTC`表示比特币
96
+ - 美股: 需加对应交易所后缀,如`usBABA.N`,`usC.N`,`usAAPL.OQ`等
97
+ - 比特币:使用`fuBTC`代码
98
+
99
+ **示例:**
100
+ ```python
101
+ from rquote import get_price
102
+
103
+ # 获取上证指数数据
104
+ sid, nm, df = get_price('sh000001')
105
+ print(df.head())
106
+
107
+ # 获取指定日期范围的数据
108
+ sid, nm, df = get_price('sz000001', sdate='2024-01-01', edate='2024-02-01')
109
+
110
+ # 获取比特币数据
111
+ sid, nm, df = get_price('fuBTC')
112
+
113
+ # 获取期货分钟数据
114
+ sid, nm, df = get_price('fuM2601', freq='min')
115
+ ```
116
+
117
+ **返回数据格式:**
118
+ | date | open | close | high | low | vol |
119
+ |------------|---------|---------|---------|---------|------------|
120
+ | 2024-02-06 | 2680.48 | 2789.49 | 2802.93 | 2669.67 | 502849313 |
121
+ | 2024-02-07 | 2791.51 | 2829.70 | 2829.70 | 2770.53 | 547117439 |
122
+
123
+ #### `get_price_longer(i, l=2, dd={})`
124
+
125
+ 获取更长时间的历史数据,默认获取2年数据
126
+
127
+ ```python
128
+ from rquote import get_price_longer
129
+
130
+ # 获取3年的历史数据
131
+ sid, nm, df = get_price_longer('sh000001', l=3)
132
+ ```
133
+
134
+ ### 股票列表获取
135
+
136
+ #### `get_cn_stock_list(money_min=2e8)`
137
+
138
+ 获取A股股票列表,按成交额排序,默认筛选成交额大于2亿的股票
139
+
140
+ ```python
141
+ from rquote import get_cn_stock_list
142
+
143
+ # 获取成交额大于5亿的股票列表
144
+ stocks = get_cn_stock_list(money_min=5e8)
145
+ # 返回格式: [{code, name, pe_ttm, volume, turnover/亿, ...}, ...]
146
+ ```
147
+
148
+ #### `get_hk_stocks_500()`
149
+
150
+ 获取港股前500只股票列表
151
+
152
+ ```python
153
+ from rquote import get_hk_stocks_500
154
+
155
+ stocks = get_hk_stocks_500()
156
+ # 返回格式: [[code, name, price, turnover, ...], ...]
157
+ ```
158
+
159
+ #### `get_us_stocks(k=100)`
160
+
161
+ 获取美股最大市值的k支股票列表
162
+
163
+ ```python
164
+ from rquote import get_us_stocks
165
+
166
+ us_stocks = get_us_stocks(k=100) # 获取前100只
167
+ # 返回格式: [{name, symbol, market, mktcap, pe, ...}, ...]
168
+ ```
169
+
170
+ ### 基金和期货
171
+
172
+ #### `get_cn_fund_list()`
173
+
174
+ 获取A股ETF基金列表,按成交额排序
175
+
176
+ ```python
177
+ from rquote import get_cn_fund_list
178
+
179
+ funds = get_cn_fund_list()
180
+ # 返回格式: [code, name, change, amount, price]
181
+ ```
182
+
183
+ #### `get_cn_future_list()`
184
+
185
+ 获取国内期货合约列表
186
+
187
+ ```python
188
+ from rquote import get_cn_future_list
189
+
190
+ futures = get_cn_future_list()
191
+ # 返回格式: ['fuSC2109', 'fuRB2110', 'fuHC2110', ...]
192
+ ```
193
+
194
+ ### 板块和概念
195
+
196
+ #### `get_all_industries()`
197
+
198
+ 获取所有行业板块列表
199
+
200
+ ```python
201
+ from rquote import get_all_industries
202
+
203
+ industries = get_all_industries()
204
+ # 返回格式: [code, name, change, amount, price, sina_sw2_id]
205
+ ```
206
+
207
+ #### `get_stock_concepts(i)`
208
+
209
+ 获取指定股票所属的概念板块
210
+
211
+ ```python
212
+ from rquote import get_stock_concepts
213
+
214
+ # 获取平安银行的概念板块
215
+ concepts = get_stock_concepts('sz000001')
216
+ # 返回概念代码列表,如 ['BK0420', 'BK0900', ...]
217
+ ```
218
+
219
+ #### `get_stock_industry(i)`
220
+
221
+ 获取指定股票所属的行业板块
222
+
223
+ ```python
224
+ from rquote import get_stock_industry
225
+
226
+ # 获取平安银行的行业板块
227
+ industries = get_stock_industry('sz000001')
228
+ ```
229
+
230
+ #### `get_industry_stocks(node)`
231
+
232
+ 获取指定行业板块的股票列表
233
+
234
+ ```python
235
+ from rquote import get_industry_stocks
236
+
237
+ # 获取行业板块股票
238
+ stocks = get_industry_stocks('sw2_480200')
239
+ ```
240
+
241
+ ### 实时行情
242
+
243
+ #### `get_tick(tgts=[])`
244
+
245
+ 获取实时行情数据
246
+
247
+ ```python
248
+ from rquote import get_tick
249
+
250
+ # 获取美股实时行情
251
+ tick_data = get_tick(['AAPL', 'GOOGL'])
252
+ # 返回格式: [{'name': 'Apple Inc', 'price': '150.25', 'price_change_rate': '1.2%', ...}]
253
+ ```
254
+
255
+ ### 可视化工具
256
+
257
+ #### `PlotUtils.plot_candle(i, sdate='', edate='', dsh=False, vol=True)`
258
+
259
+ 绘制K线图
260
+
261
+ ```python
262
+ from rquote import PlotUtils
263
+ import plotly.graph_objs as go
264
+
265
+ # 绘制平安银行的K线图
266
+ data, layout = PlotUtils.plot_candle('sz000001', sdate='2024-01-01', edate='2024-02-01')
267
+
268
+ # 使用plotly显示
269
+ fig = go.Figure(data=data, layout=layout)
270
+ fig.show()
271
+ ```
272
+
273
+ ## 高级功能
274
+
275
+ ### 配置管理
276
+
277
+ ```python
278
+ from rquote import config
279
+
280
+ # 使用默认配置
281
+ default_config = config.default_config
282
+
283
+ # 创建自定义配置
284
+ custom_config = config.Config(
285
+ http_timeout=15,
286
+ http_retry_times=5,
287
+ cache_enabled=True,
288
+ cache_ttl=7200
289
+ )
290
+
291
+ # 从环境变量创建配置
292
+ import os
293
+ os.environ['RQUOTE_HTTP_TIMEOUT'] = '20'
294
+ config_from_env = config.Config.from_env()
295
+ ```
296
+
297
+ ### 使用改进的HTTP客户端
298
+
299
+ ```python
300
+ from rquote.utils.http import HTTPClient
301
+
302
+ # 创建HTTP客户端
303
+ with HTTPClient(timeout=15, retry_times=3) as client:
304
+ response = client.get('https://example.com')
305
+ if response:
306
+ print(response.text)
307
+ ```
308
+
309
+ ### 使用缓存
310
+
311
+ ```python
312
+ from rquote.cache import MemoryCache
313
+
314
+ # 创建缓存
315
+ cache = MemoryCache(ttl=3600) # 缓存1小时
316
+
317
+ # 使用缓存
318
+ cache.put('key1', 'value1')
319
+ value = cache.get('key1')
320
+ cache.delete('key1')
321
+ cache.clear() # 清空所有缓存
322
+ ```
323
+
324
+ ### 异常处理
325
+
326
+ ```python
327
+ from rquote import get_price
328
+ from rquote.exceptions import SymbolError, DataSourceError, NetworkError
329
+
330
+ try:
331
+ sid, name, df = get_price('invalid_symbol')
332
+ except SymbolError as e:
333
+ print(f"股票代码错误: {e}")
334
+ except DataSourceError as e:
335
+ print(f"数据源错误: {e}")
336
+ except NetworkError as e:
337
+ print(f"网络错误: {e}")
338
+ ```
339
+
340
+ ### 工具类
341
+
342
+ #### `WebUtils`
343
+
344
+ 网络请求工具类
345
+
346
+ ```python
347
+ from rquote import WebUtils
348
+
349
+ # 获取随机User-Agent
350
+ ua = WebUtils.ua()
351
+
352
+ # 获取请求头
353
+ headers = WebUtils.headers()
354
+
355
+ # 测试代理
356
+ result = WebUtils.test_proxy('127.0.0.1:8080')
357
+ ```
358
+
359
+ #### `BasicFactors`
360
+
361
+ 基础因子计算工具类
362
+
363
+ ```python
364
+ from rquote import BasicFactors
365
+ import pandas as pd
366
+
367
+ # 假设df是价格数据DataFrame
368
+ # break_rise: 突破上涨
369
+ break_rise = BasicFactors.break_rise(df)
370
+
371
+ # min_resist: 最小阻力
372
+ min_resist = BasicFactors.min_resist(df)
373
+
374
+ # vol_extreme: 成交量极值
375
+ vol_extreme = BasicFactors.vol_extreme(df)
376
+
377
+ # bias_rate_over_ma60: 偏离MA60的比率
378
+ bias_rate = BasicFactors.bias_rate_over_ma60(df)
379
+
380
+ # op_ma: MA评分
381
+ ma_score = BasicFactors.op_ma(df)
382
+ ```
383
+
384
+ ## 架构改进
385
+
386
+ ### 新版本改进
387
+
388
+ **v0.3.5** 主要改进:
389
+
390
+ 1. **修复Critical Bugs**
391
+ - 修复了 `WebUtils.http_get` 中的 `cls.ua` bug
392
+ - 修复了 `test_proxy` 方法中的逻辑错误
393
+ - 改进了异常处理
394
+
395
+ 2. **新增模块化架构**
396
+ - 配置管理模块 (`config.py`)
397
+ - 异常处理体系 (`exceptions.py`)
398
+ - 缓存抽象层 (`cache/`)
399
+ - 数据源抽象层 (`data_sources/`)
400
+ - 改进的HTTP客户端 (`utils/http.py`)
401
+
402
+ 3. **向后兼容**
403
+ - 所有原有API保持不变
404
+ - 新增功能为可选使用
405
+
406
+ ### 目录结构
407
+
408
+ ```
409
+ rquote/
410
+ ├── __init__.py # 公共API导出
411
+ ├── config.py # 配置管理
412
+ ├── exceptions.py # 异常定义
413
+ ├── main.py # 主要功能(向后兼容)
414
+ ├── utils.py # 工具类(向后兼容)
415
+ ├── plots.py # 绘图工具
416
+ ├── cache/ # 缓存模块
417
+ │ ├── __init__.py
418
+ │ ├── base.py # 缓存基类
419
+ │ └── memory.py # 内存缓存实现
420
+ ├── data_sources/ # 数据源模块
421
+ │ ├── __init__.py
422
+ │ ├── base.py # 数据源基类
423
+ │ ├── sina.py # 新浪数据源
424
+ │ └── tencent.py # 腾讯数据源
425
+ ├── parsers/ # 数据解析模块
426
+ │ ├── __init__.py
427
+ │ └── kline.py # K线数据解析
428
+ └── utils/ # 工具模块
429
+ ├── __init__.py
430
+ ├── http.py # HTTP客户端
431
+ └── date.py # 日期工具
432
+ ```
433
+
434
+ ## 测试
435
+
436
+ 运行单元测试:
437
+
438
+ ```bash
439
+ # 运行所有测试
440
+ python -m pytest tests/
441
+
442
+ # 运行特定测试
443
+ python -m pytest tests/test_utils.py
444
+ python -m pytest tests/test_cache.py
445
+ python -m pytest tests/test_config.py
446
+ python -m pytest tests/test_exceptions.py
447
+ python -m pytest tests/test_api.py
448
+ ```
449
+
450
+ ## 注意事项
451
+
452
+ 1. **数据来源**: 数据来源于新浪财经、腾讯财经、东方财富等公开数据源
453
+ 2. **请求频率**: 建议合理控制请求频率,避免被限制访问
454
+ 3. **代码格式**:
455
+ - 期货代码需要加`fu`前缀,如`fuAP2110`
456
+ - 美股代码需要加对应后缀,如`usAAPL.OQ` (OQ->NASDAQ, N->NYSE, AM->ETF)
457
+ 4. **网络要求**: 部分功能需要网络连接,请确保网络畅通
458
+ 5. **缓存使用**: 建议使用缓存机制减少网络请求,提升性能
459
+
460
+ ## 更新日志
461
+
462
+ ### v0.3.5 (2024)
463
+ - 修复Critical Bugs
464
+ - 新增配置管理模块
465
+ - 新增异常处理体系
466
+ - 新增缓存抽象层
467
+ - 改进HTTP客户端
468
+ - 新增单元测试
469
+ - 完善文档
470
+
471
+ ### v0.3.4
472
+ - 初始版本
473
+
474
+ ## 贡献
475
+
476
+ 欢迎提交Issue和Pull Request!
477
+
478
+ ## 许可证
479
+
480
+ Copyright (c) 2021 Roi ZHAO
481
+
482
+ ## 相关文档
483
+
484
+ - [架构改进建议](ARCHITECTURE_IMPROVEMENTS.md)
485
+ - [重构代码示例](REFACTORING_EXAMPLES.md)
486
+ - [快速修复清单](QUICK_FIXES.md)