Files
sol-trade-sdk/src/main.rs
T

52 lines
1.6 KiB
Rust
Raw Normal View History

2025-04-02 13:39:59 +08:00
use pumpfun_sdk::common::{
2025-02-01 09:44:15 +08:00
logs_events::PumpfunEvent,
2025-01-03 11:14:39 +08:00
logs_subscribe::{tokens_subscription, stop_subscription}
};
2025-01-23 17:48:10 +08:00
use solana_sdk::commitment_config::CommitmentConfig;
2025-01-03 00:38:45 +08:00
2025-01-02 19:44:38 +08:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Starting token subscription\n");
let ws_url = "wss://api.mainnet-beta.solana.com";
2025-01-03 11:14:39 +08:00
2025-01-03 00:38:45 +08:00
// Set commitment
2025-01-02 19:44:38 +08:00
let commitment = CommitmentConfig::confirmed();
2025-01-03 00:38:45 +08:00
// Define callback function
2025-02-01 09:44:15 +08:00
let callback = |event: PumpfunEvent| {
2025-01-03 00:38:45 +08:00
match event {
2025-04-02 13:39:59 +08:00
PumpfunEvent::NewDevTrade(trade_info) => {
println!("Received new dev trade event: {:?}", trade_info);
},
2025-02-01 09:44:15 +08:00
PumpfunEvent::NewToken(token_info) => {
2025-01-03 00:38:45 +08:00
println!("Received new token event: {:?}", token_info);
},
2025-02-01 09:44:15 +08:00
PumpfunEvent::NewUserTrade(trade_info) => {
2025-01-03 00:38:45 +08:00
println!("Received new trade event: {:?}", trade_info);
},
2025-02-01 09:44:15 +08:00
PumpfunEvent::NewBotTrade(trade_info) => {
2025-01-03 17:01:07 +08:00
println!("Received new bot trade event: {:?}", trade_info);
},
2025-02-01 09:44:15 +08:00
PumpfunEvent::Error(err) => {
2025-01-03 00:38:45 +08:00
println!("Received error: {}", err);
}
2025-01-02 19:44:38 +08:00
}
};
2025-01-03 00:38:45 +08:00
// Start subscription
let subscription = tokens_subscription(
2025-01-02 19:44:38 +08:00
ws_url,
commitment,
2025-01-03 17:01:07 +08:00
callback,
None
2025-01-02 19:44:38 +08:00
).await.unwrap();
2025-01-03 00:38:45 +08:00
// Wait for a while to receive events
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
2025-01-02 19:44:38 +08:00
2025-01-03 00:38:45 +08:00
// Stop subscription
stop_subscription(subscription).await;
2025-01-02 19:44:38 +08:00
Ok(())
}