# REPLACING an order troubleshooting

**URL:** <https://forum.alpaca.markets/t/replacing-an-order-troubleshooting/10656>\
**Category:** Alpaca Trading\
**Created:** [September 21, 2022, 7:56pm UTC](https://forum.alpaca.markets/t/replacing-an-order-troubleshooting/10656 "2022-09-21T19:56:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FIRMCEO](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/firmceo/32/1924_2.png) [@FIRMCEO](https://forum.alpaca.markets/u/FIRMCEO)\
**Post date:** [September 21, 2022, 7:56pm UTC](https://forum.alpaca.markets/t/replacing-an-order-troubleshooting/10656/1 "2022-09-21T19:56:46Z")

</div>

Hey community,

Having a ton of trouble trying to get an order\_id for replacing an order using the replace\_order.

Working in python.

```auto
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.

---

<div class="post-metadata">

**Author:** ![FIRMCEO](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/firmceo/32/1924_2.png) [@FIRMCEO](https://forum.alpaca.markets/u/FIRMCEO)\
**Post date:** [September 23, 2022, 7:48pm UTC](https://forum.alpaca.markets/t/replacing-an-order-troubleshooting/10656/2 "2022-09-23T19:48:17Z")

</div>

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.
