¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: historical open interest

 

So I did some reverse engineering of TWS and found that the WhatToShow enum is just turned into a string in the protocol.? It seems that when open interest data is being requested, WhatToShow is set to either "Option_Open_Interest Call" or "Option_Open_Interest Put" in the protocol.? Is this a valid thing to do for reqHistoricalData (not just reqHistoricalTicks) and this is just a short coming of the Java API (that the WhatToShow enum is missing some things)?? Or is this some weird hack that shouldn't work which is why it isn't documented by IB?

thanx,
Hunter

On Saturday, March 13, 2021, 8:48:31 PM PST, Hunter C Payne via groups.io <hunterpayne2001@...> wrote:


Hi all,
?? I was wondering if anyone knew a way to get historical open interest data on equities from IB.? Is it buried in reqFundamentalData somewhere these days?? I know I can find it in TWS itself but I can't seem to determine which API calls return this specific data.

thanx,
Hunter


Re: event when a stock reaches a certain price

 

I am not aware of a scanner that does what you are looking for. Please keep in mind the IB API is mostly for the support af TWS and if TWS does not need it, it's probably not there.

If you are only interested in price changes, subscribing to tick id 4 (Last Price) should suffice.That tick will only be sent when the trade price changes, Take a look at . Even at 800 contracts, data volume will be quite reasonable.

But your 800 contracts simultaneously will run against the data lines limitation. Take a look at the ":How Market Data is Allocated" in
For 800 market lines you'd need:
  • $6,400 in commission monthly
  • $8,000,000 in equity
  • or purchase 7 quote boosters at $30 each per month (210 per month)

´³¨¹°ù²µ±ð²Ô


On Wed, Mar 17, 2021 at 07:28 PM, corneliu maftuleac wrote:
I think the list of tickers is around 800 (I am using ibinsync python api, but the general idea is the same).

So, your suggestion is to just use regular market data (ex: reqMktData(conId, contract, 221)) and it should be fine?
I was thinking there should be a more advanced solution like a scanner subscription or something, because in fact I dont need the data itself rather just a notification when price reaches certain level.


Re: event when a stock reaches a certain price

corneliu maftuleac
 

I think the list of tickers is around 800 (I am using ibinsync python api, but the general idea is the same).

So, your suggestion is to just use regular market data (ex: reqMktData(conId, contract, 221)) and it should be fine?
I was thinking there should be a more advanced solution like a scanner subscription or something, because in fact I dont need the data itself rather just a notification when price reaches certain level.


Re: How to create a performance efficient trading app so each sub process runs smoothly in Python?

 

You can also think of using something like ZeroMQ as your messaging/concurency backbone.
Python has a bindings module for it - pyzmq.

On Wed, Mar 17, 2021 at 2:40 AM Alex Gorbachev <ag@...> wrote:
I love Python but it has its own place and it's not good for real-time-ish parallel compute. You can hack around things but in the end it won't be crazy.

You can consider Go and node.js from mainstream languages (apart from C++).
I personally always wanted to try Elixir but never got around - perfect for highly concurrent stuff.?

On Sat, Mar 13, 2021 at 2:52 PM matt <rmdeboer82@...> wrote:
What would be the best way to do on-the-fly computations using Numpy, Pandas for trading using IB TWS API, writing to/from mySQL, and in the meanwhile receive and send data and orders?

From (and ) I conclude that CPU-bound programs, those that spend most of the their time processing data (like on the-fly computations using Pandas which is synchronous single threaded), solutions like threading (pre-emptive multitasking) and asyncio are inferior (and may disrupt the sending/receipt of data or introduce some lag or data drops) since there is only one Python interpreter on a single core/processor (asyncio aligns I/O processes more efficiently) that takes care of both the CPU computations and checking for socket data.

I know there is? a ib_insync library that implements cooperative multitasking (asyncio) in Python, but will the overall program be fast enough if you do computations using large dataframes? I read that on a socket level there might not be any limitations (¡°socket itself is actually thread-safe¡±), as suggested by . I do not assume that Ptyhon has it implemented this way since the Global Interpreter Lock is in place (single thread, synchronous). From :

