tushare 1.3.1__py3-none-any.whl → 1.3.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
tushare/__init__.py CHANGED
@@ -2,7 +2,7 @@
2
2
  import codecs
3
3
  import os
4
4
 
5
- __version__ = '1.3.1'
5
+ __version__ = '1.3.2'
6
6
  __author__ = 'Jimmy Liu'
7
7
 
8
8
  """
tushare/stock/rtq.py CHANGED
@@ -86,18 +86,26 @@ def realtime_quote(ts_code="688553.SH", src="sina", ):
86
86
  return get_realtime_quotes_dc(symbols)
87
87
 
88
88
 
89
+ sina_stock_code = {}
90
+
91
+
89
92
  def get_realtime_quotes_sina(symbol="688553"): # "688553"
93
+ global sina_stock_code
90
94
  symbols = []
95
+ syms = []
91
96
  for i in [j for j in symbol.split(",")]:
92
- symbols.append(i.split(".")[0])
97
+ s = i.split(".")
98
+ sina_stock_code[s[0]] = s[1].upper()
99
+ symbols.append(s[1].lower() + s[0])
100
+ syms.append(s[0])
93
101
  # symbols = re.search(r"(\d+)", str(symbols), re.S | re.M).group(1)
94
102
  symbols_list = ''
95
103
  if isinstance(symbols, list) or isinstance(symbols, set) or \
96
104
  isinstance(symbols, tuple) or isinstance(symbols, pd.Series):
97
105
  for code in symbols:
98
- symbols_list += ct._code_to_symbol(code) + ','
106
+ symbols_list += code + ','
99
107
  else:
100
- symbols_list = ct._code_to_symbol(symbols)
108
+ symbols_list = symbols
101
109
  symbols_list = symbols_list[:-1] if len(symbols_list) > 8 else symbols_list
102
110
  root_url = ct.LIVE_DATA_URL % (ct.P_TYPE['http'], ct.DOMAINS['sinahq'], _get_current_timestamp(), symbols_list)
103
111
  response = requests.get(root_url,
@@ -109,8 +117,6 @@ def get_realtime_quotes_sina(symbol="688553"): # "688553"
109
117
  text = response.content.decode('GBK')
110
118
  reg = re.compile(r'\="(.*?)\";')
111
119
  data = reg.findall(text)
112
- regSym = re.compile(r'(?:sh|sz)(.*?)\=')
113
- syms = regSym.findall(text)
114
120
  data_list = []
115
121
  syms_list = []
116
122
  for index, row in enumerate(data):
@@ -126,13 +132,18 @@ def get_realtime_quotes_sina(symbol="688553"): # "688553"
126
132
  for txt in ls:
127
133
  df[txt] = df[txt].map(lambda x: x[:-2])
128
134
  df.columns = rtqv.LIVE_DATA_COLS
129
- df["TS_CODE"] = df["TS_CODE"].apply(format_stock_code)
135
+ df["TS_CODE"] = df["TS_CODE"].apply(format_sina_stock_code)
130
136
  df["DATE"] = df["DATE"].apply(format_date_str)
131
137
  new_order = rtqv.LIVE_DATA_COLS_REINDEX
132
138
  df = df[new_order]
133
139
  return df
134
140
 
135
141
 
142
+ def format_sina_stock_code(x):
143
+ ts_code = f"{x}.{sina_stock_code[x]}"
144
+ return ts_code
145
+
146
+
136
147
  def format_date_str(date_str):
137
148
  return date_str.replace("-", "")
138
149
 
@@ -453,9 +464,13 @@ def get_stock_all_a_sina(interval: Optional[int] = 3, page_count: Optional[int]
453
464
 
454
465
 
455
466
  def get_realtime_quotes_dc(symbols="688553"):
467
+ """
468
+ https://quote.eastmoney.com/sh601096.html
469
+ """
456
470
  symbols = str(symbols).split(",")[0]
457
471
  url = "https://push2.eastmoney.com/api/qt/stock/get"
458
472
  symbol = re.search(r"(\d+)", symbols, re.S | re.M).group(1)
473
+ # print(symbol)
459
474
  params = {
460
475
  "invt": "2",
461
476
  "fltt": "1",
@@ -468,51 +483,74 @@ def get_realtime_quotes_dc(symbols="688553"):
468
483
  }
469
484
  response = requests.get(url, headers=rtqv.dc_cookies, cookies=rtqv.dc_headers, params=params)
470
485
  data_info = response.json()["data"]
486
+ if not data_info:
487
+ return pd.DataFrame()
471
488
  name = data_info["f58"]
472
- open = data_info["f45"] / 100
473
- high = data_info["f44"] / 100
474
- pre_close = data_info["f60"] / 100
475
- low = data_info["f46"] / 100
476
- price = data_info["f43"] / 100
489
+ open = data_info["f45"] # / 100
490
+ high = data_info["f44"] # / 100
491
+ pre_close = data_info["f60"] # / 100
492
+ low = data_info["f46"] # / 100
493
+ price = data_info["f43"] # / 100 if data_info["f43"] != "-" else ""
477
494
  b5_v = data_info["f12"]
478
- b5_p = data_info["f11"] / 100
495
+ b5_p = data_info["f11"] # / 100 if data_info["f11"] != "-" else ""
479
496
  b4_v = data_info["f14"]
480
- b4_p = data_info["f13"] / 100
497
+ b4_p = data_info["f13"] # / 100 if data_info["f13"] != "-" else ""
481
498
  b3_v = data_info["f16"]
482
- b3_p = data_info["f15"] / 100
499
+ b3_p = data_info["f15"] # / 100 if data_info["f15"] != "-" else ""
483
500
  b2_v = data_info["f18"]
484
- b2_p = data_info["f17"] / 100
501
+ b2_p = data_info["f17"] # / 100 if data_info["f17"] != "-" else ""
485
502
  b1_v = data_info["f20"]
486
- b1_p = data_info["f19"] / 100
503
+ b1_p = data_info["f19"] # / 100 if data_info["f19"] != "-" else ""
487
504
  a5_v = data_info["f32"]
488
- a5_p = data_info["f31"] / 100
505
+ a5_p = data_info["f31"] # / 100 if data_info["f31"] != "-" else ""
489
506
  a4_v = data_info["f34"]
490
- a4_p = data_info["f33"] / 100
507
+ a4_p = data_info["f33"] # / 100 if data_info["f33"] != "-" else ""
491
508
  a3_v = data_info["f36"]
492
- a3_p = data_info["f35"] / 100
509
+ a3_p = data_info["f35"] # / 100 if data_info["f35"] != "-" else ""
493
510
  a2_v = data_info["f38"]
494
- a2_p = data_info["f37"] / 100
511
+ a2_p = data_info["f37"] # / 100 if data_info["f38"] != "-" else ""
495
512
  a1_v = data_info["f40"]
496
- a1_p = data_info["f39"] / 100
513
+ a1_p = data_info["f39"] # / 100 if data_info["f39"] != "-" else ""
497
514
  date_time = timestemp_to_time(data_info["f86"])
498
515
  date = date_time[0:10]
499
516
  times = date_time[10:]
500
517
  volume = data_info["f47"]
501
518
  amount = data_info["f48"]
502
- bid = data_info["f19"] / 100
503
- ask = data_info["f39"] / 100
519
+ bid = data_info["f19"] # / 100 if data_info["f19"] != "-" else ""
520
+ ask = data_info["f39"] # / 100 if data_info["f39"] != "-" else ""
504
521
  code = symbols
505
522
  data_list = [[name, open, pre_close, price, high, low, bid, ask, volume, amount,
506
523
  b1_v, b1_p, b2_v, b2_p, b3_v, b3_p, b4_v, b4_p, b5_v, b5_p,
507
524
  a1_v, a1_p, a2_v, a2_p, a3_v, a3_p, a4_v, a4_p, a5_v, a5_p, date, times, code]]
508
525
  df = pd.DataFrame(data_list, columns=rtqv.LIVE_DATA_COLS)
509
526
  df["DATE"] = df["DATE"].apply(format_date_str)
527
+ df["ASK"] = df["ASK"].apply(format_dc_str)
528
+ df["OPEN"] = df["OPEN"].apply(format_dc_str)
529
+ df["HIGH"] = df["HIGH"].apply(format_dc_str)
530
+ df["LOW"] = df["LOW"].apply(format_dc_str)
531
+ df["PRE_CLOSE"] = df["PRE_CLOSE"].apply(format_dc_str)
532
+ df["BID"] = df["BID"].apply(format_dc_str)
533
+ df["A1_P"] = df["A1_P"].apply(format_dc_str)
534
+ df["A2_P"] = df["A2_P"].apply(format_dc_str)
535
+ df["A3_P"] = df["A3_P"].apply(format_dc_str)
536
+ df["A4_P"] = df["A4_P"].apply(format_dc_str)
537
+ df["A5_P"] = df["A5_P"].apply(format_dc_str)
538
+ df["PRICE"] = df["PRICE"].apply(format_dc_str)
539
+ df["B1_P"] = df["B1_P"].apply(format_dc_str)
540
+ df["B2_P"] = df["B2_P"].apply(format_dc_str)
541
+ df["B3_P"] = df["B3_P"].apply(format_dc_str)
542
+ df["B4_P"] = df["B4_P"].apply(format_dc_str)
543
+ df["B5_P"] = df["B5_P"].apply(format_dc_str)
510
544
  new_order = rtqv.LIVE_DATA_COLS_REINDEX
511
545
  df = df[new_order]
512
546
  return df
513
547
 
514
548
 
549
+ def format_dc_str(x):
550
+ return x / 100 if x != "-" else ""
551
+
552
+
515
553
  if __name__ == '__main__':
516
- # df = realtime_quote(ts_code="688553.SH,600630.SH", src="sina")
517
- df = realtime_list(src="dc", page_count=1)
554
+ df = realtime_quote(ts_code="000688.SH,000010.SH,000012.SH,399005.SZ", src="dc")
555
+ # df = realtime_list(src="dc", page_count=1)
518
556
  print(df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tushare
3
- Version: 1.3.1
3
+ Version: 1.3.2
4
4
  Summary: A utility for crawling historical and Real-time Quotes data of China stocks
5
5
  Home-page: https://tushare.pro
6
6
  Author: Jimmy Liu
@@ -16,7 +16,7 @@ test/test_realtime.py,sha256=YpEH3Ic3D-4dgL9BI9RbWNSD-ZM8KfuqtSxyBvexSRg,697
16
16
  test/test_stk_mins.py,sha256=ctaoAkclIKxNQT6KYuXaB5HESpZSD29dn-KLbUT2rmo,53600
17
17
  test/test_websocket.py,sha256=DgOEcX9vuYlPVfBi54AJZTh6k0eu9lG4qcOdJhGllNU,1079
18
18
  test/trading_test.py,sha256=otXiHdU0ob441x7o1swadfSEuyPusT7oYU8SQeesSxE,1147
19
- tushare/__init__.py,sha256=oyWBwCmHVxfR-F-VvB3G9u5eeeHosqS80BZoGK-dsDY,4698
19
+ tushare/__init__.py,sha256=Djsh8Mjh3nO8M8ay3OjJPgLT-L715dmNLGNAz1Tk3aE,4698
20
20
  tushare/bond/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  tushare/bond/bonds.py,sha256=PJM0xDiWZDpOPwDtbEU9PdP0M_Gu0c599YuB1rbZ3r8,232
22
22
  tushare/coins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -52,7 +52,7 @@ tushare/stock/news_vars.py,sha256=CQ18hvyoeScelBCqKgF_rgAufoEALAUT8y_LERvZKHk,45
52
52
  tushare/stock/newsevent.py,sha256=STR7C8MjtZlaXTCG0QNaojBuK4-oxP_8hT7ZIvRpbiI,6944
53
53
  tushare/stock/ref_vars.py,sha256=MIxor-2rISl65I32vUzC-z7ZC_QFzG4sxOKDyjLWuU4,4449
54
54
  tushare/stock/reference.py,sha256=x_HZlrP58T-5OTZ7SLdf2Dh9THj1h7cT4wcIp42IHFI,38227
55
- tushare/stock/rtq.py,sha256=hI-xtpmRoEE17w05hM6X-kcWxsFXe_kqOf5K_FevwAI,17034
55
+ tushare/stock/rtq.py,sha256=yhgZJmr9kTVALabI0vYwgJPFA07TILg237Zw-rbVclg,18778
56
56
  tushare/stock/rtq_vars.py,sha256=V6LeJkSP76z8veRfP_mGiQ63V5YBHoTMaqUA5hSBWh4,4200
57
57
  tushare/stock/shibor.py,sha256=Fx9OUZ429kz6l7ZdaYSD6p_X79ud69PDM9EZogm8xCY,6422
58
58
  tushare/stock/trading.py,sha256=3bvM4pexEYW-uGGEL7g6Vkte4sqGC1iYO6dC8mGLSdM,55619
@@ -84,8 +84,8 @@ tushare/util/verify_token.py,sha256=-GazF4ktzyJ7HbshHJibJeCgGhhxM31H18JmlOmEurc,
84
84
  tushare/util/protobuf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
85
85
  tushare/util/protobuf/funcs.py,sha256=UCdK8FxTyjPZsNzoEeXqYzqrQXUmRMvW5hua6GPA66A,779
86
86
  tushare/util/protobuf/response_pb2.py,sha256=vJH9ONkDuJlg6y-q1PvuDZoviKrK7hzNtMieQHK45DI,11347
87
- tushare-1.3.1.dist-info/LICENSE,sha256=C2j55UI0Ul-1-wA1-rn7OaY6b3vGl4YukiyvYzHsU9o,1503
88
- tushare-1.3.1.dist-info/METADATA,sha256=UBQ_FLajHGgbjY0eUCPpVswBbWVBERD9uXetin_KiFc,2322
89
- tushare-1.3.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
90
- tushare-1.3.1.dist-info/top_level.txt,sha256=0mgc2vMZJnuC65-OMhhOjT_zydkyE9Okxd1V3p2LeeA,13
91
- tushare-1.3.1.dist-info/RECORD,,
87
+ tushare-1.3.2.dist-info/LICENSE,sha256=C2j55UI0Ul-1-wA1-rn7OaY6b3vGl4YukiyvYzHsU9o,1503
88
+ tushare-1.3.2.dist-info/METADATA,sha256=7n6IifCUfacT3ECyRxd603liVkznLTMievsDVHwMhFU,2322
89
+ tushare-1.3.2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
90
+ tushare-1.3.2.dist-info/top_level.txt,sha256=0mgc2vMZJnuC65-OMhhOjT_zydkyE9Okxd1V3p2LeeA,13
91
+ tushare-1.3.2.dist-info/RECORD,,