Previous topic

tushare_easy.consts module

This Page

tushare_easy.getdata module

classes for get k_chart data and save data locally

class tushare_easy.getdata.RunFunc(home='.')[source]

Bases: tushare_easy.getdata.Base

run function in target directory

setup target directory and function, then run function within target directory

Parameters:

home : str

set a directory as home

Attributes

func
home

Methods

make_home([force]) make home directory
rm_home([force]) remove home directory
run(*args, **kwargs) run func
set_func(func) set a function to run
func
run(*args, **kwargs)[source]

run func

func parameter passed by args and kwargs

Parameters:

args :

args of self.func

kwargs :

keyworad args of self.func

set_func(func)[source]

set a function to run

Parameters:func : function
class tushare_easy.getdata.GetData(codes, ktypes=['5', '15', '30', '60', 'd', 'w', 'm'], start=None, end=None, home='.')[source]

Bases: tushare_easy.getdata.RunFunc

get data and save them locally

get df using tushare’s get_k_date function save df to local without duplication

Parameters:

home : str

current work directory

codes : list-like

ktypes : list-like

start : str

time format ‘%Y-%m-%d-%H-%M’

end : str

same format as start

Examples

>>> import os
>>> import pandas as pd
>>> import tushare as ts
>>> from tushare_easy.getdata import RunFunc, GetData
>>> get_code = RunFunc()
>>> get_code.set_func(ts.get_stock_basics)
>>> codes = get_code.run().index.values
>>> home = os.path.join(os.environ['HOME'], 'data', 'ts', 'k_chart')
>>> getdf = GetData(codes, home=home)
>>> getdf.run_loop()

Attributes

codes
end
func
home
ktypes
start

Methods

make_home([force]) make home directory
rm_home([force]) remove home directory
run(*args, **kwargs) run func
run_loop([codes_random]) Get data looping for codes
set_func(func) set a function to run
codes
end
ktypes
run_loop(codes_random=False)[source]

Get data looping for codes

Parameters:

codes_random : bool

if True, looping for codes randomly

start