INNER CODE UNIT · Python

position_leveraged_stop_loss

hadialaddin/crypto-genie · crypto-genie.py:2381

                                            position_leveraged_stop_loss = round_to_tick(entry_price - (((stop_loss_cap_ratio_long/100) / leverage_for_sl_calc) * entry_price), tick_size[symbol])
                                            if last_price < position_leveraged_stop_loss:
                                                try:
                                                    session.place_active_order(position_idx=position_idx, symbol=symbol, side="Sell", order_type="Market", qty=size, time_in_force="GoodTillCancel", reduce_only=True, close_on_trigger=True)
                                                    log = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ": " + (log_label + ": " if log_label != "" else "") + symbol + " LONG Force-Stopped: "+str(last_price)+"."
                                                    print(log)
                                                    with open("SL_forced.txt", "a") as myfile:
                                                        myfile.write(log+'\n')
                                                except Exception:
                                                    pass
                                        elif side == 'Sell':
                                            position_leveraged_stop_loss = round_to_tick(entry_price + (((stop_loss_cap_ratio_short/100) / leverage_for_sl_calc) * entry_price), tick_size[symbol])
                                            if last_price > position_leveraged_stop_loss:
                                                try:
                                                    session.place_active_order(position_idx=position_idx, symbol=symbol, side="Buy", order_type="Market", qty=size, time_in_force="GoodTillCancel", reduce_only=True, close_on_trigger=True)
                                                    log = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ": " + (log_label + ": " if log_label != "" else "") + symbol + " SHORT Force-Stopped: "+str(last_price)+"."
                                                    print(log)
                                                    with open("SL_forced.txt", "a") as myfile:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…