Skip to content

Commit

Permalink
Handle delisted Coinbase products
Browse files Browse the repository at this point in the history
  • Loading branch information
rupurt committed Jan 23, 2022
1 parent c8fdafc commit 1d2f3f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
10 changes: 6 additions & 4 deletions apps/tai/lib/tai/venue_adapters/bitmex/product_status.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Tai.VenueAdapters.Bitmex.ProductStatus do
@spec normalize(bitmex_state :: String.t()) :: :trading | :settled | :unlisted
def normalize("Open"), do: :trading
def normalize("Settled"), do: :settled
def normalize("Unlisted"), do: :unlisted
@type status :: Tai.Venues.Product.status()

@spec normalize(bitmex_state :: String.t()) :: status
def normalize("Open"), do: Tai.Venues.ProductStatus.trading()
def normalize("Settled"), do: Tai.Venues.ProductStatus.settled()
def normalize("Unlisted"), do: Tai.Venues.ProductStatus.delisted()
end
14 changes: 9 additions & 5 deletions apps/tai/lib/tai/venue_adapters/gdax/product_status.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
defmodule Tai.VenueAdapters.Gdax.ProductStatus do
@type status :: Tai.Venues.Product.status()
@type error_reason :: {:unknown_status, String.t()}

@spec normalize(gdax_status :: String.t()) :: {:ok, status} | {:error, :unknown_status}
def normalize(gdax_status)

def normalize("online"), do: {:ok, Tai.Venues.ProductStatus.trading()}
def normalize(_), do: {:error, :unknown_status}
@spec normalize(String.t()) :: {:ok, status} | {:error, error_reason}
def normalize(venue_status) do
case venue_status do
"online" -> {:ok, Tai.Venues.ProductStatus.trading()}
"delisted" -> {:ok, Tai.Venues.ProductStatus.delisted()}
_ -> {:error, {:unknown_status, venue_status}}
end
end
end
2 changes: 1 addition & 1 deletion apps/tai/lib/tai/venues/product.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Tai.Venues.Product do
| :auction_match
| :break
| :settled
| :unlisted
| :delisted

@typedoc """
The product to buy/sell or the underlying product used to buy/sell. For the product BTCUSD
Expand Down
2 changes: 1 addition & 1 deletion apps/tai/lib/tai/venues/product_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule Tai.Venues.ProductStatus do
def auction_match, do: :auction_match
def break, do: :break
def settled, do: :settled
def unlisted, do: :unlisted
def delisted, do: :delisted
end
4 changes: 2 additions & 2 deletions apps/tai/test/tai/venue_adapters/gdax/product_status_test.exs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule Tai.VenueAdapters.Gdax.ProductStatusTest do
use ExUnit.Case, async: true

describe "#normalize" do
describe ".normalize/1" do
test "returns an ok tuple for a supported status" do
assert Tai.VenueAdapters.Gdax.ProductStatus.normalize("online") ==
{:ok, Tai.Venues.ProductStatus.trading()}
end

test "returns an error tuple for and unsupported status" do
assert Tai.VenueAdapters.Gdax.ProductStatus.normalize("UNSUPPORTED") ==
{:error, :unknown_status}
{:error, {:unknown_status, "UNSUPPORTED"}}
end
end
end

0 comments on commit 1d2f3f1

Please sign in to comment.