bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
340 stars 113 forks source link

new implementation of _process_delta_orderbook to reduce complexity #198

Closed MFelex closed 3 days ago

MFelex commented 3 months ago

Optimize algorithm to reduce complexity from O(n^2) to O(n) in _process_delta_orderbook method

dextertd commented 2 months ago

I tested this but there is a failure in the logic somewhere because running it for a couple of minutes brings the number of items in the bid and ask lists to zero.

from pybit.unified_trading import WebSocket
from time import sleep

ws = WebSocket(
    testnet=False,
    channel_type="linear",
)

def handle_message(message):
    print(len(message["data"]["a"]), len(message["data"]["b"]), message)

ws.orderbook_stream(50, "BTCUSDT", handle_message)

while True:
    sleep(1)
dextertd commented 3 days ago

Closing to cleanup but feel free to reopen in future