本文整理汇总了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