Category Archives: Python

Subscribing to all ByBit trade streams in Python

from pybit.unified_trading import WebSocket
from pybit.unified_trading import HTTP
from time import sleep

session = HTTP(testnet=False)

info = session.get_instruments_info(category="spot")

symbol_infos = info["result"]["list"]

websockets = []

def handle_message(message):
    print(message)

def subscribe(websockets, symbols):
    print(f'Subscribing to {symbols}')
    ws = WebSocket(
        testnet=False,
        channel_type="spot",
    )
    ws.trade_stream(symbol=symbols, callback=handle_message)
    websockets += [ws]
(more…)

Subscribing to ByBit WebSocket streams in Python

Spot is limited to 10 symbols:

from pybit.unified_trading import WebSocket
from time import sleep

ws = WebSocket(
    testnet=True,
    channel_type="spot",
)

def handle_message(message):
    print(message)

#ws.orderbook_stream(50, "BTCUSDT", handle_message)
ws.ticker_stream(symbol=["BTCUSDT", "ETHUSDT"], callback=handle_message)

while True:
    sleep(1)
(more…)

Working with Git in Python on Windows

Disable Python aliases:

(more…)