A small Elixir wrapper test for the SerpApi Google Finance API using Pythonx that allows you to fetch stock quotes and financial data.
This project uses mise for managing Elixir and Erlang versions.
# On macOS
brew install mise
# On Linux
curl https://mise.jdx.dev/install.sh | sh
# Or see https://mise.jdx.dev/getting-started.html for other optionsThe project includes a mise.toml file that specifies the required Elixir and Erlang versions:
[tools]
elixir = "1.18.4-otp-28"
erlang = "28.0.2"Install the specified versions:
mise installSign up at https://serpapi.com to get your API key.
Create a .envrc file in your project root (if using direnv):
export SERPAPI_KEY=your_serpapi_key_hereOr create a .env file:
SERPAPI_KEY=your_serpapi_key_heredirenv allowThe API key is automatically loaded from the SERPAPI_KEY environment variable via the configuration in config/config.exs:
config :serp_elixir, :api_key, System.get_env("SERPAPI_KEY")iex -S mix# Get full quote data
iex> SerpElixir.quote("NVDA:NASDAQ")
%{
"summary" => %{
"currency" => "$",
"exchange" => "NASDAQ",
"extensions" => ["Closed: Sep 3, 4:42:12 AM GMT-4", "USD", "NASDAQ"],
"extracted_price" => 170.78,
"market" => %{
"currency" => "$",
"extracted_price" => 170.95,
"price" => "$170.95",
"price_movement" => %{
"movement" => "Up",
"percentage" => 0.1,
"value" => 0.17
},
"trading" => "Pre-market"
},
"price" => "$170.78",
"stock" => "NVDA",
"title" => "NVIDIA Corp"
}
}
# Get simple quote as map
iex> SerpElixir.simple_quote("GOOGL:NASDAQ")
%{stock: "GOOGL", price: "$176.77"}SerpElixir.quote/1- Returns full quote data with summary informationSerpElixir.simple_quote/1- Returns a simple map with stock and price keys
Run the tests with:
mix test