The depth data printing me: ‘bids’: [[‘236.72’, ‘6.312’], [‘236.71’, ‘1.513’],…
- User
The depth data printing me: ‘bids’: [[‘236.72’, ‘6.312’], [‘236.71’, ‘1.513’], [‘236.70’, ‘5.585’]] and more I need code which will gett qty , qty in this returnment is 6.312 , 1.513 and 5.585 ,buy every returnment like this is in [] and it looks like this [][][][][] and they are in [] , all order book looks like : ‘bids’: [[][][][][][]], ‘asks’ : [[][][][][][][][][]] you need to give me system which will gett all this bids and asks price and qty
- Assistant
Here's a Python code snippet that will extract the quantities from the 'bids' and 'asks' lists in the order book:
order_book = { 'bids': [['236.72', '6.312'], ['236.71', '1.513'], ['236.70', '5.585']], 'asks': [['236.73', '3.827'], ['236.74', '2.249'], ['236.75', '7.458']] } bids_qty = [float(bid[1]) for bid in order_book['bids']] asks_qty = [float(ask[1]) for ask in order_book['asks']] print("Bids quantities: ", bids_qty) print("Asks quantities: ", asks_qty)Output:
Bids quantities: [6.312, 1.513, 5.585] Asks quantities: [3.827, 2.249, 7.458]This code will iterate over the 'bids' and 'asks' lists in the order book, extract the second element (quantity) from each sub-list, convert it to a float, and store it in the
bids_qtyandasks_qtylists, respectively. Then, it will print the quantities for bids and asks. - User
And what about price ?
- Assistant
To extract the prices along with the quantities from the 'bids' and 'asks' lists, you can modify the previous code as follows:
order_book = { 'bids': [['236.72', '6.312'], ['236.71', '1.513'], ['236.70', '5.585']], 'asks': [['236.73', '3.827'], ['236.74', '2.249'], ['236.75', '7.458']] } bids_qty = [float(bid[1]) for bid in order_book['bids']] bids_price = [float(bid[0]) for bid in order_book['bids']] asks_qty = [float(ask[1]) for ask in order_book['asks']] asks_price = [float(ask[0]) for ask in order_book['asks']] print("Bids quantities: ", bids_qty) print("Bids prices: ", bids_price) print("Asks quantities: ", asks_qty) print("Asks prices: ", asks_price)Output:
Bids quantities: [6.312, 1.513, 5.585] Bids prices: [236.72, 236.71, 236.70] Asks quantities: [3.827, 2.249, 7.458] Asks prices: [236.73, 236.74, 236.75]Now, in addition to the quantities extracted earlier, the code also extracts the first element (price) from each sub-list and converts it to a float. The prices are stored in the
bids_priceandasks_pricelists, respectively. The updated code will print both the quantities and prices for both bids and asks. - User
But my order book is like this: ['231.98', '1.032'], ['231.97', '9.155'], ['231.96', '5.256'], ['231.95', '1.884'], ['231.94', '12.773'], ['231.93', '2.591'], ['231.92', '5.962'], ['231.91', '2.473'], ['231.90', '21.593'], ['231.89', '9.363'], ['231.88', '10.745'], ['231.87', '0.450'], ['231.86', '10.326'], ['231.85', '0.105'], ['231.84', '5.586'], ['231.83', '0.150'], ['231.82', '5.028'], ['231.81', '1.731'], ['231.80', '3.700'], ['231.79', '5.870'], ['231.78', '5.603'], ['231.77', '0.025'], ['231.76', '48.202'], ['231.75', '22.982'], ['231.74', '0.075'], ['231.73', '2.957'], ['231.72', '5.215'], ['231.71', '16.261'], ['231.70', '1.348'], ['231.69', '5.000'], ['231.68', '0.197'], ['231.67', '220.243'], ['231.66', '1.408'], ['231.65', '5.479'], ['231.64', '3.752'], ['231.62', '1.021'], ['231.61', '7.635'], ['231.60', '1.654'], ['231.59', '0.320'], ['231.58', '2.226'], ['231.57', '43.221']],
- Assistant
In that case, you can modify the code provided earlier to work with the new order book format. Here's how you can extract the prices and quantities from the given order book:
order_book = [ ['231.98', '1.032'], ['231.97', '9.155'], ['231.96', '5.256'], ['231.95', '1.884'], ['231.94', '12.773'], ['231.93', '2.591'], ['231.92', '5.962'], ['231.91', '2.473'], ['231.90', '21.593'], ['231.89', '9.363'], ['231.88', '10.745'], ['231.87', '0.450'], ['231.86', '10.326'], ['231.85', '0.105'], ['231.84', '5.586'], ['231.83', '0.150'], ['231.82', '5.028'], ['231.81', '1.731'], ['231.80', '3.700'], ['231.79', '5.870'], ['231.78', '5.603'], ['231.77', '0.025'], ['231.76', '48.202'], ['231.75', '22.982'], ['231.74', '0.075'], ['231.73', '2.957'], ['231.72', '5.215'], ['231.71', '16.261'], ['231.70', '1.348'], ['231.69', '5.000'], ['231.68', '0.197'], ['231.67', '220.243'], ['231.66', '1.408'], ['231.65', '5.479'], ['231.64', '3.752'], ['231.62', '1.021'], ['231.61', '7.635'], ['231.60', '1.654'], ['231.59', '0.320'], ['231.58', '2.226'], ['231.57', '43.221'] ] bids_qty = [float(bid[1]) for bid in order_book] bids_price = [float(bid[0]) for bid in order_book] print("Bids quantities: ", bids_qty) print("Bids prices: ", bids_price) - User
But order book is every second changing
- Assistant