do u know why this would be happening ? use tokio::{
    task::JoinHandle,
    time::{Duration, sleep},
    sync::broadcast,
};
use std::{
    collections::HashMap,
    fs::{self, File},
    io::Read,
    sync::Arc,
};
use futures::{StreamExt, SinkExt};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use parking_lot::RwLock;
use chrono::{DateTime, Utc};
use tracing::{info, warn, error, debug};
use tracing_appender::rolling::{RollingFileAppender, Rotation};
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};
use tokio_tungstenite::{connect_async, tungstenite::Message};

const JUPITER_API: &str = "https://quote-api.jup.ag/v6";
const HELIUS_RPC: &str = "https://marga-e56m84-fast-mainnet.helius-rpc.com";
const HELIUS_WS: &str = "wss://marga-e56m84-fast-mainnet.helius-rpc.com/ws";
const SOL_MINT: &str = "So11111111111111111111111111111111111111112";
const MAX_TOKEN_AGE_SECONDS: i64 = 3;
const MIN_LIQUIDITY_USD: f64 = 1000.0;
const MAX_LIQUIDITY_USD: f64 = 15000.0;
const MIN_TOTAL_SUPPLY: u64 = 900_000_000;
const TAKE_PROFIT_PCT: f64 = 20.0;
const STOP_LOSS_PCT: f64 = 5.0;
const MAX_POSITIONS: usize = 5;
const PRIORITY_FEE: u64 = 15000;
const RECONNECT_DELAY: Duration = Duration::from_secs(1);
const KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30);

#[derive(Debug, Clone, Serialize, Deserialize)]
struct Position {
    token_address: String,
    entry_price: f64,
    quantity: u64,
    entry_time: DateTime<Utc>,
    sell_attempts: u8,
    backoff_count: u8,
    last_price: f64,
    status: PositionStatus,
}

#[derive(Clone, Debug)]
struct PositionInfo {
    entry_price: f64,
    quantity: u64,
    sell_attempts: u8,
    backoff_count: u8,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
enum PositionStatus {
    Active,
    AttemptingSell { reason: String },
    Closed { reason: String, exit_price: f64 },
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
struct BotState {
    positions: HashMap<String, Position>,
    total_trades: u64,
    successful_trades: u64,
    failed_trades: u64,
    total_profit_usd: f64,
    last_update: DateTime<Utc>,
}

struct TradingBot {
    client: reqwest::Client,
    state: Arc<RwLock<BotState>>,
    keypair: Arc<[u8; 64]>,
    shutdown: broadcast::Sender<()>,
}

impl Clone for TradingBot {
    fn clone(&self) -> Self {
        Self {
            client: self.client.clone(),
            state: Arc::clone(&self.state),
            keypair: Arc::clone(&self.keypair),
            shutdown: self.shutdown.clone(),
        }
    }
}

impl TradingBot {
    async fn new() -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
        // Initialize logging
        let file_appender = RollingFileAppender::new(
            Rotation::DAILY,
            "logs",
            "bot.log",
        );

        tracing_subscriber::fmt()
            .with_env_filter(EnvFilter::from_default_env())
            .with_writer(file_appender)
            .with_span_events(FmtSpan::CLOSE)
            .with_thread_ids(true)
            .with_thread_names(true)
            .with_file(true)
            .with_line_number(true)
            .init();

        info!("🚀 Initializing trading bot...");

        // Load or create state
        let state = match Self::load_state() {
            Ok(state) => {
                info!("📝 Loaded existing state");
                state
            }
            Err(e) => {
                warn!("Unable to load state: {}. Creating new state.", e);
                BotState::default()
            }
        };

        let keypair = Arc::new(Self::load_keypair()?);
        let (shutdown_tx, _) = broadcast::channel(1);

        Ok(Self {
            client: reqwest::Client::new(),
            state: Arc::new(RwLock::new(state)),
            keypair,
            shutdown: shutdown_tx,
        })
    }

