REPLACING an order troubleshooting

Hey community,

Having a ton of trouble trying to get an order_id for replacing an order using the replace_order.

Working in python.

open_orders = self._rest_api.list_orders(symbols=[self.symbol])
                for open_order in open_orders:

                    qty_to_sell_1 = abs(round(int(self.position.qty) * 1,0))

                    if unrealized_intraday_plpc > 0 and trail_stop_order_counter[self.symbol] <= 5:
                        logging.info(f' | {self.symbol} | ########################################### LONG ADDING TO POSITION')
                        
                        submit_market_long_order()

                        trail_stop_order_counter[self.symbol] += 1

                        logging.info(f" | {self.symbol} | ADDED TO POSITION {self.symbol} - {self.position.side}")
                        logging.info(f" | {self.symbol} | Trailing stop order counter for {self.symbol} is now {trail_stop_order_counter[self.symbol]}")

                        await asyncio.sleep(2)

                        portfolio_value = self._rest_api.get_account().equity
                        shares_to_sell = (float(portfolio_value) * self.risk ) // last_bar.close

                        updated_qty_to_sell = abs(round(int(self.position.qty) * 1,0) + shares_to_sell)
                        
                        o = self._rest_api.replace_order(
                            order_id=o.id,
                            qty=int(updated_qty_to_sell),
                        )

                        self.latest_cost_basis = last_bar.close

                        return

This is a small snippet of some of my test code. Any help would be greatly appreciated, just can’t seem to figure this one out.

Was able to replace quantity on my trailing stops, however, randomly a different number will be used ratehr then the variable used even AFTER calling the position quantity to get the amount of shares.