whats wrong with this scipt use { anyhow::{anyhow, Result},…
- User
whats wrong with this scipt use { anyhow::{anyhow, Result}, base64::{engine::general_purpose::STANDARD as base64_engine, Engine}, chrono::Utc, colored::*, futures_util::{SinkExt, StreamExt}, log::{debug, error, info, warn}, reqwest::Client as HttpClient, serde::{Deserialize, Serialize}, serde_json::{json, Value}, solana_client::{ rpc_client::RpcClient, rpc_request::TokenAccountsFilter, }, solana_sdk::{ commitment_config::CommitmentConfig, pubkey::Pubkey, signature::{Keypair, Signer}, transaction::Transaction, }, std::{ collections::HashMap, fs, str::FromStr, sync::Arc, time::{Duration, Instant}, }, tokio::{ net::TcpStream, sync::Mutex, time::{interval, sleep}, }, tokio_tungstenite::{ tungstenite::protocol::Message as WsMessage, WebSocketStream, MaybeTlsStream, }, };
// Constants const HELIUS_RPC: &str = "https://marga-e56m84-fast-mainnet.helius-rpc.com"; const HELIUS_WS: &str = "wss://marga-e56m84-fast-mainnet.helius-rpc.com"; const HELIUS_API_KEY: &str = "your-api-key"; const RAYDIUM_PROGRAM_ID: &str = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"; const WSOL_MINT: &str = "So11111111111111111111111111111111111111112"; const JUPITER_V6_API: &str = "https://quote-api.jup.ag/v6"; const MIN_PRIORITY_FEE: u64 = 10_000; const MAX_RETRIES: u8 = 3; const RETRY_DELAY_MS: u64 = 500; const MIN_LIQUIDITY_USD: f64 = 50.0; const MAX_LIQUIDITY_USD: f64 = 20_000.0; const TAKE_PROFIT: f64 = 20.0; const STOP_LOSS: f64 = -3.0; const TRADE_SIZE_SOL: f64 = 0.01;
#[derive(Clone)] struct Bot { rpc_client: Arc, http_client: HttpClient, keypair: Arc, active_trades: Arc<Mutex<HashMap<String, TradeState>>>, market_data: Arc<Mutex<HashMap<String, MarketData>>>, config: Config, }
#[derive(Clone, Debug)] pub struct Config { pub rpc_url: String, pub ws_url: String, pub fallback_ws: String, pub helius_api_key: String, }
#[derive(Debug, Clone, Serialize, Deserialize)] struct TradeState { token_address: String, entry_price: f64, amount: u64, timestamp: i64, take_profit_price: f64, stop_loss_price: f64, status: TradeStatus, attempts: u8, }
#[derive(Debug, Clone, Serialize, Deserialize)] enum TradeStatus { Active, PendingBuy, PendingSell, Completed, Failed(String), }
#[derive(Debug, Clone, Serialize, Deserialize)] struct MarketData { liquidity: f64, volume_24h: f64, price: f64, last_update: i64, }
pub struct BotMonitor { bot: Arc, } impl Bot { pub async fn new(config: Config, keypair: Keypair) -> Result { println!( "{}", "🚀 Initializing Professional Trading Engine" .bright_green() .bold() );
code - Assistant