I have this code : # Retrieve depth data depthdata = client.depth(symbol=symbol) bids =…
- User
I have this code : # Retrieve depth data depth_data = client.depth(symbol=symbol)
bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price 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) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100)Give em ode which will print me all asks price and all bid price
- Assistant
Sure, here's the modified code that prints all ask prices and bid prices:
# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price 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) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100) # Print ask prices print("All Ask Prices:") for ask_price in ask_prices: print(ask_price) # Print bid prices print("All Bid Prices:") for bid_price in bid_prices: print(bid_price)This modified code will print all the ask prices and bid prices separately.
- User
Now give me code which will count middle price of asks and middle of bids
- Assistant
Here's the modified code that calculates the middle price of asks and bids:
# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price 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) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100) # Calculate middle price of asks middle_ask_price = sum(ask_prices) / len(ask_prices) # Calculate middle price of bids middle_bid_price = sum(bid_prices) / len(bid_prices) print("Middle Ask Price:", middle_ask_price) print("Middle Bid Price:", middle_bid_price)This modified code calculates the average (middle) price of all the ask prices and bid prices separately and then prints them.
- User
middle bid price of orders which pricec is higher than mark_price and middle ask price of orders which price is lowwer than mark_price
- Assistant
Here's the modified code that calculates the middle bid price of orders with prices higher than
mark_priceand the middle ask price of orders with prices lower thanmark_price:# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids if float(bid[0]) > mark_price] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price asks = depth_data['asks'] ask_prices = [float(ask[0]) for ask in asks if float(ask[0]) < mark_price] highest_ask_price = max(ask_prices) lowest_ask_price = min(ask_prices) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100) # Calculate middle bid price of orders with prices higher than mark_price middle_bid_price = sum(bid_prices) / len(bid_prices) # Calculate middle ask price of orders with prices lower than mark_price middle_ask_price = sum(ask_prices) / len(ask_prices) print("Middle Bid Price (Higher than mark_price):", middle_bid_price) print("Middle Ask Price (Lower than mark_price):", middle_ask_price) - User
I getting ERROR: Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 234, in
signals = signal_generator(df) ^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 101, in signal_generator middle_ask_price = sum(ask_prices) / len(ask_prices) ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ ZeroDivisionError: division by zero - Assistant
The error
ZeroDivisionError: division by zerois occurring because theask_priceslist is empty, resulting in a division by zero error when calculating the middle ask price.To fix this issue, you can add a condition to check if the
ask_priceslist is empty before calculating the average. Here's the updated code:# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids if float(bid[0]) > mark_price] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price asks = depth_data['asks'] ask_prices = [float(ask[0]) for ask in asks if float(ask[0]) < mark_price] highest_ask_price = max(ask_prices) lowest_ask_price = min(ask_prices) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100) # Calculate middle bid price of orders with prices higher than mark_price middle_bid_price = sum(bid_prices) / len(bid_prices) # Calculate middle ask price of orders with prices lower than mark_price middle_ask_price = sum(ask_prices) / len(ask_prices) if len(ask_prices) > 0 else 0 print("Middle Bid Price (Higher than mark_price):", middle_bid_price) print("Middle Ask Price (Lower than mark_price):", middle_ask_price) - User
Okay, return every thing I need code which will print me ask_price which higher lowwer than mark_price and bid_price which higher than mark_price
- Assistant
Certainly! Here's the code that will print the ask prices higher than
mark_priceand the bid prices higher thanmark_price:# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids if float(bid[0]) > mark_price] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) b_l = lowest_bid_price > mark_price + (mark_price / 100) b_h = highest_bid_price asks = depth_data['asks'] ask_prices = [float(ask[0]) for ask in asks if float(ask[0]) < mark_price] highest_ask_price = max(ask_prices) lowest_ask_price = min(ask_prices) s_l = lowest_ask_price s_h = highest_ask_price < mark_price - (mark_price / 100) print("Ask Prices Higher than mark_price:") for ask_price in ask_prices: print(ask_price) print("Bid Prices Higher than mark_price:") for bid_price in bid_prices: print(bid_price)This code retrieves the depth data, filters the bid prices higher than
mark_priceand ask prices lower thanmark_price, and then prints each filtered set separately. The ask prices higher thanmark_priceare printed first, followed by the bid prices higher thanmark_price.