Skip to main content

bytx — by BYTtrade

English | Русский | 中文 | Español | Português | 日本語 | 한국어 | Türkçe

PyPI Python License

A typed async Python SDK for crypto exchanges. One interface for spot and perpetual futures on Binance, Bybit, OKX, BingX, Hyperliquid, KuCoin, Bitget; in beta: Gate, MEXC, HTX, BloFin (spot and USDT-M futures).

One API for every exchange

pip install bytx            # + extras: [ws] [fast]

Quick start

import asyncio
from bytx import create_exchange

async def main():
    async with create_exchange('bybit', api_key='…', secret='…', demo=True) as ex:
        print(await ex.ticker('BTC/USDT'))                      # BTC/USDT:USDT, swap by default
        order = await ex.buy('BTC/USDT', notional=100, price=60_000, post_only=True)
        print(order.status, order.size)                         # size in BTC, not in contracts
        await ex.cancel_order('BTC/USDT', order.id)

asyncio.run(main())

demo=True uses the exchange's demo/testnet; no real money involved. Market data needs no keys at all: create_exchange('okx').

Take-profit and stop-loss — one call on every exchange:

await ex.set_tp_sl('BTC/USDT', take_profit=72_000, stop_loss=58_000)

A live order book that survives disconnects:

async for book in ex.stream.order_book('BTC/USDT', depth=20):
    print(book.best_bid, book.best_ask, book.spread_bps, book.imbalance(5))

Live order book

Paper trading on the live order book — no keys, no real money:

from bytx.paper import PaperConfig

ex = create_exchange('binance', paper=True, paper_config=PaperConfig(balance={'USDT': 1000}))
order = await ex.buy('BTC/USDT', notional=100)     # walks the book, real taker fee

Paper trading

Spot, execution algorithms, risk-based sizing:

spot = create_exchange('okx', market='spot', api_key=…, secret=…, password=…, demo=True)
await spot.buy('DOGE/USDT', notional=10)                              # market buy for 10 USDT, one request
await ex.algos.twap('BTC/USDT', 'buy', size=0.5, duration=600)       # also chase, iceberg, bracket, trailing_stop
await ex.open_position('BTC/USDT', 'long', risk_usdt=50, stop=58_000) # size from the stop distance

More in examples/: market data, backtest, arbitrage scanner, grid, DCA, Telegram alerts, scalper, multi-account, strategy with restart recovery.

Why bytx

bytx is built on ccxt and turns it into a trading SDK you don't have to fight.

  • One line instead of a page. buy('BTC/USDT', notional=100) — no contract sizes, precision or minimums to compute by hand; size in the base coin on every exchange.
  • No double entries. On a timeout bytx finds the order by client_id and tells you exactly what happened (OrderStatusUnknown only when the exchange really can't say).
  • Same call everywhere. TP/SL, leverage, margin and position mode, dead-man switch, transfers — one method instead of each exchange's private endpoints.
  • WebSocket that stays up. Reconnect with backoff, silence watchdog, resubscribe, order book gap checks and resync from a snapshot.
  • Checked against the exchange docs. Every exchange rule is tested against response examples from the official documentation; ccxt bugs found this way are fixed in the SDK.
  • Typed models and clear errors. Order, Position, OrderBook dataclasses; one BytxError hierarchy with a .retryable flag; keys never appear in error text or logs.
  • Ready for production. A proxy per account, one market cache per process, paper trading and replay, a position journal, API-key permission checks and exchange health.
Raw ccxt vs bytx: buy BTC for 100 USDT on OKX perpetuals
# raw ccxt
ex = ccxt.okx({'apiKey': key, 'secret': secret, 'password': passphrase})
await ex.load_markets()
m = ex.market('BTC/USDT:USDT')
price = (await ex.fetch_ticker(m['symbol']))['last']
contracts = 100 / price / m['contractSize']               # OKX: 1 contract = 0.01 BTC
amount = float(ex.amount_to_precision(m['symbol'], contracts))
if amount < m['limits']['amount']['min']:
    raise ValueError('order too small')
order = await ex.create_order(m['symbol'], 'market', 'buy', amount)   # dict, amount in contracts
# bytx
async with bytx.create_exchange('okx', api_key=key, secret=secret, password=passphrase,
                                margin_mode='cross') as ex:
    order = await ex.buy('BTC/USDT', notional=100)        # Order model, size in BTC

No-code bots, backtests and trade confirmations in Telegram — at byttrade.com.

Documentation

The full guide — every method, exchange specifics, errors, recovery after a restart: docs/GUIDE.md (на русском).

Features · Spot · WebSocket · Scalping · Paper trading · Algorithms · Risk sizing · Restart recovery · Proxies · Integrations · Errors

License

Free to use under the BYTtrade Source-Available License, including commercially; copying the code into other libraries, modified versions and hosted services are not permitted. Uses ccxt (MIT), see NOTICE. Not financial advice; trading cryptocurrency carries a risk of loss.

Metadata

Release files for bytx 0.2.3

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

Source distribution (sdist)

Source distribution for bytx 0.2.3
File Size Uploaded Provenance Actions
bytx-0.2.3.tar.gz 664.7 kB Without provenance Details for bytx-0.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 1.5 MB

Release files / bytx-0.2.3.tar.gz

Download URL bytx-0.2.3.tar.gz
Size 664.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a9f9fa2d96b6cbdb4a33d2e01b7ccee68b3da942ebb3ea3885c5a9544c0a2811
BLAKE2b-256 checksum
How to use checksums
3facc9e12ba5a032d4c1042e6f3e5b9aad6303553a9a1e7a862a475a05fd5aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / bytx-0.2.3-py3-none-any.whl

Download URL bytx-0.2.3-py3-none-any.whl
Size 796.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1978530b6d10f3a091f94838c51546a1105f52d21ace328cc39420de54400e15
BLAKE2b-256 checksum
How to use checksums
b18ce8e65f839993f27e9ff4f6d9522cc534f721012bf8b644c9fefdc73977f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for bytx 0.2.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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