Limit and Stop Loss Orders Vs. Current Price Discrepency

Newbie here–quick question.

My algorithm calculates limit/trailing stop orders for stocks, and limit/stop limit orders for crypto, by running a calc against the current price of the asset, which I obtain via Latest Quotes. I get the latest quotes, run a number of other analytics, then create suggested orders, and then place the order.

The orders are consistently going through but not filling because the price I’m using seems to be so different from the actual price.

Can anyone provide some guidance? Am I using the wrong API call? Has anyone had this issue? If so, was there some type of calc to compensate?

@Philip_Isles Orders fill when your limit price is better than or equal to the current quote. This is true for both paper and live trading. A buy order will fill if your limit price (ie the most you are willing to pay) is greater than or equal to the ask (ie the least someone is asking or willing to sell for). A sell order order is just reversed. The limit price must be less than the current bid (ie the most someone is willing to buy at).

Could it be the case your limit price is simply too far from the current quote?

Thanks for your response Dan. Let me give you an example, if you don’t mind taking a look. Because I’m sure I’m mising something silly.

I placed a limit order around 6:41 for 2,659.42 but it did not fill, even though the price seemed to match (and yes, I do realize my post was about the pricing not being accurate but now it appears I was mistaken).

Was it possibly because the stop limit was too close? Would the guidance be to widen the range between the limit and the stop?