> ## Documentation Index
> Fetch the complete documentation index at: https://docs.axionquant.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get started with Axion SDK in minutes - fetch stock data, prices, and market insights

## Overview

This guide will walk you through creating your first application with the Axion SDK. You'll learn how to initialize the client, fetch stock data, retrieve historical prices, and access sentiment analysis.

<Note>
  Make sure you have [installed the SDK](/installation) and have your API key ready. If you don't have an API key yet, check out the [authentication guide](/authentication).
</Note>

## Initialize the Client

First, import the Axion class and create a new client instance with your API key:

<CodeGroup>
  ```javascript JavaScript theme={null}
  import { Axion } from '@axionquant/sdk';

  const client = new Axion('your-api-key-here');
  ```

  ```typescript TypeScript theme={null}
  import { Axion } from '@axionquant/sdk';

  const client: Axion = new Axion('your-api-key-here');
  ```
</CodeGroup>

<Tip>
  For development and testing purposes, you can initialize the client without an API key if you're working with a local server or endpoints that don't require authentication.
</Tip>

## Your First Request

Let's fetch basic information about a stock:

```javascript theme={null}
const stock = await client.stocks.ticker('AAPL');
console.log('Stock data:', stock.data);
```

This retrieves comprehensive information about Apple Inc. (AAPL) including current price, market cap, and other key metrics.

## Complete Example

Here's a complete example that demonstrates multiple API features:

```javascript example.js theme={null}
import { Axion } from '@axionquant/sdk';

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

async function analyzeStock(ticker) {
  try {
    console.log(`Analyzing ${ticker}...\n`);
    
    // 1. Get basic stock information
    const stock = await client.stocks.ticker(ticker);
    console.log('Stock Info:', Object.keys(stock.data));
    
    // 2. Get historical prices with date range
    const prices = await client.stocks.prices(ticker, {
      from: '2024-01-01',
      to: '2024-01-31',
      frame: 'daily'
    });
    console.log(`Price data points: ${prices.data?.length || 0}`);
    
    // 3. Get company profile and information
    const profile = await client.profiles.info(ticker);
    console.log('Company Info:', Object.keys(profile.data));
    
    // 4. Get sentiment analysis
    const sentiment = await client.sentiment.all(ticker);
    console.log('Sentiment Data:', Object.keys(sentiment.data));
    
    // 5. Get recent company news
    const news = await client.news.company(ticker);
    console.log(`Recent news articles: ${news.data?.length || 0}`);
    
    return {
      stock: stock.data,
      priceCount: prices.data?.length || 0,
      profile: profile.data,
      sentiment: sentiment.data,
      newsCount: news.data?.length || 0
    };
  } catch (error) {
    console.error('Error:', error.message);
  }
}

// Run the analysis
analyzeStock('AAPL').then(result => {
  console.log('\nAnalysis complete!');
});
```

## Step-by-Step Walkthrough

<Steps>
  <Step title="Get Stock Tickers">
    First, retrieve a list of available stock tickers, optionally filtered by country and exchange:

    ```javascript theme={null}
    const tickers = await client.stocks.tickers({
      country: 'US',
      exchange: 'NASDAQ'
    });
    console.log('Available tickers:', tickers.data.slice(0, 5));
    ```
  </Step>

  <Step title="Fetch Stock Details">
    Get detailed information about a specific stock:

    ```javascript theme={null}
    const stock = await client.stocks.ticker('AAPL');
    console.log('Stock data:', stock.data);
    ```
  </Step>

  <Step title="Retrieve Historical Prices">
    Fetch historical price data with custom date ranges and timeframes:

    ```javascript theme={null}
    const prices = await client.stocks.prices('AAPL', {
      from: '2024-01-01',
      to: '2024-01-31',
      frame: 'daily'
    });

    if (prices.data && prices.data.length > 0) {
      console.log('First data point:', {
        date: prices.data[0].date,
        close: prices.data[0].close
      });
    }
    ```
  </Step>

  <Step title="Access Company Fundamentals">
    Get financial metrics, earnings data, and company statistics:

    ```javascript theme={null}
    // Get financial metrics
    const metrics = await client.financials.metrics('AAPL');

    // Get earnings history
    const earnings = await client.earnings.history('AAPL');

    // Get company statistics
    const stats = await client.profiles.statistics('AAPL');
    ```
  </Step>
