It can be very tempting to use stop and/or limit orders in place of market orders when implementing a strategy since these types of orders are already placed at the exchange and they can help guarantee execution at a particular price.
There are however several behaviors to be aware of when using these types of orders especially with fully automated strategies:
Limit Orders are not guaranteed to be executed. Even if the price action has traded through your limit price, it may not have been executed in a live environment if there was not enough demand to fill your order at the specified price.
Stop Orders are often triggered on Bid/Ask. It’s a common misconception that stop orders are triggered by last price. Most (if not all) brokers trigger stop orders using the bid or ask price (depending on whether it’s a buy or sell). This can cause your stop order to be executed unexpectedly early especially if there is a significant spread in the bid/ask prices.
Stop Orders are filled at market. Once a stop order is triggered, it is filled at market price. Stop Limit orders do exist, but are not currently supported by this API. Also note that not all brokers support Stop Limit orders.
If you choose to implement a fully automated strategy using non-market orders, you will need to consider these behaviors and add the appropriate code to handle cases where your orders do not get filled, or do not get filled at your expected price.
Ultimately, the choice you make will be a trade-off between order executions vs. fill price.