Skip to main content

Overview

The Futures API provides comprehensive data for futures contracts across commodities, indices, currencies, and other asset classes.

Methods

tickers()

Retrieve a list of available futures contracts with optional filtering by exchange.
const axion = new Axion('your-api-key');

// Get all futures contracts
const allFutures = await axion.futures.tickers();

// Filter by exchange
const cmeFutures = await axion.futures.tickers({ exchange: 'CME' });

// Get ICE futures
const iceFutures = await axion.futures.tickers({ exchange: 'ICE' });
exchange
string
Filter futures contracts by exchange (e.g., ‘CME’, ‘ICE’, ‘EUREX’)
data
array
Array of futures contract objects
ticker
string
Futures contract symbol
name
string
Full name of the futures contract
exchange
string
Exchange where the contract is traded
assetClass
string
Asset class (commodity, index, currency, etc.)
expirationDate
string
Contract expiration date

ticker()

Get detailed information about a specific futures contract.
const axion = new Axion('your-api-key');

// Get crude oil futures data
const crudeFutures = await axion.futures.ticker('CL');

// Get gold futures data
const goldFutures = await axion.futures.ticker('GC');

// Get S&P 500 E-mini futures
const spFutures = await axion.futures.ticker('ES');
ticker
string
required
The futures contract symbol (e.g., ‘CL’, ‘GC’, ‘ES’)
data
object
Detailed futures contract information
ticker
string
Futures contract symbol
name
string
Full name of the contract
price
number
Current price
change
number
Price change
changePercent
number
Percentage change
volume
number
Trading volume
openInterest
number
Open interest
settlementPrice
number
Settlement price
expirationDate
string
Contract expiration date

prices()

Retrieve historical price data for a futures contract with optional date range and time frame.
const axion = new Axion('your-api-key');

// Get all available historical prices
const allPrices = await axion.futures.prices('CL');

// Get prices for a specific date range
const rangedPrices = await axion.futures.prices('GC', {
  from: '2024-01-01',
  to: '2024-12-31'
});

// Get daily prices
const dailyPrices = await axion.futures.prices('ES', {
  from: '2024-01-01',
  to: '2024-12-31',
  frame: 'daily'
});

// Get weekly prices for analysis
const weeklyPrices = await axion.futures.prices('NG', {
  from: '2023-01-01',
  to: '2024-01-01',
  frame: 'weekly'
});
ticker
string
required
The futures contract symbol (e.g., ‘CL’, ‘GC’, ‘ES’)
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
openInterest
number
Open interest at this date

Example: Commodity Futures Tracker

import { Axion } from 'axion-sdk';

const axion = new Axion('your-api-key');

async function trackCommodities(contracts: string[]) {
  const commodities = [];

  for (const contract of contracts) {
    const data = await axion.futures.ticker(contract);
    
    commodities.push({
      contract: contract,
      name: data.data.name,
      price: data.data.price,
      change: data.data.change,
      changePercent: data.data.changePercent,
      volume: data.data.volume,
      openInterest: data.data.openInterest,
      expiration: data.data.expirationDate
    });
  }

  return commodities;
}

// Track energy and metals
const commodityData = await trackCommodities(['CL', 'NG', 'GC', 'SI']);

commodityData.forEach(c => {
  console.log(`${c.name} (${c.contract}):`);
  console.log(`  Price: $${c.price} (${c.changePercent > 0 ? '+' : ''}${c.changePercent.toFixed(2)}%)`);
  console.log(`  Volume: ${c.volume.toLocaleString()}`);
  console.log(`  Open Interest: ${c.openInterest.toLocaleString()}`);
  console.log(`  Expires: ${c.expiration}`);
});

Example: Futures Spread Analysis

import { Axion } from 'axion-sdk';

const axion = new Axion('your-api-key');

async function analyzeSpread(contract1: string, contract2: string, days: number) {
  const endDate = new Date();
  const startDate = new Date();
  startDate.setDate(startDate.getDate() - days);
  
  const [prices1, prices2] = await Promise.all([
    axion.futures.prices(contract1, {
      from: startDate.toISOString().split('T')[0],
      to: endDate.toISOString().split('T')[0],
      frame: 'daily'
    }),
    axion.futures.prices(contract2, {
      from: startDate.toISOString().split('T')[0],
      to: endDate.toISOString().split('T')[0],
      frame: 'daily'
    })
  ]);
  
  const spreads = prices1.data.map((p1, i) => {
    const p2 = prices2.data[i];
    return {
      date: p1.date,
      spread: p1.close - p2.close
    };
  });
  
  const currentSpread = spreads[spreads.length - 1].spread;
  const avgSpread = spreads.reduce((sum, s) => sum + s.spread, 0) / spreads.length;
  const maxSpread = Math.max(...spreads.map(s => s.spread));
  const minSpread = Math.min(...spreads.map(s => s.spread));
  
  return {
    contract1,
    contract2,
    currentSpread,
    avgSpread,
    maxSpread,
    minSpread,
    period: `${days} days`
  };
}

// Analyze crude oil vs natural gas spread
const spreadAnalysis = await analyzeSpread('CL', 'NG', 30);
console.log(`${spreadAnalysis.contract1}/${spreadAnalysis.contract2} Spread Analysis:`);
console.log(`Current: $${spreadAnalysis.currentSpread.toFixed(2)}`);
console.log(`Average: $${spreadAnalysis.avgSpread.toFixed(2)}`);
console.log(`Range: $${spreadAnalysis.minSpread.toFixed(2)} - $${spreadAnalysis.maxSpread.toFixed(2)}`);

Example: Futures Calendar Monitor

import { Axion } from 'axion-sdk';

const axion = new Axion('your-api-key');

async function monitorExpirations(exchange: string) {
  const futures = await axion.futures.tickers({ exchange });
  
  const today = new Date();
  const thirtyDaysFromNow = new Date();
  thirtyDaysFromNow.setDate(today.getDate() + 30);
  
  const expiringSoon = [];
  
  for (const future of futures.data) {
    const expirationDate = new Date(future.expirationDate);
    
    if (expirationDate >= today && expirationDate <= thirtyDaysFromNow) {
      const data = await axion.futures.ticker(future.ticker);
      
      expiringSoon.push({
        ticker: future.ticker,
        name: future.name,
        expirationDate: future.expirationDate,
        daysUntilExpiration: Math.ceil((expirationDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)),
        currentPrice: data.data.price,
        openInterest: data.data.openInterest
      });
    }
  }
  
  return expiringSoon.sort((a, b) => a.daysUntilExpiration - b.daysUntilExpiration);
}

// Monitor CME contracts expiring in the next 30 days
const expiringContracts = await monitorExpirations('CME');

console.log('Futures Expiring in Next 30 Days:');
expiringContracts.forEach(c => {
  console.log(`${c.name} (${c.ticker}):`);
  console.log(`  Expires: ${c.expirationDate} (${c.daysUntilExpiration} days)`);
  console.log(`  Price: $${c.currentPrice}`);
  console.log(`  Open Interest: ${c.openInterest.toLocaleString()}`);
});

Error Handling

try {
  const data = await axion.futures.ticker('INVALID');
} catch (error) {
  if (error.message.includes('HTTP Error 404')) {
    console.error('Futures contract not found');
  } else if (error.message.includes('Authentication required')) {
    console.error('API key is required');
  } else {
    console.error('An error occurred:', error.message);
  }
}