Launchpad
This commit is contained in:
+7
-4
@@ -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()),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
@@ -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
@@ -1,7 +1,7 @@
|
||||
pub mod bot;
|
||||
pub mod data;
|
||||
pub mod strategy;
|
||||
// pub mod types;
|
||||
pub mod launchpad;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user