tiingo数据平台api的rest客户端

tiingo的Python项目详细描述


用法

如果您想在安装之前尝试此库,请单击下面的打开一个包含联机可运行示例的文件夹。

launch binder

首先,从pypi安装库:

pip install tiingo

如果您希望以 p and as dataframe series 格式接收结果,并且您尚未安装pandas,请将其作为可选依赖项安装:

pip install tiingo[pandas]

接下来,初始化您的客户机。建议使用环境 变量以方便初始化客户端。

fromtiingoimportTiingoClient# 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"# Initializeclient=TiingoClient(config)

现在您可以使用 tiingoclient 来进行api调用。(除以下示例中使用的参数外,每个端点都可以使用其他参数,请检查每个函数的docstring以获取详细信息。)。

# Get Tickerticker_metadata=client.get_ticker_metadata("GOOGL")# Get latest prices, based on 3+ sources as JSON, sampled weeklyticker_price=client.get_ticker_price("GOOGL",frequency="weekly")# Get historical GOOGL prices from August 2017 as JSON, sampled dailyhistorical_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 domainsarticles=client.get_news(tickers=['GOOGL','AAPL'],tags=['Laptops'],sources=['washingtonpost.com'],startDate='2017-01-01',endDate='2017-08-31')

要以 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"。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用jaxrpc的Java eclipse WebService客户端   java编程方式在对象上写入名称   java Spring批处理:重试后跳过   java Android错误:错误:任务执行失败:应用程序:transformClassesWithDexForDebug'   带有清单文件nullPointerException的java Android元数据   spring Java Quartz调度作业停止运行   JavaMockito:如何在不调用实际方法的情况下,模拟带有参数和无效返回类型的静态方法?   java Tomcat连接池问题无法在关闭的连接上调用方法   java如何交换列表中的项目?   java如何停止线程并通过Toast在线程中正确显示文本?   java为什么连续写入OutputStream时偏移量0不会导致重复字节?   java我无法生成头文件   不兼容的返回类型错误java   修改值后键值对的java Jolt转换规范   java有自动更新Javadoc的工具吗?   java线程如何在ints自身实例类中共享变量   java继承一个非gwt模块   java Hibernate xml配置   使用netty4异步调用的java链接HTTP请求响应