Skip to content

Instantly share code, notes, and snippets.

@ChadThackray
ChadThackray / coinmarketcap-simple.py
Created June 21, 2024 07:50
Get Crypto Price Data from CoinMarketCap in python
# Licensed under the MIT License. See comment below for full licence information.
from requests import Request, Session
import json
import pprint
import time
url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
parameters = {
'slug':'bitcoin',
@ChadThackray
ChadThackray / ta-library.py
Last active May 31, 2025 19:19
TA library tutorial in python
# Licensed under the MIT License. See comment below for full licence information.
import pandas as pd
import matplotlib.pyplot as plt
import yfinance as yf
import ta
df = yf.Ticker("BTC-USD").history(period='max').reset_index()[["Date","Close"]]
plt.style.use("dark_background")
@ChadThackray
ChadThackray / matplotlib-dollar-ticks.py
Last active June 21, 2024 08:02
Matplotlib currency label formatting guide
# Licensed under the MIT License. See comment below for full licence information.
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import ticker
df = pd.read_csv("bitcoin-historical-price.csv")[["Date","Value"]]
df["Date"] = pd.to_datetime(df.Date)
plt.style.use("fivethirtyeight")
@ChadThackray
ChadThackray / coingecko.py
Created June 21, 2024 08:01
Take a Crypto Market Snapshot with Python and Coingecko
# Licensed under the MIT License. See comment below for full licence information.
import pandas as pd
import requests
r = requests.get("https://www.coingecko.com/en?page=2")
df = pd.read_html(r.text)[0]
df = df[["Coin","Price","Mkt Cap"]]
@ChadThackray
ChadThackray / mplfinance.py
Created June 21, 2024 08:06
Candlestick charts in python with mplfinance
# Licensed under the MIT License. See comment below for full licence information.
import yfinance as yf
import pandas as pd
import mplfinance as mpf
df = yf.Ticker("BTC-USD").history(period="max")
df["50ma"] = (df["Open"].rolling(window=50).mean() ) / 1.5
df["ma"] = (df["Open"].rolling(window=50).mean() ) * 1.5
@ChadThackray
ChadThackray / coinbase-bars.py
Last active October 22, 2024 07:39
Get OHLC/Candlestick data from Coinbase pro historical API in Python
# Licensed under the MIT License. See comment below for full licence information.
import requests
import pandas as pd
import time
from datetime import datetime,timedelta
apiUrl = "https://api.pro.coinbase.com"
sym = "ETH-USD"
@ChadThackray
ChadThackray / pandas-ta.py
Created June 21, 2024 08:21
Pandas-Ta quick start guide in python
# Licensed under the MIT License. See comment below for full licence information.
import pandas as pd
import pandas_ta as ta
import matplotlib.pyplot as plt
import plotly.graph_objects as go
df = pd.read_csv("btc.csv")[["unix","open","high","low","close"]]
df.sort_values(by="unix", inplace = True)
df["date"] = pd.to_datetime(df["unix"], unit = 's')
@ChadThackray
ChadThackray / tradingview-to-backtrader.py
Created June 21, 2024 08:24
Translating a Tradingview strategy to Backtrader
# Licensed under the MIT License. See comment below for full licence information.
import backtrader as bt
from datetime import datetime
class SwingTrade(bt.SignalStrategy):
params = (("closeThreshold",3),)
def __init__(self):
@ChadThackray
ChadThackray / backtrader-indicators.py
Created June 22, 2024 08:16
Custom indicators in backtrader
# Licensed under the MIT License. See comment below for full licence information.
from datetime import datetime
import backtrader as bt
class OverUnderIndicator(bt.Indicator):
lines = ('overunder',)
def __init__(self):
@ChadThackray
ChadThackray / renko.py
Created June 22, 2024 08:21
Renko charts in python with mplfinance
# Licensed under the MIT License. See comment below for full licence information.
import mplfinance as mpl
import pandas as pd
import yfinance as yf
## Data Gather
btc = yf.Ticker("BTC-USD").history(period = "1mo", interval = "60m")
print(btc)