I used this code: lookback = 10080 quantity = 0.05 buyentryprice = 0.0 sellentryprice =…
- User
I used this code: lookback = 10080 quantity = 0.05 buy_entry_price = 0.0 sell_entry_price = 0.0 buy_exit_price = 0.0 sell_exit_price = 0.0 entry_price_set = False consecutive_buy_signals = 0
while True: if df is not None: signals = signal_generator(df) mark_price_data = client.ticker_price(symbol=symbol) mark_price = float(mark_price_data['price']) if 'price' in mark_price_data else 0.0 print(f"The signal time is: {dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}, Price {mark_price} - Signals: {signals}")
if 'buy' in signals and sell_exit_price == 0.0: try: if not entry_price_set and consecutive_buy_signals == 0: buy_entry_price = mark_price entry_price_set = True print(f"Buy Entry Price: {buy_entry_price}") consecutive_buy_signals = 1 elif entry_price_set: consecutive_buy_signals += 1 client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print("Long order executed!") except binance.error.ClientError as e: print(f"Error executing long order: ") elif 'sell' in signals and buy_exit_price == 0.0: try: if not entry_price_set: sell_entry_price = mark_price entry_price_set = True print(f"Sell Entry Price: {sell_entry_price}") client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) print("Short order executed!") except binance.error.ClientError as e: print(f"Error executing short order: ") time.sleep(1)You need to give me same strategy like this : if 'buy' in signals and sell_exit_price == 0.0: try: if not entry_price_set and consecutive_buy_signals == 0: buy_entry_price = mark_price entry_price_set = True print(f"Buy Entry Price: {buy_entry_price}") consecutive_buy_signals = 1 elif entry_price_set: consecutive_buy_signals += 1
client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=quantity) print("Long order executed!") except binance.error.ClientError as e: print(f"Error executing long order: ")But for sell
- Assistant
Certainly! Here is the code for the "sell" strategy:
if 'sell' in signals and buy_exit_price == 0.0: try: if not entry_price_set and consecutive_sell_signals == 0: sell_entry_price = mark_price entry_price_set = True print(f"Sell Entry Price: {sell_entry_price}") consecutive_sell_signals = 1 elif entry_price_set: consecutive_sell_signals += 1 client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=quantity) print("Short order executed!") except binance.error.ClientError as e: print(f"Error executing short order: ")You can replace the existing "sell" strategy code with this code. It checks if the "sell" signal is present and there are no existing "buy" exit prices. If the conditions are met, it sets the sell entry price, increases the consecutive sell signals count, executes the sell orders, and prints a confirmation message.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.