Plot candlestick charts for cryptocurrencies across top exchanges like Binance, Bittrex, and Kraken in under 15 minutes using Python. This guide walks you through accessing live market data, normalizing it, and visualizing it with Plotly—no complex setup required.
Why Use Python for Crypto Price Charts?
- Standardized Data: Exchange APIs often have inconsistent formats.
- Customization: Tailor charts to specific trading pairs, intervals, and indicators.
- Automation: Integrate with trading bots or portfolio trackers.
👉 Explore advanced crypto trading tools
Prerequisites
1. Install Required Libraries
Run these commands to install dependencies:
pip install shrimpy-python pandas plotly==4.1.02. Generate Shrimpy API Keys
- Sign up for a free Shrimpy Developer account.
- Create a master key (store the public/secret keys securely).
Step-by-Step Script
1. Import Libraries
import shrimpy
import plotly.graph_objects as go2. Authenticate with Shrimpy
Replace placeholders with your keys:
public_key = 'your_public_key'
secret_key = 'your_secret_key'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)3. Fetch Candlestick Data
Specify exchange, trading pair, and interval (e.g., 15m, 1h, 1d):
candles = client.get_candles(
'binance', # Exchange (e.g., 'kucoin', 'bittrex')
'BTC', # Base asset (e.g., 'ETH', 'XLM')
'USDT', # Quote asset (e.g., 'BTC', 'USDC')
'1h' # Interval
)4. Format Data for Plotly
Extract timestamps, open/high/low/close prices:
dates = [candle['time'] for candle in candles]
open_data = [candle['open'] for candle in candles]
high_data = [candle['high'] for candle in candles]
low_data = [candle['low'] for candle in candles]
close_data = [candle['close'] for candle in candles]5. Generate the Chart
fig = go.Figure(data=[go.Candlestick(
x=dates,
open=open_data,
high=high_data,
low=low_data,
close=close_data
)])
fig.show()Full Script Example
import shrimpy
import plotly.graph_objects as go
public_key = 'your_public_key'
secret_key = 'your_secret_key'
client = shrimpy.ShrimpyApiClient(public_key, secret_key)
candles = client.get_candles('binance', 'BTC', 'USDT', '1h')
dates = []
open_data = []
high_data = []
low_data = []
close_data = []
for candle in candles:
dates.append(candle['time'])
open_data.append(candle['open'])
high_data.append(candle['high'])
low_data.append(candle['low'])
close_data.append(candle['close'])
fig = go.Figure(data=[go.Candlestick(
x=dates,
open=open_data,
high=high_data,
low=low_data,
close=close_data
)])
fig.show()👉 Build a crypto trading bot with these APIs
FAQs
1. Which exchanges are supported?
Shrimpy supports Binance, Kraken, Bittrex, KuCoin, and 15+ others.
2. How do I change the candle interval?
Adjust the interval parameter (e.g., 15m, 6h, 1d).
3. Can I plot multiple trading pairs?
Yes! Loop through pairs and overlay charts using Plotly’s add_trace().
4. Is historical data available?
Shrimpy provides historical candles, order books, and trades.
5. How do I secure my API keys?
Use environment variables or a secrets manager—never hardcode keys.
Next Steps
- Automate Trading: Connect this script to a trading strategy.
- Add Indicators: Overlay moving averages or RSI.
- Explore Shrimpy’s API: Access order books, trades, and portfolio endpoints.
For more tutorials, check out:
Shrimpy simplifies crypto trading with APIs and portfolio tools. Learn more at Shrimpy.io.