當前位置: 首頁>>代碼示例>>Python>>正文


Python tushare.get_hist_data方法代碼示例

本文整理匯總了Python中tushare.get_hist_data方法的典型用法代碼示例。如果您正苦於以下問題:Python tushare.get_hist_data方法的具體用法?Python tushare.get_hist_data怎麽用?Python tushare.get_hist_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tushare的用法示例。


在下文中一共展示了tushare.get_hist_data方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _init_coll

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def _init_coll(self):
        """
        Get all the history data when initiate the library.
        1. Connect to arctic and create the library.
        2. Get all the history data from tushare and strip the unused columns.
        3. Store the data to arctic.
        :return: None
        """

        # if collection is not initialized
        if self._coll_name not in self._library.list_symbols():
            self._new_added_colls.append(self._coll_name)
            his_data = ts.get_hist_data(code=self._coll_name, retry_count=5).sort_index()
            if len(his_data) == 0:
                logger.warning(
                    f'data of stock {self._coll_name} when initiation is empty'
                )
                return

            his_data = bdu.Utils.strip_unused_cols(his_data, *self._unused_cols)

            logger.debug(f'write history data for stock: {self._coll_name}.')
            self._library.write(self._coll_name, his_data) 
開發者ID:pandalibin,項目名稱:backtrader-cn,代碼行數:25,代碼來源:tushare.py

示例2: get_hist_data_cache

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def get_hist_data_cache(code, date_start, date_end):
    cache_dir = bash_stock_tmp % (date_end[0:7], date_end)
    # 如果沒有文件夾創建一個。月文件夾和日文件夾。方便刪除。
    # print("cache_dir:", cache_dir)
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    cache_file = cache_dir + "%s^%s.gzip.pickle" % (date_end, code)
    # 如果緩存存在就直接返回緩存數據。壓縮方式。
    if os.path.isfile(cache_file):
        print("######### read from cache #########", cache_file)
        return pd.read_pickle(cache_file, compression="gzip")
    else:
        print("######### get data, write cache #########", code, date_start, date_end)
        stock = ts.get_hist_data(code, start=date_start, end=date_end)
        if stock is None:
            return None
        stock = stock.sort_index(0)  # 將數據按照日期排序下。
        stock.to_pickle(cache_file, compression="gzip")
        return stock 
開發者ID:pythonstock,項目名稱:stock,代碼行數:21,代碼來源:common.py

示例3: dash_index

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def dash_index(request):
    stock_his_data = ts.get_hist_data('sz')
    stock_name = get_stock_name('sz')

    stock_his_data_dic = json.dumps(stock_his_data.to_json(orient='index'))
    pprint.pprint(stock_his_data_dic)

    print(type(stock_his_data_dic))
    date = stock_his_data.index.tolist()
    open = stock_his_data['open'].tolist()
    close = stock_his_data['close'].tolist()
    high = stock_his_data['high'].tolist()
    low = stock_his_data['low'].tolist()
    volume = stock_his_data['volume'].tolist()
    dataMA5 = stock_his_data['ma5'].tolist()
    dataMA10 = stock_his_data['ma10'].tolist()
    dataMA20 = stock_his_data['ma20'].tolist()

    return render(request, 'base_dash.html', {'stock_his_data_dic': stock_his_data_dic, 'date': json.dumps(date), 'open': json.dumps(open), 'close': json.dumps(close), 'high': json.dumps(high), 'low': json.dumps(low), 'volume': json.dumps(volume), 'dataMA5': json.dumps(dataMA5), 'dataMA10': json.dumps(dataMA10), 'dataMA20': json.dumps(dataMA20), 'stock_name': json.dumps(stock_name)}) 
開發者ID:LinLidi,項目名稱:StockSensation,代碼行數:21,代碼來源:views.py

