| name | bybit-api |
| description | Reference for Bybit exchange V5 API integration. Use when implementing order placement, balance queries, funding rate fetching, or WebSocket subscriptions on Bybit. Contains pybit patterns, authentication, and common pitfalls. |
Bybit API Skill
SDK Setup
from pybit.unified_trading import HTTP, WebSocket
session = HTTP(
testnet=False,
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
)
ws = WebSocket(
testnet=False,
channel_type="private",
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
)
Common Operations
Place Limit Order (PostOnly)
result = session.place_order(
category="linear",
symbol="ETHUSDT",
side="Buy",
orderType="Limit",
qty="0.5",
price="3000",
timeInForce="PostOnly",
)
Cancel Order
result = session.cancel_order(
category="linear",
symbol="ETHUSDT",
orderId="ORDER_ID",
)
Set Stop-Loss and Take-Profit
result = session.set_trading_stop(
category="linear",
symbol="ETHUSDT",
stopLoss="2900",
takeProfit="3200",
positionIdx=0,
)
Get Balance
result = session.get_wallet_balance(accountType="UNIFIED")
Get Positions
result = session.get_positions(
category="linear",
symbol="ETHUSDT",
)
Get Funding Rate
ticker = session.get_tickers(category="linear", symbol="ETHUSDT")
history = session.get_funding_rate_history(
category="linear",
symbol="ETHUSDT",
limit=10,
)
Set Leverage
session.set_leverage(
category="linear",
symbol="ETHUSDT",
buyLeverage="3",
sellLeverage="3",
)
WebSocket Streams
ws.order_stream(callback=handle_order_update)
ws.position_stream(callback=handle_position_update)
ws.execution_stream(callback=handle_execution)
ws_public = WebSocket(testnet=False, channel_type="linear")
ws_public.ticker_stream(symbol="ETHUSDT", callback=handle_ticker)
Pitfalls
- V5 API only — do NOT use V3 endpoints
- All qty and price values are STRINGS in API calls
- Unified Trading Account — ensure account is in unified mode
- positionIdx: 0 for one-way mode, 1 for buy-side hedge, 2 for sell-side hedge
- Funding settles every 8 HOURS (00:00, 08:00, 16:00 UTC)
- Symbol format: "ETHUSDT" for linear perps (not "ETH" like Hyperliquid)
- Rate limit: 10 req/sec for order endpoints, 120 req/min for info
- set_trading_stop() can ONLY be called on existing positions
- PostOnly orders rejected if they would immediately match (no fill)