Packages

An Elixir client for the Polymarket API.

Current section

Files

Jump to
ex_polymarket lib schemas market_metadata.ex
Raw

lib/schemas/market_metadata.ex

defmodule Polymarket.Schemas.MarketMetadata do
@moduledoc """
Sports metadata for a market. Part of a `Market` returned by the Gamma API.
Links a market to its corresponding fixture/market in the Optic Odds feed.
"""
use TypedEctoSchema
alias Polymarket.JsonUtil
@primary_key false
@derive Jason.Encoder
typed_embedded_schema do
field(:optic_odds_fixture_id, :string)
field(:optic_odds_market_id, :string)
field(:optic_odds_market_name, :string)
field(:optic_odds_selection, :string)
end
@doc "Builds a `MarketMetadata` from a decoded (JSON) map, coercing each field."
@spec from_attrs(map()) :: {:ok, t()}
def from_attrs(attrs) do
attrs = JsonUtil.snake_case_keys(attrs)
{:ok,
%__MODULE__{
optic_odds_fixture_id: attrs["optic_odds_fixture_id"],
optic_odds_market_id: attrs["optic_odds_market_id"],
optic_odds_market_name: attrs["optic_odds_market_name"],
optic_odds_selection: attrs["optic_odds_selection"]
}}
end
end