Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added includeIntradayVolume to be passed to get_dataframe in TiingoCl… #673

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
131 changes: 131 additions & 0 deletions examples/crypto-usage-tiingo-pandas.ipynb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the dependencies for the demo notebooks can be included here rather than in inline cells:

https://github.com/hydrosquall/tiingo-python/blob/master/binder/requirements.txt

!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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may want to invalidate this API key so other people can't reuse it / rewrite git history to not include this directly in your notebook.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks hydrosquall, token is reset. Can you recommend a good tutorial on setting up passwords in environments if we are developing on one machine and testing on another? Keychain perhaps ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the python ecosystem, we use

I haven't used this personally, but the world of Python seems to have this as a similar project

Most CI providers (Jenkins, Gitlab, CircleCI etc) will offer a way to supply environment variables via a UI specific to their platform. Keychain is a good option if you're using Mac everywhere.


# 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']
3 changes: 2 additions & 1 deletion tiingo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work, since includeIntradayVolume isn't defined. Once that is added, could you include a unit test that will cover this line?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added includeIntradayVolume as it was referenced in #462 which I figured includeIntradayVolume had already been defined.

Do you have any recommendations for the location where should I add it?

If you can give me a few pointers on the location of the definition, I can probably work up a unittest PR for includeIntradayVolume easily enough.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @datatalking , thanks for the patience

What I meant was that the current code doesn't work because this variable was never defined.

I think you would probably want to add includeIntradayVolume as an additional parameter to the get_dataframe method .

tiingo-python/tiingo/api.py

Lines 265 to 267 in 5142324

frequency="daily",
fmt="json",
):

params['columns'] = 'open,high,low,close,volume'
if startDate:
params["startDate"] = startDate
if endDate:
Expand Down