INNER CODE UNIT · Python
__get_marketdepth_snapshot
nkaz001/sample-trading-bot · tradingbot/binancefutures.py:393
async def __get_marketdepth_snapshot(self):
data = await self.__curl_binancefutures(verb='GET', path='/v1/depth', query={'symbol': self.symbol, 'limit': 1000})
l_bid, _ = data['bids'][-1]
h_ask, _ = data['asks'][-1]
self.depth = {price: qty for price, qty in self.depth.items() if (price < l_bid and qty > 0) or (price > h_ask and qty < 0)}
for price, qty in data['bids']:
self.depth[price] = float(qty)
for price, qty in data['asks']:
self.depth[price] = -float(qty)
lastUpdateId = data['lastUpdateId']
self.prev_u = None
# Process the pending messages.
while self.prev_u is None:
while self.pending_messages:
item = self.pending_messages.pop(0)
u = item['u']
U = item['U']
pu = item['pu']