Translation between Polymarket market identifiers and
PaperEx.Instrument.
Polymarket has two relevant identifier flavors:
- condition id —
0x…hex string identifying a market (a question). Has two outcomes: YES (outcome_index = 0) and NO (outcome_index = 1). - token id — large decimal-string integer identifying a single outcome's ERC-1155 token. One condition has two token ids.
The CLOB places orders against a token id (one side of the market). This adapter therefore keys instruments by token id — the same level the order book operates on.
from_clob_market/2 builds an Instrument from a CLOB market
metadata payload (/markets/{condition_id} or
/markets-by-token/{token_id} response) plus an explicit
:token_id so the instrument id matches the order book the engine
will walk. The full payload is preserved in
Instrument.metadata.raw_market for traceability.
Summary
Types
A CLOB market metadata payload (as returned by polymarket_clob).
Functions
Builds a PaperEx.Instrument for the given token id, using the
supplied CLOB market metadata for display fields.
Convenience: builds an Instrument for a token id with no CLOB
metadata. Useful for tests and fixture-only callers.
Types
@type clob_market() :: map()
A CLOB market metadata payload (as returned by polymarket_clob).
Functions
@spec from_clob_market(String.t(), clob_market()) :: {:ok, PaperEx.Instrument.t()}
Builds a PaperEx.Instrument for the given token id, using the
supplied CLOB market metadata for display fields.
clob_market is the raw CLOB market payload (a map). Display fields
are read defensively — "question", "market_slug", and the tick
size ("minimum_tick_size", falling back to the "tick_size" alt
key); "condition_id" falls back to "market"; the outcome
label/index come from the matching entry in "tokens". Any field
missing from the payload simply becomes nil on the instrument, and
a token id not present in "tokens" still returns {:ok, _} with a
nil outcome label/index. The full payload is preserved in
Instrument.metadata.raw_market.
Always returns {:ok, Instrument.t()} for a binary token id and a
map payload; a parsed tick size is always a valid positive float (or
nil), so PaperEx.Instrument.new/1 does not raise on this path.
@spec from_token_id( String.t(), keyword() ) :: {:ok, PaperEx.Instrument.t()}
Convenience: builds an Instrument for a token id with no CLOB
metadata. Useful for tests and fixture-only callers.
Unlike from_clob_market/2, the :tick_size opt is passed straight
through to PaperEx.Instrument.new/1, which RAISES ArgumentError
on a non-positive or non-numeric tick size. Pass a positive number
or omit it.