I am building a cryptocurrency exchange, and having some trouble with the implementation details for a stop-limit order. I have a few scenarios I would like clarification on, along with any useful resources on the subject you guys may have.
For simplicity lets just deal with sell orders. According to CapitalOne Investing:
Sell Orders: The Stop Price must be entered at least $0.01 below the current Bid Price.
So starting with a blank slate (no sell orders), I cannot add a stop-limit order. Now someone adds a limit order to the book, I can now add my stop-limit order with a slightly higher price. But they then cancel their limit order:
1 - Should my stop order get triggered (turned into a limit order) or cancelled? I assume it should get triggered
Now imagine there is a limit order, followed by many stop orders all with the exact same stop price (sorted by timestamp), but differing limit prices. If someone makes a buy order, which consumes the first limit order, what should happen with the stop orders?
2 - Should I run through and execute all stop orders into limit orders before continuing with the current buy order?
Should I start from the first stop order, and keep executing until the buy order is filled and leave the rest? What if a later stop order had a better limit price? (Seems like it should be sorted by time)