diff --git a/lazer/Cargo.lock b/lazer/Cargo.lock index db00451155..61d37a57f2 100644 --- a/lazer/Cargo.lock +++ b/lazer/Cargo.lock @@ -3176,7 +3176,7 @@ dependencies = [ [[package]] name = "pyth-lazer-protocol" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "bincode", diff --git a/lazer/sdk/js/examples/index.ts b/lazer/sdk/js/examples/index.ts index d17a212dff..670ab323e8 100644 --- a/lazer/sdk/js/examples/index.ts +++ b/lazer/sdk/js/examples/index.ts @@ -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 }); diff --git a/lazer/sdk/js/src/protocol.ts b/lazer/sdk/js/src/protocol.ts index 52c2918d56..366ad488b4 100644 --- a/lazer/sdk/js/src/protocol.ts +++ b/lazer/sdk/js/src/protocol.ts @@ -19,6 +19,12 @@ export type Request = | { type: "unsubscribe"; subscriptionId: number; + } + | { + type: "updateSubscription"; + subscriptionId: number; + priceFeedIds: number[]; + properties: PriceFeedProperty[]; }; export type ParsedFeedPayload = { diff --git a/lazer/sdk/rust/protocol/Cargo.toml b/lazer/sdk/rust/protocol/Cargo.toml index 363ba162b7..3043a36b77 100644 --- a/lazer/sdk/rust/protocol/Cargo.toml +++ b/lazer/sdk/rust/protocol/Cargo.toml @@ -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" diff --git a/lazer/sdk/rust/protocol/src/subscription.rs b/lazer/sdk/rust/protocol/src/subscription.rs index fcadbd3bf6..d1a85e831d 100644 --- a/lazer/sdk/rust/protocol/src/subscription.rs +++ b/lazer/sdk/rust/protocol/src/subscription.rs @@ -14,6 +14,7 @@ use { pub enum Request { Subscribe(SubscribeRequest), Unsubscribe(UnsubscribeRequest), + UpdateSubscription(UpdateSubscriptionRequest), } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -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")]