-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: master
Are you sure you want to change the base?
Changes from all commits
d957c46
b6020f9
a80bdd5
5142324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
!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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'] |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will work, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Lines 265 to 267 in 5142324
|
||||||||
params['columns'] = 'open,high,low,close,volume' | ||||||||
if startDate: | ||||||||
params["startDate"] = startDate | ||||||||
if endDate: | ||||||||
|
There was a problem hiding this comment.
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