Rewrite tickers function to use most current ticket data from tiingo website

This commit is contained in:
Cameron Yick
2017-09-17 16:47:18 -04:00
parent 891de629ee
commit 502acd0650
4 changed files with 26 additions and 54279 deletions

View File

@@ -69,12 +69,15 @@ Now you can use ``TiingoClient`` to make your API calls. (Other parameters are a
.. code-block:: python .. code-block:: python
# Get Ticker # Get Ticker
# See official docs for list of all supported tickers + date ranges
ticker_metadata = client.get_ticker_metadata("GOOGL") ticker_metadata = client.get_ticker_metadata("GOOGL")
# Get latest prices, based on 3+ sources, as CSV or JSON, sampled weekly # Get latest prices, based on 3+ sources, as CSV or JSON, sampled weekly
ticker_price = client.get_ticker_price("GOOGL", frequency="weekly") ticker_price = client.get_ticker_price("GOOGL", frequency="weekly")
# Check what tickers are available, as well as metadata about each ticker
# including supported currency, exchange, and available start/end dates.
tickers = client.get_stock_tickers()
# Get news articles about given tickers or search terms from given domains # Get news articles about given tickers or search terms from given domains
articles = client.get_news(tickers=['GOOGL', 'APPL'], articles = client.get_news(tickers=['GOOGL', 'APPL'],
tags=['Laptops'], tags=['Laptops'],
@@ -82,6 +85,8 @@ Now you can use ``TiingoClient`` to make your API calls. (Other parameters are a
startDate='2017-01-01', startDate='2017-01-01',
endDate='2017-08-31') endDate='2017-08-31')
# Get ai
Further Docs Further Docs
-------- --------

View File

@@ -43,6 +43,10 @@ Now you can use ``TiingoClient`` to make your API calls. (Other parameters are a
# Get latest prices, based on 3+ sources, as CSV or JSON, sampled weekly # Get latest prices, based on 3+ sources, as CSV or JSON, sampled weekly
ticker_price = client.get_ticker_price("GOOGL", frequency="weekly") ticker_price = client.get_ticker_price("GOOGL", frequency="weekly")
# Check what tickers are available, as well as metadata about each ticker
# including supported currency, exchange, and available start/end dates.
tickers = client.get_stock_tickers()
# Get news articles about given tickers. Requires Pro account. # Get news articles about given tickers. Requires Pro account.
articles = client.get_news(tickers=['GOOGL', 'APPL'], articles = client.get_news(tickers=['GOOGL', 'APPL'],
tags=['Bitcoin'], tags=['Bitcoin'],

View File

@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import io
import os import os
import csv
import pkg_resources import pkg_resources
import csv
from StringIO import StringIO
from zipfile import ZipFile
from tiingo.restclient import RestClient from tiingo.restclient import RestClient
import requests
VERSION = pkg_resources.get_distribution("tiingo").version VERSION = pkg_resources.get_distribution("tiingo").version
@@ -39,22 +43,20 @@ class TiingoClient(RestClient):
# https://api.tiingo.com/docs/tiingo/daily # https://api.tiingo.com/docs/tiingo/daily
def list_stock_tickers(self): def list_stock_tickers(self):
"""Return a list of dicts of metadata tickers for all supported Stocks """Return a list of dicts of metadata tickers for all supported Stocks
as well as metadata about each ticker. as well as metadata about each ticker. This includes supported
date range, the exchange the ticker is traded on, and the currency
the stock is traded on.
Tickers for unrelated products are omitted. Tickers for unrelated products are omitted.
https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip
""" """
resource_package = __name__ listing_file_url = "https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip"
listing_path = "/".join(('data', 'supported_tickers.csv')) response = requests.get(listing_file_url)
listing_file = pkg_resources.resource_stream(resource_package, zipdata = ZipFile(StringIO(response.content))
listing_path) raw_csv = StringIO(zipdata.read('supported_tickers.csv'))
tickers = [] reader = csv.DictReader(raw_csv)
reader = csv.DictReader(listing_file)
for row in reader:
tickers = [row for row in reader
if row.get('assetType') == 'Stock']
return [ticker for return [row for row in reader
ticker in tickers if ticker.get('assetType') == 'Stock'] if row.get('assetType') == 'Stock']
def get_ticker_metadata(self, ticker): def get_ticker_metadata(self, ticker):
"""Return metadata for 1 ticker """Return metadata for 1 ticker

File diff suppressed because it is too large Load Diff