IB.sleep(0); may be an alternative, but I do not think a Pandas groupby() can be interrupted once called.

Should I use the Multiprocessing library and do every task on its own processor (thus dataframe calculations, mySQL connection read/write, sending and receiving orders and data)?
Or should I combine some things using (I think some next level threading which can be combined with the normal way of interpretation of code by Python) or the (has to do with built-in async for Scikit-Learn, Pandas, etc. functions, if I understand correctly) library? I think this is next level, and may be an overkill.

Or should stick to Java (I do not know if there is a Pandas like alternative which allows easy manipulation of data and performing machine learning for example, but threading may be organized better)?

Any suggestions or tutorials?

(I read something about was well, but that¡¯s a whole different story since it is not directly applicable to IB TWS API, and may be prone to delays resulting from single core processing/interpreting by Python as well, if I understand correctly)


unable to build with visual studio 2019 and cpp API 9.81

 

Hi,
I get the error?
Error MSB8020 The build tools for v142 (Platform Toolset = 'v142') cannot be found.
Do I need to make changes to project solution after downloading it?
I did install v142, not sure why it is not finding it.
Thank you


Re: event when a stock reaches a certain price

 

Can you be more specific what you consider huge? Did you buy quote boosters so that you can subscribe to more than 100 contracts?

From what you are doing, I'd say you'd only need to subscribe to monitor the Last Price and Last Size ticks. So you would look at roughly 4 - 5 call backs per contract per second.

You might want to review your approach and code. I am subscribing to a pretty massive amount of data (process and log them in a Json format) and my server does not break a sweat. And it's a very small server for today's standards. Just to give you some idea:
  • The total volume is between 30million and 60million ticks per day and sometimes more than 1,000 callbacks per second for busy days
  • That is all available market data for ~75 contracts
  • Plus TickByTickLast and TickByTickBidAsk for five contracts (yes five. I ask for five and most of the days get five)
  • Plus Level II for three contracts
We use the standard Java API..

´³¨¹°ù²µ±ð²Ô

On Wed, Mar 17, 2021 at 03:54 PM, corneliu maftuleac wrote:
Hi,

I am trying to monitor a list of tickers (lets say the list is big).
I want to know when one of the tickers reaches a certain price. The target price is generated by an algo so it's not just a %-change.

I tried subscribing to realtime data to all of the instruments but this generates HUGE amount of network traffic to the point that my code is not really able to process all of the events.
Is this possible to do with scanner subscriptions?
I dont find where I can specify that scanner subscriptions to work only with a specific ticker or a list of tickers.


event when a stock reaches a certain price

corneliu maftuleac
 

Hi,

I am trying to monitor a list of tickers (lets say the list is big).
I want to know when one of the tickers reaches a certain price. The target price is generated by an algo so it's not just a %-change.

I tried subscribing to realtime data to all of the instruments but this generates HUGE amount of network traffic to the point that my code is not really able to process all of the events.
Is this possible to do with scanner subscriptions?
I dont find where I can specify that scanner subscriptions to work only with a specific ticker or a list of tickers.


Little tool for option chain contract creation

juxeiier
 

¿ªÔÆÌåÓý

Hi,

I have created a little library which can scrape option chains in a (hopefully) easy manner.
The topic is discussed here
/g/twsapi/message/46566
/g/twsapi/message/42241
/g/twsapi/topic/81356218

The source code, together with installation details, is here .
The usage is then as simple as
chain = ibt.getOptionContractsUpUntilDays(aapl, 60)

or

aapl=Stock(symbol='AAPL', exchange='SMART/AMEX')
chains = ibt.getOptionContractsUpUntilDays(aapl, 60)
It works on my site, but is very new, so probably some shortcomings :)
Would be great if someone could test it.

Cheers,
Juergen


Order cancelation reason

 

How do I distinguish order rejection at the very beginning (like margin) from order cancellation, say, on time expired for GTD orders? I get order status update event and it has status ¡®Cancelled¡¯.

