gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I sued tihs code: client = UMFutures(key = apikey, secret = apisecret) df =…
- User
I sued tihs code: client = UMFutures(key = api_key, secret = api_secret)
df = client.depth(symbol=symbol)
def signal_generator(df): if df is None or len(df) < 2: return ''
signal = [] final_signal = [] # Retrieve depth data th = 0.35 depth_data = client.depth(symbol=symbol) bids = depth_data['bids'] buy_qty = sum(float(bid[1]) for bid in bids) highest_bid_price = float(bids[0][0]) lowest_bid_price = float(bids[-1][0]) buy_price = (highest_bid_price + lowest_bid_price) / 2 asks = depth_data['asks'] sell_qty = sum(float(ask[1]) for ask in asks) highest_ask_price = float(asks[0][0]) lowest_ask_price = float(asks[-1][0]) sell_price = (highest_ask_price + lowest_ask_price) / 2 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 executed_orders_buy = 0.0 for order in bids: if float(order[0]) == mark_price: executed_orders_buy += float(order[1]) else: break buy_qty = sum(float(bid[1]) for bid in bids) buy_result = buy_qty - executed_orders_buy executed_orders_sell = 0.0 for order in asks: if float(order[0]) == mark_price: executed_orders_sell += float(order[1]) else: break sell_qty = sum(float(ask[1]) for ask in asks) sell_result = sell_qty - executed_orders_sell print(buy_qty) print(sell_qty) if (sell_result > buy_qty) and (sell_price < mark_price): signal.append('sell') elif (buy_result > sell_qty) and (buy_price > mark_price): signal.append('buy') else: signal.append('') if signal == ['buy'] and not ((buy_result < sell_qty) and (buy_price < mark_price)): final_signal.append('buy') elif signal == ['sell'] and not ((sell_result < buy_qty) and (sell_price > mark_price)): final_signal.append('sell') else: final_signal.append('') return final_signalYou need to round buy_qty sell_qty buy_price and sell_price
- Assistant