I sued this code: # Retrieve depth data depthdata = client.depth(symbol=symbol) bids =…
- User
I sued 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) buy_lowest_price = 0 for bid_price in bid_prices: if bid_price > mp + (mp / 100): buy_lowest_price = bid_price break if buy_lowest_price == 0: buy_lowest_price = mp + (mp / 100) b_h = highest_bid_price b_l = buy_lowest_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) sell_highest_price = 0.0 for ask_price in ask_prices: if ask_price < mp - (mp / 100): sell_highest_price = ask_price break if sell_highest_price == 0: sell_highest_price = mp - (mp / 100) s_h = highest_ask_price s_l = lowest_ask_priceCan you add in buy_lowest_price and in sell_highest_price that if buy_lowest_price < mp + (mp / 100 ) it need to subtract qty of this bid and same system for ask
- Assistant
Certainly! Here's the modified code that subtracts the quantity of a bid if
buy_lowest_priceis less thanmp + (mp / 100). The same logic is applied forsell_highest_priceand the associated ask quantity:# Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] bid_prices = [float(bid[0]) for bid in bids] bid_quantities = [float(bid[1]) for bid in bids] highest_bid_price = max(bid_prices) lowest_bid_price = min(bid_prices) buy_lowest_price = 0 for i, bid_price in enumerate(bid_prices): if bid_price > mp + (mp / 100): buy_lowest_price = bid_price break elif bid_price < mp + (mp / 100) and bid_price > mp: bid_quantities[i] -= 1 if buy_lowest_price == 0: buy_lowest_price = mp + (mp / 100) b_h = highest_bid_price b_l = buy_lowest_price asks = depth_data['asks'] ask_prices = [float(ask[0]) for ask in asks] ask_quantities = [float(ask[1]) for ask in asks] highest_ask_price = max(ask_prices) lowest_ask_price = min(ask_prices) sell_highest_price = 0.0 for i, ask_price in enumerate(ask_prices): if ask_price < mp - (mp / 100): sell_highest_price = ask_price break elif ask_price > mp - (mp / 100) and ask_price < mp: ask_quantities[i] -= 1 if sell_highest_price == 0: sell_highest_price = mp - (mp / 100) s_h = highest_ask_price s_l = lowest_ask_price - User
I have this system: for bid in bids: price_buy = float(bid[0]) qty_buy = float(bid[1])
Give me system which through this code will return me only bid price and qty of bids which price is > than mark_price
- Assistant
If you want to modify the existing code to return only the bid price and quantity for bids with a price greater than
mark_price, you can use the following system:price_qty_list = [] for bid in bids: price_buy = float(bid[0]) qty_buy = float(bid[1]) if price_buy > mark_price: price_qty_list.append((price_buy, qty_buy)) return price_qty_listThis system iterates through each bid in the
bidslist, extracts the price and quantity, and checks if the price is greater thanmark_price. If it meets the condition, it adds a tuple(price_buy, qty_buy)to theprice_qty_list. Finally, it returns theprice_qty_listcontaining only the bid prices and quantities that satisfy the condition.