Current section

Files

Jump to
bingex lib bingex swap model quote_info.ex
Raw

lib/bingex/swap/model/quote_info.ex

defmodule Bingex.Swap.Model.QuoteInfo do
@moduledoc """
Represents real-time quote information for a swap contract.
"""
import Bingex.{Helpers, Convertors}
defstruct [
:symbol,
:funding_rate,
:next_funding_time,
:mark_price,
:last_price
]
@type t() :: %__MODULE__{
symbol: nil | binary(),
funding_rate: nil | float(),
next_funding_time: nil | non_neg_integer(),
mark_price: nil | float(),
last_price: nil | float()
}
@spec decode(any()) :: {:ok, t()} | :error
def decode(%{} = data) do
{:ok,
%__MODULE__{
symbol: get_and_transform(data, "symbol", &to_non_empty_binary/1),
funding_rate: get_and_transform(data, "lastFundingRate", &to_float/1),
next_funding_time: get_and_transform(data, "nextFundingTime", &to_non_neg_integer/1),
mark_price: get_and_transform(data, "markPrice", &to_float/1),
last_price: get_and_transform(data, "indexPrice", &to_float/1)
}}
end
def decode(_data), do: :error
end