diff --git a/src/main.rs b/src/main.rs index a9b7604..1ca705c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,13 @@ use tokio::{ use crate::bot::Bot; async fn shutdown_listener(bot: Arc, tx: watch::Sender) -> anyhow::Result<()> { - let stdin = BufReader::new(io::stdin()); - let mut lines = stdin.lines(); + loop { + let mut stdin = BufReader::new(io::stdin()); + + let mut line = String::new(); + + stdin.read_line(&mut line).await?; - while let Ok(Some(line)) = lines.next_line().await { match line.to_lowercase().trim() { "exit" | "shutdown" => { let _ = tx.send(true); @@ -33,9 +36,13 @@ async fn shutdown_listener(bot: Arc, tx: watch::Sender) -> anyhow::Re let filename = format!("sol-hun-{}.csv", formatted_time); + let trade_log = bot.trade_log.lock().await; + + log::info!("Saving {} trades", trade_log.len()); + let mut writer = csv::Writer::from_path(&filename)?; - for trade in bot.trade_log.lock().await.iter() { + for trade in trade_log.iter() { writer.serialize(trade)?; } @@ -47,8 +54,6 @@ async fn shutdown_listener(bot: Arc, tx: watch::Sender) -> anyhow::Re _ => {} } } - - Ok(()) } #[tokio::main] diff --git a/src/strategy/veloc.rs b/src/strategy/veloc.rs index 229983f..0a061f3 100644 --- a/src/strategy/veloc.rs +++ b/src/strategy/veloc.rs @@ -179,8 +179,6 @@ impl Strategy for MomentumVelocityStrategy { if let Some(mut pos) = self.positions.remove(mint) { pos.trade.close(current_price, reason); - info!("TRADE RESULT: {:?}", pos.trade); - bot.trade_log.lock().await.push(pos.trade); }