    fn load_keypair() -> Result<[u8; 64], Box<dyn std::error::Error + Send + Sync>> {
        info!("🔑 Loading keypair...");
        let mut file = File::open("id.json")?;
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;
        
        let secret_key: Vec<u8> = serde_json::from_str(&contents)?;
        let mut keypair = [0u8; 64];
        keypair.copy_from_slice(&secret_key[..64]);
        info!("✅ Keypair loaded successfully");
        Ok(keypair)
    }

    async fn validate_token(&self, token_address: &str) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
        debug!("🔍 Validating token: {}", token_address);
        
        // Get token metadata
        let url = format!(
            "https://api.helius.xyz/v0/token-metadata?api-key={}&address={}",
            std::env::var("HELIUS_API_KEY")?,
            token_address
        );

        let metadata: Value = self.client.get(&url).send().await?.json().await?;
        
        // Check age
        let creation_time = metadata["onChainData"]["dateCreated"]
            .as_i64()
            .unwrap_or(0);
        let age = Utc::now().timestamp() - creation_time;
        
        if age > MAX_TOKEN_AGE_SECONDS {
            debug!("❌ Token too old: {} seconds", age);
            return Ok(false);
        }

        // Check liquidity
        let liquidity = self.get_pool_liquidity(token_address).await?;
        if liquidity < MIN_LIQUIDITY_USD || liquidity > MAX_LIQUIDITY_USD {
            debug!("❌ Invalid liquidity: ${:.2}", liquidity);
            return Ok(false);
        }

        // Check basic criteria
        let is_valid = metadata["onChainMetadata"]["burnt"].as_bool().unwrap_or(true) == false
            && metadata["onChainMetadata"]["mutable"].as_bool().unwrap_or(true) == false
            && metadata["onChainMetadata"]["frozen"].as_bool().unwrap_or(true) == false
            && metadata["onChainData"]["supply"].as_u64().unwrap_or(0) >= MIN_TOTAL_SUPPLY;

        if !is_valid {
            debug!("❌ Failed basic validation");
            return Ok(false);
        }

        info!("✅ Token validation successful:");
        info!("⏰ Age: {} seconds", age);
        info!("💧 Liquidity: ${:.2}", liquidity);
        info!("📊 Supply: {}", metadata["onChainData"]["supply"].as_u64().unwrap_or(0));

        Ok(true)
    }

    async fn execute_trade(&self, is_buy: bool, token_address: &str, amount: u64) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
        let trade_type = if is_buy { "BUY" } else { "SELL" };
        info!("🔄 Executing {} for {}", trade_type, token_address);
        
        let (input_mint, output_mint) = if is_buy {
            (SOL_MINT, token_address)
        } else {
            (token_address, SOL_MINT)
        };

        // Get quote
        let quote = self.get_quote(input_mint, output_mint, amount).await?;
        
        // Build swap
        let swap_data = self.get_prioritized_swap(quote).await?;
        
        // Execute transaction with priority
        let signature = self.send_priority_tx(swap_data).await?;
        