Thanks,
Alex


Re: How to create a performance efficient trading app so each sub process runs smoothly in Python?

 

I love Python but it has its own place and it's not good for real-time-ish parallel compute. You can hack around things but in the end it won't be crazy.

You can consider Go and node.js from mainstream languages (apart from C++).
I personally always wanted to try Elixir but never got around - perfect for highly concurrent stuff.?

On Sat, Mar 13, 2021 at 2:52 PM matt <rmdeboer82@...> wrote:
What would be the best way to do on-the-fly computations using Numpy, Pandas for trading using IB TWS API, writing to/from mySQL, and in the meanwhile receive and send data and orders?

From (and ) I conclude that CPU-bound programs, those that spend most of the their time processing data (like on the-fly computations using Pandas which is synchronous single threaded), solutions like threading (pre-emptive multitasking) and asyncio are inferior (and may disrupt the sending/receipt of data or introduce some lag or data drops) since there is only one Python interpreter on a single core/processor (asyncio aligns I/O processes more efficiently) that takes care of both the CPU computations and checking for socket data.

I know there is? a ib_insync library that implements cooperative multitasking (asyncio) in Python, but will the overall program be fast enough if you do computations using large dataframes? I read that on a socket level there might not be any limitations (¡°socket itself is actually thread-safe¡±), as suggested by . I do not assume that Ptyhon has it implemented this way since the Global Interpreter Lock is in place (single thread, synchronous). From :

IB.sleep(0); may be an alternative, but I do not think a Pandas groupby() can be interrupted once called.

Should I use the Multiprocessing library and do every task on its own processor (thus dataframe calculations, mySQL connection read/write, sending and receiving orders and data)?
Or should I combine some things using (I think some next level threading which can be combined with the normal way of interpretation of code by Python) or the (has to do with built-in async for Scikit-Learn, Pandas, etc. functions, if I understand correctly) library? I think this is next level, and may be an overkill.

Or should stick to Java (I do not know if there is a Pandas like alternative which allows easy manipulation of data and performing machine learning for example, but threading may be organized better)?

Any suggestions or tutorials?

(I read something about was well, but that¡¯s a whole different story since it is not directly applicable to IB TWS API, and may be prone to delays resulting from single core processing/interpreting by Python as well, if I understand correctly)


Re: Request for options contracts per expirtation date

 

I'm not a fan of TWS API design at all (to say the least). But at this point it has so much history and dependencies that it is not feasible to improve it dramatically in an evolutionary manner. You probably know that being 30 years in software development. :)

On your topic... I think I just replied how I get the chains in another thread using?reqSecDefOptParams as Francois suggested.

On Tue, Mar 16, 2021 at 7:15 AM juxeiier <juxeiier@...> wrote:
Hi Francois,

thx for the links.
All of this leaves me really speachless about the quality of the IB API.
I am a professional software developer since >30years, but a function like reqSecDefOptParams?plays in the primary league of "worst design never".
Not only does it return invalid data, but the concept inherently leads to massive server requests.

So sad, and since this topic is years old, IB obviously does not care.
Do they even have a valid email adress to their developers?


Re: How to get all VALID options

 

I do get valid chains in this way:
chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)

then I just get the one for exchange SMART.

Then for expiration date I need, I get the list of strikes and create a list of Option() objects - options.
that list I pass to reqQualifyContracts() -?ib.qualifyContracts(*options)

