diff --git a/README.rst b/README.rst index 1d7a7cf1..3f8d3c1f 100644 --- a/README.rst +++ b/README.rst @@ -21,8 +21,11 @@ Tiingo Python :target: https://mybinder.org/v2/gh/hydrosquall/tiingo-python/master?filepath=examples%2Fbasic-usage-with-pandas.ipynb :alt: Launch Binder - - +.. image:: https://mybinder.org/badge_logo.svg + :target: https://mybinder.org/v2/gh/datatalking/tiingo-python/blob/datatalking-patch-1/examples/crypto-usage-tiingo-pandas.ipynb/HEAD + :alt: Launch Crypto Binder + + Tiingo is a financial data platform that makes high quality financial tools available to all. Tiingo has a REST and Real-Time Data API, which this library helps you to access. Presently, the API includes support for the following endpoints: * Stock Market Ticker Closing Prices + Metadata. Data includes full distribution details and is validated using a proprietary EOD Price Engine. diff --git a/examples/crypto-usage-tiingo-pandas.ipynb b/examples/crypto-usage-tiingo-pandas.ipynb new file mode 100644 index 00000000..64c8ca28 --- /dev/null +++ b/examples/crypto-usage-tiingo-pandas.ipynb @@ -0,0 +1,131 @@ +#%% +#%% md + +# Tiingo Python for Cryptocurrencies + + +This notebook shows basic usage of the `tiingo-python` library. If you're running this on `mybinder.org`, you can run this code without installing anything on your computer. You can find more information about what available at the [Tiingo website](https://api.tiingo.com/docs/general/overview), but this notebook will let you play around with real code samples in your browser. + +If you've never used `jupyter` before, I recommend this [tutorial](https://www.datacamp.com/community/tutorials/tutorial-jupyter-notebook) from Datacamp. + +#%% md + +## Basic Setup + +First, you'll need to provide your API key as a string in the cell below. If you forget to do this, the notebook cannot run. You can find your API key by visiting [this link](https://www.tiingo.com/account/api/token) and logging in to your Tiingo account. + +#%% + +!pip3 install os +!pip3 install websocket +!pip3 install json +!pip3 install Tiingo.exceptions +!pip3 install matplotlib +!pip3 install pandas +!pip3 install numpy +!pip3 install pandas-datareader + +#%% + +TIINGO_API_KEY = '8c35e8407d4da9c94e39bdf0dbc7913a899c2377' + +# This is here to remind you to change your API key. +if not TIINGO_API_KEY or (TIINGO_API_KEY == 'REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY'): + raise Exception("Please provide a valid Tiingo API key!") + +#%% + +from tiingo import TiingoClient + +config = { + 'api_key': TIINGO_API_KEY, + 'session': True # Reuse HTTP sessions across API calls for better performance +} + +# Throughout the rest of this notebook, you'll use the "client" to interact with the Tiingo backend services. +client = TiingoClient(config) + +#%% md + +## Minimal Data Fetching Examples + +Below are the code samples from the `USAGE.rst` along with sample outputs, but this is just the tip of the iceberg of this library's capabilities. + +#%% + +client.get_crypto_metadata(['BTCUSD'], fmt='json') + +#%% md +## Obtaining Quotes +You can obtain top-of-book cryptocurrency quotes from the ``get_crypto_top_of_ ˓→book()`` method. +NOTE: Crypto symbol MUST be encapsulated in brackets as a Python list! + +#%% +crypto_price = client.get_crypto_top_of_book(['BTCUSD']) + +#%% md + +## Historical Crytocurrency Quotes +You can obtain historical Cryptocurrency price quotes from the get_crypto_price_ ˓→history() method. +NOTE: Crypto symbol MUST be encapsulated in brackets as a Python list! + +#%% +client.get_crypto_price_history(tickers = ['BTCUSD'], startDate='2020-12-2', endDate='2020-12-3', resampleFreq='1Hour') + +#%% md + +## Token & RESTendpoint Together + +You can access crypto pricing with a specific ticker, startdate and resampled freqency. + +#%% +from tiingo-python import RestClient + +client = RestClient(token='REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY') +prices = client.crypto.get_prices(tickers='BTCUSD', + startDate='2019-01-02', + resampleFreq='5min') + +#%% md + +## Cryptocurrency Tiingo and Pandas + +#%% + +import pandas as pd +import numpy as np + +import pandas_datareader as pdr +token='REPLACE-THIS-TEXT-WITH-A-REAL-API-KEY' + +#%% + +df = pdr.get_data_tiingo('BTCUSD', api_key=key) +df.to_csv('BTCUSD.csv') +df = pd.read_csv('BTCUSD.csv') +#%% md + +## Pandas Dataframe head displays the top five rows by default + +For more questions Read The Manual ==> https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.head.html + +#%% + +df.head() +#%% md + +## Pandas Dataframe taiil displays the top five rows by default + +For more questions Read The Manual ==> https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.tail.html + + +#%% +df.tail() + +#%% md + +## Pandas Dataframe tail showing last 100 +#%% +df.tail(100) +#%% +df1 = df.reset_index()['close'] diff --git a/tiingo/api.py b/tiingo/api.py index 9bd90b2d..5b0c7efa 100644 --- a/tiingo/api.py +++ b/tiingo/api.py @@ -310,8 +310,9 @@ def get_dataframe( """When tickers is provided as a list, metric_name is a required argument. Please provide a metric_name, or call this method with one ticker at a time.""" ) - params = {"format": fmt, "resampleFreq": frequency} + if includeIntradayVolume: + params['columns'] = 'open,high,low,close,volume' if startDate: params["startDate"] = startDate if endDate: