INNER CODE UNIT · Python

tp_price

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

                                                    tp_price = round_to_tick(entry_price - (((tp_price_ratio/100) / leverage) * entry_price), tick_size[symbol])
                                                    tp_size = round_step_size(size * (tp_size_ratio / 100),qty_step[symbol],min_trading_qty[symbol])
                                                    if tp_price==stop_price and (tp_size==conditional_order['qty'] or math.floor(tp_size * 10)/10.0==conditional_order['qty'] or math.floor(tp_size * 100)/100.0==conditional_order['qty'] or math.floor(tp_size * 1000)/1000.0==conditional_order['qty'] or math.floor(tp_size * 10000)/10000.0==conditional_order['qty']):
                                                        # We found a valid pre-defined TP, keep it (note we check the floor in case the exchange did remove decimals upon creating the order)
                                                        tp_found = True
                                                if not tp_found:
                                                    # Invalid TP (or updated position size not reflected in the TP), REMOVE IT
                                                    try:
                                                        session.cancel_conditional_order(symbol=symbol, stop_order_id=stop_order_id) 
                                                    except Exception:
                                                        pass
                                        else: # Inverse Perpetuals or Futures
                                            stop_price = float(conditional_order['stop_px'])
                                            stop_order_id = conditional_order['order_id']
                                            if conditional_order['side'] == 'Buy' and stop_price < last_price and stop_price < entry_price:
                                                # Take Profit found, make sure it is one of the pre-defined ones and make sure its quantity is up to date as well
                                                for elem in default_tp.items():
                                                    tp_price_ratio = float(elem[0])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…