rquote 0.3.1__tar.gz → 0.3.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.3.1
3
+ Version: 0.3.4
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rquote"
7
- version = "0.3.1"
7
+ version = "0.3.4"
8
8
  description = "Mostly day quotes of cn/hk/us/fund/future markets, side with quote list fetch"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.6.1"
@@ -137,6 +137,13 @@ def _check_date_format(date_str):
137
137
  return date_str
138
138
 
139
139
 
140
+ def load_js_var_json(url):
141
+ a = hget(url)
142
+ if a:
143
+ a = json.loads(a.text.split('(')[1].split(')')[0])
144
+ return a
145
+
146
+
140
147
  def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
141
148
  dd=None) -> (str, str, pd.DataFrame):
142
149
  '''
@@ -170,6 +177,8 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
170
177
  '_var=min_data_{}&code={}'
171
178
  sina_future_d = 'https://stock2.finance.sina.com.cn/futures/api/jsonp.php/' + \
172
179
  'var%20t1nf_{}=/InnerFuturesNewService.getDailyKLine?symbol={}'
180
+ sina_future_min = 'https://stock2.finance.sina.com.cn/futures/api/jsonp.php/' + \
181
+ 'var%20t1nf_{}=/InnerFuturesNewService.getMinLine?symbol={}'
173
182
  sina_btc = 'https://quotes.sina.cn/fx/api/openapi.php/BtcService.getDayKLine?' + \
174
183
  'symbol=btcbtcusd'
175
184
 
@@ -209,11 +218,28 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
209
218
  d = json.loads(hget(url).text)['result']['data'].split('|')
210
219
  d = pd.DataFrame([i.split(',') for i in d],
211
220
  columns=['date', 'open', 'high', 'low', 'close', 'vol', 'amount'])
221
+ for col in ['open','high','low','close','vol','amount']:
222
+ d[col] = pd.to_numeric(d[col], errors='coerce')
212
223
  return i, 'BTC', d
213
224
  else:
214
- d = pd.DataFrame(json.loads(hget(sina_future_d.format(
215
- ix, ix)).text.split('(')[1][:-2]))
216
- d.columns = ['date', 'open', 'high', 'low', 'close', 'vol', 'p', 's']
225
+ ix = i[2:]
226
+ if freq in ('min', '1min', 'minute'):
227
+ url = sina_future_min.format(ix, ix)
228
+ # rtext = hget(url).text
229
+ # d = pd.DataFrame(json.loads(rtext.split(i[2:])[1][2:-2]))
230
+ d = pd.DataFrame(load_js_var_json(url))
231
+ d.columns = ['dtime', 'close', 'avg', 'vol', 'hold','last_close','cur_date']
232
+ for col in ['close','avg','vol','hold']:
233
+ d[col] = pd.to_numeric(d[col], errors='coerce')
234
+ d = d.set_index(['dtime'])
235
+ return i[2:], i[2:], d
236
+ else:
237
+ # d = pd.DataFrame(json.loads(hget(sina_future_d.format(
238
+ # ix, ix)).text.split('(')[1][:-2]))
239
+ d = pd.DataFrame(load_js_var_json(sina_future_d.format(ix, ix)))
240
+ d.columns = ['date', 'open', 'high', 'low', 'close', 'vol', 'p', 's']
241
+ for col in ['open','high','low','close','vol','p','s']:
242
+ d[col] = pd.to_numeric(d[col], errors='coerce')
217
243
  d = d.set_index(['date']).astype(float)
218
244
  # d.index = pd.DatetimeIndex(d.index)
219
245
  return i, ix, d
@@ -240,7 +266,9 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
240
266
  a = json.loads(a.text.split('=')[1])['data'][i]
241
267
  nm = a['qt'][i][1]
242
268
  b = pd.DataFrame([i.split() for i in a['data']['data']],
243
- columns=['minute','price','volume']).set_index(['minute']).astype(str)
269
+ columns=['minute','price','volume']).set_index(['minute'])
270
+ for col in ['price','volume']:
271
+ b[col] = pd.to_numeric(b[col], errors='coerce')
244
272
  return i, nm, b
245
273
  a = json.loads(a.text)['data'][i]
246
274
  name = ''
@@ -251,12 +279,10 @@ def get_price(i, sdate='', edate='', freq='day', days=320, fq='qfq',
251
279
  tk = tkt
252
280
  break
253
281
  b = pd.DataFrame([j[:6] for j in a[tk]],
254
- columns=['date',
255
- 'open',
256
- 'close',
257
- 'high',
258
- 'low',
259
- 'vol']).set_index(['date']).astype(float)
282
+ columns=['date','open','close','high','low','vol']
283
+ ).set_index(['date'])
284
+ for col in ['open','high','low','close','vol']:
285
+ b[col] = pd.to_numeric(b[col], errors='coerce')
260
286
  if 'qt' in a:
261
287
  name = a['qt'][i][1]
262
288
  except Exception as e:
@@ -470,6 +496,8 @@ def get_hk_stocks_hsi():
470
496
  if __name__ == "__main__":
471
497
  # print(get_cn_stock_list())
472
498
  # print(get_price('fuBTC',sdate='20250101'))
499
+ # print(get_price('fuM2601',sdate='20250101', freq='min'))
500
+ # print(get_price('fuM2601',sdate='2025-01-01'))
473
501
  # print(get_price('sz000001', sdate='20240101', edate='20250101'))
474
502
  print(get_price('usAMZN.OQ', sdate='20250101', edate='20250101', freq='min'))
475
503
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rquote
3
- Version: 0.3.1
3
+ Version: 0.3.4
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
File without changes
File without changes
File without changes
File without changes
File without changes