Crude oiloption

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
:white_check_mark: 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…
:stop_sign: 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(“:white_check_mark: 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":stop_sign: An error occurred while fetching the option chain: {e}")