PaperExPolymarket.Adapter (PaperExPolymarket v0.3.2)

Copy Markdown View Source

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:

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

fee(fill, opts)

See PaperEx.Adapter.fee/2. Delegates to PaperExPolymarket.Fees.fee/2 — applies :fee_bps (basis points) from opts. Defaults to zero.

normalize_fill(payload, inst)

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}.

normalize_instrument(clob_market)

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.

normalize_snapshot(clob_book, inst)

See PaperEx.Adapter.normalize_snapshot/2. Accepts a CLOB /book body map; returns {:error, :polymarket_invalid_book} for malformed payloads.

reason_codes()

See PaperEx.Adapter.reason_codes/0. Returns generic engine codes plus Polymarket-tagged ones.

simulate_fill(order, snap, opts)

See PaperEx.Adapter.simulate_fill/3. Delegates to PaperExPolymarket.Execution.simulate_fill/3.