Skip to main content

Async Python library for fetching OHLCV market data from multiple free providers

Project description

ohlcv-router

CI Python 3.11+ License: MIT

Async Python library for fetching OHLCV (candlestick) market data from multiple free providers. Automatically routes symbols to the best available data source and falls back gracefully when a provider fails.

BTCUSDT  →  Binance  →  CoinGecko  →  Kraken  →  KuCoin  →  yfinance
AAPL     →  yfinance  →  Tiingo (daily/weekly)  →  Finnhub
WM.TO    →  yfinance  →  Finnhub
EURUSD   →  yfinance  →  Finnhub

Features

  • Multi-provider — Binance, CoinGecko, Kraken, KuCoin, yfinance, Tiingo, Finnhub with automatic fallback
  • Auto-routing — asset class detection picks the right provider chain per symbol
  • Async — built on asyncio / aiohttp, no blocking calls
  • Typed — full type annotations, py.typed marker included
  • CLIohlcv fetch BTCUSDT 1d 30 out of the box
  • Intervals1m, 5m, 15m, 1h, 4h, 1d, 1w
  • Resilient — structured logging on every provider attempt and failure

Installation

pip install ohlcv-router

Or from source:

git clone https://github.com/FaustoS88/ohlcv-router.git
cd ohlcv-router
pip install -e ".[dev,cli]"

Quick Start

import asyncio
from ohlcv_router import fetch

async def main():
    # Crypto — routes to Binance automatically
    candles = await fetch("BTCUSDT", interval="1d", limit=10)
    for c in candles[-3:]:
        print(f"{c.time}  O:{c.open:.2f}  H:{c.high:.2f}  L:{c.low:.2f}  C:{c.close:.2f}")

asyncio.run(main())

CLI

# Basic fetch (auto-routes to best provider)
ohlcv fetch BTCUSDT

# Custom interval and limit
ohlcv fetch AAPL 1d 30

# Force a specific provider
ohlcv fetch EURUSD 1d 20 --provider yfinance

# Output as CSV
ohlcv fetch BTCUSDT 1d 10 --csv

Supported Intervals

Interval Description
1m 1 minute
5m 5 minutes
15m 15 minutes
1h 1 hour
4h 4 hours
1d Daily
1w Weekly

Provider Routing

Asset class Pattern example Provider chain
Crypto BTCUSDT Binance → CoinGecko → Kraken → KuCoin → yfinance
US stocks AAPL, ^GSPC yfinance → Tiingo (daily/weekly) → Finnhub
Intl stocks WM.TO, RIO.L yfinance → Finnhub
Forex EURUSD yfinance → Finnhub

Tiingo requires TIINGO_API_KEY. Finnhub requires FINNHUB_API_KEY and a paid plan — the free tier does not include historical candles. Both fall back gracefully when the key is absent or the plan lacks access.

CoinGecko requires no API key. It supports 4h and 1d intervals only (granularity is automatic). Volume is not available from the OHLC endpoint and is always 0.

Kraken requires no API key. Public REST API for all listed crypto pairs. Supports all standard intervals from 1m to 1w. Returns up to 720 bars per request.

KuCoin requires no API key. Public REST API supporting all standard intervals from 1m to 1w. Returns up to 1500 bars per request. Uses BASE-QUOTE symbol format internally (e.g. BTC-USDT).

Examples

See examples/ for runnable scripts:

Roadmap

Done

  • Binance, CoinGecko, Kraken, KuCoin, yfinance, Tiingo, Finnhub providers
  • CLI tool: ohlcv fetch BTCUSDT 1d 100
  • Session reuse, structured logging, full type annotations
  • Published on PyPI: pip install ohlcv-router

Planned

  • Response caching (TTL-based, in-memory)
  • OKX and Bybit providers
  • Async context manager support

License

MIT

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

ohlcv_router-0.1.1.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

ohlcv_router-0.1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file ohlcv_router-0.1.1.tar.gz.

File metadata

  • Download URL: ohlcv_router-0.1.1.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ohlcv_router-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cde817cf62c2a6081b1a5e3de907884b7b9eaabbecafa125008e194853177dcf
MD5 06a9605212973739de5096eac8c1a450
BLAKE2b-256 538cb2632ee39ff501d9efb9a30a793a0601dad8cf774946f3ce17f45da5266a

See more details on using hashes here.

File details

Details for the file ohlcv_router-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ohlcv_router-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ohlcv_router-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ecb4ed7496f2bd9b93ee7f85e7e1e074ddc324640730b2dad8565d29f4eb8732
MD5 c0bb5835f7267cd8f8ae0103dd5e04be
BLAKE2b-256 d2d4c66dfbf612f55ae0378f814b882f51a6717705d7e5b8c74f0f9b5e8f45aa

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