The combinations of expirations and strikes that don't exist don't pass qualification (you'll see errors in the stderr but they are handled in the background).

The options that were qualified successfully have non-zero conId so I filter them out.

You don't have to do too many calls - just get a product of expirations/strikes you need and then create list of Option() objects, qualify them and filter on conId.

I use the ib-insync Python module so my method calls might be slightly different from standard API (I guess only capitalization?).

Is that what you are also doing?



On Tue, Mar 16, 2021 at 7:01 AM juxeiier <juxeiier@...> wrote:
This is really unbelievable.
The quality of this API is really low, which is especially evident in this problem.
I have now implemented something with Yahoo finance, which gives me the valid option chains.
Then I create all needed contracts and serialize them to a file(because it takes an enormous amount of time to get them).
That way, the cached contracts can be reloaded and only new expiration chains well need to be added.
But still, why do we need to do this?
We deserve better from IB, since all this data is available in the option trader window.

I now struggle in reveiving the greeks for the options. Are they even there when markets are closed?


STK/STK Combo Order with Python

 

Has anyone written a working Python code for sending orders on an STK / STK combo?


Re: Anyone upgraded Java version for TWS on Linux?

 

Thanks Hunter, very helpful.

I did some digging around in that directory as you suggested and found some differences between various files. I copied a few files over from the IB JVM directory to the stock JDK 8 directory. Still didn't work. I've given up as the performance actually does seem to be OK now; at least not bad enough that it's worth spending more time digging.

But this was helpful advice that I've filed away in case it becomes a big enough issue.

Thanks
John


On Mon, Mar 15, 2021 at 1:53 PM Hunter C Payne via <hunterpayne2001=[email protected]> wrote:
Hi,
I believe TWS comes with its own Java built into the installer.? I'm pretty sure I use that one.? TWS has never been the best written app but if you stick with stable its OK.?

I believe there are some weird security things built into IB's JVM they distribute which is why you can't make a stock JVM work.? I think if you dig into the IB JVM, you will probably find some security configs in the jre/lib directory (or inside of one of its sub-directories) that allow TWS to work.? Perhaps jre/lib/security/java.policy has been altered to only run IB signed jars or that TWS needs a custom Java security policy.? If you really want to hammer away at this that's where I would look.? As for the performance issues with TWS, perhaps the screen config you have is too busy or perhaps its using up all the pacing capacity and that's causing issues with refreshing the screen.? I have a hard time believing that upgrading the JVM would help.? The Java 8 JVM is really mature and the changes to it are mostly about very minor things that probably wouldn't impact the performance of a GUI app.

Hunter

On Monday, March 15, 2021, 11:32:32 AM PDT, John <jpelly@...> wrote:


No such luck for me - I let that error dialog sit and nothing happens; just sits there forever (rest of TWS will not start up).

I'd like to run TWS on my local Linux laptop, so hopefully someone else comments on this thread with some additional suggestions.

Correction to original message: I'm running Linux Mint 20.

Thanks all
John


On Mon, Mar 15, 2021 at 1:04 PM Ray Racine <ray.racine@...> wrote:
On latest Fedora Linux and I'm getting the exact same error as of today as well.? TWS ultimately starts up fine however.? I assume just not on the latest update :).

With regard to performance,? I've never had to do anything beyond adjusting the Max Heap. ? Performance is retalive, but I have some pretty big watch lists, charts with studies, plus API clients and performance has been fine for me.

I do get quite a few UI issues with menus and mouse pointing (not calculating the X-Y position correctly mostly) when I run under Sway / Wayland.??? The occasional annoying UI issues with XMonad / XOrg.? And no real UI issues to speak of with Gnome - Xorg or Wayland.

On Mon, Mar 15, 2021 at 11:52 AM John <jpelly@...> wrote:
I'm experiencing pretty bad performance of TWS GUI on Linux (Mint 19). I've tried to upgrade Java version that TWS uses, thinking that will help.

However I'm unable to change versions. Reading through the tws shell script, it looks like it pins the JRE version at 1.8.0_152. If I remove the check in the shell script and try to upgrade to openjdk version 1.8.0_282 (upgraded patch level), TWS won't start - says "we are unable to update the platform due to a networking error" (see attached screenshot)

Has anyone successfully been able to do this? It looks like you can upgrade Java versions on Windows so I was hoping to do it on Linux.

jws networking error.png


Option settlement price AM/PM

 

When a stock closes for trading at the end of business on expiration Friday, the last trade determines the options settlement price (PM settlement).
That is not true for those European-style options that expire in the morning (AM settlement), for instance RUT, NDX, and 3rd-Friday SPX. Settlement prices for RUT, NDX and the "original 3rd-Friday SPX options" are calculated by using the opening stock price for each stock in the index. These options stop trading when the market closes on Thursday, one day prior to expiration Friday.

Then, is there any way to get this settlement timing info about options, using API? For instance AM/PM settlement, or exact date+time of settlement time?


Re: How to get all VALID options

juxeiier
 

I probably will not need all call and put contracts, but at least say 2SD strikes prices away from current underlying prices.
Then I scan all chains for all symbols, for example to see if there is a nice Jade Lizard opportunity somewhere.
I definetly have no time to do this manually ;)


