rquote 0.2.8__py3-none-any.whl → 0.3.0__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/main.py
CHANGED
|
@@ -114,6 +114,29 @@ def get_cn_future_list():
|
|
|
114
114
|
return futurelist_active
|
|
115
115
|
|
|
116
116
|
|
|
117
|
+
def _check_date_format(date_str):
|
|
118
|
+
# 允许格式: 2099-01-01
|
|
119
|
+
if not re.match(r'^\d{4}-\d{2}-\d{2}$', date_str):
|
|
120
|
+
# 尝试转换
|
|
121
|
+
try:
|
|
122
|
+
# 常见格式尝试
|
|
123
|
+
t_struct = None
|
|
124
|
+
for fmt in ("%Y/%m/%d", "%Y%m%d", "%Y.%m.%d", "%Y_%m_%d", "%Y-%m-%d"):
|
|
125
|
+
try:
|
|
126
|
+
t_struct = time.strptime(date_str, fmt)
|
|
127
|
+
break
|
|
128
|
+
except Exception:
|
|
129
|
+
continue
|
|
130
|
+
if t_struct is None:
|
|
131
|
+
raise ValueError(f"date format not recognized: {date_str}")
|
|
132
|
+
# 转换为标准格式
|
|
133
|
+
date_str_std = time.strftime("%Y-%m-%d", t_struct)
|
|
134
|
+
return date_str_std
|
|
135
|
+
except Exception as e:
|
|
136
|
+
raise ValueError(f"date format error: {date_str}, {e}")
|
|
137
|
+
return date_str
|
|
138
|
+
|
|
139
|
+
|
|
117
140
|
def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
|
|
118
141
|
dd=None) -> (str, str, pd.DataFrame):
|
|
119
142
|
'''
|
|
@@ -131,12 +154,20 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
|
|
|
131
154
|
logger.debug('loading price from dd {}'.format(i))
|
|
132
155
|
return i, n, d
|
|
133
156
|
logger.debug('fetching price of {}'.format(i))
|
|
157
|
+
|
|
158
|
+
# 检查sdate和edate格式
|
|
159
|
+
sdate = _check_date_format(sdate) if sdate else ''
|
|
160
|
+
edate = _check_date_format(edate) if edate else ''
|
|
161
|
+
|
|
162
|
+
|
|
134
163
|
qtimg_stock = 'http://web.ifzq.gtimg.cn/appstock/app/newfqkline/get?param=' + \
|
|
135
164
|
'{},{},{},{},{},{}'
|
|
136
165
|
qtimg_stock_hk = 'http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?' + \
|
|
137
166
|
'param={},{},{},{},{},{}'
|
|
138
167
|
qtimg_stock_us = 'http://web.ifzq.gtimg.cn/appstock/app/usfqkline/get?' + \
|
|
139
168
|
'param={},{},{},{},{},{}'
|
|
169
|
+
qtimg_stock_us_min = 'https://web.ifzq.gtimg.cn/appstock/app/UsMinute/query?' + \
|
|
170
|
+
'_var=min_data_{}&code={}'
|
|
140
171
|
sina_future_d = 'https://stock2.finance.sina.com.cn/futures/api/jsonp.php/' + \
|
|
141
172
|
'var%20t1nf_{}=/InnerFuturesNewService.getDailyKLine?symbol={}'
|
|
142
173
|
sina_btc = 'https://quotes.sina.cn/fx/api/openapi.php/BtcService.getDayKLine?' + \
|
|
@@ -173,8 +204,7 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
|
|
|
173
204
|
|
|
174
205
|
if i[:2] == 'fu':
|
|
175
206
|
try:
|
|
176
|
-
|
|
177
|
-
if ix == 'btc' or ix == 'BTC':
|
|
207
|
+
if i[2:5].lower() == 'btc':
|
|
178
208
|
url = sina_btc
|
|
179
209
|
d = json.loads(hget(url).text)['result']['data'].split('|')
|
|
180
210
|
d = pd.DataFrame([i.split(',') for i in d],
|
|
@@ -198,11 +228,20 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
|
|
|
198
228
|
elif i[:2] == 'hk':
|
|
199
229
|
url = qtimg_stock_hk.format(i, freq, sdate, edate, days, fq)
|
|
200
230
|
elif i[:2] == 'us':
|
|
201
|
-
|
|
231
|
+
if freq in ('min', '1min', 'minute'):
|
|
232
|
+
url = qtimg_stock_us_min.format(i.replace('.', ''), i)
|
|
233
|
+
else:
|
|
234
|
+
url = qtimg_stock_us.format(i, freq, sdate, edate, days, fq)
|
|
202
235
|
else:
|
|
203
236
|
raise ValueError(f'target market not supported: {i}')
|
|
204
237
|
a = hget(url)
|
|
205
238
|
#a = json.loads(a.text.replace('kline_dayqfq=', ''))['data'][i]
|
|
239
|
+
if i[:2] == 'us' and freq in ('min', '1min', 'minute'):
|
|
240
|
+
a = json.loads(a.text.split('=')[1])['data'][i]
|
|
241
|
+
nm = a['qt']['usAMZN.OQ'][1]
|
|
242
|
+
b = pd.DataFrame([i.split() for i in a['data']['data']],
|
|
243
|
+
columns=['minute','price','volume']).set_index(['minute']).astype(str)
|
|
244
|
+
return i, nm, b
|
|
206
245
|
a = json.loads(a.text)['data'][i]
|
|
207
246
|
name = ''
|
|
208
247
|
try:
|
|
@@ -221,7 +260,7 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
|
|
|
221
260
|
if 'qt' in a:
|
|
222
261
|
name = a['qt'][i][1]
|
|
223
262
|
except Exception as e:
|
|
224
|
-
|
|
263
|
+
raise ValueError('error fetching {}, err: {}'.format(i, e))
|
|
225
264
|
return i, name, b
|
|
226
265
|
|
|
227
266
|
|
|
@@ -260,14 +299,13 @@ def get_tick(tgts=[]):
|
|
|
260
299
|
|
|
261
300
|
a = hget(sina_tick + ','.join(tgts))
|
|
262
301
|
if not a:
|
|
263
|
-
|
|
264
|
-
return []
|
|
302
|
+
raise ValueError('hget failed {}'.format(tgts))
|
|
265
303
|
|
|
266
304
|
try:
|
|
267
305
|
dat = [i.split('"')[1].split(',') for i in a.text.split(';\n') if ',' in i]
|
|
268
306
|
dat_trim = [{k:i[j] for j,k in enumerate(head_row) if k!='_'} for i in dat]
|
|
269
307
|
except Exception as e:
|
|
270
|
-
|
|
308
|
+
raise ValueError('data not complete, check tgt be code str or list without'+
|
|
271
309
|
' prefix, your given: {}'.format(tgts))
|
|
272
310
|
return dat_trim
|
|
273
311
|
|
|
@@ -285,8 +323,7 @@ def get_stock_concepts(i) -> []:
|
|
|
285
323
|
concepts = json.loads(hget(url).text)[
|
|
286
324
|
'hxtc'][0]['ydnr'].split()
|
|
287
325
|
except Exception as e:
|
|
288
|
-
|
|
289
|
-
concepts = ['']
|
|
326
|
+
raise ValueError(f'error fetching concepts of {i}, err: {e}')
|
|
290
327
|
#concepts = [i for i in concepts if i not in drop_cons]
|
|
291
328
|
#concepts = [i for i in concepts if i[-2:] not in drop_tails]
|
|
292
329
|
#concepts = [i for i in concepts if '股' not in i]
|
|
@@ -430,4 +467,9 @@ def get_hk_stocks_hsi():
|
|
|
430
467
|
|
|
431
468
|
|
|
432
469
|
|
|
470
|
+
if __name__ == "__main__":
|
|
471
|
+
# print(get_cn_stock_list())
|
|
472
|
+
# print(get_price('fuBTC',sdate='20250101'))
|
|
473
|
+
# print(get_price('sz000001', sdate='20240101', edate='20250101'))
|
|
474
|
+
print(get_price('usAMZN.OQ', sdate='20250101', edate='20250101', freq='min'))
|
|
433
475
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rquote
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
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
|
|
7
7
|
Requires-Dist: httpx>=0.20.0
|
|
8
8
|
Requires-Dist: pandas>=1.0.0
|
|
9
|
-
Requires-Dist: setuptools>=
|
|
9
|
+
Requires-Dist: setuptools>=42
|
|
10
10
|
Requires-Dist: twine>=3.8.0
|
|
11
11
|
|
|
12
12
|
# rquote
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rquote/__init__.py,sha256=PB620yEq2QZyfDweKY_8qMEsZMKhskGfhmfDkch_0j0,462
|
|
2
|
+
rquote/main.py,sha256=8_-JjaoMWt66SrEzKmSh30-VPMKidOTNOd2qCYDy1R0,18955
|
|
3
|
+
rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
|
|
4
|
+
rquote/utils.py,sha256=4Neb9_R-EKAd6s1Qj4O_vs9jXWyvroxEEhdqH35vxVE,6808
|
|
5
|
+
rquote-0.3.0.dist-info/METADATA,sha256=p11Jj4lQO9C2jBwrPUvLR76IEMwmtzsfp0GwJqvU9Xw,7273
|
|
6
|
+
rquote-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
rquote-0.3.0.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
|
|
8
|
+
rquote-0.3.0.dist-info/RECORD,,
|
rquote-0.2.8.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
rquote/__init__.py,sha256=PB620yEq2QZyfDweKY_8qMEsZMKhskGfhmfDkch_0j0,462
|
|
2
|
-
rquote/main.py,sha256=BzikZQ9tkcn6uJFhK2_tfeWdOnurD7h3uERWoGq6mHg,17180
|
|
3
|
-
rquote/plots.py,sha256=N8uvD6ju9tow0DllPQiXiM7EoPC2bK8X7QF6NQainKs,2342
|
|
4
|
-
rquote/utils.py,sha256=4Neb9_R-EKAd6s1Qj4O_vs9jXWyvroxEEhdqH35vxVE,6808
|
|
5
|
-
rquote-0.2.8.dist-info/METADATA,sha256=PvmiOcaBfbuwBGs47g3saetPEXOwy_zcvu1b31r1iho,7277
|
|
6
|
-
rquote-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
rquote-0.2.8.dist-info/top_level.txt,sha256=CehAiaZx7Fo8HGoV2zd5GhILUW1jQEN8YS-cWMlrK9Y,7
|
|
8
|
-
rquote-0.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|