gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
I used your code: def signalgenerator(df): if df is None or len(df) < 2: return ''…
- User
I used your code: def signal_generator(df): if df is None or len(df) < 2: return ''
codesignals = [] signal = [] # Retrieve depth data depth_data = client.depth(symbol=symbol) bid_depth = depth_data['bids'] ask_depth = depth_data['asks'] buy_price = float(bid_depth[0][0]) if bid_depth else 0.0 sell_price = float(ask_depth[0][0]) if ask_depth else 0.0 mark_price_data = client.ticker_price(symbol=symbol) mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 buy_qty = sum(float(bid[1]) for bid in bid_depth) sell_qty = sum(float(ask[1]) for ask in ask_depth) if buy_qty > sell_qty: signals.append('Bullish') elif sell_qty > buy_qty: signals.append('Bearish') if 'Bullish' in signals and buy_price > mark_price: signal.append('buy') elif 'Bearish' in signals and sell_price < mark_price: signal.append('sell') else: return '' return signalBut it doesn't give me signal to sell , and I was need to take loss
- Assistant
It seems that the code provided is only checking for a "buy" signal and not a "sell" signal. To add a condition for a "sell" signal, you can modify the code as follows:
python