Skip to content

feat(polymarket): support batched filter parameters on 3 endpoints#533

Merged
0237h merged 1 commit into
mainfrom
feat/polymarket-batched-params
May 13, 2026
Merged

feat(polymarket): support batched filter parameters on 3 endpoints#533
0237h merged 1 commit into
mainfrom
feat/polymarket-batched-params

Conversation

@0237h
Copy link
Copy Markdown
Collaborator

@0237h 0237h commented May 12, 2026

Summary

  • Flip filter parameters to batched on /markets, /users, /users/positions?condition_id=A,B, repeated ?condition_id=A&condition_id=B, and single ?condition_id=A all parse, matching the convention on /v1/{evm,svm,tvm}/* and the new Hyperliquid batched routes (feat(hyperliquid): support batched filter parameters across 8 endpoints #532).
  • Refactor /markets SQL from CASE-dispatch (first non-null filter wins) to additive AND filters, which both enables batching and aligns the endpoint with the rest of the codebase.
  • Remaining Polymarket endpoints intentionally stay scalar (see Deferred below).

Endpoints / params

Endpoint Batched params
/markets condition_id, market_slug, token_id, event_slug
/users user
/users/positions user, token_id, condition_id, market_slug

Deferred

  • /markets/activity — UNION ALL fan-out across 5 ledger tables; needs perf review.
  • /markets/oi — keeps its "exactly one of condition_id or market_slug" contract; multi-value support would change response semantics.
  • /markets/ohlc and /markets/positions — per-token time series / leaderboard. Mirrors scalar-only OHLC contracts elsewhere.

Behavior change on /markets

Previous SQL used a CASE WHEN isNotNull(...) dispatch where the first non-null filter wins and the rest are silently ignored. After this PR, /markets composes filters additively (AND): every passed filter must match. Callers that relied on the implicit drop-the-others behavior — e.g. ?condition_id=A&market_slug=B — will now see filters interact, with mismatched combinations correctly returning an empty result. Single-filter calls (the documented usage) are unchanged.

Test plan

  • bun run tsc --noEmit clean
  • Local sweep against dev cluster — 21 functional scenarios (single, CSV, array, mismatch, error) pass
  • 4 correctness checks pass: each batched call's identifier set is a subset of the requested batch and a superset of the per-value single-call sets (pagination-aware semantics — see harness)
  • Performance against main baseline on the same cluster — single-value calls match within variance; batched calls scale 1.5–2.5× per added value
  • Smoke-check staging after deploy

🤖 Generated with Claude Code

Filter params now accept a single value, a comma-separated list, or
a repeated query key — matching the batched-parameter convention
already used on EVM/SVM/TVM and Hyperliquid routes.

Batched fields per endpoint:

- `/markets`           condition_id, market_slug, token_id, event_slug
- `/users`             user
- `/users/positions`   user, token_id, condition_id, market_slug

The remaining Polymarket endpoints stay scalar for now:

- `/markets/activity` is a UNION ALL fan-out across 5 ledger tables;
  warrants a separate perf review before batching.
- `/markets/oi` keeps its "provide exactly one of condition_id or
  market_slug" contract; adding multi-value support there changes
  the response semantic.
- `/markets/ohlc` and `/markets/positions` are per-token time-series
  / leaderboard surfaces — mirrors the scalar-only contract on
  Hyperliquid OHLC and EVM/SVM/TVM `/pools/ohlc`.

Side effects:

- `/markets` SQL switches from a CASE-dispatch WHERE clause (first
  non-null filter wins) to additive AND filters. This is the same
  shape used elsewhere in the codebase. Behavior change for callers
  that previously passed two scoping filters at once (e.g.
  `condition_id=A&market_slug=B`): the CASE silently used the first
  non-null one and ignored the rest. After this change, both
  filters apply together, so mismatched combinations now correctly
  return an empty result.
- `token_id` resolution in `/markets` and `/users/positions` now
  uses `asset_id IN (SELECT toUInt256(arrayJoin(...)))` so multiple
  token ids resolve to the union of their condition ids.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@0237h 0237h force-pushed the feat/polymarket-batched-params branch from 20239c6 to a062991 Compare May 13, 2026 18:22
@YaroShkvorets YaroShkvorets temporarily deployed to feat/polymarket-batched-params - token-api PR #533 May 13, 2026 18:22 — with Render Destroyed
@0237h 0237h merged commit 115fbcc into main May 13, 2026
2 of 3 checks passed
@0237h 0237h deleted the feat/polymarket-batched-params branch May 13, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants