本文整理匯總了Python中tushare.set_token方法的典型用法代碼示例。如果您正苦於以下問題:Python tushare.set_token方法的具體用法?Python tushare.set_token怎麽用?Python tushare.set_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tushare
的用法示例。
在下文中一共展示了tushare.set_token方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __getConcepts
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def __getConcepts(cls, codeTable, info, isBackTesting):
"""
從TuSharePro獲取股票概念
"""
conceptsDict = None
needSaved2File = False # 回測時使用,這樣沒必要每次都網上抓取,節省時間。本策略回測,概念數據會導致一定的未來函數。
if isBackTesting:
conceptsDict = cls.getConceptsFromFile()
if conceptsDict is None:
needSaved2File = isBackTesting
info.print('開始從TuSharePro獲取股票所屬行業和概念...', DyLogData.ind)
ts.set_token(DyStockCommon.tuShareProToken)
pro = ts.pro_api()
try:
conceptsDict = cls.__getConceptsFromTuSharePro(pro)
except Exception as ex:
info.print('TuSharePro: 獲取概念異常: {}'.format(ex), DyLogData.error)
return None, needSaved2File
info.print('從TuSharePro獲取股票所屬行業和概念完成', DyLogData.ind)
filteredConceptsDict = {}
for code, name in codeTable.items():
if code not in conceptsDict:
info.print('TuSharePro不存在{}({})的所屬行業'.format(code, name), DyLogData.warning)
continue
filteredConceptsDict[code] = conceptsDict[code]
return filteredConceptsDict, needSaved2File
示例2: __init__
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def __init__(self, param, info):
super().__init__(param, info)
ts.set_token(DyStockCommon.tuShareProToken)
self._pro = ts.pro_api()
# unpack parameters
self._baseDate = param['基準日期']
self._forwardNTDays = param['向前N日周期'] # @self._baseDate is included
self._score = param['得分至少']
self._tuShareProInterval = param['TuSharePro訪問間隔(ms)']/1000
示例3: _startPro
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def _startPro(func):
def wrapper(cls, *args, **kwargs):
if cls.pro is None:
ts.set_token(DyStockCommon.tuShareProToken)
cls.pro = ts.pro_api()
return func(cls, *args, **kwargs)
return wrapper
示例4: _setTradeDaysViaTuSharePro
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def _setTradeDaysViaTuSharePro(self, startDate):
print("TuSharePro: 獲取交易日數據[{}]".format(startDate))
ts.set_token(DyStockCommon.tuShareProToken)
pro = ts.pro_api()
proStartDate = startDate.replace('-', '')
try:
df = pro.trade_cal(exchange='SSE', start_date=proStartDate)
df = df.set_index('cal_date')
df = df[proStartDate:]
# get trade days
dates = DyTime.getDates(startDate, df.index[-1][:4] + '-' + df.index[-1][4:6] + '-' + df.index[-1][6:], strFormat=True)
self._tradeDays = {}
for date in dates:
if df.loc[date.replace('-', ''), 'is_open'] == 1:
self._tradeDays[date] = True
else:
self._tradeDays[date] = False
except Exception as ex:
self._info.print("一鍵掛機: 從TuSharePro獲取交易日[{}]數據異常: {}".format(startDate, ex), DyLogData.warning)
return False
return True
示例5: _startTuSharePro
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def _startTuSharePro(self):
if self._tuSharePro is None:
ts.set_token(DyStockCommon.tuShareProToken)
self._tuSharePro = ts.pro_api()
示例6: set_token
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def set_token(token=None):
try:
if token is None:
# 從~/.quantaxis/setting/config.ini中讀取配置
token = QASETTING.get_config('TSPRO', 'token', None)
else:
QASETTING.set_config('TSPRO', 'token', token)
ts.set_token(token)
except:
if token is None:
print('請設置tushare的token')
else:
print('請升級tushare 至最新版本 pip install tushare -U')
示例7: get_pro
# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import set_token [as 別名]
def get_pro():
try:
set_token()
pro = ts.pro_api()
except Exception as e:
if isinstance(e, NameError):
print('請設置tushare pro的token憑證碼')
else:
print('請升級tushare 至最新版本 pip install tushare -U')
print(e)
pro = None
return pro