Skip to content

DF-25178: Adds custom subscription handling for EA specific implementations#807

Merged
cl-efornaciari merged 7 commits into
mainfrom
feature/pair-with-alejo-on-sub-batching
Jun 9, 2026
Merged

DF-25178: Adds custom subscription handling for EA specific implementations#807
cl-efornaciari merged 7 commits into
mainfrom
feature/pair-with-alejo-on-sub-batching

Conversation

@cl-efornaciari

@cl-efornaciari cl-efornaciari commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a customSubscriptionMessages builder to WebSocketTransport so EAs can fully control how subscribe/unsubscribe WebSocket messages are built each background-execute cycle. This replaces the earlier batchSubscribeMessage / batchUnsubscribeMessage API with a more flexible hook that receives full subscription deltas (new, stale, and desired).

  • Introduces WebSocketCustomBuilders with customSubscriptionMessages(context, subscriptions) => unknown[]
  • Unifies outbound message construction behind an internal subscriptionMessageBuilder; per-subscription subscribeMessage / unsubscribeMessage builders continue to work via a default adapter
  • Simplifies sendMessages to accept a single ordered message array
  • Updates docs and tests for the new API

Motivation (DF-25178): Some providers need EA-specific subscription logic—e.g. batching multiple feeds into one message, custom ordering, or provider-specific payload shapes—that the fixed per-feed and batch-builder APIs could not express cleanly.

Backward compatibility: Existing adapters using subscribeMessage / unsubscribeMessage are unchanged. Only adapters that adopt customSubscriptionMessages need updates.

API

Configure either per-subscription builders or the custom builder, not both:

builders: {
  customSubscriptionMessages: (_context, subscriptions) => {
    const messages = []
    if (subscriptions.new.length > 0) {
      messages.push({
        request: 'subscribe',
        pairs: subscriptions.new.map((s) => `${s.base}/${s.quote}`),
      })
    }
    if (subscriptions.stale.length > 0) {
      messages.push({
        request: 'unsubscribe',
        pairs: subscriptions.stale.map((s) => `${s.base}/${s.quote}`),
      })
    }
    return messages
  },
}

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

NPM Publishing labels 🏷️

🟢 This PR has valid version labels and will cause a minor bump.

Comment thread src/transports/websocket.ts Outdated
@cl-efornaciari cl-efornaciari force-pushed the feature/pair-with-alejo-on-sub-batching branch from bcc3e71 to 440c591 Compare June 8, 2026 17:48
@cl-efornaciari cl-efornaciari changed the title [WIP] pairing session with Alejo DF-25178: Adds custom subscription handling for EA specific implementations Jun 8, 2026
@cl-efornaciari cl-efornaciari marked this pull request as ready for review June 8, 2026 18:42
@cl-efornaciari cl-efornaciari requested a review from a team as a code owner June 8, 2026 18:42
alejoberardino
alejoberardino previously approved these changes Jun 8, 2026
Comment thread src/transports/websocket.ts Outdated
Comment thread src/transports/websocket.ts Outdated
Comment thread src/transports/websocket.ts Outdated
Comment thread test/transports/websocket.test.ts Outdated
Comment thread src/transports/websocket.ts Outdated
@cl-efornaciari cl-efornaciari merged commit cf530e1 into main Jun 9, 2026
17 checks passed
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Successfully created version bump PR: #822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants