Skip to main content

Data infrastructure built with ♥︎ by Laakhay

Project description

Laakhay Data

Professional Python library for cryptocurrency market data.

Async-first, type-safe wrapper for exchange APIs. Supports candles, order books, trades, liquidations, open interest, funding rates, and more.

Install

pip install -e .

Quick Start

import asyncio
from laakhay.data.providers.binance import BinanceProvider
from laakhay.data.core import TimeInterval, MarketType

async def main():
    # Spot market
    async with BinanceProvider(market_type=MarketType.SPOT) as provider:
        # Candles
        candles = await provider.get_candles("BTCUSDT", TimeInterval.M1, limit=100)
        
        # Order book
        ob = await provider.get_order_book("BTCUSDT", limit=20)
        print(f"Spread: {ob.spread_bps:.2f} bps, Pressure: {ob.market_pressure}")
        
        # Recent trades
        trades = await provider.get_recent_trades("BTCUSDT", limit=100)
        print(f"Buy volume: {sum(t.value for t in trades if t.is_buy)}")

asyncio.run(main())

Supported Data Types

Type REST WebSocket Markets
Candles Spot, Futures
Symbols - Spot, Futures
Order Book Spot, Futures
Trades Spot, Futures
Liquidations - Futures
Open Interest Futures
Funding Rates Futures
Mark Price - Futures

Key Features

Order Book Analysis

ob = await provider.get_order_book("BTCUSDT")
print(ob.spread_bps)          # Spread in basis points
print(ob.market_pressure)     # bullish/bearish/neutral
print(ob.imbalance)           # -1.0 to 1.0
print(ob.is_tight_spread)     # < 10 bps

Trade Flow

trades = await provider.get_recent_trades("BTCUSDT")
for trade in trades:
    print(f"{trade.side}: ${trade.value:.2f} ({trade.size_category})")

Liquidations (Futures)

async with BinanceProvider(market_type=MarketType.FUTURES) as provider:
    async for liq in provider.stream_liquidations():
        if liq.is_large:
            print(f"{liq.symbol}: ${liq.value_usdt:.2f} {liq.side}")

Open Interest (Futures)

oi_list = await provider.get_open_interest("BTCUSDT", historical=True)
async for oi in provider.stream_open_interest(["BTCUSDT"], period="5m"):
    print(f"OI: {oi.open_interest}")

Funding Rates (Futures)

# Historical (applied rates)
rates = await provider.get_funding_rate("BTCUSDT", limit=10)

# Real-time (predicted rates)
async for rate in provider.stream_funding_rate(["BTCUSDT"]):
    print(f"Funding: {rate.funding_rate_percentage:.4f}%")

Architecture

laakhay/data/
├── core/           # Base classes, enums, exceptions
├── models/         # Pydantic models (Candle, OrderBook, Trade, etc.)
├── providers/      # Exchange implementations
│   └── binance/    # Binance provider + WebSocket mixin
├── clients/        # High-level clients
└── utils/          # HTTP, retry, WebSocket utilities

Principles:

  • Async-first (aiohttp, asyncio)
  • Type-safe (Pydantic models)
  • Explicit APIs
  • Comprehensive testing

Models

All models are immutable Pydantic models with validation:

from laakhay.data.models import (
    Candle,        # OHLCV data
    Symbol,        # Trading pairs
    OrderBook,     # Market depth (25+ properties)
    Trade,         # Individual trades
    Liquidation,   # Forced closures
    OpenInterest,  # Outstanding contracts
    FundingRate,   # Perpetual funding
    MarkPrice,     # Mark/index prices
)

Exception Handling

from laakhay.data.core import (
    LaakhayDataError,      # Base exception
    ProviderError,         # API errors
    InvalidSymbolError,    # Symbol not found
    InvalidIntervalError,  # Invalid interval
)

try:
    candles = await provider.get_candles("INVALID", TimeInterval.M1)
except InvalidSymbolError:
    print("Symbol not found")
except ProviderError as e:
    print(f"API error: {e}")

License

MIT License - see LICENSE

Contact


Built by Laakhay Corporation

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

laakhay_data-0.0.1.tar.gz (52.4 kB view details)

Uploaded Source

Built Distribution

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

laakhay_data-0.0.1-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file laakhay_data-0.0.1.tar.gz.

File metadata

  • Download URL: laakhay_data-0.0.1.tar.gz
  • Upload date:
  • Size: 52.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for laakhay_data-0.0.1.tar.gz
Algorithm Hash digest
SHA256 60c84f9aebcfbac83b50de5a58511b7cb0ba9bfb4c8f34b94ad81665fde957c8
MD5 9545fdeb59d21e7b7b8f1b5c382995e5
BLAKE2b-256 1356da8fd7fd02c4925289bbd5c58b1d12fd7fd5581fc5a7a9bc2ed641e77286

See more details on using hashes here.

File details

Details for the file laakhay_data-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: laakhay_data-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for laakhay_data-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87f4dcf00b76ed0dd70386d178a3279603095f7bb27f0d7680b572ebe2d6bc1c
MD5 f49e5437d3d3d0914a0ba512d41be7e7
BLAKE2b-256 1f7d6015abc1fff66ca06dd97bebb79a5fd0cbcc80f6a11aa6f0a0423f46bdcf

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