Describe the bug
Assuming that I have a 10-share long position for stock X, I want to close the existing long position first, and then open a 10-share short position for the same stock. I have tried the following two approaches using the paper trading API and they have both failed:
To Reproduce
Approach 1:
Call the Close a Position endpoint to liquidate the existing long position.
After the http response was received (without knowing whether the position has been closed), place a market sell order selling 10 shares of stock X, also setting the position intent to be "sell to open".
An error will then be thrown by the API saying that "position intent mismatch. inferred sell to close".
Approach 2:
Place a market sell order selling 10 shares of stock X in attempt to close the long position.
After the http response was received (without knowing if the order has been filled), place another market sell order selling 10 shares of stock X, setting the position intent to be "sell to open".
The same error will be thrown by the API saying that "position intent mismatch. inferred sell to close".
Expected behavior
In either approach, I think the second market sell order should be accepted rather then be rejected. Basically the client program is just trying to close the existing position and build a new position of the opposite side.
I guess in either case the error was thrown because the first order has not been filled yet, but even so the second order has no reason to be rejected.
Client programs can avoid such errors by postponing the submission of the second order after the first order was filled, but this can lead to quite complex client-side logic. So I think the server side should allow orders to be placed in this manner.
Desktop (please complete the following information):
Describe the bug Assuming that I have a 10-share long position for stock X, I want to close the existing long position first, and then open a 10-share short position for the same stock. I have tried the following two approaches using the paper trading API and they have both failed:
To Reproduce
Approach 1:
Approach 2:
Expected behavior
In either approach, I think the second market sell order should be accepted rather then be rejected. Basically the client program is just trying to close the existing position and build a new position of the opposite side.
I guess in either case the error was thrown because the first order has not been filled yet, but even so the second order has no reason to be rejected.
Client programs can avoid such errors by postponing the submission of the second order after the first order was filled, but this can lead to quite complex client-side logic. So I think the server side should allow orders to be placed in this manner.
Desktop (please complete the following information):