Thanks I used a dataframe instead of a list and that worked. Only problem now is I'm getting errors "Error: 641 101 Max number of tickers has been reached" Don't know if I can solve that by using a timer so there is more time in between each request. I also obviously don't need to request every single option so will have to figure out how to filter that before. Maybe by volume or distance from the underlying price.
Sorry for using the wrong word. I'm not familiar with Python and used a Java term. This gives me the impression that you submitted the request for prices for all contracts at the same time (i.e. in parallel)? That leads to an error message if you submit this for more than 100 contracts (unless you pay extra to IB to be able to get more). You will have to chop it up in blocks of 100 contracts or less and handle these blocks sequentially.
Oh no you used the right word. I just chose to use a dataframe instead of a list, basically I made a table with columns "strike | right | expiry..." and iterate through each row. I haven't figured out which is faster though, will have to compare performance with a list but I don't think it's very different. That sounds like what I'm getting ya. How would I do it sequentially? Putting a timer of 0.1s "works", I don't the error anymore but it's painfully slow. I put the reqMktData() function in contractDetailsEnd(). Here is the code: def contractDetailsEnd(self, reqId): self.df.to_csv('C:/Users/Mischa/Documents/Options/Options_tws_005.csv') req_id = 1 for row in self.df.itertuples(name=None): self.contract.lastTradeDateOrContractMonth=row[2] self.contract.strike=row[3] self.contract.right=row[4] self.reqMktData(req_id, self.contract, '100', False, False, []) req_id += 1 time.sleep(0.1)
With reqMktData() you will only receive a price if the price is changing. You will not get a callback as long as the price remains the same. For very liquid instruments is this usually not an issue. However, if you have e.g. an option which only trades once per hour then you would have to wait one hour before you receive a reply. Instead of subscribing to live market data with reqMktData() you could initially request the latest historical prices. And use this to get the last used price (trade, bid, ask) as a starting point. The disadvantage of this approach is that you don't know how stale this data is, how long ago these prices were formed. Edit: I see that you defined ticktype 100, being the daily call/put option volumes. I don't know whether those are supposed to be returned via reqMktData() immediately, or that this could take a while. You can get the volume also via the historical data request, by asking for data for 1 trading day.