deribridge
Async, typed Python client and middleware for the Deribit API.
deribridge is a structured layer over Deribit's WebSocket API: a typed transport
client, a higher-level trading interface with order-lifecycle tracking, built-in rate
limiting, and Pydantic models for every response — so you can build trading tooling
without hand-parsing JSON or babysitting reconnects.
It is also the open-source bridge behind deribook, where the same Deribit data feeds real-time portfolio analytics, greeks, P&L, and risk views.
Features
- ⚡ Async-first — built on
asyncioandwebsockets - 🧩 Typed models — Pydantic models for orders, order books, tickers, positions, trades, account summaries, and more
- 🛡️ Thread-safe order tracking — lifecycle tracking with an internal lock and order history
- 🔁 Resilient — managed background monitoring task with cancellation + auto-restart
- 🚦 Rate limiting — built-in
RateLimiterto stay within Deribit limits - 🧪 Test & production environments — switch with a single flag
- 📊 Analytics-ready — response models that work well for portfolio dashboards, risk monitors, and tools like deribook
Installation
pip install deribridge
Until the first PyPI release you can install straight from GitHub:
pip install git+https://github.com/fracasamax/deribridge.git
Requires Python ≥ 3.12.
Development install
git clone https://github.com/fracasamax/deribridge.git
cd deribridge
uv sync # or: pip install -e .
Configuration
Credentials are read from environment variables. configure() calls
python-dotenv's load_dotenv() by default (pass load_dotenv_file=False to
disable any working-directory file read). Copy the example file and fill in your
Deribit API keys:
cp .env.example .env
DERIBIT_API_CLIENT_ID=your_client_id
DERIBIT_API_SECRET=your_client_secret
# Optional test-environment keys
DERIBIT_API_CLIENT_ID_TEST=your_test_client_id
DERIBIT_API_SECRET_TEST=your_test_client_secret
Quick start
import asyncio
from deribridge import DeribitAPIInterface
async def main():
api = DeribitAPIInterface.configure(use_test_env=True)
if await api.start_client():
await api.subscribe_to_ticker("BTC-PERPETUAL")
ticker = await api.get_ticker("BTC-PERPETUAL")
print(f"BTC-PERPETUAL mark price: {ticker.mark_price}")
await api.stop_client()
asyncio.run(main())
Fuller runnable examples live in examples/ — instrument parsing
and order building (no credentials), connecting a client, and a full
connect → quote → place/cancel flow (gated behind an env flag, testnet only).
Documentation
- docs/GUIDE.md — compact usage guide for developers (install, config, quick start, placing orders safely).
- docs/AI_REFERENCE.md — dense technical reference for building tooling (and for AI coding agents): full API surface, lifecycle & concurrency model, the three-outcome order contract, and known gotchas.
For a production example of the kind of analytics layer this bridge supports, see deribook.com.
Order safety: order-mutating calls (
submit_order,submit_limit_order,cancel_order,replace_order) have three outcomes — success, definite failure (None), and indeterminate (IndeterminateOrderError, raised on timeout/disconnect). On indeterminate, reconcile viaget_order_state/get_open_ordersbefore retrying — never resubmit blindly. See the guides above.
Project layout
src/deribridge/
├── api_client/ # WebSocket client, API interface, rate limiter, response models
├── classes/ # Domain types (Order, Instrument, Currency, ...)
└── models/ # Enums / value models (OrderType, TimeInForce, Interval, ...)
Key exports
DeribitWebSocketClient, DeribitWebSocketError, DeribitAPIInterface,
EnhancedDeribitClient, RateLimiter, plus response models (Order, OrderBook,
Position, Trade, Ticker, AccountSummary, TransactionLogEntry, …) and domain
types (Instrument, Currency, OrderPurpose). See __all__ in the package
__init__ for the full list.
Used by
- deribook — stats and advanced analytics for
derivatives portfolios on Deribit (greeks, P&L, risk, and more).
deribridgeis the open-source client layer it's built on. If you trade options or futures on Deribit and want a clearer view of your book, take a look.
Using deribridge in your own project? Open a PR adding it here.
Stability & compatibility
deribridge is beta (0.x): public names and return types may change
between minor releases, and the high-level trading helpers in particular are
still evolving. Pin a version if you need stability, and check the
CHANGELOG for breaking changes.
- Targets the Deribit WebSocket JSON-RPC v2 API, with both test and
production endpoints (switch via
use_test_env). - Supported on Python 3.12 and 3.13.
- Deribit may change its API at any time; tracking those changes may require updates here.
⚠️ Disclaimer
This software interacts with live financial markets and can place real orders. It is provided as is, without warranty of any kind. Trading derivatives carries substantial risk of loss. Use the test environment first, and you are solely responsible for any use in production. This project is not affiliated with Deribit.
Author
Built and maintained by Francesco Casamassima (dev@elnc.eu) — also the developer behind deribook. Contributions, issues, and feedback are welcome.
License
MIT © 2026 Francesco Casamassima
Metadata
Release files for deribridge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| deribridge-0.1.0.tar.gz | 137.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| deribridge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 206.4 kB
Release files / deribridge-0.1.0.tar.gz
| Download URL | deribridge-0.1.0.tar.gz |
|---|---|
| Size | 137.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6742cb4a615390e03895b3f2093096f813870a26e6f3b07e7750abadd5290b9
|
|
BLAKE2b-256 checksum How to use checksums |
0a164b940c61eeeb6e937d848f7f74727c95636bb9e6c4d708ebb823a20fb736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / deribridge-0.1.0-py3-none-any.whl
| Download URL | deribridge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 69.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d36dcc0b40a0507e1e038e40113740a8bc3541a9d4fe9dc2e9b7506753769efb
|
|
BLAKE2b-256 checksum How to use checksums |
dbeefee9405a9305b904f0471ea7b087825a39da17c42b050dd3b3161d195843
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|