YfQuote
A simple Yahoo Finance wrapper to fetch asset prices with easy currency conversion support.
Installation
Add yf_quote to your list of dependencies in mix.exs:
def deps do
[
{:yf_quote, "~> 0.1.0"}
]
endUsage
Basic Examples
# Get Bitcoin price in USD
{:ok, quote} = YfQuote.get_quote("BTC-USD")
# => {:ok, %YfQuote.Quote{price: 110715.23, currency: "USD", symbol: "BTC-USD",
# datetime: ~U[2025-09-04 20:15:30Z], market_timezone: "America/New_York"}}
# Get Apple stock price in CHF
{:ok, quote} = YfQuote.get_quote("AAPL", to: "CHF")
# => {:ok, %YfQuote.Quote{price: 191.99, currency: "CHF", symbol: "AAPL",
# datetime: ~U[2025-09-04 20:00:02Z], market_timezone: "America/New_York"}}
# Get EUR/CHF exchange rate
{:ok, quote} = YfQuote.get_quote("EUR/CHF")
# => {:ok, %YfQuote.Quote{price: 0.9382, currency: "CHF", symbol: "EUR/CHF",
# datetime: ~U[2025-09-04 15:30:00Z], market_timezone: "Europe/Zurich"}}Historical Prices
# Get Bitcoin price on a specific date
{:ok, quote} = YfQuote.get_quote("BTC-USD", to: "CHF", date: ~D[2024-12-31])
# => {:ok, %YfQuote.Quote{price: 84389.00, currency: "CHF", symbol: "BTC-USD",
# datetime: ~U[2024-12-31 23:59:59Z], market_timezone: "America/New_York"}}Error Handling
case YfQuote.get_quote("INVALID") do
{:ok, quote} ->
IO.puts("Price: #{quote.price} #{quote.currency}")
{:error, :invalid_symbol} ->
IO.puts("Symbol not found")
{:error, :no_data} ->
IO.puts("No data available for this date")
{:error, :conversion_failed} ->
IO.puts("Currency conversion failed")
endBang Version
# Raises exception on error
quote = YfQuote.get_quote!("BTC-USD")Supported Ticker Formats
-
Cryptocurrencies:
"BTC-USD","ETH-USD","ADA-USD" -
US Stocks:
"AAPL","TSLA","GOOGL","MSFT" -
International Stocks:
"NESN.SW","ASML.AS","SAP.DE" -
Forex:
"EUR/CHF","USD/JPY","GBP/USD", or use Yahoo format"EURUSD=X"
Free tier warning
This library uses the Yahoo Finance free tier that have rate limits. Please be cautious about that when using it.
License
MIT License
LLM Usage declaration
Mostly made with the help of Claude Code.