Current section

Files

Jump to
bingex lib bingex swap model income_info.ex
Raw

lib/bingex/swap/model/income_info.ex

defmodule Bingex.Swap.Model.IncomeInfo do
@moduledoc """
Represents income update as part of the capital flow.
Positive income numbers represent inflows, negative numbers represent outflows.
"""
import Bingex.{Helpers, Convertors}
alias Bingex.Types
defstruct [
:transfer_id,
:transaction_id,
:symbol,
:asset,
:income,
:income_type,
:info,
:timestamp
]
@type t() :: %__MODULE__{
transfer_id: nil | binary(),
transaction_id: nil | binary(),
symbol: nil | Types.symbol(),
asset: nil | binary(),
income: nil | float(),
income_type: nil | Types.income_type(),
info: nil | binary(),
timestamp: nil | non_neg_integer()
}
@spec decode(map()) :: {:ok, t()} | :error
def decode(%{} = data) do
{:ok,
%__MODULE__{
transfer_id: get_and_transform(data, "tradeId", &to_non_empty_binary/1),
transaction_id: get_and_transform(data, "tranId", &to_non_empty_binary/1),
symbol: get_and_transform(data, "symbol", &to_non_empty_binary/1),
asset: get_and_transform(data, "asset", &to_non_empty_binary/1),
income: get_and_transform(data, "income", &to_float/1),
income_type: get_and_transform(data, "incomeType", &decode_income_type/1),
info: get_and_transform(data, "info", &to_non_empty_binary/1),
timestamp: get_and_transform(data, "time", &to_non_neg_integer/1)
}}
end
def decode(_data), do: :error
end