Keyboard Shortcuts
Likes
Search
Strange Glitch When Requesting PNL
This took me forever to diagnose, but here is the glitch.? When request PNL message is sent there is no PNL response if you've already asked before.? Let me explain.
This only happens under certain conditions:
This does not happen with IB gateway, I can request PNL as often as I'd like.? Also this does not happen if my PNL is not zero, so if I've made or lost money it will send my my daily PNL over and over again. I'm using TWS version 10.15 |
Which PNL feed are you trying to subscribe to, Marc?
And how does your code wait after requesting PNL? I guess what I am asking is are you using any calls to a "sleep" method with some prescribed time after the PNL subscription request? You could enable the API log in TWS to see whether TWS does not send a PNL at all? or whether TWS does send it but your client logic somehow locks itself up. ´³¨¹°ù²µ±ð²Ô |
I had a couple minutes and a paper account with no positions and was able to replicate the TWS behavior you report:
In this case, subscriptions to trigger a single callback only for the first client that connects to TWS, and dailyPnL,, unrealizedPnL,, and realizedPnL? are reported as 0. That client does not receive any further callbacks (there are no positions) and all subsequent clients of that TWS do not event receive the initial callback. That behavior is definitely inconsistent, but your client should not have to lock up. In fact, for my taste, I would not have expected a callback for the first client to take place:
You may want to take a look at your client architecture and consider a "PortfoilioModel" or "AccountModel" implementation similar to those used in Model-View-Controller architectures. Callbacks from TWS API subscriptions update values in the model when they happen and your client reads the most recent values from the model when it needs one. During startup, all model values are either initialized with 0 (or "undefined" if that is what you prefer) and your client operates properly with and without the callback. The TWS API is asynchronous and event oriented in nature and your client must be resilient and always be prepared that an event just does happen (for many reasons). A couple other quick observations:
You could file a trouble ticket with IBKR for this, but I think it would get a very low priority or may even be rejected by engineering right away. Hope this helps, ´³¨¹°ù²µ±ð²Ô |
´³¨¹°ù²µ±ð²Ô,First let me apologize, somehow I must have missed your original response with questions, thanks again for taking the time to respond.? I am glad you were able to replicate the issue so that I am not alone. I agree that this is not a high priority issue since it can be easily compensated for, and usually you only need to call reqPNL once.? My issue is that I am still building my platform and debugging.? My code keeps track of the PNL based on responses to trades, specifically I listen for the??call back and record entry and exit trade prices.? As a redundancy I subscribe to reqPNL to make sure the number match. Since my code is ( or was ) prone to crashing the first thing my code does is reqPNL so it knows what the starting PNL is.? I mostly use IB gateway which does not have this issue.? But I noticed at random times my code froze, after digging I realized it froze waiting for the first PNL. I will need to look into perhaps the update account value as an alternative, to waiting for the reqPNL On Sun, Jul 17, 2022 at 11:22 PM ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote: I had a couple minutes and a paper account with no positions and was able to replicate the TWS behavior you report: |