I used this code: def signalgenerator(df): if df is None or len(df) < 2: return ''…
- User
I used this code: def signal_generator(df): if df is None or len(df) < 2: return ''
signal = [] final_signal = [] exit = [] # Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] 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]) buy_price = highest_bid_price 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]) sell_price = lowest_ask_price mark_price_data = client.ticker_price(symbol=symbol) mark_price = 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 # Calculate the threshold for order price deviation if mark_price_percent > 2: pth = 7 / 100 elif mark_price_percent < -2: pth = 7 / 100 else: pth = 7 / 100 if mark_price_percent > 2: th = 25000 elif mark_price_percent < -2: th = 25000 else: th = 15000 if ((buy_price > mark_price + pth) and ((buy_qty > th) > (sell_qty < th))): signal.append('buy') elif ((sell_price < mark_price - pth) and ((sell_qty > th) > (buy_qty < th))): signal.append('sell') else: signal.append('') if signal == ['buy'] and not ((sell_qty > buy_qty) and (buy_price < mark_price - pth)): final_signal.append('buy') elif signal == ['sell'] and not ((buy_qty > sell_qty) and (sell_price > mark_price + pth)): final_signal.append('sell') else: final_signal.append('') if ['buy'] in final_signal and ((sell_qty > buy_qty) and (buy_price < mark_price)): exit.append('buy_exit') elif ['sell'] in final_signal and ((buy_qty > sell_qty) and (sell_price > mark_price)): exit.append('sell_exit') else: exit.append('') samekh = exit and final_signal return samekhYou need to add in my code system which will print me price of every bid of all bids
- Assistant
To print the price of each bid in your code, you can modify it as follows:
- User
And their qty
- Assistant
- User
And now add in my code system which if bid_price is same like mark_price will subtract qty of this bid from buy_qty
- Assistant
- User
And it need to print me result of buy_qty and without bid qty
- Assistant
- User
Wait! I deosn't see code which will print me buy_qty without bid qty which which price will same like market price
- Assistant
Apologies for the confusion. To print the
buy_qtywithout including the bid quantity that matches the market price, you can modify the code as follows:def signal_generator(df): if df is None or len(df) < 2: return '' signal = [] final_signal = [] exit = [] # Retrieve depth data depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] highest_bid_price = float(bids[0][0]) lowest_bid_price = float(bids[1][0]) buy_price = highest_bid_price # Calculate buy_qty excluding bid with price same as mark_price buy_qty = round(sum(float(bid[1]) for bid in bids if float(bid[0]) != mark_price), 0) # Print bid prices and quantities print("Bids:") for bid in bids: price = float(bid[0]) qty = float(bid[1]) if price == mark_price: continue print(f"Bid Price: {price}") print(f"Bid Quantity: {qty}") 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]) sell_price = lowest_ask_price mark_price_data = client.ticker_price(symbol=symbol) mark_price = 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 # Calculate the threshold for order price deviation if mark_price_percent > 2: pth = 7 / 100 elif mark_price_percent < -2: pth = 7 / 100 else: pth