I used this code: asks = depthdata['asks'] sellqty = round(sum(float(ask[1]) for ask in…
- User
I used this code: asks = depth_data['asks'] sell_qty = round(sum(float(ask[1]) for ask in asks), 0) highest_ask_price = float(asks[0][0]) lowest_ask_price = float(asks[1][0]) s_h = highest_ask_price s_l = lowest_ask_price
mark_price_data = client.ticker_price(symbol=symbol) mp = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol) mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0 print(f"Low {lowest_ask_price}") print(f"High {highest_ask_price}")I need code wihch will count highest and lowest price in all order book
- Assistant
To count the highest and lowest price in the entire order book, you can modify your code to iterate over all the bids and asks in the depth_data dictionary. Here's an updated version of your code:
asks = depth_data['asks'] bids = depth_data['bids'] sell_qty = round(sum(float(ask[1]) for ask in asks), 0) highest_ask_price = float(asks[0][0]) lowest_ask_price = float(asks[-1][0]) # Updated - using the last ask price as the lowest_ask_price buy_qty = round(sum(float(bid[1]) for bid in bids), 0) highest_bid_price = float(bids[0][0]) lowest_bid_price = float(bids[-1][0]) # Updated - using the last bid price as the lowest_bid_price mark_price_data = client.ticker_price(symbol=symbol) mp = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 mark_price_data_change = client.ticker_24hr_price_change(symbol=symbol) mark_price_percent = float(mark_price_data_change['priceChangePercent']) if 'priceChangePercent' in mark_price_data_change else 0.0 print(f"Lowest ask price: {lowest_ask_price}") print(f"Highest ask price: {highest_ask_price}") print(f"Lowest bid price: {lowest_bid_price}") print(f"Highest bid price: {highest_bid_price}")In this code, we also added calculations for the highest and lowest bid prices and printed all four prices (lowest ask, highest ask, lowest bid, and highest bid).
- User
I mean of all order book
- Assistant
To calculate the highest and lowest price in the entire order book, you will need to consider both the bids and asks from the depth_data. Here's an updated code snippet that calculates the highest and lowest price across all bids and asks:
asks = depth_data['asks'] bids = depth_data['bids'] ask_prices = [float(ask[0]) for ask in asks] bid_prices = [float(bid[0]) for bid in bids] highest_price = max(max(ask_prices), max(bid_prices)) lowest_price = min(min(ask_prices), min(bid_prices)) print(f"Highest price: {highest_price}") print(f"Lowest price: {lowest_price}")This code extracts the prices from both the asks and bids lists, converts them to floats, and stores them in separate lists (ask_prices and bid_prices). Then, it calculates the highest and lowest prices among all the ask and bid prices using the max and min functions. Finally, it prints the highest and lowest prices.
- User
Only os asks
- Assistant
To calculate the highest and lowest price from the asks in the entire order book, you can modify the code as follows:
asks = depth_data['asks'] ask_prices = [float(ask[0]) for ask in asks] highest_ask_price = max(ask_prices) lowest_ask_price = min(ask_prices) print(f"Highest ask price: {highest_ask_price}") print(f"Lowest ask price: {lowest_ask_price}")This code extracts the ask prices from the asks list, converts them to floats, and stores them in the ask_prices list. Then, it calculates the highest and lowest prices among all the ask prices using the max and min functions. Finally, it prints the highest and lowest ask prices.