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第三方库


热门话题
java如何在安卓中以编程方式扫描无线网络和连接?   Java中的mysql JSP登录问题   java改造2.0多拦截器   运行方法内部的java线程状态冲突;为什么线程状态不是“正在运行”   java Ruby Compass编译器输出   java简单密钥侦听器   java无法统计应用程序。从2.0.6更新SpringBoot之后。发布到2.1.0。释放   使用Hibernate应用程序的java Spring启动失败   java CommonExec:在系统路径上执行程序?   JavaSwing实现基于阶段的GUI的正确方法是什么?   java如何使用GWT编程设置CSS类的宽度?   scala java。lang.NoSuchFieldException:_ebean_道具总是在将ebean从3.3.4升级到4.5.5时出现,   java Android:开发的应用程序可以在emulator中运行,但不能安装在我的设备中   java“null”是如何工作的?它的值是常数吗?   使用JBeret运行SleepyBatchlet时发生java JSR352 JBeret错误