Quick Start Guide
Get started with the Financial Context API in just a few minutes. This guide will walk you through making your first API call and building a simple application.
Prerequisites
Before you begin, make sure you have:
- A Financial Context API account (sign up here)
- Your API key (available in your dashboard)
- Basic knowledge of HTTP requests and JSON
Step 1: Get Your API Key
Verify Email
Check your email and verify your account
Access Dashboard
Log in to your dashboard and navigate to the API Keys section
Generate Key
Click “Generate New Key” and copy your API key
Keep your API key secure and never share it publicly. Store it as an environment variable in your applications.
Step 2: Make Your First API Call
Using cURL
Test your API key with a simple quote request:
curl -X GET "https://api.fcontext.com/api/quote/AAPL" \
-H "X-API-Key: your-api-key-here"
Expected Response:
{
"success": true,
"data": {
"symbol": "AAPL",
"price": 185.50,
"change": 2.30,
"changePercent": 1.26,
"volume": 45678900,
"marketCap": 2890000000000,
"timestamp": "2024-01-15T16:00:00Z"
}
}
Using JavaScript
const API_KEY = 'your-api-key-here';
const BASE_URL = 'https://api.fcontext.com';
async function getStockQuote(symbol) {
try {
const response = await fetch(`${BASE_URL}/api/quote/${symbol}`, {
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching quote:', error);
throw error;
}
}
// Usage
getStockQuote('AAPL')
.then(quote => {
console.log(`AAPL: $${quote.data.price} (${quote.data.changePercent}%)`);
})
.catch(error => {
console.error('Failed to get quote:', error);
});
Using Python
import requests
import os
API_KEY = os.getenv('FINANCIAL_CONTEXT_API_KEY')
BASE_URL = 'https://api.fcontext.com'
def get_stock_quote(symbol):
headers = {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
response = requests.get(f'{BASE_URL}/api/quote/{symbol}', headers=headers)
response.raise_for_status()
return response.json()
# Usage
try:
quote = get_stock_quote('AAPL')
data = quote['data']
print(f"AAPL: ${data['price']} ({data['changePercent']}%)")
except requests.exceptions.RequestException as e:
print(f"Error fetching quote: {e}")
Step 3: Explore Core Endpoints
curl -X GET "https://api.fcontext.com/api/company/profile/AAPL" \
-H "X-API-Key: your-api-key-here"
Get Financial Statements
curl -X GET "https://api.fcontext.com/api/financials/AAPL?period=annual&limit=3" \
-H "X-API-Key: your-api-key-here"
Get Technical Analysis
curl -X GET "https://api.fcontext.com/api/technicals/AAPL?interval=1d" \
-H "X-API-Key: your-api-key-here"
Get Latest News
curl -X GET "https://api.fcontext.com/api/news?symbol=AAPL&limit=5" \
-H "X-API-Key: your-api-key-here"
Step 4: Build a Simple Dashboard
Let’s create a simple stock dashboard using HTML and JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stock Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.dashboard {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}
.card {
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.symbol {
font-size: 24px;
font-weight: bold;
color: #333;
}
.price {
font-size: 32px;
font-weight: bold;
margin: 10px 0;
}
.positive { color: #22c55e; }
.negative { color: #ef4444; }
.change {
font-size: 18px;
font-weight: 500;
}
.loading {
text-align: center;
color: #666;
}
</style>
</head>
<body>
<h1>Stock Dashboard</h1>
<div id="dashboard" class="dashboard">
<div class="loading">Loading stock data...</div>
</div>
<script>
const API_KEY = 'your-api-key-here'; // Replace with your API key
const BASE_URL = 'https://api.fcontext.com';
const SYMBOLS = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA'];
async function fetchQuote(symbol) {
const response = await fetch(`${BASE_URL}/api/quote/${symbol}`, {
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`Failed to fetch ${symbol}`);
}
return response.json();
}
function createStockCard(data) {
const { symbol, price, change, changePercent } = data;
const isPositive = change >= 0;
return `
<div class="card">
<div class="symbol">${symbol}</div>
<div class="price ${isPositive ? 'positive' : 'negative'}">
$${price.toFixed(2)}
</div>
<div class="change ${isPositive ? 'positive' : 'negative'}">
${isPositive ? '+' : ''}${change.toFixed(2)}
(${isPositive ? '+' : ''}${changePercent.toFixed(2)}%)
</div>
</div>
`;
}
async function loadDashboard() {
const dashboard = document.getElementById('dashboard');
try {
const quotes = await Promise.all(
SYMBOLS.map(symbol => fetchQuote(symbol))
);
const cards = quotes.map(quote =>
createStockCard(quote.data)
).join('');
dashboard.innerHTML = cards;
} catch (error) {
dashboard.innerHTML = `
<div class="card">
<h3>Error</h3>
<p>Failed to load stock data: ${error.message}</p>
<p>Please check your API key and try again.</p>
</div>
`;
}
}
// Load dashboard on page load
loadDashboard();
// Refresh every 30 seconds
setInterval(loadDashboard, 30000);
</script>
</body>
</html>
Step 5: Error Handling
Implement proper error handling for production applications:
class FinancialContextAPI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://api.fcontext.com';
}
async makeRequest(endpoint) {
try {
const response = await fetch(`${this.baseUrl}${endpoint}`, {
headers: {
'X-API-Key': this.apiKey,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
throw new APIError(
response.status,
errorData.error?.message || 'Unknown error',
errorData.error?.code
);
}
return response.json();
} catch (error) {
if (error instanceof APIError) {
throw error;
}
throw new APIError(0, 'Network error', 'NETWORK_ERROR');
}
}
async getQuote(symbol) {
return this.makeRequest(`/api/quote/${symbol}`);
}
async getFinancials(symbol, options = {}) {
const params = new URLSearchParams(options);
return this.makeRequest(`/api/financials/${symbol}?${params}`);
}
}
class APIError extends Error {
constructor(status, message, code) {
super(message);
this.status = status;
this.code = code;
this.name = 'APIError';
}
}
// Usage with error handling
const api = new FinancialContextAPI('your-api-key');
try {
const quote = await api.getQuote('AAPL');
console.log('Quote:', quote.data);
} catch (error) {
if (error instanceof APIError) {
switch (error.status) {
case 401:
console.error('Invalid API key');
break;
case 429:
console.error('Rate limit exceeded');
break;
case 404:
console.error('Symbol not found');
break;
default:
console.error('API Error:', error.message);
}
} else {
console.error('Unexpected error:', error);
}
}
Next Steps
Common Use Cases
Portfolio Tracking
const portfolio = ['AAPL', 'MSFT', 'GOOGL'];
const quotes = await Promise.all(
portfolio.map(symbol => api.getQuote(symbol))
);
const totalValue = quotes.reduce((sum, quote) => {
return sum + (quote.data.price * getShares(quote.data.symbol));
}, 0);
console.log(`Portfolio Value: $${totalValue.toFixed(2)}`);
Price Alerts
function checkPriceAlerts(quotes, alerts) {
quotes.forEach(quote => {
const alert = alerts[quote.data.symbol];
if (alert && quote.data.price >= alert.targetPrice) {
sendNotification(
`${quote.data.symbol} reached $${quote.data.price}`
);
}
});
}
Market Screening
const symbols = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'TSLA'];
const quotes = await Promise.all(
symbols.map(symbol => api.getQuote(symbol))
);
// Find stocks with > 5% daily gain
const winners = quotes.filter(quote =>
quote.data.changePercent > 5
);
console.log('Top performers:', winners);
Support
Need help getting started?
The free plan includes 1,000 requests per day. Upgrade to Pro or Enterprise for higher limits and additional features.