Keyboard Shortcuts
Likes
Search
Is there a way to automate retrieving margin report?
There is no API request that generates a "Margin Report", but then I am not so sure that such a report would be terribly helpful since your client would have to analyze the report to make the data actionable. TWS API does however, give you access to all kinds of margin info on a transactional basis that your trading logic can base order decisions on. As bespalex already mentioned, reqAccountSummary? gives you a global margin view. Both, as a snapshot when you make the request as well as on an ongoing basis when margin changes. There are well more than 100 different values you might receive, among them (at least) these margin related ones:
When your application places orders, callbacks report their possible impact in case they execute with ~10 margin, equity, and loan related values. Your application could remember those and verify them against reqAccountSummary updates once those orders execute. You can use the feature (just like the "Check Margin" in TWS) at any point to check the possible margin impact of an order before you place it. Or, as krkeane pointed out, you can submit fully liquidating "what if" orders for the positions you are interested in to see the margin impact of those positions. And finally, there are warnings and errors your application may receive, such as:
´³¨¹°ù²µ±ð²Ô On Sat, Dec 23, 2023 at 01:16 PM, @jiamin wrote:
No, it doesn't.? I think reqAccountSummary only shows the margin status for the account,? but what I want to see if the margin requirement of every ticker.? Please let me know if I am not correct. Thank you. |
Thank you so much @´³¨¹°ù²µ±ð²Ô for the detailed reply/
I have indeed tried using whatif order but this is not enough for me. Sometimes for one symbol??(say MSFT or /es)?I have uneven number of options contracts, for example 1000 shares,? -3 puts,? -4 calls and another -2 puts on another expiration date.? TWS doesn't allow closing all of them in one order and thus I cannot see the margin impact of that symbol.? ?Using whatif order to close one position is possible but the margin impact of closing that position is also not what I want.? What margin report gives me is the margin impact of all positions related to one symbol.? Here is an example I'd love to know if I can automate it's delivery and/or I can get this information elsewhere (through flex query for example, but I doubt it) |