TraderSDKdocs

Reference

Python API#

Module tradersdk. Two classes with identical methods: PyBybitTrader and PyBingxTrader. They are separate classes, not related by inheritance. See Python for a walkthrough.

Constructor#

PyBybitTrader(api_key: str, api_secret: str, testnet: bool, market_type: str)
PyBingxTrader(api_key: str, api_secret: str, testnet: bool, market_type: str)

market_type: spot, swap, futures or perp, case-insensitive. Anything else raises ValueError.

Info#

Method Returns
exchange_name() str
market_type() str
format_symbol(symbol) str, the exchange's own symbol format

These three are synchronous. Everything below is async.

Market data#

Method Returns
get_current_price(symbol) float
get_ticker(symbol) dict
get_orderbook(symbol, depth) dict with bids, asks, plus computed best_bid, best_ask, spread
get_prices_batch(symbols) dict[str, float \| None], one request per symbol, None on failure
get_server_time() int, milliseconds
test_connection() bool

Account#

Method Returns
get_balance() dict; each balance entry has free, locked and a computed total
set_leverage(symbol, leverage) bool; symbol is optional (None allowed)

Orders#

await t.place_market_order(symbol: str, side: str, quantity: float) -> dict
await t.place_limit_order(symbol: str, side: str, quantity: float, price: float, reduce_only: bool = False) -> dict
await t.cancel_order(symbol: str, order_id: str) -> bool
await t.get_order_status(symbol: str, order_id: str) -> dict
await t.close_position(symbol: str) -> dict
await t.execute_fast_entry(
    symbol: str, direction: str, usdt_amount: float, leverage: int,
    tp_percent: float | None = None, sl_percent: float | None = None,
    current_price: float | None = None,
) -> dict

side is buy/long or sell/short, case-insensitive. Anything else raises ValueError. direction for execute_fast_entry is not validated: anything except long sells. TP/SL are only applied on Bybit swap; BingX ignores them. See Fast entry.

Errors#

Exception When
ValueError Bad market type or side.
RuntimeError The exchange or the network failed; the message comes from the adapter.

Not available in Python#

Funding and open-interest history, WebSocket streams, order-update subscriptions, dry-run order tests, capabilities and the utility crates. Use Rust for those.

Edit this page on GitHub ↗