开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育
Date

Re: How do I get portfolio delta and theta values via the TWS API

 

开云体育

?It sounds like what IB calls "Portfolio Delta", referring to the column that can be added to the position window is not really "portfolio" delta, but rather just position delta. ?

Correct

Near the upper right corner of the screen, I also have a portfolio delta and theta which I think represents those components for my entire portfolio.?

Correct. That’s what I calculate in my client and those values correspond.

?I should be able to get the exact same greeks from the API as TWS is showing

Probably check the tickId you use: 10,11,12 or 13. One of them is documented that it should return the same as what is shown on TWS. See:


Of course if strikes are very far OTM, they wouldn’t have an impact on portfolio results anyways, as delta, gamma and theta would all be close to 0. I noticed that for those far OTM, ?I get infrequent market ticks, especially outside regular trading hours so for your portfolio calculation you could just set those to 0 in practice. ?

On Aug 16, 2022, at 3:20 PM, Crow via groups.io <aaroncook394@...> wrote:

Thanks?Bart,
??????It sounds like what IB calls "Portfolio Delta", referring to the column that can be added to the position window is not really "portfolio" delta, but rather just position delta.??


Greeks Columns. To add Greeks columns to the Quote Monitor or other window, hold your mouse over an existing Market Data column heading and click the green "+" sign to insert column.

Near the upper right corner of the screen, I also have a portfolio delta and theta which I think represents those components for my entire portfolio.? Computing the position greeks is straight-forward, but I guess my question is why is the tick computation returning infinity when TWS is showing non-infinite Greeks.? You might be right that it could be looking at something else, but I should be able to get the exact same greeks from the API as TWS is showing.? For positions that are not so worthless / out of the money, the result of the API greeks from tick calculation is close to what TWS shows.


From:?[email protected]?<[email protected]> on behalf of bart??<bart@...>
Sent:?Tuesday, August 16, 2022 2:55 PM
To:?[email protected]?<[email protected]>
Subject:?Re: [TWS API] How do I get portfolio delta and theta values via the TWS API
?
More likely probably is that they call most recent historical data to show in TWS if no current data is available…


On Aug 16, 2022, at 2:48 PM, bart??via??<bart@...> wrote:

I believe TWS somehow stores the last data so that when it does not receive current valid data it displays the buffered data.
It seems on days with big moves at market open especially, greeks are not available even up to an hour into trading.
Similar also for market value or bid/ask prices outside trading hours: you won’t get anything via the API, but TWS still shows it.

On your question for portfolio greeks, I don’t think it’s returned from the API since you get greeks from ticker data (which does not take into account your position in the contract). So you need to calculate portfolio greeks yourself based off the ticker data greeks and your positions. I do this and the result comes out identical to what TWS shows.


On Aug 16, 2022, at 1:10 PM, Crow via??<aaroncook394@...> wrote:

I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?


The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.

<Screenshot at 2022-08-16 12-54-56.png>




Re: How do I get portfolio delta and theta values via the TWS API

 

开云体育

Thanks?Bart,
??????It sounds like what IB calls "Portfolio Delta", referring to the column that can be added to the position window is not really "portfolio" delta, but rather just position delta.??


Greeks Columns. To add Greeks columns to the Quote Monitor or other window, hold your mouse over an existing Market Data column heading and click the green "+" sign to insert column.
guides.interactivebrokers.com

Near the upper right corner of the screen, I also have a portfolio delta and theta which I think represents those components for my entire portfolio.? Computing the position greeks is straight-forward, but I guess my question is why is the tick computation returning infinity when TWS is showing non-infinite Greeks.? You might be right that it could be looking at something else, but I should be able to get the exact same greeks from the API as TWS is showing.? For positions that are not so worthless / out of the money, the result of the API greeks from tick calculation is close to what TWS shows.


From: [email protected] <[email protected]> on behalf of bart decanne.com <bart@...>
Sent: Tuesday, August 16, 2022 2:55 PM
To: [email protected] <[email protected]>
Subject: Re: [TWS API] How do I get portfolio delta and theta values via the TWS API
?
More likely probably is that they call most recent historical data to show in TWS if no current data is available…


