rquote 0.2.5__py3-none-any.whl → 0.2.7__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 CHANGED
@@ -7,7 +7,9 @@ Copyright (c) 2021 Roi ZHAO
7
7
 
8
8
  '''
9
9
 
10
- from .main import get_price, get_stock_concepts, get_concept_stocks
10
+ from .main import get_price, get_stock_concepts, get_concept_stocks, get_bk_stocks
11
11
  from .main import get_all_concepts, get_all_industries
12
+ from .main import get_cn_stock_list, get_hk_stocks_hsi, get_hk_stocks_ggt, get_hk_stocks_500
13
+ from .main import get_cn_future_list, get_us_stocks_biggest, get_cn_fund_list
12
14
  from .utils import WebUtils, BasicFactors
13
15
  from .plots import PlotUtils
rquote/main.py CHANGED
@@ -8,11 +8,16 @@ import pandas as pd
8
8
  from .utils import WebUtils, hget, logger
9
9
 
10
10
 
11
- def make_tgts(mkts=['ch', 'hk', 'us', 'fund', 'future'], money_min=2e8) -> []:
12
- cands = []
13
-
14
11
 
15
12
  def get_cn_stock_list(money_min=2e8):
13
+ ret = []
14
+ try:
15
+ ret = get_cn_stock_list_eastmoney(money_min)
16
+ except Exception as e:
17
+ ret = get_cn_stock_list_qq(money_min)
18
+ return ret
19
+
20
+ def get_cn_stock_list_eastmoney(money_min=2e8):
16
21
  '''
17
22
  Return sorted stock list ordered by latest amount of money, cut at `money_min`
18
23
  item in returned list are [code, name, change, amount, mktcap]
@@ -28,31 +33,39 @@ def get_cn_stock_list(money_min=2e8):
28
33
  if a:
29
34
  a = json.loads(a.text.split(
30
35
  'jQuery112409458761844374801_1627288489961(')[1][:-2])
31
-
32
- # cdir = os.path.dirname(__file__)
33
- # with open(os.path.join(cdir, 'ranka'), 'wb') as f:
34
- # f.write(a.content)
35
- # a = pd.read_excel(os.path.join(cdir, 'ranka'), header=1)
36
- # os.remove(os.path.join(cdir, 'ranka'))
37
- # a.columns = ['code', 'name', 'close', 'p_change', 'change', '_', '_', '_',
38
- # 'money', 'open', 'yest_close', 'high', 'low']
39
- # a = a[a.money > money_min]
40
36
  a = [ ['sh'+i['f12'] if i['f12'][0]=='6' else 'sz'+i['f12'],
41
37
  i['f14'], i['f3'], i['f6'], i['f21']] for i in a['data']['diff']
42
38
  if i['f6']!='-' and float(i['f6']) > money_min]
43
39
  #cands=[(i.code,i.name) for i in a[['code','name']].itertuples()]
44
40
  return a
45
41
 
42
+ def get_cn_stock_list_qq(money_min=2e8):
43
+ offset = 0
44
+ count = 200 # max, or error
45
+ df = []
46
+ while not df or float(df[-1]['turnover'])*1e4 > money_min:
47
+ a = hget(
48
+ f'https://proxy.finance.qq.com/cgi/cgi-bin/rank/hs/getBoardRankList?_appver=11.17.0'+
49
+ f'&board_code=aStock&sort_type=turnover&direct=down&offset={offset}&count={count}'
50
+ )
51
+ if a:
52
+ a = json.loads(a.text)
53
+ print('===',a)
54
+ if a['data']['rank_list']:
55
+ df.extend(a['data']['rank_list'])
56
+ offset += count
57
+ else:
58
+ break
59
+ return df
60
+
46
61
 
47
- # def get_hk_stocks_hotest80():
48
- # a = hget(
49
- # 'http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php' +
50
- # '/Market_Center.getHKStockData?page=1&num=80&sort=amount&asc=0&node=' +
51
- # 'qbgg_hk&_s_r_a=sort').text
52
- # if a:
53
- # a = [['hk'+i['symbol'], i['name'], i['changepercent'], i['amount'],
54
- # i['market_value']] for i in json.loads(a)]
55
- # return a
62
+ def get_hk_stocks_500():
63
+ a = hget(
64
+ 'https://stock.gtimg.cn/data/hk_rank.php?board=main_all&metric=amount&' +
65
+ 'pageSize=500&reqPage=1&order=desc&var_name=list_data').text
66
+ if a:
67
+ a = [i.split('~') for i in json.loads(a.split('list_data=')[1])['data']['page_data']]
68
+ return a
56
69
 
57
70
 
58
71
  def get_us_stocks_biggest(k=60):
@@ -192,7 +205,6 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
192
205
  raise ValueError('target market not supported')
