
Finnhub Stock API
FinanceAccess real-time stock data, company financials, earnings, and market news. Institutional-grade financial data API with a generous free tier.
📚 Documentation & Examples
Everything you need to integrate with Finnhub Stock API
🚀 Quick Start Examples
// Finnhub Stock API API Example
const response = await fetch('https://finnhub.io/docs/api', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);Finnhub Stock API
Finnhub provides institutional-grade financial data for developers building trading platforms, financial apps, and investment tools. Access real-time stock prices, company fundamentals, earnings data, and market news - all with a generous free tier.
Key Features
- Real-time Stock Quotes - Live prices for US stocks, forex, and crypto
- Company Fundamentals - Financial statements, metrics, and profiles
- Earnings Calendar - Track upcoming and historical earnings
- Market News - Company-specific and general market news
- Technical Indicators - Built-in support for common technical analysis
Free Tier
- 60 API calls/minute
- Real-time US stock data
- Company profiles and financials
- Market news and sentiment
JavaScript Example
const axios = require('axios');
const FINNHUB_API_KEY = 'YOUR_FINNHUB_API_KEY';
const BASE_URL = 'https://finnhub.io/api/v1';
const api = axios.create({
baseURL: BASE_URL,
params: { token: FINNHUB_API_KEY }
});
// Get real-time stock quote
async function getQuote(symbol) {
const response = await api.get('/quote', { params: { symbol } });
return {
current: response.data.c,
high: response.data.h,
low: response.data.l,
open: response.data.o,
previousClose: response.data.pc,
change: response.data.d,
changePercent: response.data.dp
};
}
// Get company profile
async function getCompanyProfile(symbol) {
const response = await api.get('/stock/profile2', { params: { symbol } });
return response.data;
}
// Get company financials
async function getFinancials(symbol) {
const response = await api.get('/stock/metric', {
params: { symbol, metric: 'all' }
});
return response.data;
}
// Get market news
async function getMarketNews(category = 'general') {
const response = await api.get('/news', { params: { category } });
return response.data;
}
// Get earnings calendar
async function getEarningsCalendar(from, to) {
const response = await api.get('/calendar/earnings', {
params: { from, to }
});
return response.data.earningsCalendar;
}
// Example usage
async function analyzeStock(symbol) {
console.log(`\n=== ${symbol} Analysis ===\n`);
const quote = await getQuote(symbol);
console.log(`Current Price: $${quote.current}`);
console.log(`Change: ${quote.change > 0 ? '+' : ''}${quote.change} (${quote.changePercent.toFixed(2)}%)`);
const profile = await getCompanyProfile(symbol);
console.log(`\nCompany: ${profile.name}`);
console.log(`Industry: ${profile.finnhubIndustry}`);
console.log(`Market Cap: $${(profile.marketCapitalization / 1000).toFixed(2)}B`);
const financials = await getFinancials(symbol);
console.log(`\nKey Metrics:`);
console.log(`P/E Ratio: ${financials.metric.peBasicExclExtraTTM?.toFixed(2)}`);
console.log(`52-Week High: $${financials.metric['52WeekHigh']}`);
console.log(`52-Week Low: $${financials.metric['52WeekLow']}`);
}
analyzeStock('AAPL');
Python Example
import requests
from datetime import datetime, timedelta
API_KEY = 'YOUR_FINNHUB_API_KEY'
BASE_URL = 'https://finnhub.io/api/v1'
def get_quote(symbol):
response = requests.get(
f'{BASE_URL}/quote',
params={'symbol': symbol, 'token': API_KEY}
)
data = response.json()
return {
'current': data['c'],
'change': data['d'],
'change_percent': data['dp']
}
def get_company_profile(symbol):
response = requests.get(
f'{BASE_URL}/stock/profile2',
params={'symbol': symbol, 'token': API_KEY}
)
return response.json()
def get_company_news(symbol, days_back=7):
end = datetime.now()
start = end - timedelta(days=days_back)
response = requests.get(
f'{BASE_URL}/company-news',
params={
'symbol': symbol,
'from': start.strftime('%Y-%m-%d'),
'to': end.strftime('%Y-%m-%d'),
'token': API_KEY
}
)
return response.json()
# Usage
quote = get_quote('MSFT')
print(f"Microsoft: ${quote['current']} ({quote['change_percent']:+.2f}%)")
news = get_company_news('MSFT', days_back=3)
for article in news[:5]:
print(f"- {article['headline']}")
WebSocket for Real-time Data
const WebSocket = require('ws');
const socket = new WebSocket(`wss://ws.finnhub.io?token=${FINNHUB_API_KEY}`);
socket.on('open', () => {
// Subscribe to stock symbols
socket.send(JSON.stringify({ type: 'subscribe', symbol: 'AAPL' }));
socket.send(JSON.stringify({ type: 'subscribe', symbol: 'GOOGL' }));
});
socket.on('message', (data) => {
const trades = JSON.parse(data);
if (trades.type === 'trade') {
trades.data.forEach(trade => {
console.log(`${trade.s}: $${trade.p} x ${trade.v}`);
});
}
});
Use Cases
- Trading Platforms - Build stock trading applications
- Portfolio Trackers - Monitor investment performance
- Financial Dashboards - Display market data and metrics
- Investment Research - Analyze company fundamentals
- Market Alerts - Track price movements and news
📊 30-Day Uptime History
Daily uptime tracking showing online vs offline minutes










