Order Filled above the market price?

Hello,
I created a sell order with a stop loss and a profit target on the GOLF instrument. The position was opened at the market price but closed shortly afterward at a price way above the market price. Why did this happen?
The below images shows the GOLF price with day candles and my orders. The market price when the stop buy order was filled was below $40 but it was filled at $40.19 each share

Was this in paper trading? Paper trade orders do not actually get routed to Alpaca’s execution partners. The order fills are simulated using the current bid/ask prices. Orders are filled at the quote prices and not the latest trade prices. This represents probably a worst case scenario because, in actual trading, orders generally fill better than than that. Alpaca doesn’t include any ‘price improvement’ in paper trade simulations. That may be why GOLF filled at a price higher than the actual traded prices. It was in paper trading (ie simulated).

If this was in live trading, this still could happen if the order was for an ‘odd lot’ (ie not a multiple of 100). Though infrequent, odd lot orders aren’t required to be handled like round lot orders. Fill prices could be higher or lower and often aren’t captured in all data feeds.

Can you envision how an order simulator might function that approximates live trading? Perhaps midpoint between bid and ask? Other?