Skip to content

Latest commit

 

History

History
123 lines (87 loc) · 2.35 KB

File metadata and controls

123 lines (87 loc) · 2.35 KB

SerpElixir

A small Elixir wrapper test for the SerpApi Google Finance API using Pythonx that allows you to fetch stock quotes and financial data.

Setup with mise

This project uses mise for managing Elixir and Erlang versions.

Install mise

# 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 options

Install Elixir and Erlang

The 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 install

Configuration

1. Get a SerpApi API Key

Sign up at https://serpapi.com to get your API key.

2. Set Environment Variable

Create a .envrc file in your project root (if using direnv):

export SERPAPI_KEY=your_serpapi_key_here

Or create a .env file:

SERPAPI_KEY=your_serpapi_key_here

3. Load direnv (if using .envrc)

direnv allow

4. Configure the Application

The 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")

Usage

Start an iex Session

iex -S mix

Basic Stock Quote

# 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"}

API Functions

  • SerpElixir.quote/1 - Returns full quote data with summary information
  • SerpElixir.simple_quote/1 - Returns a simple map with stock and price keys

Testing

Run the tests with:

mix test