Hi everyone,

I know this might be a really obvious question but I really can't figure this out…

How do you properly manage a limit and stop market order at the same time? I've been having issues where they both fill or maybe its the limit order partially filling and then the stop market order filling. 

Obviously when one Order gets filled the other gets cancelled but there still seems to be some problem in the code.

Should the stop market order be adjusted if the limit order partially fills? How does everyone handle this? It seems to me that this is a quite important piece of every algorithm yet I didn't find a lot of information about the topic.

I've provided an example that has this problem. Obviously I've placed the orders very close to the current price to illustrate but it also happens with larger ranges.

 

Thank you very much!

 

Author