Skip to content

feat(perps): support account notifications in session reads and events#186

Open
kartojal wants to merge 8 commits into
mainfrom
feature/dev-409-support-notifications-in-unified-python-sdk
Open

feat(perps): support account notifications in session reads and events#186
kartojal wants to merge 8 commits into
mainfrom
feature/dev-409-support-notifications-in-unified-python-sdk

Conversation

@kartojal

@kartojal kartojal commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

Adds perps account notifications to the SDK, covering both REST reads and live session events.

What's included

  • Notification models (models/perps/notifications.py): typed, discriminated union PerpsNotification covering position opened/increased/reduced/closed, limit order canceled, liquidation warning (isolated and cross variants, discriminated by margin_type), and position liquidated. Entries carry account-scoped read state (read_at) via PerpsNotificationEntry.
  • Session reads:
    • session.list_notifications(since_seq=..., limit=...) newest-first paginator whose pages also report the account's unread count and durable_source_seq high-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.
  • Session events: new PerpsNotificationEvent on the notifications channel, added to PerpsSessionEvent.
  • Resync handling: notification frames carry the source engine sequence, which is not dense per channel, so local sequence-gap detection is disabled for notifications. Instead, server-sent resync control frames are surfaced as PerpsResyncEvent with a new reason="server" (plus optional timestamp), where sequence is 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
New authenticated account APIs and session channel behavior; list_fills pagination semantics change may affect existing callers relying on the old cursor scheme.

Overview
Adds perps account notifications end-to-end: discriminated notification models, REST list (newest-first pages with unread and durable_source_seq) and mark read (by ids or inclusive up_to), plus session list_notifications / mark_notifications_read.

Live session work subscribes to notifications, emits PerpsNotificationEvent, maps server resync frames to PerpsResyncEvent (reason="server"), and skips client sequence-gap resync on that channel so sparse engine sequences do not false-trigger gaps.

list_fills switches from client-side descending history cursors to the API’s native sort, cursor, and trade-id pagination (optional initial_cursor).

Public exports include notification paginator types and PerpsSortDirection.

Reviewed by Cursor Bugbot for commit 00382e7. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/polymarket/_internal/actions/perps/account.py
Comment thread src/polymarket/models/perps/notifications.py
Comment thread src/polymarket/_internal/actions/perps/account.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f595e5a. Configure here.

Comment thread src/polymarket/models/perps/notifications.py Outdated
@kartojal
kartojal requested a review from cesarenaldi July 24, 2026 09:26
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.

1 participant