bytx — by BYTtrade
English | Русский | 中文 | Español | Português | 日本語 | 한국어 | Türkçe
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).
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))
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
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_idand tells you exactly what happened (OrderStatusUnknownonly 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,OrderBookdataclasses; oneBytxErrorhierarchy with a.retryableflag; 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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bytx-0.2.2.tar.gz | 664.4 kB | Without provenance | Details for bytx-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bytx-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for bytx-0.2.2-py3-none-any.whl |
Total release size: 1.5 MB
Release files / bytx-0.2.2.tar.gz
| Download URL | bytx-0.2.2.tar.gz |
|---|---|
| Size | 664.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0dafb8cb1d9e436346783188853395dadad93131cf94f63a8117f6d829fa996
|
|
BLAKE2b-256 checksum How to use checksums |
1c806c650e19c54a2c77691d2ebeb2debf6c51e974c0e30d633e68b7c3e7b2e4
|
| 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.2-py3-none-any.whl
| Download URL | bytx-0.2.2-py3-none-any.whl |
|---|---|
| Size | 795.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84bade521bc65ed0e522ccf8026d967040cb8c481334de91649102c46937eecf
|
|
BLAKE2b-256 checksum How to use checksums |
34d073d6717c5bade1b1be38913913d0f12e651b2e1aee407667e7d9dcd0eea2
|
| 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.2
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.