Skip to main content

Real-time multi-exchange crypto market data in Python — WebSocket streaming, order book metrics, and per-symbol actor workers for Binance, Bybit, and Bitget.

Project description

flowex

CI PyPI Python License

Real-time multi-exchange crypto market data for Python — powered by Go via cgo shared library. WebSocket streaming, order book metrics, and per-symbol actor workers for Binance, Bybit, and Bitget.

No subprocess, no gRPC, no serialization overhead on the hot path. The Go runtime lives inside the Python process. Every symbol gets its own goroutine. get_snapshot() hits the atomic store directly.

Install

pip install flowex

Quick start

import time
from flowex import Manager

mgr = Manager("binance")
mgr.subscribe(["BTCUSDT", "ETHUSDT", "SOLUSDT"])
time.sleep(2)

snap = mgr.get_snapshot("BTCUSDT")
print(snap.depth.spread_bps)
print(snap.depth.mid_price)
print(snap.candles[-1].close)

mgr.close()

Or use as a context manager:

with Manager("binance") as mgr:
    mgr.subscribe(["BTCUSDT"])
    time.sleep(2)
    snap = mgr.get_snapshot("BTCUSDT")

Supported exchanges

  • Binance — futures WebSocket (candles, depth, aggTrade)
  • Bybit — linear futures WebSocket
  • Bitget — USDT futures WebSocket

API

Manager(exchange)

Create a manager for an exchange. Initializes the Go runtime and WebSocket connections.

mgr = Manager("binance")  # or "bybit", "bitget"

mgr.subscribe(symbols)

Subscribe to one or more symbols. Starts candle, depth, and trade streams for each.

mgr.subscribe("BTCUSDT")
mgr.subscribe(["BTCUSDT", "ETHUSDT", "SOLUSDT"])

mgr.get_snapshot(symbol) -> Snapshot | None

Get the latest point-in-time snapshot for a symbol.

snap = mgr.get_snapshot("BTCUSDT")
snap.timestamp      # Unix ms
snap.depth          # DepthMetrics
snap.candles        # list[CandleHLCV]
snap.trades         # list[NormalizedTrade]

mgr.get_all_snapshots() -> dict[str, Snapshot]

Get snapshots for all subscribed symbols in one call.

mgr.unsubscribe(symbol)

Remove all streams for a symbol.

mgr.close()

Shutdown all managers and WebSocket connections.

Data models

DepthMetrics

Order book metrics computed from raw depth data:

Field Description
mid_price (best_bid + best_ask) / 2
spread_bps Spread in basis points
bid_liquidity_10 USD liquidity, top 10 bid levels
ask_liquidity_10 USD liquidity, top 10 ask levels
imbalance_ratio_10 bid_liq / ask_liq (>1 = bullish)
slippage_buy_10k Estimated slippage % for $10k buy

Plus 70+ more fields: liquidity at 5/10/20/50 levels, volumes, imbalance deltas, largest walls, slippage at 8 USD sizes, velocity, momentum, z-scores, and depth quality metrics.

CandleHLCV

candle.ts       # Unix ms
candle.open
candle.high
candle.low
candle.close
candle.volume

NormalizedTrade

trade.timestamp  # Unix ms
trade.price
trade.size
trade.side       # "buy" or "sell"
trade.symbol

Architecture

Python process
|
+-- ctypes loads libflowex.so  <--  Go runtime starts inside Python
|                                    |
|                                    +-- Manager (binance)
|                                    |     +-- Worker: BTCUSDT -> atomic snapshot
|                                    |     +-- Worker: ETHUSDT -> atomic snapshot
|                                    |     +-- Worker: SOLUSDT -> atomic snapshot
|                                    |
|                                    +-- Manager (bybit)
|                                          +-- Worker: BTCUSDT -> atomic snapshot
|
+-- mgr.subscribe(["BTCUSDT"])     ->  FlowexSubscribeBatch()
+-- mgr.get_snapshot("BTCUSDT")    ->  FlowexGetSnapshot() -> atomic.Load -> JSON -> Python
+-- mgr.get_all_snapshots()        ->  FlowexGetSnapshots() -> one call, all symbols

Build from source

Requires Go 1.22+ and Python 3.10+.

# macOS (Apple Silicon)
make build-mac

# Linux (amd64)
make build-linux

# All platforms (requires cross-compilers)
make build-all

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

flowex-0.1.1.tar.gz (13.9 MB view details)

Uploaded Source

Built Distribution

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

flowex-0.1.1-py3-none-any.whl (14.0 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flowex-0.1.1.tar.gz
  • Upload date:
  • Size: 13.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flowex-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0150a69195aa49d8a1db272a6f8210e8d8c785aa4a30dfd30beb43a2f53d0be9
MD5 f7b2c7a8aa54e14ec2a2cca13992e995
BLAKE2b-256 8ebb4687ff08e5eee2eb72aaf07ad80b3faf886aa36851bab6cfacbc9f4f54bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowex-0.1.1.tar.gz:

Publisher: build.yml on KhavrTrading/flowex-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: flowex-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flowex-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cce8ec931baca8d57c344571112b86a9e000f0609d4194c4b6cc1c4510d497b2
MD5 465adab992f8ae988f561b5fb8ef7e8a
BLAKE2b-256 904be3e7692f76df102e2e7a61355f5733e97ff331468bbcf4e3cb2d798e1371

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowex-0.1.1-py3-none-any.whl:

Publisher: build.yml on KhavrTrading/flowex-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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