An interface encapsulated based on Tushare, which implements rate limiting and retry mechanisms.
Project description
tushare-interface
将tushare接口封装在类中,并提供限流、重试功能
安装教程
- pip install tushare-interface
- 在.bashrc中添加环境变量:
- export TUSHARE_TOKEN='xxxxxxxxxx' 该api从tushare.pro网站购买
- export TUSHARE_POINTS='120', 设置你的实际积分,将据此设定每分钟可访问接口的次数,需要注意的是,与网站上说明的不同,120积分实际只支持10次查询/分钟
使用说明
- from tushare_interface import interfaceTuShare as pro
- package内有实例化对象: interfaceTuShare,
- 如果环境变量已经设置好,import后即可使用
- 如果环境变量未设置,可通过setToken函数设置从htp://tushare.pro获得的token; 以及
- 通过setPoints函数设置积分,最低120
- interfaceTuShare还可以使用setRetry设置重试次数(最少0次)和重试间隔(以秒为单位,最低1秒)
- 如果发现请求后出现流控告警,可以通过setTimesPerMinutus直接设置每分钟发送请求的数量,最低1次/分钟。
- 调用query接口从tushare下载数据,接口与tushare原始的query保持一致
- 函数原型
- setToken(self, token: str) -> None
- setPoints(self, points: int) -> None:
- setTimesPerMinutus(self, timesPerMinutus: int) -> None
- setRetry(self, retrys: int, secondsWaitRetry: int) -> None
- query(self, func_name: str, **kwds: object) -> pandas.DataFrame | None
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters