Tiingo 数据平台 API 的 REST 客户端
项目描述
Tiingo 是一个金融数据平台,为所有人提供高质量的金融工具。Tiingo 有一个 REST 和实时数据 API,这个库可以帮助你访问。目前,API 包括对以下端点的支持:
股市收盘价+元数据。数据包括完整的分销细节,并使用专有的 EOD 价格引擎进行验证。
来自顶级财经新闻来源 + 博客的精选新闻。Tiingo 的算法用主题标签和相关股票代码标记故事。
用法
如果您想在安装前试用此库,请单击下面打开在线可运行示例的文件夹。
首先,从 PyPi 安装库:
pip install tiingo
如果您希望以pandas DataFrame或Series格式接收结果,并且尚未安装 pandas,请将其安装为可选依赖项:
pip install tiingo[pandas]
接下来,初始化您的客户端。为方便起见,建议使用环境变量来初始化您的客户端。
from tiingo import TiingoClient
# Set TIINGO_API_KEY in your environment variables in your .bash_profile, OR
# pass a dictionary with 'api_key' as a key into the TiingoClient.
client = TiingoClient()
或者,您可以使用字典来自定义/授权您的客户端。
config = {}
# To reuse the same HTTP Session across API calls (and have better performance), include a session key.
config['session'] = True
# If you don't have your API key as an environment variable,
# pass it in via a configuration dictionary.
config['api_key'] = "MY_SECRET_API_KEY"
# Initialize
client = TiingoClient(config)
现在您可以使用TiingoClient进行 API 调用。(除了以下示例中使用的参数之外,每个端点都可以使用其他参数,请检查每个函数的文档字符串以获取详细信息。)。
# Get Ticker
ticker_metadata = client.get_ticker_metadata("GOOGL")
# Get latest prices, based on 3+ sources as JSON, sampled weekly
ticker_price = client.get_ticker_price("GOOGL", frequency="weekly")
# Get historical GOOGL prices from August 2017 as JSON, sampled daily
historical_prices = client.get_ticker_price("GOOGL",
fmt='json',
startDate='2017-08-01',
endDate='2017-08-31',
frequency='daily')
# Check what tickers are available, as well as metadata about each ticker
# including supported currency, exchange, and available start/end dates.
tickers = client.list_stock_tickers()
# Get news articles about given tickers or search terms from given domains
articles = client.get_news(tickers=['GOOGL', 'AAPL'],
tags=['Laptops'],
sources=['washingtonpost.com'],
startDate='2017-01-01',
endDate='2017-08-31')
# Get definitions for fields available in the fundamentals-api, ticker is
# optional
definitions = get_fundamentals_definitions('GOOGL')
# Get fundamentals which require daily-updated (like marketCap). A start-
# and end-date can be passed. If omited, will get all available data.
fundamentals_daily = CLIENT.get_fundamentals_daily('GOOGL',
startDate='2020-01-01',
endDate='2020-12-31')
# Get fundamentals based on quarterly statements. Accepts time-range like
# daily-fundamentals. asReported can be set to get the data exactly like
# it was reported to SEC. Set to False if you want to get data containing
# corrections
fundamentals_stmnts = CLIENT.get_fundamentals_statements('GOOGL',
startDate='2020-01-01',
endDate='2020-12-31',
asReported=True)
要以pandas格式接收结果,请使用get_dataframe()方法:
#Get a pd.DataFrame of the price history of a single symbol (default is daily):
ticker_history = client.get_dataframe("GOOGL")
#The method returns all of the available information on a symbol, such as open, high, low, close,
#adjusted close, etc. This page in the tiingo api documentation lists the available information on each
#symbol: https://api.tiingo.com/docs/tiingo/daily#priceData.
#Frequencies and start and end dates can be specified similarly to the json method above.
#Get a pd.Series of only one column of the available response data by specifying one of the valid the
#'metric_name' parameters:
ticker_history = client.get_dataframe("GOOGL", metric_name='adjClose')
#Get a pd.DataFrame for a list of symbols for a specified metric_name (default is adjClose if no
#metric_name is specified):
ticker_history = client.get_dataframe(['GOOGL', 'AAPL'],
frequency='weekly',
metric_name='volume',
startDate='2017-01-01',
endDate='2018-05-31')
您可以为get_ticker_price和get_dataframe方法指定任何结束日的频率(每天、每周、每月和每年)或任何日内频率。每周频率重新采样到周五的一天结束,每月频率重新采样到当月的最后一天,每年的频率重新采样到每年 12-31 的一天结束。日内频率使用整数指定,后跟“Min”或“Hour”,例如“30Min”或“1Hour”。
更多文档
Tiingo 官方文档:https ://api.tiingo.com
tiingo-python文档:https ://tiingo-python.readthedocs.io 。
特征
以编程方式轻松访问 Tiingo API
跨 API 调用重用请求会话以获得更好的性能
在大多数方法中,将fmt=”object”作为关键字传递,以使您的响应以NamedTuples 形式返回,这应该比常规 Python 字典具有更低的内存影响。
路线图:
代码的客户端验证
返回响应的数据验证
代码名称不区分大小写
更多文档/代码示例
随意提交实现上述任何项目的 PR。
学分
非常感谢 Rishi Singh 创建 Tiingo。
这个包是用Cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。
历史
0.15.0(2021-XX - 未发布)
0.14.0 (2021-03-06 - 未发布)
功能:为基础端点添加了 3 种新方法:定义、每日和报表
[/news] 修复源列表为空时 get_news() 中的错误 (#566)
开发:在 Github Actions 而不是 Travis.org 中运行测试
开发:这是支持 Python 3.5 及更低版本的 tiingo 的最后一个版本。(#601)
0.13.0 (2020-12-12)
次要:解决 pd.concat 中排序的 Pandas 未来警告 (#392)
功能:在 get_dataframe 方法中添加选项以请求 csv 格式的数据,可能将速度提高 4-5 倍。(#523)
次要:碰撞库依赖关系,特别是密码学
开发:放弃对 Python 3.5 的官方支持,取而代之的是 3.7
开发:使用 Github Actions 而不是 Travis 发布库 (#546)
0.12.0 (2019-10-20)
功能:为 crypo 端点添加了 3 种新方法:最高价格、历史和元数据端点 (@n1rna #340)
功能:允许 list_tickers 一次支持多种资产类型 (@n1rna #346)
0.11.0 (2019-09-01)
[/news] 在内部将源参数重命名为“source”,确保列表作为逗号分隔值传递 #325。不间断的外部变化。
[/news] 为“onlyWithTickers”添加新的 URL 参数 #327
0.10.x (2019-05-11)
文档:在“/examples”下添加了“同行比较分析”Jupyter Notebook (@i3creations #197)
次要:更新错误消息以阐明多个代码仅适用于单个指标
更新了开发依赖项
0.9.x (2019-01-30)
文档:在“/examples”下添加了可运行的 jupyter notebook 示例
次要:碰撞了各种库依赖项
0.8.0 (2018-07-06)
主要:添加 IEX 端点以检索具有日内频率的数据 (@dcwtx #125)
次要:更新文档以贡献/发布新版本
使用 pip 缓存加速 Travis 构建过程
0.7.0 (2018-06-14)
主要:提供以 pandas Dataframes 或 Series 形式返回数据的函数 (@dcwtx #112)
少量文档编辑
0.6.0 (2018-04-30)
修复重采样参数名称中的错误 (@dcwtx #82)
添加用于从测试夹具中删除 API 密钥的工具 (@dcwtx #107)
删除对 Python 3.3 的官方支持
0.5.0 (2018-03-11)
更新了文档中用于获取历史价格的示例
添加接口以获取共同基金和 ETF 代码 (@savagesmc #62)
缺少 API 密钥时引发显式错误 (#44)
更新开发依赖
0.4.0 (2017-10-22)
使用vcr.py (@condemil #32)使测试以 1/10 的时间运行
添加对返回 python 对象而不是字典的支持 (@BharatKalluri #33)
0.3.0 (2017-09-17)
添加对列出所有代码 + 日期范围的支持
添加对与/news API交互的支持
改进 REST 客户端错误的日志记录
0.2.0 (2017-09-01)
提高代码端点的测试覆盖率
弃用共同基金端点
0.1.0 (2017-08-24)
PyPI 上的第一个版本。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。