Current section
Files
Jump to
Current section
Files
lib/bitcoin_price.ex
defmodule BitcoinPrice do
use HTTPoison.Base
@api_url "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"
@moduledoc """
Documentation for Bitcoin Price functionality.
"""
@doc """
Retrieves the current bitcoin price in $USD at the time of the request
## Examples
iex> BitcoinPrice.current
#=> 7589.87
"""
def current() do
btc = HTTPoison.get!(@api_url)
if btc.status_code == 200 do
btc.body
|> String.slice(7..13)
|> String.to_float
else
"Error: Unable to retrieve bitcoin price from crypto compare."
end
end
end