From e7ec2dece9218d2d240a746b11daf9787fbeafaf Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 7 Aug 2026 16:13:50 +0200 Subject: [PATCH] Event listener --- src/bot.rs | 38 ++++++++++++++++++++++---------------- src/launchpad/mod.rs | 13 ++++++++++++- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index b67e1ec..3486ff6 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use anyhow::Context; -use tokio::sync::{Mutex, watch}; +use tokio::sync::{Mutex, mpsc, watch}; use crate::{ data::{ @@ -44,6 +44,8 @@ impl Bot { self: &Arc, mut shutdown: watch::Receiver, ) -> anyhow::Result<()> { + let mut rx = self.executor.listen().await?; + loop { tokio::select! { _ = shutdown.changed() => { @@ -62,7 +64,7 @@ impl Bot { } } - result = self.tick() => { + result = self.tick(&mut rx) => { if result? { log::warn!("Websocket closed."); break; @@ -74,22 +76,26 @@ impl Bot { Ok(()) } - pub async fn tick(self: &Arc) -> anyhow::Result { - // drop(ws); - // self.strategy - // .lock() - // .await - // .on_new_coin(self.clone(), token) - // .await?; + pub async fn tick(self: &Arc, rx: &mut mpsc::Receiver) -> anyhow::Result { + if let Some(data) = rx.recv().await { + // drop(ws); + // self.strategy + // .lock() + // .await + // .on_new_coin(self.clone(), token) + // .await?; - // drop(ws); - // self.strategy - // .lock() - // .await - // .on_trade(self.clone(), trade) - // .await?; + // drop(ws); + // self.strategy + // .lock() + // .await + // .on_trade(self.clone(), trade) + // .await?; - Ok(false) + Ok(false) + } else { + Ok(true) + } } } diff --git a/src/launchpad/mod.rs b/src/launchpad/mod.rs index dc98385..2735ee8 100644 --- a/src/launchpad/mod.rs +++ b/src/launchpad/mod.rs @@ -1,10 +1,11 @@ mod pump_fun; use crate::launchpad::pump_fun::PumpFun; +use anyhow::Context; use helius::Helius; use rust_decimal::Decimal; use std::{collections::HashMap, sync::Arc}; -use tokio::sync::Mutex; +use tokio::sync::{Mutex, mpsc}; pub struct Executor { pub client: Helius, @@ -89,4 +90,14 @@ impl Executor { Ok(()) } + + pub async fn listen(self: &Arc) -> anyhow::Result> { + let (tx, rx) = mpsc::channel(10); + + let ws = self.client.ws().context("Failed to get WebSocket")?; + + tokio::spawn(async move {}); + + Ok(rx) + } }