tushare 1.4.21__py3-none-any.whl → 1.4.23__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.
- tushare/__init__.py +1 -1
- tushare/stock/histroy_divide.py +67 -1
- {tushare-1.4.21.dist-info → tushare-1.4.23.dist-info}/METADATA +5 -1
- {tushare-1.4.21.dist-info → tushare-1.4.23.dist-info}/RECORD +7 -7
- {tushare-1.4.21.dist-info → tushare-1.4.23.dist-info}/LICENSE +0 -0
- {tushare-1.4.21.dist-info → tushare-1.4.23.dist-info}/WHEEL +0 -0
- {tushare-1.4.21.dist-info → tushare-1.4.23.dist-info}/top_level.txt +0 -0
tushare/__init__.py
CHANGED
tushare/stock/histroy_divide.py
CHANGED
@@ -16,6 +16,7 @@ from tushare.util.verify_token import require_permission
|
|
16
16
|
from tushare.util.format_stock_code import format_stock_code
|
17
17
|
from tushare.stock.rtq_vars import zh_sina_a_stock_cookies, zh_sina_a_stock_headers
|
18
18
|
import time
|
19
|
+
import json
|
19
20
|
from typing import Optional
|
20
21
|
from tushare.util.form_date import get_current_date
|
21
22
|
from tushare.stock import rtq_vars
|
@@ -50,6 +51,8 @@ def realtime_tick(ts_code: str = "000001.SZ", src: Optional[str] = "tx",
|
|
50
51
|
symbol = symbol_verify(ts_code)
|
51
52
|
if src == "sina":
|
52
53
|
return get_stock_sina_a_divide_amount(symbol, page_count)
|
54
|
+
elif src == 'dc':
|
55
|
+
return get_stock_dc_a_divide_amount(symbol, page_count)
|
53
56
|
else:
|
54
57
|
return get_stock_tx_a_divide_amount(symbol, page_count)
|
55
58
|
|
@@ -183,7 +186,70 @@ def get_stock_sina_a_divide_amount(symbol: str = "sz000001", page_count: Optiona
|
|
183
186
|
return big_df
|
184
187
|
|
185
188
|
|
189
|
+
def __event_stream(url, params, ):
|
190
|
+
response = requests.get(url, params=params, stream=True)
|
191
|
+
event_data = ""
|
192
|
+
|
193
|
+
for line in response.iter_lines():
|
194
|
+
# 过滤掉保持连接的空行
|
195
|
+
if line:
|
196
|
+
event_data += line.decode() + "\n"
|
197
|
+
elif event_data:
|
198
|
+
yield event_data
|
199
|
+
event_data = ""
|
200
|
+
|
201
|
+
|
202
|
+
def get_stock_dc_a_divide_amount(symbol: str = "000001", page_count: Optional[int] = None) -> pd.DataFrame:
|
203
|
+
"""
|
204
|
+
东方财富-分时数据
|
205
|
+
https://quote.eastmoney.com/f1.html?newcode=0.000001
|
206
|
+
:param symbol: 股票代码
|
207
|
+
:type symbol: str
|
208
|
+
:return: 分时数据
|
209
|
+
:rtype: pandas.DataFrame
|
210
|
+
"""
|
211
|
+
symbols = str(symbol).lower().split(".")
|
212
|
+
symbol = symbols[0]
|
213
|
+
# print(symbol)
|
214
|
+
market_code = 1 if symbol.startswith("6") else 0
|
215
|
+
url = "https://70.push2.eastmoney.com/api/qt/stock/details/sse"
|
216
|
+
params = {
|
217
|
+
"fields1": "f1,f2,f3,f4",
|
218
|
+
"fields2": "f51,f52,f53,f54,f55",
|
219
|
+
"mpi": "2000",
|
220
|
+
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
221
|
+
"fltt": "2",
|
222
|
+
"pos": "-0",
|
223
|
+
"secid": f"{market_code}.{symbol}",
|
224
|
+
"wbp2u": "|0|0|0|web",
|
225
|
+
}
|
226
|
+
|
227
|
+
big_df = pd.DataFrame() # 创建一个空的 DataFrame
|
228
|
+
|
229
|
+
for event in __event_stream(url, params):
|
230
|
+
# 从每个事件的数据行中删除 "data: ",然后解析 JSON
|
231
|
+
event_json = json.loads(event.replace("data: ", ""))
|
232
|
+
# 将 JSON 数据转换为 DataFrame,然后添加到主 DataFrame 中
|
233
|
+
temp_df = pd.DataFrame(
|
234
|
+
[item.split(",") for item in event_json["data"]["details"]]
|
235
|
+
)
|
236
|
+
big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)
|
237
|
+
break
|
238
|
+
|
239
|
+
big_df.columns = ["TIME", "PRICE", "VOLUME", "-", "TYPE"]
|
240
|
+
big_df["TYPE"] = big_df["TYPE"].map(
|
241
|
+
{"2": "买盘", "1": "卖盘", "4": "中性盘"}
|
242
|
+
)
|
243
|
+
big_df = big_df[["TIME", "PRICE", "VOLUME", "TYPE"]]
|
244
|
+
big_df["PRICE"] = pd.to_numeric(big_df["PRICE"], errors="coerce")
|
245
|
+
big_df["VOLUME"] = pd.to_numeric(big_df["VOLUME"], errors="coerce")
|
246
|
+
|
247
|
+
return big_df
|
248
|
+
|
249
|
+
|
186
250
|
if __name__ == '__main__':
|
187
|
-
df = realtime_tick(ts_code="000001.SZ", src="
|
251
|
+
df = realtime_tick(ts_code="000001.SZ", src="dc", page_count=1)
|
188
252
|
print(help(realtime_tick))
|
189
253
|
print(df)
|
254
|
+
# r = get_stock_dc_a_divide_amount()
|
255
|
+
# print(r)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: tushare
|
3
|
-
Version: 1.4.
|
3
|
+
Version: 1.4.23
|
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
|
@@ -80,6 +80,10 @@ return::
|
|
80
80
|
|
81
81
|
Log
|
82
82
|
--------------
|
83
|
+
1.4.22
|
84
|
+
-------
|
85
|
+
- 新增 realtime_tick 腾讯源
|
86
|
+
--------------
|
83
87
|
1.4.21
|
84
88
|
-------
|
85
89
|
- 修复 realtime_list ts_code 格式化
|
@@ -1,4 +1,4 @@
|
|
1
|
-
tushare/__init__.py,sha256=
|
1
|
+
tushare/__init__.py,sha256=FHJ2PWB_0RIhXQ5oBdFPWkaHRW3ea5bNf2h2tj69jks,4778
|
2
2
|
tushare/bond/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
tushare/bond/bonds.py,sha256=PJM0xDiWZDpOPwDtbEU9PdP0M_Gu0c599YuB1rbZ3r8,232
|
4
4
|
tushare/coins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -26,7 +26,7 @@ tushare/stock/classifying.py,sha256=3yWqlLhgj2irk-9ksKWFFS5HY-SnjfEr5erwJxBidG8,
|
|
26
26
|
tushare/stock/cons.py,sha256=P3DOSYH-B1iLF2nAj2jpYzCbxBDYK-g7hK4BG-3d28M,31812
|
27
27
|
tushare/stock/fundamental.py,sha256=3H6-mA0o0xUjEIQ4EHKiuuzKO454FPyjp1Cz4A9qNRU,20304
|
28
28
|
tushare/stock/globals.py,sha256=eW9c44HX1QMUmPco-GZ0sXDrq5qsEmIGwO_kvU6dw6w,2118
|
29
|
-
tushare/stock/histroy_divide.py,sha256=
|
29
|
+
tushare/stock/histroy_divide.py,sha256=aFyZ5L_1CwHOU_xjK99UZrtcXZsRwrZwedUj0M3B7No,8903
|
30
30
|
tushare/stock/indictor.py,sha256=ZmtEkJVTNqI5Nn2X3T2sICgwo0MDgoKV0abgz8f4aRQ,25443
|
31
31
|
tushare/stock/macro.py,sha256=aQpRMCFiBNLbfGnL7cTJ_F7a9c8Is0T5uEVOt4wlsRg,14211
|
32
32
|
tushare/stock/macro_vars.py,sha256=EwYcEv_A_iToKxnbCk4tEyfNUV6HkRHoeukYi2TpsTw,1453
|
@@ -72,8 +72,8 @@ tushare/util/verify_token.py,sha256=cuV3RErWbOC318NANCYL6K1LKZ3wSAL2yMwZHA7tD3s,
|
|
72
72
|
tushare/util/protobuf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
73
73
|
tushare/util/protobuf/funcs.py,sha256=UCdK8FxTyjPZsNzoEeXqYzqrQXUmRMvW5hua6GPA66A,779
|
74
74
|
tushare/util/protobuf/response_pb2.py,sha256=vJH9ONkDuJlg6y-q1PvuDZoviKrK7hzNtMieQHK45DI,11347
|
75
|
-
tushare-1.4.
|
76
|
-
tushare-1.4.
|
77
|
-
tushare-1.4.
|
78
|
-
tushare-1.4.
|
79
|
-
tushare-1.4.
|
75
|
+
tushare-1.4.23.dist-info/LICENSE,sha256=C2j55UI0Ul-1-wA1-rn7OaY6b3vGl4YukiyvYzHsU9o,1503
|
76
|
+
tushare-1.4.23.dist-info/METADATA,sha256=Xz9jvCTEUlpFPzihsb-MnnNzhUUycGihmPMqaMy3eho,3374
|
77
|
+
tushare-1.4.23.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
78
|
+
tushare-1.4.23.dist-info/top_level.txt,sha256=HHOxMuqc31KuAIcxpE0t5dAPMKbaiRtjsjTMFd7FlXI,8
|
79
|
+
tushare-1.4.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|