Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system_status/1 #17

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/krakex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Krakex do
## Public market data

* `server_time/1` - Get server time.
* `system_status/1` - Get system status.
* `assets/2` - Get asset info.
* `asset_pairs/2` - Get tradable asset pairs.
* `ticker/2` - Get ticker information.
Expand Down Expand Up @@ -74,6 +75,29 @@ defmodule Krakex do
@api.public_request(client, "Time")
end

@doc """
Get system status.

Returns a map with the fields:

* `"status"` - one of:
* `"online"` - operational, full trading available.
* `"cancel_only"` - existing orders are cancelable, but new orders cannot be created.
* `"post_only"` - existing orders are cancelable, and only new post limit orders can be submitted.
* `"limit_only"` - existing orders are cancelable, and only new limit orders can be submitted.
* `"maintenance"` - system is offline for maintenance.
* `"timestamp"` - ISO-8601 datetime.

## Example response:

{:ok, %{"status" => "online", "timestamp" => "2021-03-05T16:04:53Z"}}

"""
@spec system_status(Client.t()) :: Krakex.API.response()
def system_status(client \\ @api.public_client()) do
@api.public_request(client, "SystemStatus")
end

@doc """
Get asset info.

Expand Down
8 changes: 8 additions & 0 deletions test/krakex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ defmodule KrakexTest do
assert client() |> Krakex.server_time() == {:ok, :server_time_1}
end

test "system_status/0" do
assert Krakex.system_status() == {:ok, :system_status_0}
end

test "system_status/1" do
assert client() |> Krakex.system_status() == {:ok, :system_status_1}
end

test "assets/0" do
assert Krakex.assets() == {:ok, :assets_0}
end
Expand Down
2 changes: 2 additions & 0 deletions test/support/test_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ defmodule Krakex.TestAPI do

def public_request(@public_client, "Time", []), do: {:ok, :server_time_0}
def public_request(@custom_client, "Time", []), do: {:ok, :server_time_1}
def public_request(@public_client, "SystemStatus", []), do: {:ok, :system_status_0}
def public_request(@custom_client, "SystemStatus", []), do: {:ok, :system_status_1}
def public_request(@public_client, "Assets", []), do: {:ok, :assets_0}
def public_request(@custom_client, "Assets", []), do: {:ok, :assets_1_client}
def public_request(@public_client, "Assets", asset: ["BTC"]), do: {:ok, :assets_1_opts}
Expand Down