193
206
  a = hget(url)
194
207
  #a = json.loads(a.text.replace('kline_dayqfq=', ''))['data'][i]
195
- print('=====',url,a)
196
208
  a = json.loads(a.text)['data'][i]
197
209
  name = ''
198
210
  try:
rquote/utils.py CHANGED
@@ -52,7 +52,7 @@ class WebUtils:
52
52
  return header
53
53
 
54
54
  @classmethod
55
- def reqget(cls, url, headers, method, proxy=None):
55
+ def http_get(cls, url, headers, method, proxy=None):
56
56
  '''
57
57
  request.get() wrapper
58
58
  '''
@@ -187,7 +187,8 @@ class hget:
187
187
  self.url = url
188
188
  try:
189
189
  r = httpx.get(
190
- self.url, follow_redirects=True, *args, **kwargs)
190
+ self.url, follow_redirects=True, headers=WebUtils.headers(),
191
+ *args, **kwargs)
191
192
  self.text = r.text
192
193
  self.content = r.content
193
194
  except Exception as e:
@@ -1,14 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch
5
5
  Home-page: https://github.com/kids/rquote
6
6
  Author: Roizhao
7
7
  Author-email: roizhao@gmail.com
8
- Requires-Python: >=3.4.0
8
+ Requires-Python: >=3.6.1
9
9
  Description-Content-Type: text/markdown
10
10
  Requires-Dist: httpx>=0.20.0
11
11
  Requires-Dist: pandas>=1.0.0
12
+ Requires-Dist: setuptools>=59.6.0
13
+ Requires-Dist: twine>=3.8.0
12
14
  Dynamic: author
13
15
  Dynamic: author-email
14
16
  Dynamic: home-page
@@ -16,11 +18,11 @@ Dynamic: requires-python
16
18
 
17
19
  # rquote
18
20
 
19
- `get_price`方法提供 A股/港股/美股/ETF基金/期货 日线(及其他周期)历史数据获取
21
+ `get_price`方法提供 A股/港股/美股/ETF基金/期货 日线历史数据获取
20
22
 
21
23
  使用新浪/腾讯的id形式,如`sh000001`表示上证指数,`sz000001`表示深市000001股票`平安银行`,`sh510050`表示上证50指数ETF,`hk00700`表示港股腾讯。
22
24
  期货代码需加`fu`前缀,如`fuAP2110`,美股需加对应交易所后缀,如`usBABA.N`,`usC.N`,`usAAPL.OQ`等
23
- BTC/USD放在fu下面,i.e.`fuBTC`
25
+ BTC/USD也放在fu下面,i.d.`fuBTC`
24
26
 
25
27
  e.g.
26
28
  ```
@@ -36,7 +38,3 @@ df.head() # 数据为pandas dataframe
36
38
  > 2024-02-19 2886.59 2910.54 2910.54 2867.71 458967704.0
37
39
  > 2024-02-20 2902.88 2922.73 2927.31 2887.47 350138735.0
38
40
 
39
- Notes:
40
- 使用GenImage需要补充依赖
41
- > kaleido>=1.0.0rc0
42
- > plolty>=5.0.0
@@ -0,0 +1,8 @@
1
+ rquote/__init__.py,sha256=owCwRRDJoYUuR7-NKb_Nj3-2CCsL7TtrRVp6px_8RGA,470
2
+ rquote/main.py,sha256=BrY6TnYcW2NhphHHD0FBsBTr3C4cFaKUAgM1nQ097-o,17322
3
+ rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
4
+ rquote/utils.py,sha256=v8j8R2xoXyTsHSAWXD7x2FUV7w1a4xgfswfSDdfg5p8,6827
5
+ rquote-0.2.7.dist-info/METADATA,sha256=8Ztlu-8Inaa7fw9URPv_eaqw6k3h2yZx64RiEP3elOs,1457
6
+ rquote-0.2.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ rquote-0.2.7.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
8
+ rquote-0.2.7.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- rquote/__init__.py,sha256=hTIZoLK37R9sSJdjnmCLA-P6wHcm1u4pgNx89Gsq1lI,284
2
- rquote/main.py,sha256=CoZ1EBGSbSJ1422wotxWKXAjaGjVAZwMDnmIsz9iAeE,17108
3
- rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
4
- rquote/utils.py,sha256=ztDIlW9UyJQHPO_Q-DCzp0sOsKT24sFdHhpizw3P9x8,6781
5
- rquote-0.2.5.dist-info/METADATA,sha256=Dfe3VO9e41TSmHWwh32rwSxDd9sPQGJR5-v7QQsFzzs,1493
6
- rquote-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- rquote-0.2.5.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
8
- rquote-0.2.5.dist-info/RECORD,,
File without changes