From c7d28d6cc761cc93d8f25f7b40d699e1f689ff56 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 7 Aug 2026 16:59:16 +0200 Subject: [PATCH] Testing websocket --- Cargo.lock | 65 ++++++++++++++++++++++++++++++++++----- Cargo.toml | 7 +++-- src/data/mod.rs | 52 +++++++++++++++++++++++++++++++ src/launchpad/mod.rs | 37 +++++++++++++++++----- src/launchpad/pump_fun.rs | 6 ++-- src/strategy/mod.rs | 57 +++------------------------------- src/strategy/veloc.rs | 3 +- 7 files changed, 153 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a836be..2c954a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -729,6 +729,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "constant_time_eq" version = "0.4.2" @@ -1036,7 +1042,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "zeroize", ] @@ -1073,7 +1079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid", + "const-oid 0.9.6", "crypto-common 0.1.7", "subtle", ] @@ -1085,6 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.1", + "const-oid 0.10.2", "crypto-common 0.2.2", "ctutils", ] @@ -1666,7 +1673,7 @@ dependencies = [ "thiserror 2.0.19", "tokio", "tokio-stream", - "tokio-tungstenite", + "tokio-tungstenite 0.28.0", "url", ] @@ -3505,6 +3512,17 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sha1" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.3", +] + [[package]] name = "sha2" version = "0.10.9" @@ -3639,12 +3657,14 @@ dependencies = [ "chrono", "csv", "env_logger", + "futures-util", "helius", "log", "rust_decimal", "serde", "serde_json", "tokio", + "tokio-tungstenite 0.30.0", ] [[package]] @@ -4652,8 +4672,8 @@ dependencies = [ "thiserror 2.0.19", "tokio", "tokio-stream", - "tokio-tungstenite", - "tungstenite", + "tokio-tungstenite 0.28.0", + "tungstenite 0.28.0", "url", ] @@ -6026,10 +6046,24 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls", - "tungstenite", + "tungstenite 0.28.0", "webpki-roots 0.26.11", ] +[[package]] +name = "tokio-tungstenite" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17a073bfed563fa236697a068031408a93cd9522e08abf9933ead3e73411bd71" +dependencies = [ + "futures-util", + "log", + "native-tls", + "tokio", + "tokio-native-tls", + "tungstenite 0.30.0", +] + [[package]] name = "tokio-util" version = "0.7.19" @@ -6165,12 +6199,29 @@ dependencies = [ "rand 0.9.5", "rustls", "rustls-pki-types", - "sha1", + "sha1 0.10.7", "thiserror 2.0.19", "utf-8", "webpki-roots 0.26.11", ] +[[package]] +name = "tungstenite" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48ac77174b19c110a50ab2128b24215ac9cb40e0e12e093fb602d175c569d22" +dependencies = [ + "bytes", + "data-encoding", + "http 1.5.0", + "httparse", + "log", + "native-tls", + "rand 0.10.2", + "sha1 0.11.0", + "thiserror 2.0.19", +] + [[package]] name = "typenum" version = "1.20.1" diff --git a/Cargo.toml b/Cargo.toml index 6178806..2e5632d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,15 +5,18 @@ edition = "2024" [dependencies] tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "fs", "io-std"] } +tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] } +futures-util = "0.3.33" anyhow = "1.0.104" serde = { version = "1.0.229", features = ["derive", "serde_derive"] } serde_json = "1.0.151" +csv = "1.4.0" log = "0.4.33" env_logger = "0.11.11" -rust_decimal = { version = "1.42.1", features = ["macros"] } async-trait = "0.1.91" -csv = "1.4.0" + +rust_decimal = { version = "1.42.1", features = ["macros"] } chrono = { version = "0.4.45", features = ["serde"] } helius = "1.1.0" diff --git a/src/data/mod.rs b/src/data/mod.rs index 6e2986e..94beafb 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -1,2 +1,54 @@ pub mod account; pub mod tradelog; + +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +pub struct NewToken { + pub mint: String, + #[serde(rename = "traderPublicKey")] + pub trader_public_key: String, + + pub name: String, + pub symbol: String, + pub uri: String, + #[serde(rename = "marketCapSol")] + pub market_cap_sol: f64, + #[serde(rename = "solAmount")] + pub sol_amount: f64, +} + +#[derive(Debug, Clone, Deserialize)] +pub enum TradeType { + #[serde(rename = "buy")] + Buy, + #[serde(rename = "sell")] + Sell, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct Trade { + pub signature: String, + pub mint: String, + + #[serde(rename = "traderPublicKey")] + pub trader: String, + + #[serde(rename = "txType")] + pub tx_type: TradeType, + + #[serde(rename = "solAmount")] + pub sol_amount: f64, + + #[serde(rename = "tokenAmount")] + pub token_amount: f64, + + #[serde(rename = "marketCapSol")] + pub market_cap_sol: f64, + + #[serde(rename = "vTokensInBondingCurve")] + pub v_tokens_in_bonding_curve: f64, + + #[serde(rename = "vSolInBondingCurve")] + pub v_sol_in_bonding_curve: f64, +} diff --git a/src/launchpad/mod.rs b/src/launchpad/mod.rs index 2735ee8..5b68390 100644 --- a/src/launchpad/mod.rs +++ b/src/launchpad/mod.rs @@ -1,14 +1,22 @@ mod pump_fun; use crate::launchpad::pump_fun::PumpFun; -use anyhow::Context; -use helius::Helius; +use futures_util::StreamExt; use rust_decimal::Decimal; use std::{collections::HashMap, sync::Arc}; use tokio::sync::{Mutex, mpsc}; +use tokio_tungstenite::tungstenite::Message; + +pub struct Client( + pub Mutex< + tokio_tungstenite::WebSocketStream< + tokio_tungstenite::MaybeTlsStream, + >, + >, +); pub struct Executor { - pub client: Helius, + pub client: Arc, pub pump_fun: Mutex, } @@ -18,7 +26,7 @@ pub struct Executor { pub trait Launchpad: Send + Sync { async fn buy( &mut self, - client: &Helius, + client: &Client, mint: &str, amount: Decimal, @@ -28,7 +36,7 @@ pub trait Launchpad: Send + Sync { async fn sell( &mut self, - client: &Helius, + client: &Client, mint: &str, amount: u8, @@ -42,7 +50,13 @@ pub trait Launchpad: Send + Sync { impl Executor { pub async fn new(api_key: &str) -> anyhow::Result> { Ok(Arc::new(Self { - client: Helius::new_async(api_key, helius::types::Cluster::Devnet).await?, + client: Arc::new(Client(Mutex::new( + tokio_tungstenite::connect_async(format!( + "wss://devnet.helius-rpc.com/?api-key={api_key}" + )) + .await? + .0, + ))), pump_fun: Mutex::new(PumpFun::new()), })) @@ -94,9 +108,16 @@ impl Executor { pub async fn listen(self: &Arc) -> anyhow::Result> { let (tx, rx) = mpsc::channel(10); - let ws = self.client.ws().context("Failed to get WebSocket")?; + let client = self.client.clone(); - tokio::spawn(async move {}); + tokio::spawn(async move { + match client.0.lock().await.next().await { + Some(Ok(Message::Text(msg))) => {} + Some(Ok(msg)) => {} + Some(Err(e)) => {} + None => {} + } + }); Ok(rx) } diff --git a/src/launchpad/pump_fun.rs b/src/launchpad/pump_fun.rs index 7e1bfff..9e153ad 100644 --- a/src/launchpad/pump_fun.rs +++ b/src/launchpad/pump_fun.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use helius::Helius; use rust_decimal::Decimal; +use crate::launchpad::Client; use crate::launchpad::Launchpad; pub struct PumpFun { @@ -22,7 +22,7 @@ impl PumpFun { impl Launchpad for PumpFun { async fn buy( &mut self, - client: &Helius, + client: &Client, mint: &str, amount: Decimal, @@ -34,7 +34,7 @@ impl Launchpad for PumpFun { async fn sell( &mut self, - client: &Helius, + client: &Client, mint: &str, amount: u8, diff --git a/src/strategy/mod.rs b/src/strategy/mod.rs index 77ad8ef..7471feb 100644 --- a/src/strategy/mod.rs +++ b/src/strategy/mod.rs @@ -2,59 +2,10 @@ pub mod veloc; use std::sync::Arc; -use crate::bot::Bot; - -use serde::Deserialize; - -#[derive(Debug, Clone, Deserialize)] -pub struct NewToken { - pub mint: String, - #[serde(rename = "traderPublicKey")] - pub trader_public_key: String, - - pub name: String, - pub symbol: String, - pub uri: String, - #[serde(rename = "marketCapSol")] - pub market_cap_sol: f64, - #[serde(rename = "solAmount")] - pub sol_amount: f64, -} - -#[derive(Debug, Clone, Deserialize)] -pub enum TradeType { - #[serde(rename = "buy")] - Buy, - #[serde(rename = "sell")] - Sell, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct Trade { - pub signature: String, - pub mint: String, - - #[serde(rename = "traderPublicKey")] - pub trader: String, - - #[serde(rename = "txType")] - pub tx_type: TradeType, - - #[serde(rename = "solAmount")] - pub sol_amount: f64, - - #[serde(rename = "tokenAmount")] - pub token_amount: f64, - - #[serde(rename = "marketCapSol")] - pub market_cap_sol: f64, - - #[serde(rename = "vTokensInBondingCurve")] - pub v_tokens_in_bonding_curve: f64, - - #[serde(rename = "vSolInBondingCurve")] - pub v_sol_in_bonding_curve: f64, -} +use crate::{ + bot::Bot, + data::{NewToken, Trade}, +}; #[async_trait::async_trait] pub trait Strategy: Send + Sync { diff --git a/src/strategy/veloc.rs b/src/strategy/veloc.rs index ef55206..9a3fa94 100644 --- a/src/strategy/veloc.rs +++ b/src/strategy/veloc.rs @@ -7,8 +7,9 @@ use rust_decimal::{Decimal, dec}; use super::{NewToken, Trade}; use crate::bot::Bot; +use crate::data::TradeType; use crate::data::tradelog::{ExitReason, TradeLog}; -use crate::strategy::{Strategy, TradeType}; +use crate::strategy::Strategy; const BUY_AMOUNT_SOL: Decimal = dec!(0.2); const PRIORITY: Decimal = dec!(0.0002);