Helius on executor

This commit is contained in:
2026-08-07 15:57:27 +02:00
parent d5c446b779
commit bd9f883a94
4 changed files with 50 additions and 39 deletions
+5 -18
View File
@@ -1,7 +1,6 @@
use std::sync::Arc;
use anyhow::{Context, anyhow};
use helius::Helius;
use anyhow::Context;
use tokio::sync::{Mutex, watch};
@@ -15,15 +14,11 @@ use crate::{
};
pub struct Bot {
pub executor: Arc<Executor>,
pub strategy: Mutex<Box<dyn Strategy>>,
pub account_manager: Mutex<AccountManager>,
pub current_account: Mutex<Account>,
pub strategy: Mutex<Box<dyn Strategy>>,
pub executor: Mutex<Executor>,
pub trade_log: Mutex<Vec<TradeLog>>,
pub helius: Helius,
}
impl Bot {
@@ -37,14 +32,11 @@ impl Bot {
.clone();
Ok(Arc::new(Self {
helius: Helius::new_async(&accounts.api_key, helius::types::Cluster::Devnet).await?,
executor: Executor::new(&accounts.api_key).await?,
strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())),
account_manager: Mutex::new(accounts),
current_account: Mutex::new(account),
strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())),
trade_log: Mutex::new(Vec::new()),
executor: Mutex::new(Executor::new()),
}))
}
@@ -83,11 +75,6 @@ impl Bot {
}
pub async fn tick(self: &Arc<Self>) -> anyhow::Result<bool> {
let ws = self
.helius
.ws()
.ok_or_else(|| anyhow!("Unable to obtain ws"))?;
// drop(ws);
// self.strategy
// .lock()
+38 -13
View File
@@ -1,11 +1,15 @@
mod pump_fun;
use crate::launchpad::pump_fun::PumpFun;
use helius::Helius;
use rust_decimal::Decimal;
use std::collections::HashMap;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::Mutex;
pub struct Executor {
pub pump_fun: PumpFun,
pub client: Helius,
pub pump_fun: Mutex<PumpFun>,
}
#[allow(unused_variables)]
@@ -13,6 +17,8 @@ pub struct Executor {
pub trait Launchpad: Send + Sync {
async fn buy(
&mut self,
client: &Helius,
mint: &str,
amount: Decimal,
priority: Decimal,
@@ -21,6 +27,8 @@ pub trait Launchpad: Send + Sync {
async fn sell(
&mut self,
client: &Helius,
mint: &str,
amount: u8,
priority: Decimal,
@@ -31,35 +39,52 @@ pub trait Launchpad: Send + Sync {
}
impl Executor {
pub fn new() -> Self {
Self {
pump_fun: PumpFun::new(),
}
pub async fn new(api_key: &str) -> anyhow::Result<Arc<Self>> {
Ok(Arc::new(Self {
client: Helius::new_async(api_key, helius::types::Cluster::Devnet).await?,
pump_fun: Mutex::new(PumpFun::new()),
}))
}
pub async fn buy(
&mut self,
self: &Arc<Self>,
mint: &str,
amount: Decimal,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
self.pump_fun.buy(mint, amount, priority, slippage).await
self.pump_fun
.lock()
.await
.buy(&self.client, mint, amount, priority, slippage)
.await
}
pub async fn sell(
&mut self,
self: &Arc<Self>,
mint: &str,
amount: u8,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
self.pump_fun.sell(mint, amount, priority, slippage).await
self.pump_fun
.lock()
.await
.sell(&self.client, mint, amount, priority, slippage)
.await
}
pub async fn sell_all(&mut self, priority: Decimal, slippage: u16) -> anyhow::Result<()> {
for (mint, _) in self.pump_fun.get_positions() {
self.pump_fun.sell(&mint, 100, priority, slippage).await?;
pub async fn sell_all(
self: &Arc<Self>,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
let mut pump = self.pump_fun.lock().await;
for (mint, _) in pump.get_positions() {
pump.sell(&self.client, &mint, 100, priority, slippage)
.await?;
}
Ok(())
+5
View File
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use helius::Helius;
use rust_decimal::Decimal;
use crate::launchpad::Launchpad;
@@ -21,6 +22,8 @@ impl PumpFun {
impl Launchpad for PumpFun {
async fn buy(
&mut self,
client: &Helius,
mint: &str,
amount: Decimal,
priority: Decimal,
@@ -31,6 +34,8 @@ impl Launchpad for PumpFun {
async fn sell(
&mut self,
client: &Helius,
mint: &str,
amount: u8,
priority: Decimal,
+2 -8
View File
@@ -75,7 +75,7 @@ impl MomentumVelocityStrategy {
#[async_trait::async_trait]
impl Strategy for MomentumVelocityStrategy {
async fn execute_sell_all(&mut self, bot: Arc<Bot>) -> anyhow::Result<()> {
bot.executor.lock().await.sell_all(PRIORITY, SLIPPAGE).await
bot.executor.sell_all(PRIORITY, SLIPPAGE).await
}
async fn on_new_coin(&mut self, bot: Arc<Bot>, token: NewToken) -> anyhow::Result<()> {
@@ -170,11 +170,7 @@ impl Strategy for MomentumVelocityStrategy {
price_change_pct * 100.0
);
bot.executor
.lock()
.await
.sell(mint, 100, PRIORITY, SLIPPAGE)
.await?;
bot.executor.sell(mint, 100, PRIORITY, SLIPPAGE).await?;
if let Some(mut pos) = self.positions.remove(mint) {
pos.trade.close(current_price, reason);
@@ -244,8 +240,6 @@ impl Strategy for MomentumVelocityStrategy {
);
bot.executor
.lock()
.await
.buy(mint, BUY_AMOUNT_SOL, PRIORITY, SLIPPAGE)
.await?;