On Aug 16, 2022, at 2:48 PM, bart decanne.com via groups.io <bart@...> wrote:

I believe TWS somehow stores the last data so that when it does not receive current valid data it displays the buffered data.
It seems on days with big moves at market open especially, greeks are not available even up to an hour into trading.
Similar also for market value or bid/ask prices outside trading hours: you won’t get anything via the API, but TWS still shows it.

On your question for portfolio greeks, I don’t think it’s returned from the API since you get greeks from ticker data (which does not take into account your position in the contract). So you need to calculate portfolio greeks yourself based off the ticker data greeks and your positions. I do this and the result comes out identical to what TWS shows.


On Aug 16, 2022, at 1:10 PM, Crow via groups.io <aaroncook394@...> wrote:

I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?


The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.

<Screenshot at 2022-08-16 12-54-56.png>



Re: How do I get portfolio delta and theta values via the TWS API

 

开云体育

More likely probably is that they call most recent historical data to show in TWS if no current data is available…


On Aug 16, 2022, at 2:48 PM, bart decanne.com via groups.io <bart@...> wrote:

I believe TWS somehow stores the last data so that when it does not receive current valid data it displays the buffered data.
It seems on days with big moves at market open especially, greeks are not available even up to an hour into trading.
Similar also for market value or bid/ask prices outside trading hours: you won’t get anything via the API, but TWS still shows it.

On your question for portfolio greeks, I don’t think it’s returned from the API since you get greeks from ticker data (which does not take into account your position in the contract). So you need to calculate portfolio greeks yourself based off the ticker data greeks and your positions. I do this and the result comes out identical to what TWS shows.


On Aug 16, 2022, at 1:10 PM, Crow via groups.io <aaroncook394@...> wrote:

I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?


The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.

<Screenshot at 2022-08-16 12-54-56.png>



Re: How do I get portfolio delta and theta values via the TWS API

 

开云体育

I believe TWS somehow stores the last data so that when it does not receive current valid data it displays the buffered data.
It seems on days with big moves at market open especially, greeks are not available even up to an hour into trading.
Similar also for market value or bid/ask prices outside trading hours: you won’t get anything via the API, but TWS still shows it.

On your question for portfolio greeks, I don’t think it’s returned from the API since you get greeks from ticker data (which does not take into account your position in the contract). So you need to calculate portfolio greeks yourself based off the ticker data greeks and your positions. I do this and the result comes out identical to what TWS shows.


On Aug 16, 2022, at 1:10 PM, Crow via groups.io <aaroncook394@...> wrote:

I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?


The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.

<Screenshot at 2022-08-16 12-54-56.png>


How do I get portfolio delta and theta values via the TWS API

 

开云体育

I configured IB TWS workstation to show the portfolio delta and theta values for each position aggregated in my portfolio as shown in the screenshot.? It basically just adds up the position delta and theta of each leg.? However, when I reqMktData() for those two positions shown in the screenshot, the resulting tickOptionComputation() callback returns Infinity for delta and theta.? Likely because the options are too far OTM and there was a problem with the calculation.? But if that is the case, how is TWS workstation getting the delta and theta, is it possible to pull those values via the API?


The Implied Volatility of an underlying based on its current option prices is returned in tick 24. See Available Tick Types. The IB 30-day volatility is the at-market volatility estimated for a maturity thirty calendar days forward of the current trading day, and is based on option prices from two consecutive expiration months.
interactivebrokers.github.io

Screenshot at 2022-08-16 12-54-56.png


Re: Which Java version to use?

 

are the current Long Term Support versions. But is sounds like your problem relates more to dependency management and not so much to Java versioning.

You might want to look into something like Maven or Gradle to manage all direct and indirect dependencies your code has. Those tools can make deployment packages for you that prevent "class not found" situations at runtime. Both tools have plug-ins for NetBeans.

闯ü谤驳别苍


Re: Which Java version to use?

 

