Quant.Explorer.Providers.TwelveData (quant v0.1.0-alpha.1)

Twelve Data financial API provider.

Provides access to comprehensive financial data including:

  • Stock historical data and real-time prices
  • Forex exchange rates
  • Cryptocurrency data
  • Technical indicators
  • Company fundamentals

Rate Limits

Twelve Data API has the following rate limits:

  • Basic (Free): 8 requests per minute
  • Grow: 54 requests per minute
  • Pro: 164 requests per minute
  • Enterprise: Custom limits

Configuration

API key is required for most endpoints:

config :quant,
  api_keys: %{
    twelve_data: "your_api_key_here"
  }

Examples

# Get Apple stock historical data
{:ok, df} = TwelveData.history("AAPL", interval: "1day", outputsize: 30)

# Get real-time stock quote
{:ok, df} = TwelveData.quote("AAPL")

# Search for stocks
{:ok, df} = TwelveData.search("Apple")

# Get company profile
{:ok, info} = TwelveData.info("AAPL")

Summary

Functions

Gets forex exchange rates.

Fetches historical stock data.

Fetches company profile and fundamental data.

Fetches current market data for stocks.

Searches for stocks by symbol or company name.

Functions

forex_rate(from_currencies, to_currency)

@spec forex_rate(String.t() | [String.t()], String.t()) ::
  {:ok, Explorer.DataFrame.t()} | {:error, term()}

Gets forex exchange rates.

Options

  • :from - Base currency (default: "USD")
  • :to - Target currency (default: "EUR")

Examples

{:ok, df} = TwelveData.forex_rate("USD", "EUR")
{:ok, df} = TwelveData.forex_rate(["USD", "GBP"], "EUR")

history(symbols, opts \\ [])

@spec history(
  String.t() | [String.t()],
  keyword()
) :: {:ok, Explorer.DataFrame.t()} | {:error, term()}

Fetches historical stock data.

Options

  • :api_key - Twelve Data API key (optional, will use config if not provided)
  • :interval - Time interval ("1min", "5min", "15min", "30min", "45min", "1h", "2h", "4h", "1day", "1week", "1month")
  • :outputsize - Number of data points (default: 30, max: 5000)
  • :format - Response format (default: "json")
  • :country - Country filter
  • :exchange - Exchange filter

Examples

# Get Apple daily data for last 30 days
{:ok, df} = TwelveData.history("AAPL", interval: "1day", outputsize: 30)

# Get intraday data
{:ok, df} = TwelveData.history("AAPL", interval: "5min", outputsize: 100)

# With API key
{:ok, df} = TwelveData.history("AAPL",
  interval: "1day",
  outputsize: 30,
  api_key: "YOUR_API_KEY"
)

info(symbol, opts \\ [])

@spec info(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Fetches company profile and fundamental data.

Options

  • :api_key - Twelve Data API key (optional, will use config if not provided)

Examples

{:ok, info} = TwelveData.info("AAPL")
{:ok, info} = TwelveData.info("AAPL", api_key: "YOUR_API_KEY")

quote(symbols, opts \\ [])

@spec quote(
  String.t() | [String.t()],
  keyword()
) :: {:ok, Explorer.DataFrame.t()} | {:error, term()}

Fetches current market data for stocks.

Options

  • :api_key - Twelve Data API key (optional, will use config if not provided)

Examples

# Single stock
{:ok, df} = TwelveData.quote("AAPL")

# Multiple stocks
{:ok, df} = TwelveData.quote(["AAPL", "MSFT", "GOOGL"])

# With API key
{:ok, df} = TwelveData.quote("AAPL", api_key: "YOUR_API_KEY")

search(query, opts \\ [])

@spec search(
  String.t(),
  keyword()
) :: {:ok, Explorer.DataFrame.t()} | {:error, term()}

Searches for stocks by symbol or company name.

Options

  • :api_key - Twelve Data API key (optional, will use config if not provided)

Examples

{:ok, df} = TwelveData.search("Apple")
{:ok, df} = TwelveData.search("AAPL", api_key: "YOUR_API_KEY")