I am trying to understand what is the best way to close a specific number of contracts. For example if i am net short 10 positions of a certain contract and i only want to close out 2 positions, what is the best way for me to do this with the API?
This is a little messy as the API does not offer this capability.
You have place 2 market orders in opposite direction. The issue is that when you place these orders, ToV does a risk assessment based on margin and reject the order if you are when you’re out of margin even when it is in the opposite direction. This feels like a bug to me, but it happens and your code should be able to deal with that.