Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: About commissionReport.realizedPNL
Brendan is correct about the UNSET_DOUBLE or Double.MAX_VALUE the various languages use to indicate "undefined value". The same is true for integer fields where the Integer.MAX_VALUE (2^31)-1 = 2,147,483,647 is used as the UNSET_INTEGER indicator. You should get "undefined realizedPNL" only for commission reports of entry trades, since there is no PNL from price changes yet. Commission reports for exit trades will show the actual realized PNL for that trade. Depending on how you think about PNL, you could set "realizedPNL = -commission" for entry positions (when realizedPNL is undefined) since the commission you pay for entering into the position is a small loss right from the start. 闯ü谤驳别苍 On Thu, Jul 21, 2022 at 12:37 PM, Brendan Caffrey wrote:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: SPX Betas?
I'm afraid unless someone here is feeling generous you are going to have to 1) get the price feeds, 2) do the maths according to your own flavouring and 3) make it robust to all the errors, data failures and other issues that are part of real trading. If you have problems with 1) or 3) we are definitely the right place to ask. 2) is more of a personal choice. Best of luck with it all, M On Thu, 21 Jul 2022, 16:47 , <jthechu365@...> wrote: Hi all - new to this forum, hoping to learn a lot here!? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: About commissionReport.realizedPNL
That value (1.797...e+308) is the maximum value a double can hold. IB uses that to indicate the value is unset. In the C++ API code, they have an UNSET_DOUBLE constant that you can compare against, there may be something similar in the python code. Also, my python is a little rusty, but I think you need to pass an array to writerow, something like: writer.writerow([commissionReport.realizedPNL]) On Thu, Jul 21, 2022 at 10:01 AM <david03kimo@...> wrote: When I execute an order I get the?commissionReport.But I cannot read the?commissionReport.realizedPNL such like?1.7976931348623157e+308. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SPX Betas?
jthechu365@gmail.com
Hi all - new to this forum, hoping to learn a lot here!?
Wondering if anyone has been able to use the excel API to pull in Beta to the S&P500 for a particular stock that is in your portfolio? I am looking to calculate a beta-adjusted equity exposure figure for each position. Thanks, Justin |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
About commissionReport.realizedPNL
When I execute an order I get the?commissionReport.But I cannot read the?commissionReport.realizedPNL such like?1.7976931348623157e+308.
When I create a new position, the?commissionReport.realizedPNL shows?1.7976931348623157e+308.After the position closed,the?commissionReport.realizedPNL shows the normal profit and loss amount. I'd like to export the Profit and loss to csv after every positions closed.But I don't know how to handle the??commissionReport.realizedPNL such like?1.7976931348623157e+308. It cannot export?commissionReport.realizedPNL to csv by?writer.writerow(commissionReport.realizedPNL).It shows error message:csv.Error: iterable expected, not float I don't know how to do? Any ideas is welcome. -- ------ Forex trader David Liao |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: difference between Good Till Cancel and autuCancelDate
Richard already pointed the relevant time-in-force options out and you can learn more about GTC orders in . Interesting read, since there are a few (not so obvious) events that can cancel your order. Your question made me curious about the autoCancelDate field you mentioned. I had seen it before but never paid attention to it so I did a little research. The order object field autoCancelDate, and one called autoCancelParent must have been around for quite a while, but at least since APII 976.1. Documentation is very thin but the reference guide says:
And the for 10.10 say "Added AutoCancelParent attribute to placeOrder/openOrder". I read that as "the order object field autoCancelParent is now sent to and received from TWS/IBGW". autoCancelDate is not mentioned in the release notes so I checked the API source code. At least in the Java API, values for autoCancelDate are ignored when order objects are sent to TWS/IBGW via placeOrder. In other words the field can not be used to cause order cancellation at a certain point in the future. But the field is properly initialized in order objects received from TWS/IBGW via openOrder callbacks. So the field could possibly carry the date/time when an order was cancelled related to autoCancelParent = true. But that is just a guess. 闯ü谤驳别苍 On Mon, Jul 18, 2022 at 11:03 AM, <ajinkya@...> wrote:
Hi All,? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: difference between Good Till Cancel and autuCancelDate
开云体育You can’t specify a date with ‘Good Till Cancel’. It just means that the order will remain valid until either it is filled or it is cancelled (for example via CancelOrder): so it will persist beyond the end of the day’s trading session, whereas a ‘DAY’ order is only valid till the end of the session. ? Don’t confuse ‘Good Till Cancel’ with ‘Good Till Date’ and ‘Good After Time’, where you can specify a date and time. ? Richard ? ? From: twsapi@groups.io <twsapi@groups.io> On Behalf Of ajinkya@...
Sent: 18 July 2022 16:17 To: twsapi@groups.io Subject: [TWS API] difference between Good Till Cancel and autuCancelDate ? Hi All,? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
difference between Good Till Cancel and autuCancelDate
ajinkya@rebootinvesting.com
Hi All,?
I was going through TWS API order structure. I found that we have GTC orders in which we can specify date and time to cancel the order. Why we have seperate field called autoCancelDate? Isn't it same as GTC. Thanks Ajinkya |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Strange Glitch When Requesting PNL
闯ü谤驳别苍,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=Reinold.org@groups.io> wrote: I had a couple minutes and a paper account with no positions and was able to replicate the TWS behavior you report: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Strange Glitch When Requesting PNL
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, 闯ü谤驳别苍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: can two clients for the same ibgateway share market data?
I ran two and more clients connected to the same IB Gateway 981.3o in paper and real accounts and received no error conditions. Everything worked fine, as expected, and just like always, and I cannot confirm any changes in the policy for sharing of market data by multiple clients connected to the same IB GW/TWS. My clients subscribed to a wide range of instruments (40 to 80 each), including TickByTick and Level II data feeds. Maybe you could enable API logging in your IB Gateway and share the occurrence of 10197 errors in your setup? 闯ü谤驳别苍 On Sat, Jul 16, 2022 at 10:42 AM, <liulinglll@...> wrote:ibgateway is 981 and only the 2nd connected client has 10197...it happens consistently |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Strange Glitch When Requesting PNL
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. 闯ü谤驳别苍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: VIX weekly settlement price
Glad this helped. And I learned a few new VIX tidbits, too. 闯ü谤驳别苍 On Fri, Jul 15, 2022 at 12:30 AM, Despair wrote:Wonderful! Thank you so much. This was exactly what I was looking for. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: can two clients for the same ibgateway share market data?
Does this happen all the time? Which IB Gateway version are you running, and will both clients get the error? We sometimes (but rarely) see "Code: 10197" errors during the nightly IBKR maintenance and reset windows or over the weekend. 闯ü谤驳别苍 I have 2 clients connecting to the same ibgateway and both of them subscribe to some market data. The 2nd connected client has error - "Code: 10197, Msg: No market data during competing live session". |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: Tws Vs Gateway Api
Are you referring to the Global Configuration -> Presets -> ... settings in TWS, Adam? Those only impact orders you manually place from within TWS and they are missing from IB Gateway since it does not provide manual order processing. Those TWS order presets have no impact on orders your client applications place through the TWS API. But you can easily write a small function that initializes presets in the objects you send to the API. 闯ü谤驳别苍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: VIX weekly settlement price
IBKR has some material online about VIX trading. Among them is this . On page 17 they describe "Settlement Pricing" and "Special Opening Quotations" and say on page 18 that SOQ values are available as index symbol VRO. the IBKR long name for contract VROLINDEX is "CBOE S&P 500 Volatility Index SOQ". When you grab daily historical bars for VRO:INDEX you get something like what you see below:. Is this what you are looking for? A count value of 1 seems to indicate a new SOQ. 闯ü谤驳别苍
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: updateAccountValue callbacks received but not accountDownloadEnd
开云体育Thanks 闯ü谤驳别苍. I wasn’t aware of observable data objects, so that is a great tip.? Yes, using Python. ? From: twsapi@groups.io <twsapi@groups.io> On Behalf Of 闯ü谤驳别苍 Reinold via groups.io
Sent: Friday, 15 July 2022 1:02 PM To: twsapi@groups.io Subject: Re: [TWS API] updateAccountValue callbacks received but not accountDownloadEnd ? Details depend on your application architecture, your framework(s), and to some degree the programming language you use. In the simplest case you could use a model (as in Model-View-Controller) with read-only fields for the account values you are interested in. Callbacks from the initial request and from ongoing incremental updates simply change the corresponding fields in the model. The various client parts read the most recent value from the model when they need a value. In case you can use "Observable" data objects or some kind of "Data Binding" framework for fields in your model, updates from TWS API callbacks can trigger chains of notifications and method calls in your client. That can work in single-threaded and multi-threaded designs. I assume when you mention "thread event object" you refer to Python. I am not fluent enough in Python to give you concrete advice and "thread event objects" may very well all you need. But there are Python libraries and frameworks available that implement "observable patterns" or more general "data binding" services that may provide more features and more convenient APIs with less programming effort. 闯ü谤驳别苍 |