PaperEx.Adapter implementation for Polymarket.
This is the entry point the generic PaperEx.Engine uses when
configured with adapter: PaperExPolymarket.Adapter. The adapter
delegates to four sibling modules:
PaperExPolymarket.Market—normalize_instrument/1reads a CLOB market metadata payload (%{"token_id" => …, "market" => …, "tokens" => …}) and produces aPaperEx.Instrument. A simpler{:token_id, "…"}tuple is also accepted for tests.PaperExPolymarket.OrderBook—normalize_snapshot/2reads a CLOB/bookbody and anInstrument, producing a normalizedPaperEx.MarketSnapshot.PaperExPolymarket.ActivityMapper—normalize_fill/2reads a Data-API or RTDS trade event and produces aPaperEx.Fillfor live-mirror reconciliation.PaperExPolymarket.Execution—simulate_fill/3walks the snapshot per Polymarket's FAK (market) / GTC (limit) defaults.
Fees default to zero. Pass fee_bps: <bps> in :adapter_opts to
apply a take-fee for stress-testing.
Bounded reason codes
The adapter declares its bounded reason set in reason_codes/0.
In addition to the generic engine codes from
PaperEx.ReasonCodes.engine_codes/0, Polymarket-specific codes
include :polymarket_invalid_market_payload (market payload was
malformed), :polymarket_invalid_book (book payload was malformed),
:polymarket_invalid_trade_payload (trade event was malformed —
bad side/size/price/timestamp or not a map), and
:polymarket_instrument_mismatch (live-mirror fill arrived for the
wrong token). Every failure returned by normalize_fill/2 /
normalize_snapshot/2 / normalize_instrument/1 is one of these
bounded codes — the underlying ActivityMapper / OrderBook /
Market atoms never leak through.
Summary
Functions
See PaperEx.Adapter.fee/2. Delegates to
PaperExPolymarket.Fees.fee/2 — applies :fee_bps (basis points)
from opts. Defaults to zero.
See PaperEx.Adapter.normalize_fill/2. Maps a Polymarket
Data-API or RTDS trade event into a PaperEx.Fill.
See PaperEx.Adapter.normalize_instrument/1. Accepts CLOB market
payloads with a "token_id" / :token_id field, a bare token id
string, or a {:token_id, "…"} tuple.
See PaperEx.Adapter.normalize_snapshot/2. Accepts a CLOB
/book body map; returns {:error, :polymarket_invalid_book} for
malformed payloads.
See PaperEx.Adapter.reason_codes/0. Returns generic engine
codes plus Polymarket-tagged ones.
Functions
See PaperEx.Adapter.fee/2. Delegates to
PaperExPolymarket.Fees.fee/2 — applies :fee_bps (basis points)
from opts. Defaults to zero.
See PaperEx.Adapter.normalize_fill/2. Maps a Polymarket
Data-API or RTDS trade event into a PaperEx.Fill.
All ActivityMapper failures are remapped into the bounded
reason_codes/0 set so nothing untagged escapes:
- an asset/instrument identity mismatch becomes
{:error, :polymarket_instrument_mismatch}; - any malformed trade content (bad side, size, price, or
timestamp) becomes
{:error, :polymarket_invalid_trade_payload}.
See PaperEx.Adapter.normalize_instrument/1. Accepts CLOB market
payloads with a "token_id" / :token_id field, a bare token id
string, or a {:token_id, "…"} tuple.
See PaperEx.Adapter.normalize_snapshot/2. Accepts a CLOB
/book body map; returns {:error, :polymarket_invalid_book} for
malformed payloads.
See PaperEx.Adapter.reason_codes/0. Returns generic engine
codes plus Polymarket-tagged ones.
See PaperEx.Adapter.simulate_fill/3. Delegates to
PaperExPolymarket.Execution.simulate_fill/3.