示例4: dash_index

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def dash_index(request):
    stock_his_data = ts.get_hist_data('sz')
    stock_name = get_stock_name('sz')

    stock_his_data_dic = json.dumps(stock_his_data.to_json(orient='index'))
    pprint.pprint(stock_his_data_dic)

    print(type(stock_his_data_dic))
    date = stock_his_data.index.tolist()
    open = stock_his_data['open'].tolist()
    close = stock_his_data['close'].tolist()
    high = stock_his_data['high'].tolist()
    low = stock_his_data['low'].tolist()
    volume = stock_his_data['volume'].tolist()
    dataMA5 = stock_his_data['ma5'].tolist()
    dataMA10 = stock_his_data['ma10'].tolist()
    dataMA20 = stock_his_data['ma20'].tolist()

    return render(request, 'base_dash.html',
                  {'stock_his_data_dic': stock_his_data_dic, 'date': json.dumps(date), 'open': json.dumps(open),
                   'close': json.dumps(close), 'high': json.dumps(high), 'low': json.dumps(low),
                   'volume': json.dumps(volume), 'dataMA5': json.dumps(dataMA5), 'dataMA10': json.dumps(dataMA10),
                   'dataMA20': json.dumps(dataMA20), 'stock_name': json.dumps(stock_name)}) 
開發者ID:Rockyzsu,項目名稱:StockPredict,代碼行數:25,代碼來源:views.py

示例5: home

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def home(request):
    stock_his_data = ts.get_hist_data('sh000001')
    stock_name = get_stock_name('sh000001')

    date = stock_his_data.index.tolist()
    open = stock_his_data['open'].tolist()
    close = stock_his_data['close'].tolist()
    high = stock_his_data['high'].tolist()
    low = stock_his_data['low'].tolist()
    volume = stock_his_data['volume'].tolist()
    dataMA5 = stock_his_data['ma5'].tolist()
    dataMA10 = stock_his_data['ma10'].tolist()
    dataMA20 = stock_his_data['ma20'].tolist()

    return render(request, 'home.html', {'date': json.dumps(date), 'open': json.dumps(open), 'close': json.dumps(close),
                                         'high': json.dumps(high), 'low': json.dumps(low), 'volume': json.dumps(volume),
                                         'dataMA5': json.dumps(dataMA5), 'dataMA10': json.dumps(dataMA10),
                                         'dataMA20': json.dumps(dataMA20), 'stock_name': json.dumps(stock_name)}) 
開發者ID:Rockyzsu,項目名稱:StockPredict,代碼行數:20,代碼來源:views.py

示例6: _cache_monthly

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def _cache_monthly(self, date):
        '''
        緩存date所在月的數據,等緩存成功後返回True
        :param code:
        :param ktype:
        :param date:
        :return:
        '''
        print 'caching...'
        start, end = self._get_date_range_of_month(date, 'str')
        df = ts.get_hist_data(code=self.code, ktype=self.ktype, start=start, end=end, retry_count=6)
        if df is not None:
            df.to_csv(self._get_cache_filename(date))

        waiting_seconds = 0
        while not self._in_cache(date=date):
            sleep(1)
            waiting_seconds += 1
            if waiting_seconds > 30:
                self._cache_monthly(date=date)
        return True 
開發者ID:tenstone,項目名稱:klineyes,代碼行數:23,代碼來源:cache.py

示例7: download_delta_data

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def download_delta_data(self):
        """
        Get yesterday's data and append it to collection,
        this method is planned to be executed at each day's 8:30am to update the data.
        1. Connect to arctic and get the library.
        2. Get today's history data from tushare and strip the unused columns.
        3. Store the data to arctic.
        :return: None
        """

        self._init_coll()

        if self._coll_name in self._new_added_colls:
            return

        # 15:00 PM can get today data
        # start = latest_date + 1 day
        latest_date = self.get_data().index[-1]
        start = latest_date + dt.timedelta(days=1)
        start = dt.datetime.strftime(start, '%Y-%m-%d')

        his_data = ts.get_hist_data(
            code=self._coll_name,
            start=start,
            retry_count=5
        )

        # delta data is empty
        if len(his_data) == 0:
            logger.info(
                f'delta data of stock {self._coll_name} is empty, after {start}')
            return

        his_data = bdu.Utils.strip_unused_cols(his_data, *self._unused_cols)

        logger.info(f'got delta data of stock: {self._coll_name}, after {start}')
        self._library.append(self._coll_name, his_data) 
開發者ID:pandalibin,項目名稱:backtrader-cn,代碼行數:39,代碼來源:tushare.py

示例8: csv

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def csv():
    df = ts.get_hist_data('000875')
    df.to_csv('c:/day/000875.csv',columns=['open','high','low','close']) 
開發者ID:waditu,項目名稱:tushare,代碼行數:5,代碼來源:storing_test.py

