Skip to content

Commit

Permalink
Merge pull request #1 from datatalking/datatalking-patch-1
Browse files Browse the repository at this point in the history
Crypto Jupyter Notebook
  • Loading branch information
datatalking authored Aug 26, 2021
2 parents a80bdd5 + b6020f9 commit 5142324
Showing 1 changed file with 131 additions and 0 deletions.
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
!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']

0 comments on commit 5142324

Please sign in to comment.