Skip to main content

The best agentic AI wrapper for Binance orderbook data. Typed schemas, context-window-aware output, built-in data cleaning, and orderbook analytics.

Project description

binance-book

The best agentic AI wrapper for Binance orderbook data.

PyPI License: MIT Python 3.10+

Documentation · PyPI · Examples


  • Typed schemas — Pydantic models for all data types (trade, quote, level, bar, info)
  • Three orderbook representations — levels (per-side), wide (paired), flat (single-row)
  • Context-window-aware output — Auto-sizes data to fit your LLM's token budget
  • Built-in data cleaning — Dust removal, stale quote detection, gap handling, anomaly detection
  • Agentic AI native — Auto-exports tools for OpenAI, Anthropic, and MCP
  • Built-in analytics — Book imbalance, sweep (VWAP), spread computation
  • Standalone — Talks directly to Binance REST/WS APIs, no third-party Binance libs

Install

pip install binance-book

With optional extras:

pip install binance-book[all]        # pandas + numpy + pyarrow
pip install binance-book[dataframe]  # pandas only

Quick Start

from binance_book import BinanceBook

book = BinanceBook()

# Three orderbook representations
book.ob_snapshot("BTCUSDT", max_levels=5)       # per level per side
book.ob_snapshot_wide("BTCUSDT", max_levels=5)  # per level, both sides paired
book.ob_snapshot_flat("BTCUSDT", max_levels=5)  # single row, all levels flattened

# Analytics
book.imbalance("BTCUSDT", levels=5)                         # → -0.55 (ask-heavy)
book.sweep_by_qty("BTCUSDT", side="ASK", qty=10.0)          # → {vwap, total_cost, ...}
book.spread("BTCUSDT")                                       # → {quoted, quoted_bps, mid, ...}

# Data cleaning
book.ob_snapshot("BTCUSDT", max_levels=50, clean=True)       # removes dust orders
book.ob_snapshot("BTCUSDT", max_levels=20, annotate=True)    # adds IS_DUST, IS_OUTLIER cols

# Output formats
book.ob_snapshot_wide("BTCUSDT", format="narrative")         # natural language for LLMs
book.ob_snapshot_wide("BTCUSDT", format="markdown")          # markdown table
book.ob_snapshot_wide("BTCUSDT", format="dataframe")         # pandas DataFrame

# Streaming (async)
async for update in book.ob_stream("BTCUSDT", max_levels=5, format="flat"):
    print(update)

For AI Agents

Every method auto-exports as a callable tool:

# OpenAI function-calling
tools = book.tools(format="openai")
# → Pass to ChatCompletion(tools=tools)

# Anthropic tool_use
tools = book.tools(format="anthropic")
# → Pass to messages.create(tools=tools)

# Dispatch tool calls from LLM responses
result = book.execute("ob_snapshot_wide", {"symbol": "BTCUSDT", "max_levels": 5})

# MCP server mode
book.serve_mcp(port=8080)

No API key is required for public market data. Supports Spot, USDT-M Futures, and COIN-M Futures.

Schema Introspection

book.schema("trade")   # → {'PRICE': 'float', 'SIZE': 'float', 'TRADE_ID': 'int', ...}
book.schema("level")   # → {'SIDE': 'str', 'PRICE': 'float', 'SIZE': 'float', 'LEVEL': 'int', ...}
book.schema("bar")     # → {'OPEN': 'float', 'HIGH': 'float', 'LOW': 'float', 'CLOSE': 'float', ...}
book.schema("quote")   # → {'BID_PRICE': 'float', 'ASK_PRICE': 'float', ...}
book.schema("ticker")  # → {'VOLUME': 'float', 'PRICE_CHANGE_PERCENT': 'float', ...}
book.schema("info")    # → {'SYMBOL': 'str', 'TICK_SIZE': 'float', 'LOT_SIZE': 'float', ...}

Documentation

Full documentation at hero88888888.github.io/binance-python-connector

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

binance_book-0.1.1.tar.gz (59.9 kB view details)

Uploaded Source

Built Distribution

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

binance_book-0.1.1-py3-none-any.whl (70.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: binance_book-0.1.1.tar.gz
  • Upload date:
  • Size: 59.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for binance_book-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff93d0c754872fdc97598f7dfb18186f33fda524052d305c1b155c602a052587
MD5 85872b4dcb721256f5afe521b37048f9
BLAKE2b-256 efdf92cca1c228da4ea9fd7ef19e49a2ce293e20cf552cc805668753a8aed01a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binance_book-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 70.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for binance_book-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 369c7b0dd7ae75b1eb76b8104e26335728f6e06197735f23dae57575ff7eb1fb
MD5 5c8e99cbe9de6bc07bb69a8fe85288a7
BLAKE2b-256 a11500defe467a41bc6c0f80c8cef4f495a04775863a9040a91c8d74fa43fdb8

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