Skip to main content

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' 
});
country
string
Filter tickers by country code (e.g., ‘US’, ‘GB’, ‘JP’)
exchange
string
Filter tickers by exchange name (e.g., ‘NYSE’, ‘NASDAQ’, ‘LSE’)
data
array
Array of ticker objects
ticker
string
Stock ticker symbol
name
string
Company name
exchange
string
Exchange where the stock is traded
country
string
Country code

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');
ticker
string
required
The stock ticker symbol (e.g., ‘AAPL’, ‘TSLA’, ‘MSFT’)
data
object
Detailed ticker information
ticker
string
Stock ticker symbol
name
string
Company name
price
number
Current price
volume
number
Trading volume
marketCap
number
Market capitalization
change
number
Price change
changePercent
number
Percentage change

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'
});
ticker
string
required
The stock ticker symbol (e.g., ‘AAPL’, ‘TSLA’, ‘MSFT’)
from
string
Start date in YYYY-MM-DD format
to
string
End date in YYYY-MM-DD format
frame
string
Time frame for price data (‘daily’, ‘weekly’, ‘monthly’)
data
array
Array of historical price points
date
string
Date of the price point
open
number
Opening price
high
number
Highest price
low
number
Lowest price
close
number
Closing price
volume
number
Trading volume
adjustedClose
number
Adjusted closing price

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);
  }
}