Code to fetch live LTP of Natural Gas Call

how to fetch live LTP of
MCX,M,538685,FUTCOM,0,NATURALGAS-28Jul2026-FUT,1.0,NATURALGAS JUL FUT,2026-07-28 23:30:00,0.00000,XX,10.0000,M,FUTCOM,2,NATURALGAS (api_master_scrip data)

Hi @pawanyadavdelhi ,

Do run the command on the cm terminal -

pip install dhanhq==2.2.0
pip install Dhan-Tradehull==3.2.2

Refer the code to get LTP -

from Dhan_Tradehull import Tradehull
client_code = ""
tsl = Tradehull(client_code, mode="pin_totp", pin="", totp_secret="")
ltp = tsl.get_ltp_data('NATURALGAS')
print(ltp)

Output-

Screenshot 2026-07-14 094350

not for natural gas i am asking about NATURALGAS-28Jul2026-FUT
i mean call or put chart data/ltp

Hi @pawanyadavdelhi ,

Refer the code -

from Dhan_Tradehull import Tradehull
client_code = ""
tsl = Tradehull(client_code, mode="pin_totp", pin="", totp_secret="")
watchlist = ["NATURALGAS 24 JUL 270 CALL","NATURALGAS 24 JUL 270 PUT","NATURALGAS JUL FUT"]
ltp = tsl.get_ltp_data(watchlist)
print(ltp)

Output-

image

1 Like

not possible without tradehull? I mean I am using dhanhq only

HI @pawanyadavdelhi ,

Refer this code -

from dhanhq import DhanContext, dhanhq

a = [
    "NATURALGAS 24 JUL 270 CALL",
    "NATURALGAS 24 JUL 270 PUT",
    "NATURALGAS JUL FUT",
]

client_id = ""
access_token = ""
dhan = dhanhq(DhanContext(client_id, access_token))

df = dhanhq.fetch_security_list("compact")
df = df[(df["SEM_EXM_EXCH_ID"] == "MCX") & df["SEM_CUSTOM_SYMBOL"].isin(a)]

symbols = {
    row["SEM_CUSTOM_SYMBOL"]: str(int(float(row["SEM_SMST_SECURITY_ID"])))
    for _, row in df.iterrows()
}

response = dhan.ticker_data({"MCX_COMM": list(map(int, symbols.values()))})

print(response)

Output -

image

thanks its working now

1 Like

Fully functional live virtual trading code is ready, thanks

Screenshot_20260717_175728

1 Like