示例9: xls

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def xls():
    df = ts.get_hist_data('000875')
    #直接保存
    df.to_excel('c:/day/000875.xlsx', startrow=2,startcol=5) 
開發者ID:waditu,項目名稱:tushare,代碼行數:6,代碼來源:storing_test.py

示例10: hdf

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def hdf():
    df = ts.get_hist_data('000875')
#     df.to_hdf('c:/day/store.h5','table')
    
    store = HDFStore('c:/day/store.h5')
    store['000875'] = df
    store.close() 
開發者ID:waditu,項目名稱:tushare,代碼行數:9,代碼來源:storing_test.py

示例11: json

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def json():
    df = ts.get_hist_data('000875')
    df.to_json('c:/day/000875.json',orient='records')

    #或者直接使用
    print(df.to_json(orient='records')) 
開發者ID:waditu,項目名稱:tushare,代碼行數:8,代碼來源:storing_test.py

示例12: appends

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def appends():
    filename = 'c:/day/bigfile.csv'
    for code in ['000875', '600848', '000981']:
        df = ts.get_hist_data(code)
        if os.path.exists(filename):
            df.to_csv(filename, mode='a', header=None)
        else:
            df.to_csv(filename) 
開發者ID:waditu,項目名稱:tushare,代碼行數:10,代碼來源:storing_test.py

示例13: stock_his_data2json

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def stock_his_data2json(stock_code):
    stock_name = get_stock_name(stock_code)
    stock_his_data_json = json.dumps(ts.get_hist_data(stock_code).to_json(orient='index'))
    return stock_name,stock_his_data_json

#----------------------------- Request Methos -----------------------------# 
開發者ID:LinLidi,項目名稱:StockSensation,代碼行數:8,代碼來源:views.py

示例14: home

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def home(request):
    stock_his_data = ts.get_hist_data('sh000001')
    stock_name = get_stock_name('sh000001')

    date = stock_his_data.index.tolist()
    open = stock_his_data['open'].tolist()
    close = stock_his_data['close'].tolist()
    high = stock_his_data['high'].tolist()
    low = stock_his_data['low'].tolist()
    volume = stock_his_data['volume'].tolist()
    dataMA5 = stock_his_data['ma5'].tolist()
    dataMA10 = stock_his_data['ma10'].tolist()
    dataMA20 = stock_his_data['ma20'].tolist()

    return render(request, 'home.html', {'date': json.dumps(date), 'open': json.dumps(open), 'close': json.dumps(close), 'high': json.dumps(high), 'low': json.dumps(low), 'volume': json.dumps(volume), 'dataMA5': json.dumps(dataMA5), 'dataMA10': json.dumps(dataMA10), 'dataMA20': json.dumps(dataMA20), 'stock_name': json.dumps(stock_name)}) 
開發者ID:LinLidi,項目名稱:StockSensation,代碼行數:17,代碼來源:views.py

示例15: __init__

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_hist_data [as 別名]
def __init__(self,code=None,start=None,end=None,save=True):
        """
        get symbol history data
        @@param:code:股票代碼,如果code is None,或者全部股票
        @@parm:start:開始時間
        @@end:結束時間
        """
        now = dt.datetime.now()
        if end is None:
            end = (now -dt.timedelta(1)).strftime('%Y-%m-%d')
        if start is None:
            start = '1990-01-01'
            
        if code is None:
            mongo =mongodb()##獲取股票代碼
            collectname = 'SymbolMdm'
            where = {}
            kwargs = {'code':1}##獲取code代碼字斷
            codes = mongo.select(collectname,where,kwargs)
            for code in codes:
                HistData(code.get('code'),HistData,end)##遞歸請求曆史數據
        else:
            try:
                data = ts.get_hist_data(code,start=start,end=end) 
                data['datatime']  =  now.strftime('%Y-%m-%d')
                data['datatimestramp']  =  now.strftime('%H:%M:%S')
                data['date'] =data.index
                data['code'] = code
                indexlist = ['code','date']##數據庫索引
                tableName = 'HistData'  
                database(data,indexlist,tableName,save)
                print 'info:{} downloaded is ok,num:{}!       '.format(code,len(data))
            except:
                pass 
開發者ID:lywen52,項目名稱:quantproject,代碼行數:36,代碼來源:spyder_tushare.py


注:本文中的tushare.get_hist_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。