Support for firstock Code

Hi Team,

I am working on firstock broker, this is the code I have received from the team. this is working fine till now. I am able to login and fetch the option chain.

I will stay connect on this link for any questions if there.

from firstock import firstock
import pyotp
userId = "VN0773"
password = "XXXX"
totpsecret = "XXXX"
apikey = "XXXX"
vendorCode = "XXX"
totp = pyotp.TOTP(totpsecret)
login = firstock.login(
    userId=userId,
    password=password,
    TOTP=totp.now(),
    vendorCode=vendorCode,
    apiKey=apikey,
  )
print(login)
optionChain = firstock.optionChain(
    userId= userId,
    exchange="NFO",
    symbol="NIFTY",
    strikePrice="23000",
    expiry= "30MAR26",
    count="5"
            )
print(optionChain)

Using environment variable I am facing some difficulaty…

this is the code I am using

import os
import csv
import time
import pyotp
from dotenv import load_dotenv
from firstock import firstock
# Load environment variables
load_dotenv()
userId = os.getenv("FIRSTOCK_USER_ID")
password = os.getenv("FIRSTOCK_PASSWORD")
totpsecret = os.getenv("FIRSTOCK_TOTP_SECRET")
apikey = os.getenv("FIRSTOCK_API_KEY")
vendorCode = os.getenv("FIRSTOCK_VENDOR_CODE")
totp = pyotp.TOTP(totpsecret)
# Login
login = firstock.login(
    userId=userId,
    password=password,
    TOTP=totp.now(),
    vendorCode=vendorCode,
    apiKey=apikey,
)
print("Login response:", login)
# Get option chain
optionChain = firstock.optionChain(
    userId=userId,
    exchange="NFO",
    symbol="NIFTY",
    strikePrice="23000",
    expiry="30MAR26",
    count="5"
)
# Save to CSV
filename = "nifty_option_chain.csv"
if isinstance(optionChain, list) and len(optionChain) > 0:
    headers = optionChain[0].keys()
    with open(filename, "w", newline="") as file:
        writer = csv.DictWriter(file, fieldnames=headers)
        writer.writeheader()
        writer.writerows(optionChain)
    print("Option chain saved to", filename)
else:
    print("No option chain data received.")