mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-09 07:07:44 +00:00
add yellowstone
This commit is contained in:
@@ -80,6 +80,8 @@ pub enum ClientError {
|
||||
|
||||
Other(String),
|
||||
|
||||
Anyhow(&'static str),
|
||||
|
||||
InvalidData(String),
|
||||
|
||||
PumpFunBuy(String),
|
||||
@@ -109,6 +111,7 @@ impl std::fmt::Display for ClientError {
|
||||
Self::ExternalService(msg) => write!(f, "External service error: {}", msg),
|
||||
Self::RateLimitExceeded => write!(f, "Rate limit exceeded"),
|
||||
Self::OrderLimitExceeded => write!(f, "Order limit exceeded"),
|
||||
Self::Anyhow(msg) => write!(f, "Anyhow error: {}", msg),
|
||||
Self::Solana(msg, details) => write!(f, "Solana error: {}, details: {}", msg, details),
|
||||
Self::Parse(msg, details) => write!(f, "Parse error: {}, details: {}", msg, details),
|
||||
Self::Jito(msg, details) => write!(f, "Jito error: {}, details: {}", msg, details),
|
||||
|
||||
+20
@@ -658,6 +658,26 @@ impl PumpFun {
|
||||
let token_price_in_usdc = sol_price_in_usdc * token_amount;
|
||||
Ok(token_price_in_usdc)
|
||||
}
|
||||
|
||||
pub async fn get_sol_price_in_usdc(&self) -> Result<f64, ClientError> {
|
||||
let url = "https://api.jup.ag/price/v2?ids=So11111111111111111111111111111111111111112";
|
||||
let response: serde_json::Value = reqwest::get(url)
|
||||
.await
|
||||
.map_err(|_| ClientError::Anyhow("Failed to install crypto provider"))?
|
||||
.json()
|
||||
.await
|
||||
.map_err(|_| ClientError::Anyhow("Failed to install crypto provider"))?;
|
||||
|
||||
let sol_price_str = response["data"]["So11111111111111111111111111111111111111112"]["price"]
|
||||
.as_str()
|
||||
.ok_or(ClientError::Anyhow("Failed to find SOL price as a string"))?;
|
||||
|
||||
let sol_price_in_usdc: f64 = sol_price_str
|
||||
.parse()
|
||||
.map_err(|_| ClientError::Anyhow("Failed to parse SOL price as a string"))?;
|
||||
|
||||
Ok(sol_price_in_usdc)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
use mai3_pumpfun_sdk::common::{
|
||||
logs_events::DexEvent,
|
||||
logs_events::PumpfunEvent,
|
||||
logs_subscribe::{tokens_subscription, stop_subscription}
|
||||
};
|
||||
use solana_sdk::commitment_config::CommitmentConfig;
|
||||
@@ -14,18 +14,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let commitment = CommitmentConfig::confirmed();
|
||||
|
||||
// Define callback function
|
||||
let callback = |event: DexEvent| {
|
||||
let callback = |event: PumpfunEvent| {
|
||||
match event {
|
||||
DexEvent::NewToken(token_info) => {
|
||||
PumpfunEvent::NewToken(token_info) => {
|
||||
println!("Received new token event: {:?}", token_info);
|
||||
},
|
||||
DexEvent::NewUserTrade(trade_info) => {
|
||||
PumpfunEvent::NewUserTrade(trade_info) => {
|
||||
println!("Received new trade event: {:?}", trade_info);
|
||||
},
|
||||
DexEvent::NewBotTrade(trade_info) => {
|
||||
PumpfunEvent::NewBotTrade(trade_info) => {
|
||||
println!("Received new bot trade event: {:?}", trade_info);
|
||||
},
|
||||
DexEvent::Error(err) => {
|
||||
PumpfunEvent::Error(err) => {
|
||||
println!("Received error: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user