how to fetch crude oil option ltp , bit confused with segment , shud i use NSE_FNO or MCX_COMM
They do not have crude oil option chain data fetching function yet. Please wait till they bring - God know when
Hey @butta12 ,
To fetch option chain data for Crude Oil, mention the exchange segment as MCX_COMM and use the security ID of any option contract.
for example for Gold option data:
dhan.option_chain(
under_security_id=481575,
under_exchange_segment=âMCX_COMMâ,
expiry=â2025-11-26â
)
Same error for long now -----Logged into Dhan-----
reading existing file all_instrument 2025-11-08.csv
Got the instrument file
Dhan Master file saved as dhan_master_file.csv
[âFUTCURâ âOPTCURâ âOPTSTKâ âOPTIDXâ âFUTSTKâ âFUTIDXâ âEQUITYâ âINDEXâ
âFUTCOMâ âOPTFUTâ]
Fetching Option Chain for Security ID: 481575 on MCX_COMMâŚ
An error occurred while fetching the option chain: âTradehullâ object has no attribute âoption_chainâ
Hey @raj001 ,
Thanks for bringing this up @Tradehull_Imran might be able to assist here.
Thank you @Tradehull_Imran could you please check this. otherwise, I have to move to Zerodha.
Below is the code @Tradehull_Imran and @Shrutika_Poojari @PravinJ
import time
from datetime import datetime
import pandas as pd
import talib
import traceback
from Dhan_Tradehull_V2 import Tradehull
â DHAN LOGIN â
â DHAN LOGIN â
CLIENT_ID = " your CLIENT_ID"
ACCESS_TOKEN = âyour token detailsâ
print(âInitializing Tradehull connectionâŚâ)
tsl = Tradehull(client_code, token_id)
Initialize the official dhanhq client for data fetching
dhan = Tradehull(CLIENT_ID, ACCESS_TOKEN)
URL for the compact master file (lighter to download)
MASTER_URL = pd.read_csv(âhttps://images.dhan.co/api-data/api-scrip-master-detailed.csvâ, low_memory=False)
â SAVE THE DATAFRAME â
MASTER_URL.to_csv(âdhan_master_file_01.csvâ, index=False)
print(â
Dhan Master file saved as dhan_master_file.csvâ)
------------------------------------
â 2. DYNAMICALLY FIND THE CRUDE OIL SCRIP ID (Optional step for context) â
a = MASTER_URL.INSTRUMENT.unique()
print(a)
indexdf=MASTER_URL[MASTER_URL.INSTRUMENT == âOPTFUTâ]
NAME_01 =indexdf[(indexdf.DISPLAY_NAME == âCRUDEOIL 17 NOV 5400 CALLâ)]
print(NAME_01)
opt_crd=dhan.option_chain(
under_security_id =467015,
under_exchange_segment=âMCX_COMMâ,
expiry=â2025-11-17â
)
print(opt_crd)
Assuming dhan object is correctly initialized
from dhanhq import dhanhq
dhan = dhanhq(CLIENT_ID, ACCESS_TOKEN)
1. Define Parameters for Crude Oil Options
CRUDEOIL_FUTURE_ID = â481575â
EXCHANGE = âMCX_COMMâ
INSTRUMENT = âOPTFUTâ # Options on Commodity Futures
try:
# *** Use the V2 Python Client standard parameters ***
option_chain_data = dhan.option_chain(
under_security_id=481575,
under_exchange_segment= MCX_COMM,
expiry=2025-11-26
)
# ... rest of your code to process the DataFrame
# option_chain_df = pd.DataFrame(option_chain_data.get('optionChain', []))
# ...
except Exception as e:
print(f"
An error occurred while fetching the option chain: {e}")
Hi @raj001 ,
- Open your command prompt
- Run the following command to find where the
Dhan_Tradehull.pyfile is located:
pip show Dhan-Tradehull
- Look for the line starting with
Location:in the output. - Example:
Location: C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages
- Inside that folder, navigate to:
Dhan_Tradehull.py
- Scroll or search (Ctrl + F) for:
def get_option_chain():
- Inside the function, locate this line:
else:
raise Exception(f"No option chain data available for the {Underlying}")
Before this line add the below code-
elif Underlying in self.commodity_step_dict:
strike_step = self.commodity_step_dict[Underlying]
And save the file. This will solve the problem, Let me know if you face any issues. We will update the codebase for this in our upcoming version.
Hello @Tradehull_Imran , I am using Dhan_Tradehull_V2.py not Dhan_Tradehull.py, I checked in the Dhan_Tradehull_V2,py file and placed the code you said just before (elif Underlying in self.commodity_step_dict: strike_step = self.commodity_step_dict[Underlying] ) else statement but still showing the same error.
Please check the attached images for reference.
Please refer the current code that i am using to test :-
import time
from datetime import datetime
import pandas as pd
import talib
import traceback
from Dhan_Tradehull_V2 import Tradehull
CLIENT_ID = âPlease use your client IDâ
ACCESS_TOKEN = âPlease use your tokenâ
Dhan = Tradehull(CLIENT_ID, ACCESS_TOKEN)
try:
option_chain_data = Dhan.option_chain(
under_security_id=467015,
under_exchange_segment=MCX_COMM,
expiry= 2025-11-17
)
option_chain_df = pd.DataFrame(option_chain_data.get(âoptionChainâ, ))
print(â
Option Chain Fetched Successfully.â)
print(option_chain_df.head())
except Exception as e:
print(f"
An error occurred while fetching the option chain: {e}")
Please refer the error :â
C:\Users\Admin\Desktop\20250925_DHAN_01\SLEF_PROJECTS\20251108_CRUDEOI_TEST>py 02_20251110_CRUDEOIL_TEST.py
Codebase Version 2.8 : Solved - Strike Selection Issue
-----Logged into Dhan-----
reading existing file all_instrument 2025-11-10.csv
Got the instrument file
An error occurred while fetching the option chain: âTradehullâ object has no attribute âoption_chainâ
Your timely response will save much time for me as well for others those are waiting for long .
Thank you in advance @Tradehull_Imran ,@Shrutika_Poojari and @PravinJ
Hi @raj001 ,
Do update to our latest codebase version 3.0.6:
- Open Command Prompt: Press Win, type cmd, and press Enter.
- Install Dhan-Tradehull: Run
pip install Dhan-Tradehull - Confirm the installation by running
pip show Dhan-Tradehull
Guide to use the updated codebase:
Refer the below pypi link for more details:
Video reference :
Refer the below code-
strike,option_chain = tsl.get_option_chain(âGOLDâ, âMCXâ,0,10)
Hello I got the data for CRUDEOIL Option chain data.
Thank you @Tradehull_Imran @Shrutika_Poojari @butta12
Hello @Tradehull_Imran
Some suggestions to consider into the new development for Dhan_Tradehull_V3, Please Compare Dhan_Tradehull.py- get_option_chain function with Dhan_Tradehull_V2.py- get_option_chain function , I have fixed on my side.
Commodities Trading ![]()
![]()
please use the Dhan_Tradehull.py file for commodities option chain data
Hello @Tradehull_Imran
MINI -OPTION CHAIN data are missing like CRUDEOILMINI, SILVERMINI, NATURALGASMIN in the self.commodity_step_dict
self.commodity_step_dict = {âGOLDâ: 100,âSILVERâ: 250,âCRUDEOILâ: 50,âNATURALGASâ: 5,âCOPPERâ: 5,âNICKELâ: 10,âZINCâ: 2.5,âLEADâ: 1, âALUMINIUMâ: 1, âCOTTONâ: 100, âMENTHAOILâ: 10, âGOLDMâ: 50, âGOLDPETALâ: 5, âGOLDGUINEAâ: 10, âSILVERMâ: 250, âSILVERMICâ: 10, âBRASSâ: 5, âCASTORSEEDâ: 100, âCOTTONSEEDOILCAKEââCARDAMOMâ: 50, âRBDPALMOLEINâ: 10,âCRUDEPALMOILâ: 10,âPEPPERâ: 100, âJEERAâ: 100, âSOYABEANâ: 50, âSOYAOILâ: 10, âTURMERICâ: 100, âGUARGUMâ: 100, âGUARSEEDâ: 100, âCHANAâ: 50, âMUSTARDSEEDâ: 50, âBARLEYâ: 50, âSUGARMâ: 50, âWHEATâ: 50, âMAIZEâ: 50, âPADDYâ: 50, âBAJRAâ: 50, âJUTEâ: 50, âRUBBERâ: 100, âCOFFEEâ: 50, âCOPRAâ: 50, âSESAMESEEDâ: 50, âTEAâ: 100, âKAPASâ: 100, âBARLEYFEEDâ: 50, âRAPESEEDâ: 50, âLINSEEDâ: 50, âSUNFLOWERâ: 50, âCORIANDERâ: 50, âCUMINSEEDâ: 100 }
so that i canât get the mini option chain data please let me know code no for all minis or please update the code and let me know . Big Thank you @Tradehull_Imran
Hi @raj001 ,
You can add required symbol in self.commodity_step_dict
As in for SILVERMINI - âSILVERMâ : 250 is already present
{âCRUDEOILMâ : 50, âNATGASMINIâ: 5}
Hello @Tradehull_Imran, CRUDEOILM and NATGASMINI is not working please check the below error tried changing name from NATGASMINI to NATGASM but still not getting the data
Error
Codebase Version 2.8 : Solved - Strike Selection Issue
-----Logged into Dhan-----
reading existing file all_instrument 2025-11-12.csv
Got the instrument file
INFO: Output file: 2025-11-12_NATGASMINI_59-Seconds.xlsx
qty: 250
INFO: Using hardcoded expiry date for output display: 20 NOV
Exception for instrument name NATGASMINI 20 NOV 400 CALL as Check the Tradingsymbol
INFO: Trade limit (2/3) reached. Monitoring current position or waiting for EOD.
================================================================================
Hi @raj001 ,
Itseems you are still using the old version of codebase of 2.8. Firstly do update to our latest codebase version 3.0.6. Then update the necessary changes in the new file.
- Open Command Prompt: Press Win, type cmd, and press Enter.
- Install Dhan-Tradehull: Run
pip install Dhan-Tradehull - Confirm the installation by running
pip show Dhan-Tradehull
Guide to use the updated codebase:
Refer the below pypi link for more details:
Video reference :
Hello @Tradehull_Imran, I checked I am using the correct version and reconfirm using the shared videos and guidelines its just print massage and now All MINIs of commodities are working well.
My algorithm now supports all Index, F&O Stocks, and MCX instruments.
Thank you so much for valuable support, If I need any future assistance, I will drop a msg

