Maybe this is a basic question, but I haven't been needing to get down into the gritty details of order execution until now as I'm trying to make an intraday algo production ready.

Let's say that I want several orders at once. Two scenarios I can think of:

- Multiple orders to exit a position: A stop market (or stop limit) order as a hard condition stoploss, plus a limit order to try to sell for a profit. If both are issued at once, what happens if the latter is partially filled and then the stoploss triggers?

- An order to enter a position plus a stoploss order to protect the quantity filled so far. Aside from "would this work", it's also a question of what happens when latency enters the equation. Creating a new order after another has been submitted isn't atomic of course.

Any comments or samples illustration such issues would be welcome.