How to fetch Option Chain data based on specific expiry date

how can fetch Option Chain data based on specific expiry date

data = { “symbol”:“NSE:NIFTY50-INDEX”, “strikecount”:50, “timestamp”: " " } response = fyers.optionchain(data=data); print(response)

in this code what is timestamp mean?

if we give specific expiry date in to timestamp is it fetch currentexpiry based on the input date ?


Hey @G6XZcJckyW

If you run the option chain API , you will see the response of all expiries , You can just pick the timestamp of the specific expiry and use it in the inputs to get the data of that expiry :
https://myapi.fyers.in/docsv3#tag/Data-Api/paths/~1DataApi/delete

thanks for your replay

it means “timestamp:''241128” (if the date is 2024-11-28)

is it work . what about the date format ?

my query is I need to get optionchain in this date 2024-11-28

i tried this but not getting the given date data !

fyers = fyersModel.FyersModel(client_id=client_id, is_async=False, token=access_token, log_path="")

data = {
    "symbol":"NSE:NIFTY50-INDEX",
    "strikecount":2,
    "timestamp": "241128"
}
response = fyers.optionchain(data=data);
print(response)

exp_date=pd.DataFrame(response['data']["expiryData"])
exp_date
op_chain=pd.DataFrame(response['data']["optionsChain"])
pd.options.display.max_rows = None
pd.options.display.max_columns = None
op_chain

'message': 'Please provide valid expiry', 's': 'error

solution for my question = insert expiry in to timestamp instant of Date

from dictionary {‘date’: ‘21-11-2024’, ‘expiry’: ‘1732183200’}

example “timestamp”: ‘1732183200’

Yes @G6XZcJckyW you should pick the expiry date and use it in the timestamp field to get data of the specific expiry

Fyers API devlopers have really no sense of creating docs and working , they just sitting on copnay money and passing time . Nonsense developers… fyers ke sare developers… tm sabki maa ki Ch***t

async function getAllExpiryData() {
    try {
        console.log("🔄 Fetching data for all three expiries...");
        
        // Get current expiry data (empty timestamp for current)
        const currentExpiryData = await getOptionChainForExpiry('');
        
        if (!currentExpiryData || !currentExpiryData.expiryData) {
            throw new Error("Could not fetch current expiry data");
        }
        
        // Get next expiry timestamp from current response
        const nextExpiryTimestamp = currentExpiryData.expiryData[1]?.expiry;
        const afterNextExpiryTimestamp = currentExpiryData.expiryData[2]?.expiry;
        
        if (!nextExpiryTimestamp || !afterNextExpiryTimestamp) {
            throw new Error("Could not find next and after-next expiry timestamps");
        }
        
        console.log(`📅 Expiry timestamps - Next: ${nextExpiryTimestamp}, After Next: ${afterNextExpiryTimestamp}`);
        
        // Get next expiry data
        const nextExpiryData = await getOptionChainForExpiry(nextExpiryTimestamp);
        // Get after-next expiry data
        const afterNextExpiryData = await getOptionChainForExpiry(afterNextExpiryTimestamp);
        
        return {
            currentExpiryData,
            nextExpiryData,
            afterNextExpiryData,
            expiryTimestamps: {
                current: '',
                next: nextExpiryTimestamp,
                afterNext: afterNextExpiryTimestamp
            }
        };
        
    } catch (error) {
        console.error("❌ Error fetching all expiry data:", error);
        return null;
    }
}

async function getOptionChainForExpiry(timestamp = '') {
    try {
        console.log(`🔍 Fetching Nifty option chain for timestamp: ${timestamp || 'current'}`);
        
        const data = {
            "symbol": "NSE:NIFTY50-INDEX",
            "strikecount": '',
            "timestamp": timestamp
        };
        
        const response = await fyers.getOptionChain(data);
        
        if (response.s === 'ok' && response.data && response.data.optionsChain) {
            console.log(`✅ Found option chain with ${response.data.optionsChain.length} strike entries for timestamp ${timestamp}`);
            return response.data;
        } else {
            console.log(`❌ No option chain data found for timestamp ${timestamp}`);
            return null;
        }
    } catch (error) {
        console.error(`❌ Error fetching option chain for timestamp ${timestamp}:`, error);
        return null;
    }
}