Overview
The Stocks API provides comprehensive access to equity market data, including ticker information, current quotes, and historical price data across global exchanges.
Methods
tickers()
Retrieve a list of available stock tickers with optional filtering.
const axion = new Axion('your-api-key');
// Get all stock tickers
const allTickers = await axion.stocks.tickers();
// Filter by country
const usTickers = await axion.stocks.tickers({ country: 'US' });
// Filter by exchange
const nasdaqTickers = await axion.stocks.tickers({ exchange: 'NASDAQ' });
// Filter by both country and exchange
const filtered = await axion.stocks.tickers({
country: 'US',
exchange: 'NYSE'
});
Filter tickers by country code (e.g., ‘US’, ‘GB’, ‘JP’)
Filter tickers by exchange name (e.g., ‘NYSE’, ‘NASDAQ’, ‘LSE’)
Array of ticker objectsExchange where the stock is traded
ticker()
Get detailed information about a specific stock ticker.
const axion = new Axion('your-api-key');
// Get information for Apple Inc.
const appleData = await axion.stocks.ticker('AAPL');
// Get information for Tesla
const teslaData = await axion.stocks.ticker('TSLA');
The stock ticker symbol (e.g., ‘AAPL’, ‘TSLA’, ‘MSFT’)
Detailed ticker information
prices()
Retrieve historical price data for a stock with optional date range and time frame.
const axion = new Axion('your-api-key');
// Get all available historical prices
const allPrices = await axion.stocks.prices('AAPL');
// Get prices for a specific date range
const rangedPrices = await axion.stocks.prices('AAPL', {
from: '2024-01-01',
to: '2024-12-31'
});
// Get daily prices for the last year
const dailyPrices = await axion.stocks.prices('AAPL', {
from: '2024-01-01',
to: '2024-12-31',
frame: 'daily'
});
// Get weekly prices
const weeklyPrices = await axion.stocks.prices('MSFT', {
from: '2023-01-01',
to: '2024-01-01',
frame: 'weekly'
});
The stock ticker symbol (e.g., ‘AAPL’, ‘TSLA’, ‘MSFT’)
Start date in YYYY-MM-DD format
End date in YYYY-MM-DD format
Time frame for price data (‘daily’, ‘weekly’, ‘monthly’)
Array of historical price points
Example: Building a Stock Dashboard
import { Axion } from 'axion-sdk';
const axion = new Axion('your-api-key');
async function buildStockDashboard(tickers: string[]) {
const dashboard = [];
for (const ticker of tickers) {
// Get current quote
const quote = await axion.stocks.ticker(ticker);
// Get 30-day price history
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const prices = await axion.stocks.prices(ticker, {
from: thirtyDaysAgo.toISOString().split('T')[0],
to: new Date().toISOString().split('T')[0],
frame: 'daily'
});
dashboard.push({
ticker,
currentPrice: quote.data.price,
change: quote.data.change,
changePercent: quote.data.changePercent,
priceHistory: prices.data
});
}
return dashboard;
}
// Build dashboard for tech stocks
const techDashboard = await buildStockDashboard(['AAPL', 'MSFT', 'GOOGL', 'AMZN']);
console.log(techDashboard);
Error Handling
try {
const data = await axion.stocks.ticker('INVALID');
} catch (error) {
if (error.message.includes('HTTP Error 404')) {
console.error('Ticker not found');
} else if (error.message.includes('Authentication required')) {
console.error('API key is missing or invalid');
} else {
console.error('An error occurred:', error.message);
}
}