CDSL OTP Fetch retrieves eCAS (electronic Consolidated Account Statement) PDF files directly from CDSL’s CAS portal (https://www.cdslindia.com/cas/) via OTP authentication.What you get:
Cross-depository: Includes holdings from both CDSL and NSDL accounts
No manual portal login required
Critical: CDSL eCAS statements are not limited to CDSL demat accounts. They contain a consolidated view of all holdings across both CDSL and NSDL depositories, including both demat and non-demat assets. Similarly, NSDL eCAS also contains holdings from both depositories.
What you need:
PAN number
CDSL BO ID (16-digit Client ID)
Date of birth
At least one CDSL demat account (required to access CDSL CAS portal)
Portal access requirement: Only users with at least one CDSL demat account can access the CDSL CAS portal. NSDL does not have an equivalent OTP-based fetch portal yet.
import requestsimport timeAPI_KEY = "YOUR_API_KEY"def fetch_cdsl_cas_files(pan: str, bo_id: str, dob: str, otp_callback): """ Fetch CDSL CAS PDF files via OTP. Args: pan: PAN number bo_id: 16-digit CDSL BO ID (Client ID) dob: Date of birth (YYYY-MM-DD) otp_callback: A function that prompts user for OTP and returns it Returns: List of PDF download URLs """ # Step 1: Request OTP response = requests.post( "https://api.casparser.in/v4/cdsl/fetch", headers={"x-api-key": API_KEY}, json={"pan": pan, "bo_id": bo_id, "dob": dob}, timeout=50 ) data = response.json() if data.get("status") != "success": raise Exception(f"Failed to request OTP: {data.get('msg')}") session_id = data["session_id"] # User receives OTP on their registered mobile otp = otp_callback() # Your UI prompts user for OTP # Step 2: Verify OTP and get PDF URLs response = requests.post( f"https://api.casparser.in/v4/cdsl/fetch/{session_id}/verify", headers={"x-api-key": API_KEY}, json={"otp": otp, "num_periods": 6} ) result = response.json() # Now parse each PDF file parsed_files = [] for file in result.get("files", []): parse_response = requests.post( "https://api.casparser.in/v4/smart/parse", headers={"x-api-key": API_KEY}, json={"pdf_url": file["url"], "password": pan} ) parsed_files.append(parse_response.json()) return parsed_files# Usagedef prompt_otp(): return input("Enter OTP received on your phone: ")cas_files = fetch_cdsl_cas_files( pan="ABCDE1234F", bo_id="1234567890123456", dob="1990-01-15", otp_callback=prompt_otp)# Process each CAS filefor cas_data in cas_files: print(f"Total Value: ₹{cas_data['summary']['total_value']:,.2f}")