INNER CODE UNIT · Python
position_leveraged_p_level
hadialaddin/crypto-genie · crypto-genie.py:1563
position_leveraged_p_level = round_to_tick(entry_price - (((lock_in_p_price_ratio/100) / leverage) * entry_price), tick_size[symbol])
position_leveraged_p_sl_level = round_to_tick(entry_price - (((lock_in_p_sl_ratio/100) / leverage) * entry_price), tick_size[symbol])
if last_price <= position_leveraged_p_level:
# Sarch Conditional Orders if Stop Loss already exists with 'qty'=position size AND 'trigger_price' better than the Take Profit Level
total_in_profit_stop_loss_found = 0.0
if(fetched_conditional_orders):
for conditional_order in fetched_conditional_orders["result"]:
# Note: order side should be opposite of position side
if conditional_order['side'] == "Buy" and conditional_order['order_type'] == 'Market' and conditional_order['order_status'] == 'Untriggered': # Stop Loss for a Short
if symbol.endswith('USDT'): # USDT Perpetual
stop_price = float(conditional_order['trigger_price'])
stop_order_id = conditional_order['stop_order_id']
if stop_price > position_leveraged_p_level and conditional_order['close_on_trigger'] == True and conditional_order['reduce_only'] == True:
if stop_price <= position_leveraged_p_sl_level:
# Stop Loss found inside the allowed range, keep it
total_in_profit_stop_loss_found += float(conditional_order['qty'])