INNER CODE UNIT · Python

limit_close_price_levels

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

                                limit_close_price_levels = np.sort(limit_close_price_levels)[::-1] # First we sort the Limit Close Targets Descending to have the nearest (highest) value at the first index, as the assumption is when you are Shorting the indicator is below current price
                                for limit_close_price_level in limit_close_price_levels: # Loop through them to find the nearest, but also valid (profitable)
                                    if limit_close_price_level - entry_price < 0 and limit_close_price_level < last_price: # Only if the dynamic Limit Close is in Profit for the Entry Price of Position AND is above Current Price
                                        # First go through all Active Orders searching for Close Orders only:
                                        limit_close_order_ids = []
                                        try:
                                            fetched_active_orders = session.query_active_order(symbol=symbol)
                                        except Exception:
                                            pass
                                        if(fetched_active_orders):
                                            for active_order in fetched_active_orders["result"]:
                                                if symbol.endswith('USDT'): # USDT Perpetual
                                                    # Note: order side should be opposite of position side
                                                    if active_order['side'] == "Buy" and active_order['order_type'] == 'Limit' and active_order['reduce_only'] == True and active_order['close_on_trigger'] == True: # Active Limit Close Order for Short
                                                        # Count the Active Orders and record Order ID
                                                        limit_close_order_ids.append(active_order['order_id'])
                                                else: # Inverse Perpetuals or Futures
                                                    # Note: order side should be opposite of position side

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…