Thank you for your reply 闯ü谤驳别苍. I am indeed not concerned about TWS/Gateway itself as I am aware that it comes with its own Java software. My question is more directed at recommendations or caveats related to Java for my client software which runs my trading strategy.
The error I observed in my software was not directly related to the IB wrappers. I got a "class not found" error when sending an email. This error caused my software to crash. And it did so repeatedly, it was not a one-time incident. Investigating this I found that my upgraded computer has now different Java versions installed than my trading computer, of which I have not yet upgraded the Ubuntu version.
I am not a seasoned programmer and my software is very simple in setup. So I want to standardize to one Java version, as you suggest. Preferably a Java version which will remain stable for a very long time (a "long term support" version, if this terminology applies). My understanding is that Netbeans 8.2, which I'm currently using, is not able to handle newer versions of Java, so I would also need to upgrade that.


Re: Which Java version to use?

 

What kind of issues do you experience, JG?

TWS and IBGW bring their own customized Oracle Java 8 VM with JavaFX and my strong suggestion is that you don't change that and let TWS/IBGW use their embedded JVM.

The appropriate Java VM for your own software and the TWS API jar depends on what requirements the frameworks and libraries have that your software depends. It would make sense to standardize on one Java version for your entire workflow from IDE, through testing, and deployment.

For us that is currently Java 9 (though we are evaluating a migration to Java 11 or 17) and we have rock stable results running identical jars on OpenJDK 9 for Windows and Linux. Running our Java 9 jars on OpenJDK 11 works fine without any problems, too.

For better version control, compatibility, and debugging we build our own TWS API jar from the Java source code provided by IBKR. The IBKR jar that comes with API distributions is compiled with Java 8 and has version 52 class files.

闯ü谤驳别苍


Which Java version to use?

 

A few days ago I upgraded my desktop computer from Ubuntu 20.04 to 22.04. Since then am I experiencing issues with my trading software. Investigating this I get the impression that it is caused by using old and/or outdated versions of Java and the Netbeans IDE I'm using. I have been carrying it over for many years, but fear that by now it is considered obsolete.
What are the recommendations from other users related to Java? For example: does it matter whether I use OpenJDK or Oracle's Java? I seem to recall that a couple of years ago there were some issues with OpenJDK and IB's software, but don't know the current situation. What version should I upgrade to? Are there other considerations?
Of course am I looking for the "path of least resistance": my software is running for more than five years and I would like to change as little as possible. And do the bare minimum required to get it to work to the current versions of the Java language and IDE on the current (and future) Ubuntu LTS versions.


Reuters / Refinitiv and Dow Jones Press Release subscriptions using the API

 

If I subscribe to?Reuters / Refinitiv and Dow Jones Press Release - will I also get the data using the API?
And how can I subscribe to Reuters / Refinitiv data with API? I can't see it on the "Research Subscriptions" page on my user settings.


Re: ScannerSubscription

 

Must be a bug in TWS since it's Avrg Vlm ($) equals the Avrg Vlm (expressed in # shares) for all of these symbols.

Either the TWS developers mapped the wrong data field to the column, or they forgot to multiply the Avrg Vlm (expressed in # shares) with the average share price.

Max


ScannerSubscription

 

I'm trying to build some scripting for a market scanner based on average dollar volume, however this figure doesn't seem to make sense.

In the case of tesla for example:
1) the daily dollar volume= 26.6M x ~$900 = $24 billion. This looks right
2) the 90 day average dollar volume = 30.8M x ~$800 = $24 billion. (assuming average price was $800 for the last 90 days).?

However the Average Volume ($) is only showing $30.8M which is about 1000 times less. Any ideas?

tws.png


Get company analyst forecasts

 

Is there a way using the TWS API get?analyst forecasts for all upcoming quarters and years?
I try?reqFundamentalData but I only get forecast for the current quarter, next quarter and current year.
I need data for few following quarters and years to come, which exist on TWS fundamentals explorer.



Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Thanks a lot

On Fri, 12 Aug 2022 at 21:29 Joel Gross <joelrgross@...> wrote:
The empty string appears to work normally.

On Fri, Aug 12, 2022, 11:26 AM Edward <ed.gonen@...> wrote:
Joel