Re: How to get all VALID options

Matthias Frener
 

>??If I get all contracts for all chains for 120days from today, that takes 2hours just for 3 symbols!!
Do you need them all? (and you probably do something wrong, should be way faster with?reqSecDefOptParams).
Wanted to speed up option chain on UI - so no point on download all because I won't look at all anyhow. I keep the last 16 queried option chains on cache. If I open #17, #0 falls out of cache and #17 goes into. So if you want to look at #0 again, it will need to get strikes again, but #17 is fast now.



Am Di., 16. M?rz 2021 um 11:26?Uhr schrieb juxeiier <juxeiier@...>:

Hi Matthias,

thx for help.
You really cache the contracts locally? If I get all contracts for all chains for 120days from today, that takes 2hours just for 3 symbols!!
That is the reason I implemented a little serializer/caching mechanism with the pickler module(python).
After restart of the algorithm, I have all the contracts almost immediatly at my disposal.


Re: How to get all VALID options

juxeiier
 

Hi Matthias,

thx for help.
You really cache the contracts locally? If I get all contracts for all chains for 120days from today, that takes 2hours just for 3 symbols!!
That is the reason I implemented a little serializer/caching mechanism with the pickler module(python).
After restart of the algorithm, I have all the contracts almost immediatly at my disposal.


Re: Getting last Expired Option Price

Matthias Frener
 

I actually the closing the pricing of the current trading day.
Maybe we have different use-cases, but I only need expired option prices for the daily?settlement. So I use last price just after markte close.
The exact value (used on monthly balance) will than later sync from FlexQuery after the transaction shows up there.

Am Di., 16. M?rz 2021 um 10:19?Uhr schrieb Francois G via <namasteparis=[email protected]>:

Hi Mattias & Alexandre,
To get the underlying closing price, do you use reqHistoricalData for the expiration date?
Using Regular Trading Hours (RTH) = 1 or 0 ?
The closing price of the underlying for option calculation is normally based on the price AFTER market close, so RTH=0
Please confirm.


Re: How to get all VALID options

Matthias Frener
 

> I now struggle in reveiving the greeks for the options. Are they even there when markets are closed?

You probably have to switch to frozen market-data type. You will only see live-greeks while market is open, otherwise there is no bid/ask and difficult to calculate it. (the exact time depends on markte, e.g. 9:30-16:00 for stock options on CBEO or 24/5 (with 10min stop each day) at GLOBEX),

> But still,?why do we need to do this?
We deserve better from IB, since all this data is available in the option trader window.

TWS has same issue. Option an option chain and change between dates and scroll up/down the strikes. You will that is terrible slow, takes seconds until you have all the strikes and even longer until prices show up - because they probably have to da same as we have to.
What I did to make it smooth in my App is indeed to store it locally. I cache option chains that have been requested from TWS locally. So it only slow the first time, second time it's cache hit and there immediatly.










Am Di., 16. M?rz 2021 um 11:01?Uhr schrieb juxeiier <juxeiier@...>:

This is really unbelievable.
The quality of this API is really low, which is especially evident in this problem.
I have now implemented something with Yahoo finance, which gives me the valid option chains.
Then I create all needed contracts and serialize them to a file(because it takes an enormous amount of time to get them).
That way, the cached contracts can be reloaded and only new expiration chains well need to be added.
But still, why do we need to do this?
We deserve better from IB, since all this data is available in the option trader window.

I now struggle in reveiving the greeks for the options. Are they even there when markets are closed?