-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not understanding IB open positions and closing them #47
Comments
I can only comment on your 2nd question:
I was wondering the same: See IBKR docs on the endpoint here: https://www.interactivebrokers.com/campus/ibkr-api-page/webapi-ref/#tag/Trading-Portfolio/paths/~1portfolio~1%7BaccountId%7D~1positions~1%7BpageId%7D/get There is a parameter named See also position2(), which is not mentioned in IBKR docs. Never tried it. |
hey @weklund great questions. @salsasepp gave you a great explanation for the second - do try the position2 endpoint, it's meant to avoid IBKR server caching, - so let me address the first:
That's correct. 'Closing' a position isn't actually an action that one can take explicitly, as far as I know no trading platform exposes a In a simple case your example is correct - closing a position equals making one or more orders that will sell all your currently held positions of a stock. Note that you could close a position using several orders, not just one, eg, over a course of a day - the intent to close all is still there. And contrarily, note that simply selling a portion - but not all - of your stock would probably be referred to as 'reducing' a position rather than 'closing' it.
Did you happen to submit these when the markets were closed? Eg. see NYSE trading hours: https://www.nyse.com/markets/hours-calendars |
@salsasepp That helps thank you! wow I've been looking at the wrong docs....
@Voyz I'm doing Futures exclusively but during after hours trading, and on paper account. Maybe it's harder for paper accounts to simulate order books after hours? Will try again during normal market hours and follow up. |
I'd imagine the after hours would be the cause of your issues here. For futures the concept of closing position is pretty much the same as for stocks. |
Haven't tried |
Glad to hear it worked! 👏 Do try |
@weklund @Voyz
You still need to know which direction the order has to take, however, one important difference is, that if there are OCO orders (or generally other orders for the given symbol?) they can be cancelled automatically.
This is how the web trading in the client portal does it, because it has the extra feature of closing an exisiting position. |
Wow @mmarihart that is super useful! How did you find about this endpoint? I'll add this parameter 🙌 |
Not technically an ibind issue, but this repo seems to be the best brain trust for understanding the API, outside of spamming IB customer support. Hoping I can get some extra context 😁
My question is 2 part:
1. How do I go about 'closing' an open position?
I'm going through and following the example given in the place order file here
I see the response from using
client.place_order()
from itCool.
So I can double check when the order is filled that it's open with
client.positions()
Now I want to close this position. Am I making another order that takes the opposite side and same size?
Both open and close orders I made were MKT, but the close orders stayed unfulfilled for a really long time so I feel like I'm missing something.
2. Does an API response change based on a particular reason?
After I opened the position, everytime I called to the status via
client.positions()
I would get this response:But other times I'll make the exact same call seconds later but get a different response type
Is this common? Is there anything I can do to get consistent API behavior?
The text was updated successfully, but these errors were encountered: