-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule BasketWeb.Live.Overview.TickerAdd do | ||
@moduledoc """ | ||
Creates a new ticker in the table. | ||
""" | ||
|
||
alias Basket.Http | ||
alias BasketWeb.Live.Overview.TickerBar | ||
|
||
require Logger | ||
|
||
@doc """ | ||
Creates a row to be added to the ticker bar table. | ||
""" | ||
def call(ticker) do | ||
case Http.Alpaca.latest_quote(ticker) do | ||
{:ok, response} -> | ||
case build_ticker_bars(response) do | ||
:no_data -> | ||
# TODO: info flash | ||
:no_data | ||
|
||
:market_closed -> | ||
:market_closed | ||
|
||
bars -> | ||
bars | ||
end | ||
|
||
{:error, error} -> | ||
# TODO: error flash | ||
Logger.error("Could not subscribe to ticker: #{error}") | ||
end | ||
end | ||
|
||
defp build_ticker_bars(%{"bars" => nil}) do | ||
end | ||
|
||
defp build_ticker_bars(%{"bars" => ticker_bars}) do | ||
# TODO: check first | ||
new_ticker_bars = Map.to_list(ticker_bars) |> List.first() | ||
|
||
case new_ticker_bars do | ||
nil -> | ||
:no_data | ||
|
||
%{} -> | ||
:market_closed | ||
|
||
bars -> | ||
Enum.reduce(bars, %{}, fn {k, v}, acc -> | ||
Map.put(acc, k, %TickerBar{value: v}) | ||
end) | ||
|
||
# TODO: check | ||
# Map.merge(new_bars, %{"S" => %TickerBar{value: ticker}}) | ||
end | ||
end | ||
end |