Repository navigation
Expand file tree
/
Copy pathtest-eod-api.js
More file actions
53 lines (44 loc) · 1.72 KB
/
Copy pathtest-eod-api.js
File metadata and controls
53 lines (44 loc) · 1.72 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
// Simple test script to check EOD API integration
import axios from 'axios';
import { config } from 'dotenv';
// Load environment variables
config();
// EOD Historical Data API endpoint
const EOD_API_KEY = process.env.EODHD_API_KEY || '';
const EOD_API_BASE_URL = 'https://eodhistoricaldata.com/api';
async function testEodApi() {
console.log('Testing EOD Historical Data API Integration');
console.log(`API Key available: ${EOD_API_KEY ? 'Yes' : 'No'}`);
// Test with a few different tickers from different exchanges
const testTickers = ['AAPL', 'FOXF', 'SPY', 'BTC-USD.COINBASE', '9921.TW', '7309.T'];
for (const ticker of testTickers) {
try {
console.log(`\nFetching data for ${ticker}...`);
const response = await axios.get(`${EOD_API_BASE_URL}/real-time/${ticker}`, {
params: {
api_token: EOD_API_KEY,
fmt: 'json',
}
});
console.log(`Response for ${ticker}:`);
console.log('- Status:', response.status);
console.log('- Code:', response.data.code);
console.log('- Price:', response.data.close || response.data.price);
console.log('- Change %:', response.data.change_p || response.data.change_percent);
// Print some of the timestamp info
if (response.data.timestamp) {
const date = new Date(response.data.timestamp * 1000);
console.log('- Timestamp:', date.toISOString());
}
} catch (error) {
console.error(`Error fetching ${ticker}:`, error.message);
if (error.response) {
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
}
}
}
}
testEodApi().catch(err => {
console.error('Test failed:', err);
});