Join the 80,000 other DTN customers who enjoy the fastest, most reliable data available. There is no better value than DTN!

(Move your cursor to this area to pause scrolling)

"I've been using Neoticker RT with IQFeed for two months, and I'm very happy with both of the products (I've had IQFeed for two years with very few complaints). The service from both companies is exceptional." - Comment from Public Forum
"DTN feed was the only feed that consistently matched Bloomberg feed for BID/ASK data verification work these past years......DTN feed is a must for my supply & demand based trading using Cumulative Delta" - Comment from Public Forum Post
"I will tell others who want to go into trading that DTN ProphetX is an invaluable tool, I don't think anyone can trade without it..." - Comment from Luther
"As a past ******* customer(and not a happy one), IQ Feed by DTN is a much better and cheaper product with great customer support. I have had no problems at all since switching over." - Comment from Public Forum
"I noticed that ******* quotes locked up shortly after the interest rate announcement yesterday while yours stayed stable." - Comment from Ron in Utah
"I have been using IQFeed now for a few years in MultiCharts and I have zero complaints. Very, very rare to have any data hiccups or anything at all go wrong." - Comment from Public Forum
"I had always used ******* but for the past 2 weeks have been trying DTN IQFeed. Customer support has been extraordinary. They call just to make sure your problem hasn't recurred." - Comment from Public Forum
"There is no doubt that IQFeed is the best data provider. I am very satisfied with your services. And IQFeed is the only one that I would recommend to my friends. Now, most of them are using your product in China." - Comment from Zhezhe
"Boy, probably spent a thousand hours trying to get ******* API to work right. And now two hours to have something running with IQFeed. Hmmm, guess I was pretty stupid to fight rather than switch all this time. And have gotten more customer service from you guys already than total from them… in five years." - Comment from Jim
"Can I get another account from you? I am tired of ******* going down so often" - Comment from George
Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »NEW IQFEED FORUMS »New IQFeed Forum »Futures Option Chain prices
Author Topic: Futures Option Chain prices (5 messages, Page 1 of 1)

-Interested User-
Posts: 32
Joined: Aug 10, 2011

Posted: Apr 20, 2023 12:18 AM          Msg. 1 of 5
I opened a new thread for 1 question because my previous thread got cluttered with too many questions.

When I open the "IQFeed option chain" App, select "Futures Options" then type in the Futures symbols @ES and in the "Chains criteria" chose the month June and the year 2023 I almost instantly get a table with Open Interest numbers for all the options in the chain, see attached PDF.

When I however use my code below to access the Open Interest for all the option symbols in the chain it takes forever.

My question: is there a better way to access the open interest numbers. Maybe some automated way to save the data from the "IQFeed Option Chain" App to CSV files? How does IQFeed do this internally? I guess IQFeed stores these numbers somewhere where they can be accessed instantly in a table form?

thank you

# filesname:
# To run code IQFeed should be launched already
# To run code type in the CMD window (path to python should be known)
# python

# Dynamically add IQFeed.CSharpApiClient DLL
# for instructions see:
import sys
import clr
assembly_path = r'C:/Program Files/AmiBroker/IQFeedCSharpApiClient'
from System import DateTime
from datetime import datetime, timedelta
from IQFeed.CSharpApiClient.Lookup import LookupClientFactory
from IQFeed.CSharpApiClient.Lookup.Chains import OptionSideFilterType
import pandas as pd
import matplotlib.pyplot as plt

lookupClient = LookupClientFactory.CreateNew()

def total_loss_at_strike(chainC, chainP, expiry_price):
"""Calculate loss at strike price"""
# All call options with strike price below the expiry price will result in loss for option writers
in_money_calls = chainC[chainC['Strike'] < expiry_price][["OpenInterest", "Strike"]]
in_money_calls["CE loss"] = (expiry_price - in_money_calls['Strike'])*in_money_calls["OpenInterest"]

# All put options with strike price above the expiry price will result in loss for option writers
in_money_puts = chainP[chainP['Strike'] > expiry_price][["OpenInterest", "Strike"]]
in_money_puts["PE loss"] = (in_money_puts['Strike'] - expiry_price)*in_money_puts["OpenInterest"]
total_loss = in_money_calls["CE loss"].sum() + in_money_puts["PE loss"].sum()

return total_loss

def createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, o_side):
f_symbol = str(f_symbol)
o_month = str(o_month)
o_year = str(o_year)

if( o_side == 1):
side = OptionSideFilterType.C
if( o_side == 2):
side = OptionSideFilterType.P

ticks = lookupClient.Chains.GetChainFutureOption( f_symbol, side, o_month, o_year )
symbollist = '
strikepricelist = '
for tt in ticks:
symbollist += str(tt.Symbol)
symbollist += ','
strikepricelist += str(tt.StrikePrice)
strikepricelist += ','

# remove last comma
symbollist = symbollist[:len(symbollist)-1]
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")

return symbollist,strikepricelist

def getOpenInterestdata( sym, d1, d2 ):
sym = str(sym)
#ticks = lookupClient.Historical.GetHistoryDailyDatapoints(sym, 1)
ticks = lookupClient.Historical.GetHistoryDailyTimeframe(sym, d1, d2)

