I used your code: while True: lookback = 10080 df = getklines(symbol, interval,…
- User
I used your code: while True: lookback = 10080 df = get_klines(symbol, interval, lookback)
if df is not None: signals = signal_generator(df) print(f"The signal time is: {dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Signals: {signals}") mark_price = client.ticker_price(symbol=symbol) if signals == 'buy': try: client.new_order(symbol=symbol, side='BUY', type='MARKET', quantity=0.1) print("Long order executed!") stop_loss_price = mark_price - (mark_price * 0.002) print(f"Stop loss set at: {stop_loss_price}") try: client.new_order( symbol=symbol, side='SELL', type='STOP_MARKET', quantity=0.1, stopPrice=stop_loss_price ) print("Stop loss order placed!") except binance.error.ClientError as e: print(f"Error placing stop loss order: {e}") time.sleep(1) except binance.error.ClientError as e: print(f"Error executing long order: {e}") time.sleep(1) if signals == 'sell': try: client.new_order(symbol=symbol, side='SELL', type='MARKET', quantity=0.1) print("Short order executed!") stop_loss_price = mark_price + (mark_price * 0.002) print(f"Stop loss set at: {stop_loss_price}") try: client.new_order( symbol=symbol, side='BUY', type='STOP_MARKET', quantity=0.1, stopPrice=stop_loss_price ) print("Stop loss order placed!") except binance.error.ClientError as e: print(f"Error placing stop loss order: {e}") time.sleep(1) except binance.error.ClientError as e: print(f"Error executing short order: {e}") time.sleep(1) time.sleep(1)But it still doesn;t place stop loss order
- Assistant
There could be different reasons why the stop loss order is not being placed. Here are a few potential issues and suggestions:
-
Check if the stop loss condition is being met: Double-check the logic in your
signal_generatorfunction to ensure it correctly identifies the sell signal. If the condition for a sell signal is not being met, the stop loss order won't be placed. -
Ensure the stop price is set correctly: Verify that the stop loss price calculation is accurate and aligns with your desired strategy. It should be set at an appropriate level to trigger the stop loss order when needed.
-
Validate the symbol and interval: Confirm that the
symbolprovided matches the symbol you are trading and that the aligns with the data you are analyzing. Using the wrong symbol or interval can lead to incorrect signals and prevent the stop loss order from being executed.
-
- User
Okay, how my code need to seem with your advcies ?
- Assistant
- User
It need to be mark price - 0.2%
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.