gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I used your code: lookback = 10080 quantity = 0.05 activesignal = None buyentryprice =…
- User
I used your code: lookback = 10080 quantity = 0.05 active_signal = None buy_entry_price = None sell_entry_price = None
def calculate_percentage_difference(entry_price, exit_price): percentage_difference = ((exit_price - entry_price) / entry_price) * 100 return percentage_difference
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 active_signal != 'buy': try: active_signal = 'buy' buy_entry_price = mark_price # Record the buy entry price print(f"Buy Entry Price: {buy_entry_price}") # Execute buy orders here 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!") if buy_entry_price is not None: buy_exit_price = mark_price difference_buy = calculate_percentage_difference(buy_entry_price, buy_exit_price) profit_buy = difference_buy * 50 total_profit_buy = profit_buy + (0.04 * profit_buy) print(f"Buy Profit: {total_profit_buy}") else: print("Buy Entry price is not defined.") except binance.error.ClientError as e: print(f"Error executing long order: {e}") elif 'sell' in signals and active_signal != 'sell': try: active_signal = 'sell' sell_entry_price = mark_price # Record the sell entry price print(f"Sell Entry Price: {sell_entry_price}") # Execute sell orders here 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: {e}") if sell_entry_price is not None and buy_entry_price is not None: sell_exit_price = buy_entry_price difference_sell = calculate_percentage_difference(sell_entry_price, sell_exit_price) profit_sell = difference_sell * 50 total_profit_sell = profit_sell + (0.04 * profit_sell) print(f"Sell Profit: {total_profit_sell}") difference_buy = calculate_percentage_difference(buy_entry_price, sell_exit_price) profit_buy = difference_buy * 50 total_profit_buy = profit_buy + (0.04 * profit_buy) print(f"Buy Profit: {total_profit_buy}") else: print("Sell Entry price or Buy Entry price is not defined.") time.sleep(1) - Assistant
I'm glad you found the code helpful! Is there anything specific you would like me to assist you with regarding the code?