Current section
7 Versions
Jump to
Current section
7 Versions
Compare versions
4
files changed
+34
additions
-5
deletions
| @@ -15,8 +15,8 @@ elixir libs: [HTTPoison](https://github.com/edgurgel/httpoison/), [Jason](https: | |
| 15 15 | - [x] market data (bars) |
| 16 16 | - [x] positions |
| 17 17 | - [x] watchlists |
| 18 | - - [ ] calendar |
| 19 | - - [ ] clock |
| 18 | + - [x] calendar |
| 19 | + - [x] clock |
| 20 20 | - [ ] account config |
| 21 21 | - [ ] account activities |
| 22 22 | - [x] portfolio history |
| @@ -158,6 +158,8 @@ end | |
| 158 158 | |
| 159 159 | 0.1.4 added portfolio history, README/docs cleanup |
| 160 160 | |
| 161 | + 0.1.5 added calendar, clock, handle 422 error |
| 162 | + |
| 161 163 | ## Contributing |
| 162 164 | |
| 163 165 | Suggestions welcomed. Please open an [issue](https://github.com/phiat/alpa/issues) |
| @@ -19,4 +19,4 @@ | |
| 19 19 | {<<"optional">>,false}, |
| 20 20 | {<<"repository">>,<<"hexpm">>}, |
| 21 21 | {<<"requirement">>,<<"~> 1.1">>}]]}. |
| 22 | - {<<"version">>,<<"0.1.4">>}. |
| 22 | + {<<"version">>,<<"0.1.5">>}. |
| @@ -175,6 +175,32 @@ defmodule Alpa do | |
| 175 175 | get(@endpoint_paper,"/v2/account/portfolio/history?period=#{period}&timeframe=#{timeframe}&date_end=#{date_end}&extended_hour=#{extended_hours}") |
| 176 176 | end |
| 177 177 | |
| 178 | + @doc """ |
| 179 | + get the calendar |
| 180 | + |
| 181 | + 1970 - 2029 |
| 182 | + """ |
| 183 | + def calendar(start_time \\ Date.utc_today, end_time \\ Date.utc_today) do |
| 184 | + get(@endpoint_paper,"/v2/calendar?start=#{start_time}&end=#{end_time}") |
| 185 | + end |
| 186 | + |
| 187 | + @doc """ |
| 188 | + get the market clock |
| 189 | + """ |
| 190 | + def clock do |
| 191 | + get(@endpoint_paper,"/v2/clock") |
| 192 | + end |
| 193 | + |
| 194 | + @doc """ |
| 195 | + get market open status |
| 196 | + """ |
| 197 | + def market_open? do |
| 198 | + case clock() do |
| 199 | + {:ok, %{"is_open" => is_open}} -> {:ok, is_open} |
| 200 | + {:error, reason} -> {:error, reason} |
| 201 | + end |
| 202 | + end |
| 203 | + |
| 178 204 | @doc """ |
| 179 205 | list bars |
| 180 206 | |
| @@ -241,7 +267,6 @@ defmodule Alpa do | |
| 241 267 | |
| 242 268 | defp get(endpoint, path) do |
| 243 269 | url = "#{endpoint}#{path}" |
| 244 | - IO.puts url |
| 245 270 | HTTPoison.get(url, headers()) |
| 246 271 | |> handle_response |
| 247 272 | end |
| @@ -268,6 +293,8 @@ defmodule Alpa do | |
| 268 293 | {:ok, :success} |
| 269 294 | {:ok, %HTTPoison.Response{status_code: 403, body: body}} -> |
| 270 295 | {:ok, Jason.decode!(body)} |
| 296 | + {:ok, %HTTPoison.Response{status_code: 422, body: body}} -> |
| 297 | + {:ok, Jason.decode!(body)} |
| 271 298 | {:error, reason} -> |
| 272 299 | {:error, reason} |
| 273 300 | end |
| @@ -4,7 +4,7 @@ defmodule Alpa.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :alpa, |
| 7 | - version: "0.1.4", |
| 7 | + version: "0.1.5", |
| 8 8 | elixir: "~> 1.10", |
| 9 9 | start_permanent: Mix.env() == :prod, |
| 10 10 | deps: deps(), |