-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-option-chain-api.js
More file actions
43 lines (35 loc) · 1.68 KB
/
test-option-chain-api.js
File metadata and controls
43 lines (35 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
async function testApi() {
const testCases = [
{ symbol: 'NIFTY', expiry: '13-01-2026' }, // DD-MM-YYYY format
{ symbol: 'BANKNIFTY', expiry: '27-Jan-2026' }, // DD-MMM-YYYY format
{ symbol: 'FINNIFTY', expiry: null } // Auto-detect
];
const baseUrl = 'http://localhost:3000';
for (const testCase of testCases) {
console.log(`\nTesting ${testCase.symbol} with expiry ${testCase.expiry}...`);
try {
const url = `${baseUrl}/api/option-chain?symbol=${testCase.symbol}${testCase.expiry ? `&expiryDate=${testCase.expiry}` : ''}`;
console.log(`Fetching: ${url}`);
const response = await fetch(url);
console.log(`Status: ${response.status} ${response.statusText}`);
if (!response.ok) {
const error = await response.json();
console.error('Error Response:', error);
continue;
}
const data = await response.json();
console.log('Success:', data.success);
console.log('Symbol:', data.symbol);
console.log('Requested Expiry:', testCase.expiry);
console.log('Final NSE Expiry:', data.expiryDate);
console.log('Spot Price:', data.spotPrice);
const strikes = Object.keys(data.optionChain || {});
console.log('Strikes count in optionChain:', strikes.length);
const recordsData = data.records?.data || data.records?.records?.data || [];
console.log('Records data count:', recordsData.length);
} catch (error) {
console.error(`Fatal error testing ${testCase.symbol}:`, error.message);
}
}
}
testApi();