Launchpad

This commit is contained in:
2026-08-07 15:41:56 +02:00
parent 2f084bab24
commit d5c446b779
5 changed files with 121 additions and 6 deletions
+7 -4
View File
@@ -6,8 +6,11 @@ use helius::Helius;
use tokio::sync::{Mutex, watch};
use crate::{
data::account::{Account, AccountManager},
data::tradelog::TradeLog,
data::{
account::{Account, AccountManager},
tradelog::TradeLog,
},
launchpad::Executor,
strategy::{Strategy, veloc::MomentumVelocityStrategy},
};
@@ -17,7 +20,7 @@ pub struct Bot {
pub strategy: Mutex<Box<dyn Strategy>>,
pub executor: Mutex<()>,
pub executor: Mutex<Executor>,
pub trade_log: Mutex<Vec<TradeLog>>,
pub helius: Helius,
@@ -41,7 +44,7 @@ impl Bot {
strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())),
trade_log: Mutex::new(Vec::new()),
executor: Mutex::new(()),
executor: Mutex::new(Executor::new()),
}))
}
+67
View File
@@ -0,0 +1,67 @@
mod pump_fun;
use crate::launchpad::pump_fun::PumpFun;
use rust_decimal::Decimal;
use std::collections::HashMap;
pub struct Executor {
pub pump_fun: PumpFun,
}
#[allow(unused_variables)]
#[async_trait::async_trait]
pub trait Launchpad: Send + Sync {
async fn buy(
&mut self,
mint: &str,
amount: Decimal,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()>;
async fn sell(
&mut self,
mint: &str,
amount: u8,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()>;
fn get_positions(&self) -> HashMap<String, Decimal>;
}
impl Executor {
pub fn new() -> Self {
Self {
pump_fun: PumpFun::new(),
}
}
pub async fn buy(
&mut self,
mint: &str,
amount: Decimal,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
self.pump_fun.buy(mint, amount, priority, slippage).await
}
pub async fn sell(
&mut self,
mint: &str,
amount: u8,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
self.pump_fun.sell(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?;
}
Ok(())
}
}
+45
View File
@@ -0,0 +1,45 @@
use std::collections::HashMap;
use rust_decimal::Decimal;
use crate::launchpad::Launchpad;
pub struct PumpFun {
pub positions: HashMap<String, Decimal>,
}
impl PumpFun {
pub fn new() -> Self {
Self {
positions: HashMap::new(),
}
}
}
#[allow(unused_variables)]
#[async_trait::async_trait]
impl Launchpad for PumpFun {
async fn buy(
&mut self,
mint: &str,
amount: Decimal,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
Ok(())
}
async fn sell(
&mut self,
mint: &str,
amount: u8,
priority: Decimal,
slippage: u16,
) -> anyhow::Result<()> {
Ok(())
}
fn get_positions<'a>(&'a self) -> HashMap<String, Decimal> {
self.positions.clone()
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
pub mod bot;
pub mod data;
pub mod strategy;
// pub mod types;
pub mod launchpad;
use std::sync::Arc;
+1 -1
View File
@@ -173,7 +173,7 @@ impl Strategy for MomentumVelocityStrategy {
bot.executor
.lock()
.await
.sell_percent(mint, 100, PRIORITY, SLIPPAGE)
.sell(mint, 100, PRIORITY, SLIPPAGE)
.await?;
if let Some(mut pos) = self.positions.remove(mint) {