If you can, please update on your results. I didn't have a chance to check this yet as after my failure with cancellation I had reverted to the "old" API.?

Thanks in advance
Ed

On Fri, 12 Aug 2022 at 20:46 Joel Gross <joelrgross@...> wrote:
I tried passing in a datetime string and it ended up not cancelling my orders properly. I will try the empty string.

--
Ed Gonen

--
Ed Gonen


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

Joel Gross
 

The empty string appears to work normally.


On Fri, Aug 12, 2022, 11:26 AM Edward <ed.gonen@...> wrote:
Joel

If you can, please update on your results. I didn't have a chance to check this yet as after my failure with cancellation I had reverted to the "old" API.?

Thanks in advance
Ed

On Fri, 12 Aug 2022 at 20:46 Joel Gross <joelrgross@...> wrote:
I tried passing in a datetime string and it ended up not cancelling my orders properly. I will try the empty string.

--
Ed Gonen


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

 

Joel

If you can, please update on your results. I didn't have a chance to check this yet as after my failure with cancellation I had reverted to the "old" API.?

Thanks in advance
Ed

On Fri, 12 Aug 2022 at 20:46 Joel Gross <joelrgross@...> wrote:
I tried passing in a datetime string and it ended up not cancelling my orders properly. I will try the empty string.

--
Ed Gonen


Re: What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)

Joel Gross
 

I tried passing in a datetime string and it ended up not cancelling my orders properly. I will try the empty string.


Locked Re: No documentation for new manualCancelOrderTime in cancelOrder?

 

We had a thread about this very recently. Please see "What is manualOrderCancelTime param of Eclient::cancelOrder( int id, String manualOrderCancelTime)". That topic should answer your question. If not, let's continue on the original topic.

闯ü谤驳别苍


Locked No documentation for new manualCancelOrderTime in cancelOrder?

Joel Gross
 

I saw this has been added, but did not see documentation for it (in client.py):
def cancelOrder(self, orderId:OrderId, manualCancelOrderTime:str):
? ? ? ? """Call this function to cancel an order.

? ? ? ? orderId:OrderId - The order ID that was specified previously in the call
? ? ? ? ? ? to placeOrder()"""

? ? ? ? self.logRequest(current_fn_name(), vars())

? ? ? ? if not self.isConnected():
? ? ? ? ? ? self.wrapper.error(NO_VALID_ID, NOT_CONNECTED.code(), NOT_CONNECTED.msg())
? ? ? ? ? ? return

? ? ? ? if self.serverVersion() < MIN_SERVER_VER_MANUAL_ORDER_TIME and manualCancelOrderTime:
? ? ? ? ? ? self.wrapper.error(orderId, UPDATE_TWS.code(), UPDATE_TWS.msg() + " ?It does not support manual order cancel time attribute")
? ? ? ? ? ? return

? ? ? ? VERSION = 1

? ? ? ? flds = []
? ? ? ? flds += [make_field(OUT.CANCEL_ORDER)]
? ? ? ? flds += [make_field(VERSION)]
? ? ? ? flds += [make_field(orderId)]

? ? ? ? if self.serverVersion() >= MIN_SERVER_VER_MANUAL_ORDER_TIME:
? ? ? ? ? ? flds += [make_field(manualCancelOrderTime)]

? ? ? ? msg = "".join(flds)

? ? ? ? self.sendMsg(msg)


Re: TypeError: TestApp.error() takes 4 positional arguments but 5 were given

 

Well, if your code was written against a version 9 API, you might want to stay with the stable API? 9.81 track for now. You can still run your code against all (even the latest and beta) TWS and IBGW versions. It's a good practice to lock the API version in and to avoid automatic and uncontrolled version changes.

But by its nature, the stable track is a couple years old and is lacking the latest features version 10 provides. So you might want to start the development, unit, system, and regression testing cycles so that you can eventually move to the version 10 API.

闯ü谤驳别苍

On Thu, Aug 11, 2022 at 08:44 PM, Joel Gross wrote:

Wow, thanks guys! Tons of major changes it looks like.?

I have not been developing much... is it worth it to upgrade or should I switch from Latest to Stable?