tushare 1.3.1__tar.gz → 1.3.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. {tushare-1.3.1 → tushare-1.3.2}/PKG-INFO +1 -1
  2. {tushare-1.3.1 → tushare-1.3.2}/tushare/__init__.py +1 -1
  3. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/rtq.py +63 -25
  4. {tushare-1.3.1 → tushare-1.3.2}/tushare.egg-info/PKG-INFO +1 -1
  5. {tushare-1.3.1 → tushare-1.3.2}/README.md +0 -0
  6. {tushare-1.3.1 → tushare-1.3.2}/setup.cfg +0 -0
  7. {tushare-1.3.1 → tushare-1.3.2}/setup.py +0 -0
  8. {tushare-1.3.1 → tushare-1.3.2}/test/__init__.py +0 -0
  9. {tushare-1.3.1 → tushare-1.3.2}/test/bar_test.py +0 -0
  10. {tushare-1.3.1 → tushare-1.3.2}/test/billboard_test.py +0 -0
  11. {tushare-1.3.1 → tushare-1.3.2}/test/classifying_test.py +0 -0
  12. {tushare-1.3.1 → tushare-1.3.2}/test/dateu_test.py +0 -0
  13. {tushare-1.3.1 → tushare-1.3.2}/test/fund_test.py +0 -0
  14. {tushare-1.3.1 → tushare-1.3.2}/test/indictor_test.py +0 -0
  15. {tushare-1.3.1 → tushare-1.3.2}/test/macro_test.py +0 -0
  16. {tushare-1.3.1 → tushare-1.3.2}/test/nav_test.py +0 -0
  17. {tushare-1.3.1 → tushare-1.3.2}/test/news_test.py +0 -0
  18. {tushare-1.3.1 → tushare-1.3.2}/test/pro_test.py +0 -0
  19. {tushare-1.3.1 → tushare-1.3.2}/test/ref_test.py +0 -0
  20. {tushare-1.3.1 → tushare-1.3.2}/test/shibor_test.py +0 -0
  21. {tushare-1.3.1 → tushare-1.3.2}/test/storing_test.py +0 -0
  22. {tushare-1.3.1 → tushare-1.3.2}/test/test_realtime.py +0 -0
  23. {tushare-1.3.1 → tushare-1.3.2}/test/test_stk_mins.py +0 -0
  24. {tushare-1.3.1 → tushare-1.3.2}/test/test_websocket.py +0 -0
  25. {tushare-1.3.1 → tushare-1.3.2}/test/trading_test.py +0 -0
  26. {tushare-1.3.1 → tushare-1.3.2}/tushare/bond/__init__.py +0 -0
  27. {tushare-1.3.1 → tushare-1.3.2}/tushare/bond/bonds.py +0 -0
  28. {tushare-1.3.1 → tushare-1.3.2}/tushare/coins/__init__.py +0 -0
  29. {tushare-1.3.1 → tushare-1.3.2}/tushare/coins/market.py +0 -0
  30. {tushare-1.3.1 → tushare-1.3.2}/tushare/data/__init__.py +0 -0
  31. {tushare-1.3.1 → tushare-1.3.2}/tushare/fund/__init__.py +0 -0
  32. {tushare-1.3.1 → tushare-1.3.2}/tushare/fund/cons.py +0 -0
  33. {tushare-1.3.1 → tushare-1.3.2}/tushare/fund/nav.py +0 -0
  34. {tushare-1.3.1 → tushare-1.3.2}/tushare/futures/__init__.py +0 -0
  35. {tushare-1.3.1 → tushare-1.3.2}/tushare/futures/cons.py +0 -0
  36. {tushare-1.3.1 → tushare-1.3.2}/tushare/futures/domestic.py +0 -0
  37. {tushare-1.3.1 → tushare-1.3.2}/tushare/futures/domestic_cons.py +0 -0
  38. {tushare-1.3.1 → tushare-1.3.2}/tushare/futures/intlfutures.py +0 -0
  39. {tushare-1.3.1 → tushare-1.3.2}/tushare/internet/__init__.py +0 -0
  40. {tushare-1.3.1 → tushare-1.3.2}/tushare/internet/boxoffice.py +0 -0
  41. {tushare-1.3.1 → tushare-1.3.2}/tushare/internet/caixinnews.py +0 -0
  42. {tushare-1.3.1 → tushare-1.3.2}/tushare/internet/indexes.py +0 -0
  43. {tushare-1.3.1 → tushare-1.3.2}/tushare/pro/__init__.py +0 -0
  44. {tushare-1.3.1 → tushare-1.3.2}/tushare/pro/client.py +0 -0
  45. {tushare-1.3.1 → tushare-1.3.2}/tushare/pro/data_pro.py +0 -0
  46. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/__init__.py +0 -0
  47. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/billboard.py +0 -0
  48. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/classifying.py +0 -0
  49. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/cons.py +0 -0
  50. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/fundamental.py +0 -0
  51. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/globals.py +0 -0
  52. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/histroy_divide.py +0 -0
  53. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/indictor.py +0 -0
  54. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/macro.py +0 -0
  55. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/macro_vars.py +0 -0
  56. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/minsdata.py +0 -0
  57. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/news_vars.py +0 -0
  58. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/newsevent.py +0 -0
  59. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/ref_vars.py +0 -0
  60. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/reference.py +0 -0
  61. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/rtq_vars.py +0 -0
  62. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/shibor.py +0 -0
  63. {tushare-1.3.1 → tushare-1.3.2}/tushare/stock/trading.py +0 -0
  64. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/__init__.py +0 -0
  65. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/ht_subs/__init__.py +0 -0
  66. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/ht_subs/service/__init__.py +0 -0
  67. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/ht_subs/service/covert.py +0 -0
  68. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/model/__init__.py +0 -0
  69. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/model/min.py +0 -0
  70. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/model/tick.py +0 -0
  71. {tushare-1.3.1 → tushare-1.3.2}/tushare/subs/ts_subs.py +0 -0
  72. {tushare-1.3.1 → tushare-1.3.2}/tushare/trader/__init__.py +0 -0
  73. {tushare-1.3.1 → tushare-1.3.2}/tushare/trader/trader.py +0 -0
  74. {tushare-1.3.1 → tushare-1.3.2}/tushare/trader/utils.py +0 -0
  75. {tushare-1.3.1 → tushare-1.3.2}/tushare/trader/vars.py +0 -0
  76. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/__init__.py +0 -0
  77. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/common.py +0 -0
  78. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/conns.py +0 -0
  79. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/dateu.py +0 -0
  80. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/form_date.py +0 -0
  81. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/format_stock_code.py +0 -0
  82. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/formula.py +0 -0
  83. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/mailmerge.py +0 -0
  84. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/netbase.py +0 -0
  85. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/protobuf/__init__.py +0 -0
  86. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/protobuf/funcs.py +0 -0
  87. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/protobuf/response_pb2.py +0 -0
  88. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/store.py +0 -0
  89. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/upass.py +0 -0
  90. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/vars.py +0 -0
  91. {tushare-1.3.1 → tushare-1.3.2}/tushare/util/verify_token.py +0 -0
  92. {tushare-1.3.1 → tushare-1.3.2}/tushare.egg-info/SOURCES.txt +0 -0
  93. {tushare-1.3.1 → tushare-1.3.2}/tushare.egg-info/dependency_links.txt +0 -0
  94. {tushare-1.3.1 → tushare-1.3.2}/tushare.egg-info/requires.txt +0 -0
  95. {tushare-1.3.1 → tushare-1.3.2}/tushare.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.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
@@ -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
  """
@@ -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: 1.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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes