Python tushare.set_token() Examples

The following are 7 code examples of tushare.set_token(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tushare , or try the search function .
Example #1
Source File: DySS_GrowingStocks.py    From DevilYuan with MIT License 5 votes vote down vote up
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 
Example #2
Source File: DyStockDataGateway.py    From DevilYuan with MIT License 5 votes vote down vote up
def _startTuSharePro(self):
        if self._tuSharePro is None:
            ts.set_token(DyStockCommon.tuShareProToken)
            self._tuSharePro = ts.pro_api() 
Example #3
Source File: DyStockDataSpider.py    From DevilYuan with MIT License 5 votes vote down vote up
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 
Example #4
Source File: DyST_TraceFocus.py    From DevilYuan with MIT License 5 votes vote down vote up
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 
Example #5
Source File: DyStockTradeOneKeyHangUp.py    From DevilYuan with MIT License 5 votes vote down vote up
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 
Example #6
Source File: QATushare.py    From QUANTAXIS with MIT License 5 votes vote down vote up
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') 
Example #7
Source File: QATushare.py    From QUANTAXIS with MIT License 5 votes vote down vote up
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