</Steps>

## Working with Different Asset Classes

The SDK supports multiple asset classes beyond stocks:

<CodeGroup>
  ```javascript Cryptocurrency theme={null}
  // Get crypto tickers
  const cryptoTickers = await client.crypto.tickers({ type: 'spot' });

  // Get Bitcoin prices
  const btcPrices = await client.crypto.prices('BTC-USD', {
    from: '2024-01-01',
    to: '2024-01-07',
    frame: 'daily'
  });
  ```

  ```javascript ETFs theme={null}
  // Get ETF fund data
  const etfFund = await client.etfs.fund('SPY');

  // Get ETF holdings
  const holdings = await client.etfs.holdings('SPY');

  // Get ETF exposure
  const exposure = await client.etfs.exposure('SPY');
  ```

  ```javascript Economic Data theme={null}
  // Search economic datasets
  const econSearch = await client.econ.search('GDP');

  // Get economic calendar
  const calendar = await client.econ.calendar({
    from: '2024-01-01',
    to: '2024-01-31',
    country: 'US',
    minImportance: 2
  });
  ```
</CodeGroup>

## Error Handling

The SDK provides detailed error messages for different failure scenarios:

```javascript theme={null}
try {
  const stock = await client.stocks.ticker('AAPL');
  console.log('Success!', stock.data);
} catch (error) {
  if (error.message.includes('HTTP Error')) {
    console.error('API error:', error.message);
  } else if (error.message.includes('Connection Error')) {
    console.error('Network issue:', error.message);
  } else if (error.message.includes('Authentication required')) {
    console.error('Missing or invalid API key');
  } else {
    console.error('Unexpected error:', error.message);
  }
}
```

<Warning>
  Always wrap API calls in try-catch blocks to handle potential errors gracefully. The SDK throws errors for:

  * HTTP errors (4xx, 5xx status codes)
  * Connection failures
  * Authentication issues
  * Request configuration errors
</Warning>

## Advanced Example: Multi-Asset Analysis

Here's a more sophisticated example that analyzes multiple data sources:

```javascript theme={null}
async function comprehensiveAnalysis(ticker) {
  const client = new Axion('your-api-key-here');
  
  try {
    // Fetch data from multiple endpoints in parallel
    const [stock, prices, sentiment, financials, earnings, news] = await Promise.all([
      client.stocks.ticker(ticker),
      client.stocks.prices(ticker, { from: '2024-01-01', to: '2024-01-31' }),
      client.sentiment.all(ticker),
      client.financials.snapshot(ticker),
      client.earnings.history(ticker),
      client.news.company(ticker)
    ]);
    
    return {
      ticker,
      currentPrice: stock.data,
      priceHistory: prices.data,
      sentiment: sentiment.data,
      financials: financials.data,
      earnings: earnings.data,
      latestNews: news.data?.slice(0, 5) // Get top 5 news articles
    };
  } catch (error) {
    console.error(`Analysis failed for ${ticker}:`, error.message);
    throw error;
  }
}

// Analyze multiple stocks
const tickers = ['AAPL', 'MSFT', 'GOOGL'];
const analyses = await Promise.all(
  tickers.map(ticker => comprehensiveAnalysis(ticker))
);

console.log('All analyses complete:', analyses);
```

## API Response Structure

All API methods return a response object with a `data` property:

```javascript theme={null}
const response = await client.stocks.ticker('AAPL');

// Access the data
console.log(response.data);

// Check if data exists
if (response.data && response.data.length > 0) {
  // Process the data
}
```

<Note>
  The exact structure of `response.data` varies by endpoint. Refer to the [API Reference](/reference/client) for detailed response schemas for each endpoint.
</Note>

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/authentication">
    Learn how to manage API keys and authentication
  </Card>

  <Card title="API Reference" icon="book" href="/reference/client">
    Explore all available endpoints and methods
  </Card>

  <Card title="Stocks API" icon="chart-line" href="/api/stocks">
    Deep dive into stock market data endpoints
  </Card>

  <Card title="Sentiment API" icon="brain" href="/api/sentiment">
    Learn about sentiment analysis features
  </Card>
</CardGroup>
