Skip to content

Commit 6d08902

Browse files
committed
Add Finnhub test endpoint
1 parent 00e871c commit 6d08902

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

backend/src/routes/stocks.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ const Stock = require('../models/Stock');
44
const stockPriceService = require('../services/stockPriceService');
55
const { Op } = require('sequelize');
66
const { finnhubClient } = require('../config/finnhub');
7+
const axios = require('axios');
8+
9+
// Test Finnhub connection
10+
router.get('/test-finnhub/:ticker', async (req, res) => {
11+
try {
12+
const { ticker } = req.params;
13+
console.log('Testing Finnhub connection for ticker:', ticker);
14+
15+
const response = await axios.get('https://finnhub.io/api/v1/quote', {
16+
params: {
17+
symbol: ticker,
18+
token: process.env.FINNHUB_API_KEY
19+
}
20+
});
21+
22+
console.log('Finnhub response:', response.data);
23+
res.json(response.data);
24+
} catch (error) {
25+
console.error('Finnhub test error:', error.response?.data || error.message);
26+
res.status(500).json({
27+
error: 'Finnhub test failed',
28+
details: error.response?.data || error.message,
29+
apiKey: process.env.FINNHUB_API_KEY ? 'Present' : 'Missing'
30+
});
31+
}
32+
});
733

834
// Get all stocks
935
router.get('/', async (req, res) => {

0 commit comments

Comments
 (0)