Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): add update subscription message type #2192

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lazer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lazer/sdk/js/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ client.ws.addEventListener("open", () => {
channel: "fixed_rate@200ms",
jsonBinaryEncoding: "hex",
});

// Example: Update an existing subscription
setTimeout(() => {
client.send({
type: "updateSubscription",
subscriptionId: 1,
priceFeedIds: [1, 2, 3],
properties: ["price", "bestBidPrice"],
});
}, 2000); // Wait 2 seconds before updating
});
6 changes: 6 additions & 0 deletions lazer/sdk/js/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export type Request =
| {
type: "unsubscribe";
subscriptionId: number;
}
| {
type: "updateSubscription";
subscriptionId: number;
priceFeedIds: number[];
properties: PriceFeedProperty[];
};

export type ParsedFeedPayload = {
Expand Down
2 changes: 1 addition & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
15 changes: 15 additions & 0 deletions lazer/sdk/rust/protocol/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use {
pub enum Request {
Subscribe(SubscribeRequest),
Unsubscribe(UnsubscribeRequest),
UpdateSubscription(UpdateSubscriptionRequest),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand All @@ -33,6 +34,20 @@ pub struct UnsubscribeRequest {
pub subscription_id: SubscriptionId,
}

/// A request to update an existing subscription with new parameters.
/// This is idempotent - the new parameters completely replace the old ones.
/// The subscription parameters include:
/// - price_feed_ids: List of price feeds to subscribe to
/// - properties: List of properties to include in updates (e.g., price, confidence, timestamp)
/// These properties determine what data fields will be included in price feed updates
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateSubscriptionRequest {
pub subscription_id: SubscriptionId,
#[serde(flatten)]
pub params: SubscriptionParams,
}

/// A response sent from the server to the client.
#[derive(Debug, Clone, Serialize, Deserialize, From)]
#[serde(tag = "type")]
Expand Down
Loading