in order to manage local order book i had subscribed to the stream:
‘wss://stream.binance.com:9443/ws/btcusdt@depth@100ms’,
unfortunately i found that :
Final update ID - First update ID + 1 != sum of updates ( bids + asks)
Is this normal ???
#My code:
import json, websocket
from time import sleep
from threading import Lock
lock = Lock()
count_false = 0
count_true = 0
depthupdate= {‘Event_time’:,‘Symbol’:,‘First_update_id’:,‘Final_update_id’:,
‘Bids_nb’:,‘Asks_nb’:,‘Bids’:,‘Asks’:}
def on_error(ws, error):
print(‘error on :’,error)
def on_message(ws, message):
global count_false,count_true
msg = json.loads(message)
if msg['e'] =='depthUpdate':
depthupdate['Event_time'].append(msg['E'])
depthupdate['Symbol'].append(msg['s'])
depthupdate['First_update_id'].append(msg['U'])
depthupdate['Final_update_id'].append(msg['u'])
depthupdate['Bids_nb'].append(len(msg['b']))
depthupdate['Asks_nb'].append(len(msg['a']))
depthupdate['Bids'].append(msg['b'])
depthupdate['Asks'].append(msg['a'])
#testing
lock.acquire()
test = len(msg['b']) + len(msg['a']) == msg['u'] - msg['U'] + 1
print(len(msg['b']) + len(msg['a']) ,' ', msg['u'] - msg['U'] + 1)
if test == False:
count_false += 1
print('fail count :',count_false)
if test == True:
count_true += 1
print('success count :',count_true)
lock.release()
sleep(1)
socket = ‘wss://stream.binance.com:9443/ws/btcusdt@depth@100ms’
ws = websocket.WebSocketApp(socket,on_message= on_message, on_error= on_error)
ws.run_forever()
Hi.
When placing an order, it will either add one record in the order book (i.e. maker order), or remove one record from the order book (i.e. taker order, filled).
That means, if Final update ID - First update ID + 1 = sum of updates ( bids + asks)
is valid, each update involves one order only, and none of them is filled during that period of time.
thank you for your response
the problem is that i have always dismatch bitween updates id and updates, i’m very confused