feat(perps): support account notifications in session reads and events - #186
Conversation
…rt-notifications-in-unified-python-sdk # Conflicts: # tests/unit/test_perps_session.py
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 29d71f6. Configure here.
naruto11eth
left a comment
There was a problem hiding this comment.
approved. verified the contract against the spec sync (docs#256): the {ts,id} cursor encoding, the inclusive since_seq re-sent with follow-up cursors, the non-dense engine sq justifying the gap-detection opt-out, and the 7-kind set all match the documented protocol exactly.
two small things: this carries #188's commits, so land that one first and rebase. and the synthetic empty page reports unread=0 / durable_source_seq=0 — since the docs give durable_source_seq operational meaning as a backfill anchor, a fabricated 0 there could mislead; int | None would be honest. non-blocking.
…rt-notifications-in-unified-python-sdk # Conflicts: # src/polymarket/_internal/actions/perps/account.py # tests/unit/test_perps_account_actions.py

Description
Adds perps account notifications to the SDK, covering both REST reads and live session events.
What's included
models/perps/notifications.py): typed, discriminated unionPerpsNotificationcovering position opened/increased/reduced/closed, limit order canceled, liquidation warning (isolated and cross variants, discriminated bymargin_type), and position liquidated. Entries carry account-scoped read state (read_at) viaPerpsNotificationEntry.session.list_notifications(since_seq=..., limit=...)newest-first paginator whose pages also report the account'sunreadcount anddurable_source_seqhigh-water mark (for backfilling after a gap).session.mark_notifications_read(ids=... | up_to=...)mark by explicit ids, or everything up to and including a given entry.PerpsNotificationEventon thenotificationschannel, added toPerpsSessionEvent.notifications. Instead, server-sent resync control frames are surfaced asPerpsResyncEventwith a newreason="server"(plus optionaltimestamp), wheresequenceis the highest engine sequence among the dropped notifications.Tests
Unit coverage for the account actions (listing, paging with
since_seq, mark-read), event parsing (including server resync frames), and session wiring (~380 new test lines).Note
Medium Risk
Adds new account APIs and changes resync semantics for notifications (no client gap detection, new server resync reason); liquidation-related payloads are user-facing but read-only with validation and tests.
Overview
Adds perps account notifications end-to-end: typed notification payloads, REST list/mark-read, and a live
notificationssession channel.REST:
list_notificationspages newest-first via/v1/account/notifications, carryingunreadanddurable_source_seqon each page and pinning optionalsince_seq/limitacross cursor pages.mark_notifications_readaccepts explicit ids or anup_toentry (base64url{ts, id}beforecursor).Session: Subscribes to
notifications; exposes the same list/mark-read helpers.PerpsNotificationEventjoinsPerpsSessionEvent. Notification sequences are not treated like dense per-channel seqs—localsequence_gapresync is skipped fornotifications; servertype: resyncframes becomePerpsResyncEventwithreason="server"(optional timestamp).New discriminated notification models cover position lifecycle, limit cancel, liquidation warnings (isolated/cross), and liquidations; public exports updated in
models/perpsandperps.py.Reviewed by Cursor Bugbot for commit 2b0bfe9. Bugbot is set up for automated code reviews on this repo. Configure here.