for tick in ticks:
s = str(tick)
datalist = s.split(',')
#print(int(str(datalist[6]).replace(' OpenInterest: ',')))
oi = int(str(datalist[6]).replace(' OpenInterest: ','))

return oi

def main():
# input parameters
Month codes:
January: F
February: G
March: H
April: J
May: K
June: M
July: N
August: Q
September: U
October: V
November: X
December: Z
f_symbol = '@ES'
o_month = 'M'
o_year = '23'

yesterday = - timedelta(1)
d1 = DateTime(yesterday.year,yesterday.month,
d2 = DateTime(yesterday.year,yesterday.month,

# Calls
symbollist,strikepricelist = createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, 1)
list1 = symbollist.split(',')
list2 = strikepricelist.split(',')
df_calls = pd.DataFrame(list(zip(list1, list2)), columns =['Symbols', 'Strike'])
df_calls = df_calls.astype({'Strike':'float'})
df_calls = df_calls.sort_values(by=['Strike'])
df_calls['OpenInterest'] = 0

idx = 0
for index, row in df_calls.iterrows():
sym = row['Symbols']
oi = getOpenInterestdata( sym, d1, d2 )
df_calls.iloc[idx, 2] = oi
idx += 1


# Puts
symbollist,strikepricelist = createListofSymbolPlusStrikePrice(f_symbol, o_month, o_year, 2)
list1 = symbollist.split(',')
list2 = strikepricelist.split(',')
df_puts = pd.DataFrame(list(zip(list1, list2)), columns =['Symbols', 'Strike'])
df_puts = df_puts.astype({'Strike':'float'})
df_puts = df_puts.sort_values(by=['Strike'])
df_puts['OpenInterest'] = 0

idx = 0
for index, row in df_puts.iterrows():
sym = row['Symbols']
oi = getOpenInterestdata( sym, d1, d2 )
df_puts.iloc[idx, 2] = oi
idx += 1


strikes = list(df_calls['Strike'])
losses = [total_loss_at_strike(df_calls, df_puts, strike)/1000000 for strike in strikes]

m = losses.index(min(losses))
print("Max pain > {}".format(strikes[m]))

plt.plot(strikes, losses)
plt.ylabel('Total loss in (Millon)')

if __name__ == "__main__":

File Attached: optionschain.pdf (downloaded 322 times)

-Interested User-
Posts: 1
Joined: Jul 19, 2023

Posted: Jul 19, 2023 05:29 AM          Msg. 2 of 5
The reason your code takes a long time to access open interest numbers for all the option symbols is likely due to the way it queries the data one by one, which can be time-consuming.

A better approach would be to directly access the data in bulk from IQFeed, if it provides such functionality. For example, you could check if IQFeed has an API method that allows you to retrieve the entire option chain's open interest data in one request, rather than making individual requests for each option symbol.

If such bulk data access is not available through IQFeed's API, another option could be to automate the process of exporting the data from the "IQFeed Option Chain" App into CSV files. This way, you can save the data locally and then read it into your code for analysis, which should be much faster than querying the data live each time.

As for how IQFeed internally handles and stores the data, it's proprietary information, and the exact implementation details are not publicly disclosed. However, most financial data providers optimize their data storage and retrieval systems to ensure fast and efficient access to data, especially for frequently requested information like option chain data.

To summarize, check if IQFeed has bulk data access through its API. If not, consider automating the export of data to CSV files for quicker access in your code. This way, you can improve the speed of accessing open interest numbers for your analysis.

-Interested User-
Posts: 32
Joined: Aug 10, 2011

Posted: Jul 19, 2023 05:37 AM          Msg. 3 of 5
hi, thanks. Yes that is what I did. I exported the data to a CSV file and then processed that file with Python code. But I lost interest in the chains because I used them to do Max Pain calculations and I watched it for a while but it is basically pretty useless. It does not give predictions that are anywhere near accurate.

-DTN Guru-
Posts: 391
Joined: Jul 3, 2019

Posted: Jul 20, 2023 09:55 AM          Msg. 4 of 5
Other than the FDS and EDS reports, there's no way to get a statistic in bulk for all symbols in an exchange. Whether a Level 1 watch or historical lookup, it has to retrieve the data symbol-by-symbol. The Options Chains command can filter for the option symbols you want, but you still have to retrieve the data for each. The Options Chains IQFeed client app does this to display Price, Open Interest, and other stats for each options symbol.

Gary Stephen
DTN IQFeed Implementation Support Specialist

-Interested User-
Posts: 32
Joined: Aug 10, 2011

Posted: Jul 21, 2023 04:59 AM          Msg. 5 of 5
thanks. Exporting from the options chains app worked fine for me. Gave the same result when I used the more time consuming method. But I have lost interest in option chains for the moment. At least this "Maximum Pain" method appears to be useless. It does not give accurate longer term predictions.


Time: Wed February 21, 2024 9:04 AM CFBB v1.2.0 8 ms.
© AderSoftware 2002-2003