        info!("✅ {} executed - sig: {}", trade_type, signature);
        Ok(signature)
    }

    async fn get_prioritized_swap(&self, quote: Value) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
        let swap_request = json!({
            "quoteResponse": quote,
            "userPublicKey": hex::encode(&self.keypair[32..]),
            "computeUnitPriceMicroLamports": PRIORITY_FEE,
            "priorityFeeLamports": PRIORITY_FEE,
            "asLegacyTransaction": false,
            "maxAccounts": 64
        });

        let response = self.client
            .post(format!("{}/swap", JUPITER_API))
            .json(&swap_request)
            .send()
            .await?
            .json::<Value>()
            .await?;

        match response.get("swapTransaction") {
            Some(tx) => Ok(tx.as_str().unwrap_or_default().to_string()),
            None => {
                error!("No swap transaction in response: {:?}", response);
                Err("No swap transaction in response".into())
            }
        }
    }

    async fn monitor_position(&self, token_address: String) {
        info!("👀 Starting position monitor for {}", token_address);
        let mut interval = tokio::time::interval(Duration::from_secs(1));
        
        'monitoring: loop {
            interval.tick().await;
            
            // Get the current price first
            let current_price = match self.get_token_price(&token_address).await {
                Ok(price) => price,
                Err(e) => {
                    error!("Error getting price for {}: {}", token_address, e);
                    tokio::time::sleep(Duration::from_secs(1)).await;
                    continue;
                }
            };
    
            // Get position info under a scoped lock
            let position_info = {
                let mut state = self.state.write();
                if let Some(position) = state.positions.get_mut(&token_address) {
                    position.last_price = current_price;
                    let profit_pct = (current_price - position.entry_price) / position.entry_price * 100.0;
                    
                    debug!(
                        "Token: {} | Price: ${:.6} | Profit: {:.2}%",
                        token_address, current_price, profit_pct
                    );
    
                    if profit_pct >= TAKE_PROFIT_PCT || profit_pct <= -STOP_LOSS_PCT {
                        Some(PositionInfo {
                            entry_price: position.entry_price,
                            quantity: position.quantity,
                            sell_attempts: position.sell_attempts,
                            backoff_count: position.backoff_count,
                        })
                    } else {
                        None
                    }
                } else {
                    break 'monitoring;
                }
            };
    
            if let Some(mut info) = position_info {
                // Attempt to exit position
                let exit_result = self.execute_trade(false, &token_address, info.quantity).await;
                
                match exit_result {
                    Ok(signature) => {
                        let mut state = self.state.write();
                        if let Some(position) = state.positions.get_mut(&token_address) {
                            position.status = PositionStatus::Closed {
                                reason: "SUCCESS".to_string(),
                                exit_price: current_price,
                            };
                            
                            // Update statistics
                            let profit = (current_price - info.entry_price) * info.quantity as f64;
                            state.total_trades += 1;
                            state.successful_trades += 1;
                            state.total_profit_usd += profit;
                            
                            info!("💰 Position closed successfully!");
                            info!("📊 Entry: ${:.6} | Exit: ${:.6}", info.entry_price, current_price);
                            info!("💵 Profit: ${:.2}", profit);
                            info!("🔗 Transaction: {}", signature);
                            
                            // Remove the position
                            state.positions.remove(&token_address);
                        }
                        break 'monitoring;
                    }
                    Err(e) => {
                        info.sell_attempts += 1;
                        let should_backoff = info.sell_attempts >= 3;
                        
                        // Update position state
                        let should_exit = {
                            let mut state = self.state.write();
                            if let Some(position) = state.positions.get_mut(&token_address) {
                                position.sell_attempts = info.sell_attempts;
                                
                                if should_backoff {
                                    position.backoff_count += 1;
                                    position.sell_attempts = 0;
                                    
                                    if position.backoff_count >= 3 {
                                        error!("❌ All sell attempts exhausted for {}", token_address);
                                        position.status = PositionStatus::Closed {
                                            reason: "FAILED".to_string(),
                                            exit_price: current_price,
                                        };
                                        state.failed_trades += 1;
                                        state.total_trades += 1;
                                        true
                                    } else {
                                        false
                                    }
                                } else {
                                    false
                                }
                            } else {
                                true
                            }
                        };
    
                        if should_exit {
                            let mut state = self.state.write();
                            state.positions.remove(&token_address);
                            break 'monitoring;
                        }
    
                        error!("Sell attempt {} failed: {}", info.sell_attempts, e);
                        
                        if should_backoff {
                            info!("⏳ Backing off for 30 seconds (backoff {}/3)", info.backoff_count);
                            tokio::time::sleep(Duration::from_secs(30)).await;
                        } else {
                            tokio::time::sleep(Duration::from_secs(1)).await;
                        }
                    }
                }
            }
        }
        
        info!("🏁 Finished monitoring {}", token_address);
    }

    async fn attempt_position_exit(&self, token_address: &str, current_price: f64) -> bool {
        let position_info = {
            let mut state = self.state.write();
            if let Some(position) = state.positions.get_mut(token_address) {
                (position.quantity, position.entry_price)
            } else {
                return true;
            }
        };

        let (quantity, entry_price) = position_info;

        for _ in 0..3 {
            match self.execute_trade(false, token_address, quantity).await {
                Ok(signature) => {
                    let mut state = self.state.write();
                    if let Some(position) = state.positions.get_mut(token_address) {
                        position.status = PositionStatus::Closed {
                            reason: "SUCCESS".to_string(),
                            exit_price: current_price,
                        };

                        // Update statistics
                        let profit = (current_price - entry_price) * quantity as f64;
                        state.total_trades += 1;
                        state.successful_trades += 1;
                        state.total_profit_usd += profit;
                        
                        info!("💰 Position closed successfully!");
                        info!("📊 Entry: ${:.6} | Exit: ${:.6}", entry_price, current_price);
                        info!("💵 Profit: ${:.2}", profit);
                        info!("🔗 Transaction: {}", signature);
                        
                        return true;
                    }
                }
                Err(e) => {
                    let mut state = self.state.write();
                    if let Some(position) = state.positions.get_mut(token_address) {
                        position.sell_attempts += 1;
                        error!("Sell attempt {} failed: {}", position.sell_attempts, e);
                    }
                    drop(state);
                    sleep(Duration::from_secs(1)).await;
                }
            }
        }

        // Handle backoff
        let mut state = self.state.write();
        if let Some(position) = state.positions.get_mut(token_address) {
            position.backoff_count += 1;
            if position.backoff_count >= 3 {
                position.status = PositionStatus::Closed {
                    reason: "FAILED".to_string(),
                    exit_price: current_price,
                };
                state.failed_trades += 1;
                state.total_trades += 1;
                error!("❌ All sell attempts exhausted for {}", token_address);
                return true;
            }

            info!("⏳ Backing off for 30 seconds (backoff {}/3)", position.backoff_count);
            position.sell_attempts = 0;
        }
        drop(state);
        
        sleep(Duration::from_secs(30)).await;
        false
    }

    async fn handle_new_token(&self, token_address: String) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        if self.state.read().positions.len() >= MAX_POSITIONS {
            info!("⚠️ Max positions ({}) reached, skipping {}", MAX_POSITIONS, token_address);
            return Ok(());
        }

        match self.validate_token(&token_address).await {
            Ok(true) => {
                info!("✅ Token {} passed validation", token_address);
                
                for attempt in 1..=3 {
                    info!("📍 Buy attempt {} for {}", attempt, token_address);
                    
                    match self.execute_trade(true, &token_address, 5_000_000).await {
                        Ok(signature) => {
                            if let Ok(entry_price) = self.get_token_price(&token_address).await {
                                let position = Position {
                                    token_address: token_address.clone(),
                                    entry_price,
                                    quantity: 5_000_000,
                                    entry_time: Utc::now(),
                                    sell_attempts: 0,
                                    backoff_count: 0,
                                    last_price: entry_price,
                                    status: PositionStatus::Active,
                                };

                                {
                                    let mut state = self.state.write();
                                    state.positions.insert(token_address.clone(), position);
                                }
                                
                                info!("✅ Entry successful for {}:", token_address);
                                info!("💰 Entry Price: ${:.6}", entry_price);
                                info!("🔗 Transaction: {}", signature);

                                let bot = self.clone();
                                let addr = token_address.clone();
                                tokio::spawn(async move {
                                    bot.monitor_position(addr).await;
                                });
                                
                                return Ok(());
                            }
                        }
                        Err(e) => {
                            error!("❌ Buy attempt {} failed: {}", attempt, e);
                            if attempt < 3 {
                                info!("⏳ Waiting before retry...");
                                sleep(Duration::from_millis(100)).await;
                            }
                        }
                    }
                }
                
                error!("❌ All buy attempts failed for {}", token_address);
            }
            Ok(false) => {
                debug!("Token {} failed validation", token_address);
            }
            Err(e) => {
                error!("Error validating token {}: {}", token_address, e);
            }
        }

        Ok(())
    }

    async fn maintain_websocket_connection(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        info!("🔄 Starting WebSocket connection manager");
        
        loop {
            let ws_url = format!(
                "{}?api-key={}", 
                HELIUS_WS, 
                std::env::var("HELIUS_API_KEY")?
            );
    
            info!("📡 Connecting to WebSocket...");
            
            match connect_async(&ws_url).await {
                Ok((ws_stream, _)) => {
                    let (mut write, mut read) = ws_stream.split();
                    
                    // Send initial subscription
                    let subscription = json!({
                        "jsonrpc": "2.0",
                        "id": 1,
                        "method": "subscribePool",
                        "params": [
                            "LIQUIDITY_POOL",
                            {
                                "accountId": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
                                "tokenMetadata": true
                            }
                        ]
                    });
    
                    if let Err(e) = write.send(Message::Text(subscription.to_string())).await {
                        error!("Failed to send subscription: {}", e);
                        sleep(RECONNECT_DELAY).await;
                        continue;
                    }
    
                    info!("✅ WebSocket connected and subscribed");
    
                    // Use a channel for keepalive messages
                    let (tx, mut rx) = tokio::sync::mpsc::channel(32);
                    
                    // Spawn keepalive task
                    let tx_clone = tx.clone();
                    let keepalive = tokio::spawn(async move {
                        let mut interval = tokio::time::interval(KEEPALIVE_INTERVAL);
                        loop {
                            interval.tick().await;
                            let ping = json!({
                                "jsonrpc": "2.0",
                                "method": "ping",
                                "params": [],
                                "id": "keepalive"
                            });
                            
                            if tx_clone.send(Message::Text(ping.to_string())).await.is_err() {
                                break;
                            }
                        }
                    });
    
                    // Message processing loop
                    loop {
                        tokio::select! {
                            // Handle incoming messages
                            Some(msg_result) = read.next() => {
                                match msg_result {
                                    Ok(msg) => {
                                        match msg {
                                            Message::Text(text) => {
                                                if let Ok(data) = serde_json::from_str::<Value>(&text) {
                                                    if let Some(token_mint) = data["params"]["result"]["tokenMint"].as_str() {
                                                        let token_address = token_mint.to_string();
                                                        let bot = self.clone();
                                                        tokio::spawn(async move {
                                                            if let Err(e) = bot.handle_new_token(token_address).await {
                                                                error!("Error processing token: {}", e);
                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                            Message::Close(_) => break,
                                            _ => {}
                                        }
                                    }
                                    Err(e) => {
                                        error!("WebSocket error: {}", e);
                                        break;
                                    }
                                }
                            }
                            // Handle keepalive messages
                            Some(msg) = rx.recv() => {
                                if let Err(e) = write.send(msg).await {
                                    error!("Failed to send keepalive: {}", e);
                                    break;
                                }
                                debug!("💓 Keepalive sent");
                            }
                            else => break
                        }
                    }
    
                    keepalive.abort();
                    info!("Connection dropped, reconnecting...");
                }
                Err(e) => {
                    error!("Failed to connect: {}", e);
                }
            }
    
            sleep(RECONNECT_DELAY).await;
            info!("🔄 Attempting reconnection...");
        }
    }

    // Helper methods for trading
    async fn get_quote(&self, input_mint: &str, output_mint: &str, amount: u64) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
        let url = format!(
            "{}/quote?inputMint={}&outputMint={}&amount={}&slippageBps=1000&onlyDirectRoutes=true",
            JUPITER_API, input_mint, output_mint, amount
        );
        
        Ok(self.client.get(&url).send().await?.json().await?)
    }

    async fn get_token_price(&self, token_address: &str) -> Result<f64, Box<dyn std::error::Error + Send + Sync>> {
        let quote = self.get_quote(token_address, SOL_MINT, 1_000_000).await?;
        Ok(quote["price"].as_str().unwrap_or("0").parse()?)
    }

    async fn get_pool_liquidity(&self, token_address: &str) -> Result<f64, Box<dyn std::error::Error + Send + Sync>> {
        let request = json!({
            "jsonrpc": "2.0",
            "id": "get-pool",
            "method": "getAsset",
            "params": {
                "id": token_address,
                "displayOptions": {
                    "showPoolAnalytics": true
                }
            }
        });

        let response = self.client
            .post(HELIUS_RPC)
            .header("Authorization", format!("Bearer {}", std::env::var("HELIUS_API_KEY")?))
            .json(&request)
            .send()
            .await?
            .json::<Value>()
            .await?;

        Ok(response["result"]["pools"][0]["liquidity"].as_f64().unwrap_or(0.0))
    }

    async fn send_priority_tx(&self, swap_data: String) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
        let request = json!({
            "jsonrpc": "2.0",
            "id": "helius-priority",
            "method": "sendTransaction",
            "params": [
                swap_data,
                {
                    "encoding": "base64",
                    "maxRetries": 0,
                    "skipPreflight": true,
                    "priorityFee": PRIORITY_FEE
                }
            ]
        });

        let response = self.client
            .post(HELIUS_RPC)
            .header("Authorization", format!("Bearer {}", std::env::var("HELIUS_API_KEY")?))
            .json(&request)
            .send()
            .await?
            .json::<Value>()
            .await?;

        match response.get("result") {
            Some(result) => Ok(result.as_str().unwrap_or_default().to_string()),
            None => {
                error!("No result in response: {:?}", response);
                Err("No result in response".into())
            }
        }
    }

    fn spawn_metrics_display(&self) -> JoinHandle<()> {
        let state = self.state.clone();
        tokio::spawn(async move {
            let mut interval = tokio::time::interval(Duration::from_secs(1));
            loop {
                interval.tick().await;
                let state_data = state.read();
                
                println!("\x1B[2J\x1B[1;1H"); // Clear screen
                println!("╔═══════ BOT METRICS ═══════╗");
                println!("║ Active Positions: {:8} ║", state_data.positions.len());
                println!("║ Total Trades: {:11} ║", state_data.total_trades);
                println!("║ Successful: {:13} ║", state_data.successful_trades);
                println!("║ Failed: {:17} ║", state_data.failed_trades);
                println!("║ Total Profit: ${:10.2} ║", state_data.total_profit_usd);
                println!("╠═══════ POSITIONS ════════╣");
                
                for (addr, pos) in state_data.positions.iter() {
                    let profit_pct = (pos.last_price - pos.entry_price) / pos.entry_price * 100.0;
                    println!("║ {:10}... {:6.2}% ║", &addr[..10], profit_pct);
                }
                
                println!("╚══════════════════════════╝");
            }
        })
    }

    fn spawn_state_saver(&self) -> JoinHandle<()> {
        let state = self.state.clone();
        tokio::spawn(async move {
            let mut interval = tokio::time::interval(Duration::from_secs(30));
            loop {
                interval.tick().await;
                if let Err(e) = Self::save_state_to_file(&state.read()) {
                    error!("Failed to save state: {}", e);
                }
            }
        })
    }

    async fn start(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        info!("🚀 Starting trading bot...");

        // Spawn metrics display and state saver
        let metrics_display = self.spawn_metrics_display();
        let state_saver = self.spawn_state_saver();

        // Maintain WebSocket connection with automatic recovery
        let result = self.maintain_websocket_connection().await;

        // Cleanup
        metrics_display.abort();
        state_saver.abort();
        self.save_state()?;

        result
    }

    // State management methods
    fn save_state(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        Self::save_state_to_file(&self.state.read())
    }

    fn save_state_to_file(state: &BotState) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        let json = serde_json::to_string_pretty(state)?;
        fs::write("bot_state.json", json)?;
        Ok(())
    }

    fn load_state() -> Result<BotState, Box<dyn std::error::Error + Send + Sync>> {
        let contents = fs::read_to_string("bot_state.json")?;
        Ok(serde_json::from_str(&contents)?)
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    // Load environment variables
    dotenv::dotenv().ok();
    
    // Create bot instance
    let bot = TradingBot::new().await?;
    
    // Handle graceful shutdown
    let shutdown_sender = bot.shutdown.clone();
    tokio::spawn(async move {
        if tokio::signal::ctrl_c().await.is_ok() {
            info!("Shutdown signal received");
            let _ = shutdown_sender.send(());
        }
    });

    // Start the bot
    if let Err(e) = bot.start().await {
        error!("Bot error: {}", e);
    }
    
    info!("Bot shutting down...");
    bot.save_state()?;
    info!("Final state saved. Goodbye!");
    
    Ok(())
}   2m2024-10-31T12:00:00.518233Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m110:[0m 🚀 Initializing trading bot...
[2m2024-10-31T12:00:00.518384Z[0m [33m WARN[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m119:[0m Unable to load state: missing field `positions` at line 11 column 1. Creating new state.
[2m2024-10-31T12:00:00.518401Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m136:[0m 🔑 Loading keypair...
[2m2024-10-31T12:00:00.518439Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m144:[0m ✅ Keypair loaded successfully
[2m2024-10-31T12:00:00.518611Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m459:[0m 🚀 Starting trading bot...
[2m2024-10-31T12:00:00.642542Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m661:[0m Bot error: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:00:00.642575Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m664:[0m Bot shutting down...
[2m2024-10-31T12:00:00.642709Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m666:[0m Final state saved. Goodbye!
[2m2024-10-31T12:00:04.887431Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m110:[0m 🚀 Initializing trading bot...
[2m2024-10-31T12:00:04.887549Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m115:[0m 📝 Loaded existing state
[2m2024-10-31T12:00:04.887557Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m136:[0m 🔑 Loading keypair...
[2m2024-10-31T12:00:04.887584Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m144:[0m ✅ Keypair loaded successfully
[2m2024-10-31T12:00:04.887644Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m459:[0m 🚀 Starting trading bot...
[2m2024-10-31T12:00:04.979591Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m661:[0m Bot error: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:00:04.979610Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m664:[0m Bot shutting down...
[2m2024-10-31T12:00:04.979752Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m666:[0m Final state saved. Goodbye!
[2m2024-10-31T12:22:24.653655Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m111:[0m 🚀 Initializing trading bot...
[2m2024-10-31T12:22:24.653786Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m116:[0m 📝 Loaded existing state
[2m2024-10-31T12:22:24.653793Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m137:[0m 🔑 Loading keypair...
[2m2024-10-31T12:22:24.653824Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m145:[0m ✅ Keypair loaded successfully
[2m2024-10-31T12:22:24.653898Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m748:[0m 🚀 Starting trading bot...
[2m2024-10-31T12:22:24.653916Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m518:[0m 🔄 Starting WebSocket connection manager
[2m2024-10-31T12:22:24.653926Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:24.775302Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:25.792549Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:25.792574Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:25.867049Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:26.871387Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:26.871414Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:26.971752Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:27.981098Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:27.981119Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:28.584009Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:29.585046Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:29.585105Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:29.666585Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:30.677238Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:30.677268Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:30.764676Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:31.775392Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:31.775420Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:31.859733Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:32.875042Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:32.875066Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:32.956610Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:33.959364Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:33.959853Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:34.037888Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:35.039569Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:35.039610Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:35.127145Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:36.142241Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:36.142277Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:36.223447Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:37.224962Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:37.224995Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:37.298628Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:38.308021Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:38.308076Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:38.396288Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:39.405482Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:39.405509Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:39.486001Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:40.502823Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:40.502848Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:40.585155Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:41.590892Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:41.590947Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:41.678247Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:42.691742Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:42.691767Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:42.771078Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:43.776384Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:43.776407Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:43.863054Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:44.869850Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:44.869878Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:44.944677Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:45.950093Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:45.950120Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:46.040081Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:47.043314Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:47.043341Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:47.128021Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:48.141616Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:48.141648Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:48.224731Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:49.226053Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:49.226078Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:49.305505Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:50.307863Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:50.307933Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:50.387569Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:51.389290Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:51.389352Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:51.472037Z[0m [31mERROR[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m624:[0m Failed to connect: HTTP error: 522 <unknown status code>
[2m2024-10-31T12:22:52.484701Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m629:[0m 🔄 Attempting reconnection...
[2m2024-10-31T12:22:52.484726Z[0m [32m INFO[0m main ThreadId(01) [2msolana_rust_bot[0m[2m:[0m [2msrc/main.rs[0m[2m:[0m[2m527:[0m 📡 Connecting to WebSocket...
[2m2024-10-31T12:22:52.570723Z[0m [31mERROR[0m main ThreadId(01) [2msolan