tushare 1.4.14__py3-none-any.whl → 1.4.16__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 +2 -2
- tushare/pro/data_pro.py +179 -7
- {tushare-1.4.14.dist-info → tushare-1.4.16.dist-info}/METADATA +1 -1
- {tushare-1.4.14.dist-info → tushare-1.4.16.dist-info}/RECORD +7 -7
- {tushare-1.4.14.dist-info → tushare-1.4.16.dist-info}/WHEEL +1 -1
- {tushare-1.4.14.dist-info → tushare-1.4.16.dist-info}/LICENSE +0 -0
- {tushare-1.4.14.dist-info → tushare-1.4.16.dist-info}/top_level.txt +0 -0
tushare/__init__.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
import codecs
|
3
3
|
import os
|
4
4
|
|
5
|
-
__version__ = '1.4.
|
5
|
+
__version__ = '1.4.16'
|
6
6
|
__author__ = 'Jimmy Liu'
|
7
7
|
|
8
8
|
"""
|
@@ -78,7 +78,7 @@ from tushare.stock.shibor import (shibor_data, shibor_quote_data,
|
|
78
78
|
"""
|
79
79
|
for tushare pro api
|
80
80
|
"""
|
81
|
-
from tushare.pro.data_pro import (pro_api, pro_bar, subs, ht_subs)
|
81
|
+
from tushare.pro.data_pro import (pro_api, pro_bar, subs, ht_subs, pro_bar_vip)
|
82
82
|
|
83
83
|
"""
|
84
84
|
for LHB
|
tushare/pro/data_pro.py
CHANGED
@@ -26,7 +26,6 @@ FACT_LIST = {
|
|
26
26
|
'pe': 'pe',
|
27
27
|
'pe_ttm': 'pe_ttm',
|
28
28
|
}
|
29
|
-
|
30
29
|
def pro_api(token='', timeout=30):
|
31
30
|
"""
|
32
31
|
初始化pro API,第一次可以通过ts.set_token('your token')来记录自己的token凭证,临时token可以通过本参数传入
|
@@ -37,10 +36,10 @@ def pro_api(token='', timeout=30):
|
|
37
36
|
pro = client.DataApi(token=token, timeout=timeout)
|
38
37
|
return pro
|
39
38
|
else:
|
40
|
-
raise Exception('api init error.')
|
41
|
-
|
39
|
+
raise Exception('api init error.')
|
42
40
|
|
43
|
-
|
41
|
+
|
42
|
+
def pro_bar(ts_code='', api=None, start_date='', end_date='', freq='D', asset='E',
|
44
43
|
exchange='',
|
45
44
|
adj = None,
|
46
45
|
ma = [],
|
@@ -70,13 +69,13 @@ def pro_bar(ts_code='', api=None, start_date='', end_date='', freq='D', asset='E
|
|
70
69
|
tor:换手率,默认不返回,返回需指定:factor=['tor']
|
71
70
|
以上两种都需要:factor=['vr', 'tor']
|
72
71
|
retry_count:网络重试次数
|
73
|
-
|
72
|
+
|
74
73
|
Return
|
75
74
|
----------
|
76
75
|
DataFrame
|
77
76
|
code:代码
|
78
77
|
open:开盘close/high/low/vol成交量/amount成交额/maN均价/vr量比/tor换手率
|
79
|
-
|
78
|
+
|
80
79
|
期货(asset='FT')
|
81
80
|
code/open/close/high/low/avg_price:均价 position:持仓量 vol:成交总量
|
82
81
|
"""
|
@@ -87,7 +86,7 @@ def pro_bar(ts_code='', api=None, start_date='', end_date='', freq='D', asset='E
|
|
87
86
|
freq = freq.strip().lower()
|
88
87
|
else:
|
89
88
|
freq = freq.strip().upper() if asset != 'C' else freq.strip().lower()
|
90
|
-
|
89
|
+
|
91
90
|
if 'min' not in freq:
|
92
91
|
today= datetime.datetime.today().date()
|
93
92
|
today = str(today)[0:10]
|
@@ -200,6 +199,179 @@ def pro_bar(ts_code='', api=None, start_date='', end_date='', freq='D', asset='E
|
|
200
199
|
return data
|
201
200
|
raise IOError('ERROR.')
|
202
201
|
|
202
|
+
def pro_api(token='', timeout=30):
|
203
|
+
"""
|
204
|
+
初始化pro API,第一次可以通过ts.set_token('your token')来记录自己的token凭证,临时token可以通过本参数传入
|
205
|
+
"""
|
206
|
+
if token == '' or token is None:
|
207
|
+
token = upass.get_token()
|
208
|
+
if token is not None and token != '':
|
209
|
+
pro = client.DataApi(token=token, timeout=timeout)
|
210
|
+
return pro
|
211
|
+
else:
|
212
|
+
raise Exception('api init error.')
|
213
|
+
|
214
|
+
|
215
|
+
def pro_bar_vip(ts_code='', api=None, start_date='', end_date='', freq='D', asset='E',
|
216
|
+
exchange='',
|
217
|
+
adj = None,
|
218
|
+
ma = [],
|
219
|
+
factors = None,
|
220
|
+
adjfactor = False,
|
221
|
+
offset = None,
|
222
|
+
limit = None,
|
223
|
+
fields = '',
|
224
|
+
contract_type = '',
|
225
|
+
retry_count = 3):
|
226
|
+
"""
|
227
|
+
BAR数据
|
228
|
+
Parameters:
|
229
|
+
------------
|
230
|
+
ts_code:证券代码,支持股票,ETF/LOF,期货/期权,港股,数字货币
|
231
|
+
start_date:开始日期 YYYYMMDD
|
232
|
+
end_date:结束日期 YYYYMMDD
|
233
|
+
freq:支持1/5/15/30/60分钟,周/月/季/年
|
234
|
+
asset:证券类型 E:股票和交易所基金,I:沪深指数,C:数字货币,FT:期货 FD:基金/O期权/H港股/CB可转债
|
235
|
+
exchange:市场代码,用户数字货币行情
|
236
|
+
adj:复权类型,None不复权,qfq:前复权,hfq:后复权
|
237
|
+
ma:均线,支持自定义均线频度,如:ma5/ma10/ma20/ma60/maN
|
238
|
+
offset:开始行数(分页功能,从第几行开始取数据)
|
239
|
+
limit: 本次提取数据行数
|
240
|
+
factors因子数据,目前支持以下两种:
|
241
|
+
vr:量比,默认不返回,返回需指定:factor=['vr']
|
242
|
+
tor:换手率,默认不返回,返回需指定:factor=['tor']
|
243
|
+
以上两种都需要:factor=['vr', 'tor']
|
244
|
+
retry_count:网络重试次数
|
245
|
+
|
246
|
+
Return
|
247
|
+
----------
|
248
|
+
DataFrame
|
249
|
+
code:代码
|
250
|
+
open:开盘close/high/low/vol成交量/amount成交额/maN均价/vr量比/tor换手率
|
251
|
+
|
252
|
+
期货(asset='FT')
|
253
|
+
code/open/close/high/low/avg_price:均价 position:持仓量 vol:成交总量
|
254
|
+
"""
|
255
|
+
if (ts_code=='' or ts_code is None) and (adj is not None):
|
256
|
+
print('提取复权行情必须输入ts_code参数')
|
257
|
+
return
|
258
|
+
if len(freq.strip())>=3:
|
259
|
+
freq = freq.strip().lower()
|
260
|
+
else:
|
261
|
+
freq = freq.strip().upper() if asset != 'C' else freq.strip().lower()
|
262
|
+
|
263
|
+
if 'min' not in freq:
|
264
|
+
today= datetime.datetime.today().date()
|
265
|
+
today = str(today)[0:10]
|
266
|
+
start_date = '' if start_date is None else start_date
|
267
|
+
end_date = today if end_date == '' or end_date is None else end_date
|
268
|
+
start_date = start_date.replace('-', '')
|
269
|
+
end_date = end_date.replace('-', '')
|
270
|
+
ts_code = ts_code.strip().upper() if asset != 'C' else ts_code.strip().lower()
|
271
|
+
asset = asset.strip().upper()
|
272
|
+
api = api if api is not None else pro_api()
|
273
|
+
for _ in range(retry_count):
|
274
|
+
try:
|
275
|
+
if asset == 'E':
|
276
|
+
if freq == 'D':
|
277
|
+
data = api.daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
278
|
+
if factors is not None and len(factors) >0 :
|
279
|
+
ds = api.daily_basic_vip(ts_code=ts_code, start_date=start_date, end_date=end_date)[['trade_date', 'turnover_rate', 'volume_ratio']]
|
280
|
+
ds = ds.set_index('trade_date')
|
281
|
+
data = data.set_index('trade_date')
|
282
|
+
data = data.merge(ds, left_index=True, right_index=True)
|
283
|
+
data = data.reset_index()
|
284
|
+
if ('tor' in factors) and ('vr' not in factors):
|
285
|
+
data = data.drop('volume_ratio', axis=1)
|
286
|
+
if ('vr' in factors) and ('tor' not in factors):
|
287
|
+
data = data.drop('turnover_rate', axis=1)
|
288
|
+
if freq == 'W':
|
289
|
+
data = api.weekly_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
290
|
+
if freq == 'M':
|
291
|
+
data = api.monthly_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
292
|
+
if 'min' in freq:
|
293
|
+
data = api.stk_mins_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, freq=freq, offset=offset, limit=limit)
|
294
|
+
data['trade_date'] = data['trade_time'].map(lambda x: x.replace('-', '')[0:8])
|
295
|
+
data['pre_close'] = data['close'].shift(-1)
|
296
|
+
if adj is not None:
|
297
|
+
fcts = api.adj_factor_vip(ts_code=ts_code, start_date=start_date, end_date=end_date)[['trade_date', 'adj_factor']]
|
298
|
+
if fcts.shape[0] == 0:
|
299
|
+
return None
|
300
|
+
data = data.set_index('trade_date', drop=False).merge(fcts.set_index('trade_date'), left_index=True, right_index=True, how='left')
|
301
|
+
if 'min' in freq:
|
302
|
+
data = data.sort_values('trade_time', ascending=False)
|
303
|
+
data['adj_factor'] = data['adj_factor'].fillna(method='bfill')
|
304
|
+
for col in PRICE_COLS:
|
305
|
+
if adj == 'hfq':
|
306
|
+
data[col] = data[col] * data['adj_factor']
|
307
|
+
if adj == 'qfq':
|
308
|
+
data[col] = data[col] * data['adj_factor'] / float(fcts['adj_factor'][0])
|
309
|
+
data[col] = data[col].map(FORMAT)
|
310
|
+
data[col] = data[col].astype(float)
|
311
|
+
if adjfactor is False:
|
312
|
+
data = data.drop('adj_factor', axis=1)
|
313
|
+
if 'min' not in freq:
|
314
|
+
data['change'] = data['close'] - data['pre_close']
|
315
|
+
data['pct_chg'] = data['change'] / data['pre_close'] * 100
|
316
|
+
data['pct_chg'] = data['pct_chg'].map(lambda x: FORMAT(x)).astype(float)
|
317
|
+
else:
|
318
|
+
data = data.drop(['trade_date', 'pre_close'], axis=1)
|
319
|
+
else:
|
320
|
+
data['pre_close'] = data['close'].shift(-1)
|
321
|
+
data['change'] = data['close'] - data['pre_close']
|
322
|
+
data['pct_chg'] = data['change'] / data['pre_close'] * 100
|
323
|
+
data['pct_chg'] = data['pct_chg'].map(lambda x: FORMAT(x)).astype(float)
|
324
|
+
elif asset == 'I':
|
325
|
+
if freq == 'D':
|
326
|
+
data = api.index_daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
327
|
+
if freq == 'W':
|
328
|
+
data = api.index_weekly_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
329
|
+
if freq == 'M':
|
330
|
+
data = api.index_monthly_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
331
|
+
if 'min' in freq:
|
332
|
+
data = api.stk_mins_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, freq=freq, offset=offset, limit=limit)
|
333
|
+
elif asset == 'FT':
|
334
|
+
if freq == 'D':
|
335
|
+
data = api.fut_daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, exchange=exchange, offset=offset, limit=limit)
|
336
|
+
if 'min' in freq:
|
337
|
+
data = api.ft_mins_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, freq=freq, offset=offset, limit=limit)
|
338
|
+
elif asset == 'O':
|
339
|
+
if freq == 'D':
|
340
|
+
data = api.opt_daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, exchange=exchange, offset=offset, limit=limit)
|
341
|
+
if 'min' in freq:
|
342
|
+
data = api.opt_mins_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, freq=freq, offset=offset, limit=limit)
|
343
|
+
elif asset == 'CB':
|
344
|
+
if freq == 'D':
|
345
|
+
data = api.cb_daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
346
|
+
elif asset == 'FD':
|
347
|
+
if freq == 'D':
|
348
|
+
data = api.fund_daily_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, offset=offset, limit=limit)
|
349
|
+
if 'min' in freq:
|
350
|
+
data = api.stk_mins_vip(ts_code=ts_code, start_date=start_date, end_date=end_date, freq=freq, offset=offset, limit=limit)
|
351
|
+
if asset == 'C':
|
352
|
+
if freq == 'd':
|
353
|
+
freq = 'daily'
|
354
|
+
elif freq == 'w':
|
355
|
+
freq = 'week'
|
356
|
+
data = api.coinbar(exchange=exchange, symbol=ts_code, freq=freq, start_dae=start_date, end_date=end_date,
|
357
|
+
contract_type=contract_type)
|
358
|
+
if ma is not None and len(ma) > 0:
|
359
|
+
for a in ma:
|
360
|
+
if isinstance(a, int):
|
361
|
+
data['ma%s'%a] = MA(data['close'], a).map(FORMAT).shift(-(a-1))
|
362
|
+
data['ma%s'%a] = data['ma%s'%a].astype(float)
|
363
|
+
data['ma_v_%s'%a] = MA(data['vol'], a).map(FORMAT).shift(-(a-1))
|
364
|
+
data['ma_v_%s'%a] = data['ma_v_%s'%a].astype(float)
|
365
|
+
data = data.reset_index(drop=True)
|
366
|
+
except Exception as e:
|
367
|
+
print(e)
|
368
|
+
else:
|
369
|
+
if fields is not None and fields != '':
|
370
|
+
f_list = [col.strip() for col in fields.split(',')]
|
371
|
+
data = data[f_list]
|
372
|
+
return data
|
373
|
+
raise IOError('ERROR.')
|
374
|
+
|
203
375
|
|
204
376
|
def subs(token=''):
|
205
377
|
if token == '' or token is None:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
tushare/__init__.py,sha256=
|
1
|
+
tushare/__init__.py,sha256=WGp2WFHHZkVf028VsTtx31RvngjcKDEFQCE4Zt3JFcE,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
|
@@ -18,7 +18,7 @@ tushare/internet/caixinnews.py,sha256=IwNOB5F1q_CxfuP93-jgUpTW5yY5NANPRJXySm_bj2
|
|
18
18
|
tushare/internet/indexes.py,sha256=oteQCv0k2X0pbhXRHwMSviD1AowJWE6xRjKkqr5RNCo,3595
|
19
19
|
tushare/pro/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
20
|
tushare/pro/client.py,sha256=w7LfXtlmSd4Aiq7Bz5-tPFfkfjrPS_7jroUiRs7BUWw,1388
|
21
|
-
tushare/pro/data_pro.py,sha256=
|
21
|
+
tushare/pro/data_pro.py,sha256=3ZVaHCsHqJlMouXsqgAeayqD9rThX-EGZ_REOYsAWbs,20568
|
22
22
|
tushare/pro/llm.py,sha256=Zdb81mhr9lQKX6p-JDml7THSbmBm8NmFQT54B8FkgvI,3444
|
23
23
|
tushare/stock/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
tushare/stock/billboard.py,sha256=vCrbN7-NGXSpXMc8jq7NcjjHyu9pTcr4uXp559iA1wA,12833
|
@@ -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.16.dist-info/LICENSE,sha256=C2j55UI0Ul-1-wA1-rn7OaY6b3vGl4YukiyvYzHsU9o,1503
|
76
|
+
tushare-1.4.16.dist-info/METADATA,sha256=6cwUt3uKNk6ItLZukKycsUOZvHvfdia9ivJR1FOK-S8,2965
|
77
|
+
tushare-1.4.16.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
78
|
+
tushare-1.4.16.dist-info/top_level.txt,sha256=HHOxMuqc31KuAIcxpE0t5dAPMKbaiRtjsjTMFd7FlXI,8
|
79
|
+
tushare-1.4.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|