Repository navigation
Expand file tree
/
Copy pathtest-eodh-api.js
More file actions
58 lines (48 loc) · 1.69 KB
/
Copy pathtest-eodh-api.js
File metadata and controls
58 lines (48 loc) · 1.69 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Script to test the EODHD API key functionality
import 'dotenv/config';
import axios from 'axios';
const EOD_API_KEY = process.env.EODHD_API_KEY || '';
const EOD_API_BASE_URL = 'https://eodhistoricaldata.com/api';
async function testTickerData(ticker) {
console.log(`Testing ticker: ${ticker}`);
try {
const endpoint = `${EOD_API_BASE_URL}/real-time/${ticker}`;
const params = {
api_token: EOD_API_KEY,
fmt: 'json'
};
console.log(`Using API key: ${EOD_API_KEY ? 'API key is set' : 'No API key found'}`);
console.log(`Requesting: ${endpoint}`);
const response = await axios.get(endpoint, { params });
console.log(`Response status: ${response.status}`);
console.log('Response data:', JSON.stringify(response.data, null, 2));
return { ticker, success: true, data: response.data };
} catch (error) {
console.error(`Error for ${ticker}:`, error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
return { ticker, success: false, error: error.message };
}
}
async function main() {
console.log('Testing EODHD API...');
// Test a few different tickers from different exchanges
const tickers = [
'FOXF', // US stock
'9921.TW', // Taiwan stock
'7309.T', // Japan stock
'THULE.ST', // Sweden stock
'HFD.L', // London stock
'PKTM.VI' // Vienna stock
];
for (const ticker of tickers) {
await testTickerData(ticker);
console.log('-'.repeat(50));
}
}
main().catch(err => {
console.error('Unhandled error:', err);
process.exit(1);
});