Current section
Files
Jump to
Current section
Files
lib/bingex/swap/data/place_test_order.ex
defmodule Bingex.Swap.Data.PlaceTestOrder do
@moduledoc """
Represents response content on `Bingex.Swap.place_test_order` request.
"""
alias Bingex.API.Reply
alias Bingex.Swap.Model.OrderInfo
defstruct [:order]
@type t() :: %__MODULE__{
order: nil | OrderInfo.t()
}
@spec embed_in_reply(Reply.t()) :: Reply.t(t())
def embed_in_reply(%Reply{payload: payload} = reply) do
Reply.put_data(reply, decode(payload))
end
@spec decode(any()) :: t()
def decode(%{"data" => %{"order" => data}}) when is_map(data) do
case OrderInfo.decode(data) do
{:ok, order} -> %__MODULE__{order: order}
:error -> %__MODULE__{}
end
end
def decode(_data), do: %__MODULE__{}
end