Skip to content
Merged
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 Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-stream"
version = "0.1.5"
version = "0.1.6"
edition = "2021"

[lib]
Expand Down
5 changes: 4 additions & 1 deletion src/bin/pyth_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct PriceInfo {
conf: String,
expo: i32,
publish_time: i64,
slot: u64, // Add this field
}

// Add this struct to deserialize the configuration
Expand Down Expand Up @@ -149,12 +150,14 @@ async fn fetch_price_updates(jetstream: jetstream::Context, config: &AppConfig)
conf: price_account.agg.conf.to_string(),
expo: price_account.expo,
publish_time: price_account.timestamp,
slot: update.context.slot, // Add this field
},
ema_price: PriceInfo {
price: price_account.ema_price.val.to_string(),
conf: price_account.ema_conf.val.to_string(),
expo: price_account.expo,
publish_time: price_account.timestamp,
slot: update.context.slot, // Add this field
},
},
};
Expand All @@ -164,7 +167,7 @@ async fn fetch_price_updates(jetstream: jetstream::Context, config: &AppConfig)
// Create a unique message ID
let message_id = format!(
"{}:{}",
price_update.price_feed.id, price_update.price_feed.price.publish_time
price_update.price_feed.id, price_update.price_feed.price.slot
);

// Create headers with the Nats-Msg-Id
Expand Down
11 changes: 9 additions & 2 deletions src/bin/websocket_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ struct PriceInfo {
conf: String,
expo: i32,
publish_time: i64,
slot: u64, // Add this field
}

async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -> Result<()> {
Expand Down Expand Up @@ -309,7 +310,10 @@ async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -
};
price_update.price_feed.id = hex_id.clone();

debug!("Parsed price update for feed ID: {}", hex_id);
debug!(
"Parsed price update for feed ID: {} at slot: {}",
hex_id, price_update.price_feed.price.slot
);

let clients = clients.lock().await;
debug!("Number of connected clients: {}", clients.len());
Expand All @@ -320,7 +324,10 @@ async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -
if let Err(e) = sender.send(Message::Text(update_json)) {
warn!(client_addr = %client_addr, error = %e, "Failed to send price update to client");
} else {
debug!("Successfully sent update to client: {}", client_addr);
debug!(
"Successfully sent update to client: {} for slot: {}",
client_addr, price_update.price_feed.price.slot
);
}
} else {
debug!(
Expand Down