1
0
mirror of https://github.com/payden/libwsclient synced 2026-03-02 04:09:18 +00:00

feat : add strategy

This commit is contained in:
deniyuda348
2025-05-16 15:09:24 +09:00
parent d416fcb62c
commit 17c1e2d5e0
81 changed files with 7848 additions and 2858 deletions

37
monitoring/dashboard.rs Normal file
View File

@@ -0,0 +1,37 @@
use crate::monitoring::metrics::Metrics;
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio::time;
pub struct Dashboard {
pub metrics: Arc<Metrics>,
pub update_interval: u64,
}
impl Dashboard {
pub fn new(metrics: Arc<Metrics>, update_interval: u64) -> Self {
Dashboard {
metrics,
update_interval,
}
}
pub async fn run(&self) {
loop {
self.render().await;
time::sleep(time::Duration::from_secs(self.update_interval)).await;
}
}
async fn render(&self) {
let orders = self.metrics.get_orders().await;
let profits = self.metrics.get_profits().await;
let volumes = self.metrics.get_volumes().await;
println!("=== MEV Bot Dashboard ===");
println!("Total Orders: {}", orders.len());
println!("Total Profit: {:.2} SOL", profits.values().sum::<f64>());
println!("Total Volume: {:.2} SOL", volumes.values().sum::<f64>());
println!("==========================");
}
}

48
monitoring/metrics.rs Normal file
View File

@@ -0,0 +1,48 @@
use crate::models::market::Market;
use crate::models::order::Order;
use solana_sdk::pubkey::Pubkey;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::Mutex;
pub struct Metrics {
pub orders: Arc<Mutex<Vec<Order>>>,
pub profits: Arc<Mutex<HashMap<Pubkey, f64>>>,
pub volumes: Arc<Mutex<HashMap<Market, f64>>>,
}
impl Metrics {
pub fn new() -> Self {
Metrics {
orders: Arc::new(Mutex::new(Vec::new())),
profits: Arc::new(Mutex::new(HashMap::new())),
volumes: Arc::new(Mutex::new(HashMap::new())),
}
}
pub async fn add_order(&self, order: Order) {
self.orders.lock().await.push(order);
}
pub async fn update_profit(&self, market: &Market, profit: f64) {
let mut profits = self.profits.lock().await;
*profits.entry(market.address).or_insert(0.0) += profit;
}
pub async fn update_volume(&self, market: &Market, volume: f64) {
let mut volumes = self.volumes.lock().await;
*volumes.entry(market.clone()).or_insert(0.0) += volume;
}
pub async fn get_orders(&self) -> Vec<Order> {
self.orders.lock().await.clone()
}
pub async fn get_profits(&self) -> HashMap<Pubkey, f64> {
self.profits.lock().await.clone()
}
pub async fn get_volumes(&self) -> HashMap<Market, f64> {
self.volumes.lock().await.clone()
}
}