Skip to main content

A Python library for fetching cryptocurrency data from Coinbase

Project description

Coinbase Data Fetcher

A Python CLI and library for fetching historical crypto price data from Coinbase with caching support.

Features

  • Fetch historical price data for multiple cryptocurrencies
  • Built-in rate limiting and retry logic
  • Local caching to minimize API calls
  • Support for multiple time granularities (1min, 5min, 15min, 1hour, 6hour, 1day)
  • Optional candlestick high/low interpolation
  • Progress bar support
  • Command-line tool for batch data fetching

Installation

pip install coinbase-data-fetcher

Command Line Tool

After installation, you can use the coinbase-fetch command to fetch data:

# List all supported coins
coinbase-fetch --list-coins

# Pre-fetch all data for all coins and granularities
coinbase-fetch

# Pre-fetch all data with custom date range
coinbase-fetch --start-date 2024-01-01 --end-date 2024-01-31

# Pre-fetch specific coin (all granularities)
coinbase-fetch --coin bitcoin

# Pre-fetch XRP (Ripple) data
coinbase-fetch --coin xrp --granularity 3600

# Pre-fetch various cryptocurrencies
coinbase-fetch --coin avalanche --granularity 3600
coinbase-fetch --coin polygon --granularity 300
coinbase-fetch --coin uniswap --granularity 900

# Pre-fetch specific coin and granularity
coinbase-fetch --coin bitcoin --granularity 3600

# Pre-fetch with custom date range
coinbase-fetch --coin bitcoin --granularity 3600 --start-date 2023-01-01 --end-date 2023-12-31

# Use custom cache directory
coinbase-fetch --cache-path /custom/cache/path

# Don't save CSV files (cache only)
coinbase-fetch --no-csv

# Enable price interpolation using candlestick hi/lo data
coinbase-fetch --coin bitcoin --granularity 3600 --interpolate-price

Command Line Options

  • --list-coins: List all supported coins with their start dates
  • --coin: Specific coin to fetch (e.g., bitcoin, ethereum, xrp, ada)
  • --granularity: Time granularity in seconds (60, 300, 900, 3600, 21600, 86400)
  • --start-date: Start date for fetching (e.g., 2023-01-01). Default: earliest available date for the coin
  • --end-date: End date for fetching (e.g., 2023-12-31). Default: yesterday
  • --interpolate-price: Enable price interpolation using candlestick hi/lo data (default: disabled)
  • --cache-path: Override default cache directory
  • --no-csv: Don't save CSV files, only cache JSON data

Python API Usage

Object-Oriented Interface

from coinbase_data_fetcher import CoinDataModel, CoinData, Coins
import pandas as pd

# Create a model for Bitcoin data
model = CoinDataModel(
    coin=Coins.BITCOIN,
    data_granularity=3600,  # 1 hour
    start_date=pd.Timestamp('2023-01-01'),
    end_date=pd.Timestamp('2023-12-31'),
    price_interpolation='mean'
)

# Create data fetcher
coin_data = CoinData(model)

# Fetch prices
df = coin_data.fetch_prices()

Direct API Usage

from coinbase_data_fetcher import fetch_prices, Coins

df = fetch_prices(
    coin=Coins.ETHEREUM,
    start_time='2023-06-01',
    end_time='2023-06-30',
    granularity=300,  # 5 minutes
    use_candle_hi_lo=True
)

Programmatic Pre-fetching

from coinbase_data_fetcher import fetch_data_for_coin

# Pre-fetch specific coin and granularity
fetch_data_for_coin('bitcoin', 3600)  # Bitcoin, 1 hour granularity

# Pre-fetch with custom parameters
fetch_data_for_coin(
    'ethereum', 
    300,  # 5 minute granularity
    start_date='2024-01-01',
    end_date='2024-01-31',
    save_csv=False,  # Only cache, don't save CSVs
    interpolate_price=False  # Raw candlestick data
)

Configuration

Set the cache directory using environment variable:

export COINBASE_CACHE_PATH=/path/to/cache

Or programmatically:

from coinbase_data_fetcher.config import config
config.cache_path = '/path/to/cache'

Available Coins

The library supports 57 cryptocurrencies available on Coinbase, including:

Major Cryptocurrencies

  • Bitcoin (BTC-USD) - Since 2015-07-20
  • Ethereum (ETH-USD) - Since 2016-07-21

Top Market Cap Coins

  • Solana (SOL-USD), Ripple (XRP-USD), Cardano (ADA-USD)
  • Avalanche (AVAX-USD), Polkadot (DOT-USD), Polygon (MATIC-USD)
  • Chainlink (LINK-USD), Dogecoin (DOGE-USD)

DeFi Tokens

  • Uniswap (UNI-USD), Aave (AAVE-USD), Curve (CRV-USD)
  • Maker (MKR-USD), Compound (COMP-USD), SushiSwap (SUSHI-USD)

Layer 2 Solutions

  • Arbitrum (ARB-USD), Optimism (OP-USD)

Gaming & Metaverse

  • Sandbox (SAND-USD), Decentraland (MANA-USD), ApeCoin (APE-USD)
  • Axie Infinity (AXS-USD), ImmutableX (IMX-USD)

And many more...

Including Cosmos (ATOM), Filecoin (FIL), The Graph (GRT), Algorand (ALGO), and others.

Use coinbase-fetch --coin <name> with the lowercase name (e.g., bitcoin, ethereum, avalanche)

To see all available coins with their start dates, run:

coinbase-fetch --list-coins

Development

Setup

  1. Clone the repository
  2. Create and activate a virtual environment:
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install development dependencies:
    pip install -e ".[dev]"
    

Testing

Run tests with pytest:

source .venv/bin/activate
pytest

Run tests with coverage:

pytest --cov=coinbase_data_fetcher

Code Quality

The project uses Ruff for linting and Pyright for type checking:

ruff check src tests
pyright

Requirements

  • Python 3.9+
  • Dependencies managed via pyproject.toml

API Rate Limiting

The library includes built-in rate limiting (10 calls per second) and automatic retry logic with exponential backoff to handle Coinbase API limits gracefully.

Caching

Fetched data is automatically cached locally to minimize API calls. The cache directory can be configured via the COINBASE_CACHE_PATH environment variable.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coinbase_data_fetcher-0.4.1.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coinbase_data_fetcher-0.4.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file coinbase_data_fetcher-0.4.1.tar.gz.

File metadata

  • Download URL: coinbase_data_fetcher-0.4.1.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for coinbase_data_fetcher-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ebc72cbe9822e6558bac5f45fc942e9f785d9654f981c157b77ffa852efe308a
MD5 a2a73ce725b60953514a35e9c3027e8e
BLAKE2b-256 a0c4c2efe5dfdf8222a3703de455a5b318818d08893db027d81022414ba1fe9d

See more details on using hashes here.

File details

Details for the file coinbase_data_fetcher-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for coinbase_data_fetcher-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20c540bf00cd46ec622a19c11c631ab92f3642ae8159f71dec14726f30c83bee
MD5 c55759b50f2f9e61c136daaf1a5ab406
BLAKE2b-256 80d762c24e04dc97b9ebd6aa33f1d6bc7e28166a842dccd05f363324ab2aa58b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page