Skip to main content

betdex

A Python client for the BetDEX Exchange API (REST and Stream).

  • One typed method per endpoint on a single BetDexClient
  • Responses are dataclasses; each keeps its raw JSON (.raw) plus sent_at, received_at and latency_ms
  • A blocking stream with pluggable listeners.
pip install betdex

Quick Start

from betdex import BetDexClient

client = BetDexClient(app_id, api_key, wallet_id, environment="sandbox")  # or "prod"
client.create_session()

markets = client.get_markets(statuses=["Open"], size=10).markets
live = [m for m in markets if m.is_in_play]

book = client.get_market_prices_v2(markets[0].id).prices[0]
best_back = book.available_to_back(outcome_id)[:1]
best_lay = book.available_to_lay(outcome_id)[:1]

Orders

from betdex.utils import batch, new_reference

order = client.create_order(market_id, outcome_id, "For", price=2.5, stake=10,
                            keep_when_in_play=False, reference=new_reference("bot_")).orders[0]
print(order.status, order.stake_matched, order.liability)

for result in batch(client.create_orders, requests):    # 50 per call
    ...

client.cancel_orders(wallet_ids=[wallet_id])

Paging

  • Many endpoints are paginated. A paginate utility is supplied:
from betdex.utils import paginate

for page in paginate(client.get_markets, event_ids=["123"]):
    ...

Errors

  • All errors derive from BetDexError:
from betdex import BetDexAPIError, BetDexTransportError

try:
    client.get_order("123")
except BetDexAPIError as exc:          # error status: status_code, title, details, response
    print(exc.status_code, exc.title, exc.latency_ms)
except BetDexTransportError as exc:    # no response
    print(exc, exc.latency_ms)

Streaming

import threading
from betdex.streaming import MarketBook, OrderUpdate, StreamListener

listener = StreamListener()
stream = client.create_stream(listener)
stream.subscribe_to_orders()
stream.subscribe_to_market_prices(["123"])         # or no argument for every market
threading.Thread(target=stream.start, daemon=True).start()

while True:
    update = listener.output_queue.get()
    if isinstance(update, MarketBook):
        best_back = update.available_to_back(outcome_id)[:1]
    elif isinstance(update, OrderUpdate):
        filled = update.stake_matched
  • start() blocks; stop() ends it from any thread
  • On a dropped connection start() raises BetDexSocketError; call it again to reconnect and resubscribe
  • Updates missed while disconnected aren't replayed; catch up on orders with get_orders
  • For raw frames, subclass BaseListener and override on_data(raw)

Execution

from betdex.execution import add_ticks, round_down_to_nearest_price

round_down_to_nearest_price(5.55)    # 5.5
add_ticks(1.99, 2)                   # 2.02

Metadata

Release files for betdex 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for betdex 0.2.0
File Size Uploaded Provenance
betdex-0.2.0.tar.gz 32.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for betdex 0.2.0
File Interpreter ABI Platform
betdex-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 78.7 kB

Release files / betdex-0.2.0.tar.gz

Download URL betdex-0.2.0.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e645b94caec0d2bb716156db7e22153177997602a6e04e246784b67f3e81a083
BLAKE2b-256 checksum
How to use checksums
d22c821ade0d2d2457b6b40e7843987d84982ab1084f9a8804d810aa7c30f60b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / betdex-0.2.0-py3-none-any.whl

Download URL betdex-0.2.0-py3-none-any.whl
Size 45.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9966b62edb3e860b4cebd25edbfefff932b69072ef528fe758b72e17c6b4ffd
BLAKE2b-256 checksum
How to use checksums
71cbd8a0557b088acddd0aa32ef720a7d730c40fb4bbd5fc1d30e34bf11c9c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for betdex 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for betdex-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page