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' });
Filter by cryptocurrency type (e.g., ‘coin’, ‘token’, ‘stablecoin’)
Array of cryptocurrency ticker objectsCryptocurrency ticker symbol
Full name of the cryptocurrency
Type of cryptocurrency (coin, token, etc.)
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');
The cryptocurrency ticker symbol (e.g., ‘BTC’, ‘ETH’, ‘SOL’)
Detailed cryptocurrency informationCryptocurrency ticker symbol
Full name of the cryptocurrency
24-hour percentage change
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'
});
The cryptocurrency ticker symbol (e.g., ‘BTC’, ‘ETH’, ‘SOL’)
Start date in YYYY-MM-DD format
End date in YYYY-MM-DD format
Time frame for price data (‘hourly’, ‘daily’, ‘weekly’, ‘monthly’)
Array of historical price pointsTimestamp of the price point
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);
}
}