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 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
"You have an excellent feed. Very few spikes for Spot Forex." - Comment from Public Forum Post
"IQ feed is brilliant. The support is mind-bending. What service!" - Comment from Public Forum Post
"I just wanted to tell you what a fine job you have been doing. While *******, from what I hear, has been down and out, off and on, IQ feed has held like a champ this week." - Comment from Shirin
"Awesome response, as usual. It is a sincere and refreshing pleasure to do business with DTN, compared to your competition." - Comment from Ryan
"I've been using IQFeed 4 in a multi-threaded situation for the last week or two on 2600 symbols or so with 100 simultaneous daily charts, and I have had 100% responsiveness." - Comment from Scott
"Everything is working great ! Very impressive client. The news refreshes better and is more pertinent than the ******* feed I paid $ 100/month for. I Also like the charts a lot." - Comment from Leon
"DTN has never given me problems. It is incredibly stable. In fact I've occasionally lost the data feed from Interactive Brokers, but still been able to trade because I'm getting good data from DTN." - Comment from Leighton
"I'm very glad I switched to IQFeed. It's working perfectly with no lag, even during fast market conditions." - Comment from Andy via Email
"IQFeed version 4 is a real screamer compared to anything else I have seen." - Comment from Tom
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 410 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: 394
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: Mon April 15, 2024 7:54 AM CFBB v1.2.0 8 ms.
© AderSoftware 2002-2003