Skip to main content

Overview

The Crypto API provides real-time and historical data for cryptocurrencies, including Bitcoin, Ethereum, and thousands of altcoins.

Methods

tickers()

Retrieve a list of available cryptocurrency tickers with optional filtering by type.
const axion = new Axion('your-api-key');

// Get all cryptocurrency tickers
const allCryptos = await axion.crypto.tickers();

// Filter by type (e.g., 'coin', 'token')
const coins = await axion.crypto.tickers({ type: 'coin' });
type
string
Filter by cryptocurrency type (e.g., ‘coin’, ‘token’, ‘stablecoin’)
data
array
Array of cryptocurrency ticker objects
ticker
string
Cryptocurrency ticker symbol
name
string
Full name of the cryptocurrency
type
string
Type of cryptocurrency (coin, token, etc.)
blockchain
string
Underlying blockchain network

ticker()

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

// Get Bitcoin data
const bitcoinData = await axion.crypto.ticker('BTC');

// Get Ethereum data
const ethereumData = await axion.crypto.ticker('ETH');

// Get Solana data
const solanaData = await axion.crypto.ticker('SOL');
ticker
string
required
The cryptocurrency ticker symbol (e.g., ‘BTC’, ‘ETH’, ‘SOL’)
data
object
Detailed cryptocurrency information
ticker
string
Cryptocurrency ticker symbol
name
string
Full name of the cryptocurrency
price
number
Current price in USD
volume24h
number
24-hour trading volume
marketCap
number
Market capitalization
change24h
number
24-hour price change
changePercent24h
number
24-hour percentage change
circulatingSupply
number
Circulating supply
totalSupply
number
Total supply

prices()

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

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

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

// Get hourly prices for the last week
const hourlyPrices = await axion.crypto.prices('BTC', {
  from: '2024-12-01',
  to: '2024-12-07',
  frame: 'hourly'
});

// Get daily prices for analysis
const dailyPrices = await axion.crypto.prices('SOL', {
  from: '2024-01-01',
  to: '2024-12-31',
  frame: 'daily'
});
ticker
string
required
The cryptocurrency ticker symbol (e.g., ‘BTC’, ‘ETH’, ‘SOL’)
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 (‘hourly’, ‘daily’, ‘weekly’, ‘monthly’)
data
array
Array of historical price points
timestamp
string
Timestamp of the price point
open
number
Opening price
high
number
Highest price
low
number
Lowest price
close
number
Closing price
volume
number
Trading volume
marketCap
number
Market cap at this timestamp

Example: Crypto Portfolio Tracker

import { Axion } from 'axion-sdk';

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

interface PortfolioHolding {
  ticker: string;
  amount: number;
}

async function trackCryptoPortfolio(holdings: PortfolioHolding[]) {
  let totalValue = 0;
  const portfolio = [];

  for (const holding of holdings) {
    const data = await axion.crypto.ticker(holding.ticker);
    const value = data.data.price * holding.amount;
    
    totalValue += value;
    
    portfolio.push({
      ticker: holding.ticker,
      name: data.data.name,
      amount: holding.amount,
      currentPrice: data.data.price,
      value: value,
      change24h: data.data.changePercent24h
    });
  }

  return {
    totalValue,
    holdings: portfolio
  };
}

// Track a portfolio
const myPortfolio = await trackCryptoPortfolio([
  { ticker: 'BTC', amount: 0.5 },
  { ticker: 'ETH', amount: 5.0 },
  { ticker: 'SOL', amount: 100 }
]);

console.log(`Total Portfolio Value: $${myPortfolio.totalValue.toFixed(2)}`);
myPortfolio.holdings.forEach(h => {
  console.log(`${h.name}: $${h.value.toFixed(2)} (${h.change24h > 0 ? '+' : ''}${h.change24h.toFixed(2)}%)`);
});

Example: Price Alert System

import { Axion } from 'axion-sdk';

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

async function checkPriceAlerts(ticker: string, targetPrice: number) {
  const data = await axion.crypto.ticker(ticker);
  const currentPrice = data.data.price;
  
  if (currentPrice >= targetPrice) {
    console.log(`🚨 ALERT: ${ticker} has reached $${currentPrice}!`);
    return true;
  }
  
  console.log(`${ticker} current price: $${currentPrice} (Target: $${targetPrice})`);
  return false;
}

// Check if Bitcoin reached $100,000
await checkPriceAlerts('BTC', 100000);

Error Handling

try {
  const data = await axion.crypto.ticker('INVALID');
} catch (error) {
  if (error.message.includes('HTTP Error 404')) {
    console.error('Cryptocurrency not found');
  } else if (error.message.includes('Connection Error')) {
    console.error('Unable to connect to API');
  } else {
    console.error('An error occurred:', error.message);
  }
}