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.0.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.0-py3-none-any.whl (70.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: binance_book-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 748b860a58d5a00097b3b90fa3681761eefb984da842daa49963d77e4ee19dc4
MD5 8df51c5246f59a09c7c6d0ccf64199bd
BLAKE2b-256 b400d9fdebf039e4291204221f7617e932b077c91f1a5af7948a0e0b69357523

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binance_book-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5aced4b401fb9e83f4bd28017a98e704c74d1e240ac593ec1ad072875a6578fa
MD5 c770547b86afb0a0a342d7e9a55bb409
BLAKE2b-256 78a9329888ebcdc653eb11c425a1fd747d5fad3f87bca54cdfd2765b40e4776d

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