Hedging Strategies Utilizing Delta Exchange API in Python

Identify ATM Strike Price Symbol through Search and Sorting Method for Trading Straddle Strategy:


For Instructions Watch The Video Here:



import requests 
import pandas as pd

underlying_asset_symbols='BTC'
expiry_date='02-09-2026'

url=f"https://api.india.delta.exchange/v2/tickers?contract_types=call_options,put_options&underlying_asset_symbols={underlying_asset_symbols}&expiry_date={expiry_date}"

df=pd.json_normalize(requests.get(url).json().get('result'))
df['strike_price']=pd.to_numeric(df['strike_price'])
spot_price=df['spot_price'].astype(float).loc[0]
atm_strike=df.loc[(df['strike_price']-spot_price).abs().idxmin(), 'strike_price']
date=expiry_date.replace('-','')
ce_symbol=f'C-{underlying_asset_symbols}-{atm_strike}-{date}'
pe_symbol=f'P-{underlying_asset_symbols}-{atm_strike}-{date}'
print(ce_symbol,pe_symbol)