Testing websocket
This commit is contained in:
Generated
+58
-7
@@ -729,6 +729,12 @@ version = "0.9.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const-oid"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "constant_time_eq"
|
name = "constant_time_eq"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -1036,7 +1042,7 @@ version = "0.7.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
|
checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const-oid",
|
"const-oid 0.9.6",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1073,7 +1079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer 0.10.4",
|
"block-buffer 0.10.4",
|
||||||
"const-oid",
|
"const-oid 0.9.6",
|
||||||
"crypto-common 0.1.7",
|
"crypto-common 0.1.7",
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
@@ -1085,6 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer 0.12.1",
|
"block-buffer 0.12.1",
|
||||||
|
"const-oid 0.10.2",
|
||||||
"crypto-common 0.2.2",
|
"crypto-common 0.2.2",
|
||||||
"ctutils",
|
"ctutils",
|
||||||
]
|
]
|
||||||
@@ -1666,7 +1673,7 @@ dependencies = [
|
|||||||
"thiserror 2.0.19",
|
"thiserror 2.0.19",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite 0.28.0",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3505,6 +3512,17 @@ dependencies = [
|
|||||||
"digest 0.10.7",
|
"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]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -3639,12 +3657,14 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"csv",
|
"csv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"futures-util",
|
||||||
"helius",
|
"helius",
|
||||||
"log",
|
"log",
|
||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-tungstenite 0.30.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4652,8 +4672,8 @@ dependencies = [
|
|||||||
"thiserror 2.0.19",
|
"thiserror 2.0.19",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite 0.28.0",
|
||||||
"tungstenite",
|
"tungstenite 0.28.0",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -6026,10 +6046,24 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"tokio-native-tls",
|
"tokio-native-tls",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tungstenite",
|
"tungstenite 0.28.0",
|
||||||
"webpki-roots 0.26.11",
|
"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]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.19"
|
version = "0.7.19"
|
||||||
@@ -6165,12 +6199,29 @@ dependencies = [
|
|||||||
"rand 0.9.5",
|
"rand 0.9.5",
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
"sha1",
|
"sha1 0.10.7",
|
||||||
"thiserror 2.0.19",
|
"thiserror 2.0.19",
|
||||||
"utf-8",
|
"utf-8",
|
||||||
"webpki-roots 0.26.11",
|
"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]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.20.1"
|
version = "1.20.1"
|
||||||
|
|||||||
+5
-2
@@ -5,15 +5,18 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "fs", "io-std"] }
|
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"
|
anyhow = "1.0.104"
|
||||||
|
|
||||||
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
||||||
serde_json = "1.0.151"
|
serde_json = "1.0.151"
|
||||||
|
csv = "1.4.0"
|
||||||
|
|
||||||
log = "0.4.33"
|
log = "0.4.33"
|
||||||
env_logger = "0.11.11"
|
env_logger = "0.11.11"
|
||||||
rust_decimal = { version = "1.42.1", features = ["macros"] }
|
|
||||||
async-trait = "0.1.91"
|
async-trait = "0.1.91"
|
||||||
csv = "1.4.0"
|
|
||||||
|
rust_decimal = { version = "1.42.1", features = ["macros"] }
|
||||||
chrono = { version = "0.4.45", features = ["serde"] }
|
chrono = { version = "0.4.45", features = ["serde"] }
|
||||||
helius = "1.1.0"
|
helius = "1.1.0"
|
||||||
|
|||||||
@@ -1,2 +1,54 @@
|
|||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod tradelog;
|
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,
|
||||||
|
}
|
||||||
|
|||||||
+29
-8
@@ -1,14 +1,22 @@
|
|||||||
mod pump_fun;
|
mod pump_fun;
|
||||||
|
|
||||||
use crate::launchpad::pump_fun::PumpFun;
|
use crate::launchpad::pump_fun::PumpFun;
|
||||||
use anyhow::Context;
|
use futures_util::StreamExt;
|
||||||
use helius::Helius;
|
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
use tokio::sync::{Mutex, mpsc};
|
use tokio::sync::{Mutex, mpsc};
|
||||||
|
use tokio_tungstenite::tungstenite::Message;
|
||||||
|
|
||||||
|
pub struct Client(
|
||||||
|
pub Mutex<
|
||||||
|
tokio_tungstenite::WebSocketStream<
|
||||||
|
tokio_tungstenite::MaybeTlsStream<tokio::net::TcpStream>,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
);
|
||||||
|
|
||||||
pub struct Executor {
|
pub struct Executor {
|
||||||
pub client: Helius,
|
pub client: Arc<Client>,
|
||||||
|
|
||||||
pub pump_fun: Mutex<PumpFun>,
|
pub pump_fun: Mutex<PumpFun>,
|
||||||
}
|
}
|
||||||
@@ -18,7 +26,7 @@ pub struct Executor {
|
|||||||
pub trait Launchpad: Send + Sync {
|
pub trait Launchpad: Send + Sync {
|
||||||
async fn buy(
|
async fn buy(
|
||||||
&mut self,
|
&mut self,
|
||||||
client: &Helius,
|
client: &Client,
|
||||||
|
|
||||||
mint: &str,
|
mint: &str,
|
||||||
amount: Decimal,
|
amount: Decimal,
|
||||||
@@ -28,7 +36,7 @@ pub trait Launchpad: Send + Sync {
|
|||||||
|
|
||||||
async fn sell(
|
async fn sell(
|
||||||
&mut self,
|
&mut self,
|
||||||
client: &Helius,
|
client: &Client,
|
||||||
|
|
||||||
mint: &str,
|
mint: &str,
|
||||||
amount: u8,
|
amount: u8,
|
||||||
@@ -42,7 +50,13 @@ pub trait Launchpad: Send + Sync {
|
|||||||
impl Executor {
|
impl Executor {
|
||||||
pub async fn new(api_key: &str) -> anyhow::Result<Arc<Self>> {
|
pub async fn new(api_key: &str) -> anyhow::Result<Arc<Self>> {
|
||||||
Ok(Arc::new(Self {
|
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()),
|
pump_fun: Mutex::new(PumpFun::new()),
|
||||||
}))
|
}))
|
||||||
@@ -94,9 +108,16 @@ impl Executor {
|
|||||||
pub async fn listen(self: &Arc<Self>) -> anyhow::Result<mpsc::Receiver<u32>> {
|
pub async fn listen(self: &Arc<Self>) -> anyhow::Result<mpsc::Receiver<u32>> {
|
||||||
let (tx, rx) = mpsc::channel(10);
|
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)
|
Ok(rx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use helius::Helius;
|
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
|
use crate::launchpad::Client;
|
||||||
use crate::launchpad::Launchpad;
|
use crate::launchpad::Launchpad;
|
||||||
|
|
||||||
pub struct PumpFun {
|
pub struct PumpFun {
|
||||||
@@ -22,7 +22,7 @@ impl PumpFun {
|
|||||||
impl Launchpad for PumpFun {
|
impl Launchpad for PumpFun {
|
||||||
async fn buy(
|
async fn buy(
|
||||||
&mut self,
|
&mut self,
|
||||||
client: &Helius,
|
client: &Client,
|
||||||
|
|
||||||
mint: &str,
|
mint: &str,
|
||||||
amount: Decimal,
|
amount: Decimal,
|
||||||
@@ -34,7 +34,7 @@ impl Launchpad for PumpFun {
|
|||||||
|
|
||||||
async fn sell(
|
async fn sell(
|
||||||
&mut self,
|
&mut self,
|
||||||
client: &Helius,
|
client: &Client,
|
||||||
|
|
||||||
mint: &str,
|
mint: &str,
|
||||||
amount: u8,
|
amount: u8,
|
||||||
|
|||||||
+4
-53
@@ -2,59 +2,10 @@ pub mod veloc;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::bot::Bot;
|
use crate::{
|
||||||
|
bot::Bot,
|
||||||
use serde::Deserialize;
|
data::{NewToken, Trade},
|
||||||
|
};
|
||||||
#[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,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait Strategy: Send + Sync {
|
pub trait Strategy: Send + Sync {
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use rust_decimal::{Decimal, dec};
|
|||||||
|
|
||||||
use super::{NewToken, Trade};
|
use super::{NewToken, Trade};
|
||||||
use crate::bot::Bot;
|
use crate::bot::Bot;
|
||||||
|
use crate::data::TradeType;
|
||||||
use crate::data::tradelog::{ExitReason, TradeLog};
|
use crate::data::tradelog::{ExitReason, TradeLog};
|
||||||
use crate::strategy::{Strategy, TradeType};
|
use crate::strategy::Strategy;
|
||||||
|
|
||||||
const BUY_AMOUNT_SOL: Decimal = dec!(0.2);
|
const BUY_AMOUNT_SOL: Decimal = dec!(0.2);
|
||||||
const PRIORITY: Decimal = dec!(0.0002);
|
const PRIORITY: Decimal = dec!(0.0002);
|
||||||
|
|||||||
Reference in New Issue
Block a user