INNER CODE UNIT · Python

position_leveraged_stop_loss

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

                                            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:
                                                        myfile.write(log+'\n')
                                                except Exception:
                                                    pass

                                # Otherwise, search Conditional Orders if Stop Loss already exists with 'qty'=position size AND 'trigger_price' within allowed range
                                total_allowed_stop_loss_found = 0.0
                                
                                try:
                                    fetched_conditional_orders = session.query_conditional_order(symbol=symbol)
                                except Exception:
                                    pass

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…