diff --git a/src/trading/core/executor.rs b/src/trading/core/executor.rs index b58c277..0e3184e 100755 --- a/src/trading/core/executor.rs +++ b/src/trading/core/executor.rs @@ -48,7 +48,7 @@ impl TradeExecutor for GenericTradeExecutor { .instruction_builder .build_buy_instructions(¶ms) .await?; - timer.stage("买入交易指令"); + timer.stage("构建rpc交易指令"); // 构建交易 let transaction = build_rpc_transaction( @@ -60,7 +60,7 @@ impl TradeExecutor for GenericTradeExecutor { params.data_size_limit, ) .await?; - timer.stage("买入交易签名"); + timer.stage("rpc提交确认"); // 发送交易 rpc.send_and_confirm_transaction(&transaction).await?; @@ -73,7 +73,7 @@ impl TradeExecutor for GenericTradeExecutor { if params.data_size_limit == 0 { params.data_size_limit = MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT; } - let mut timer = TradeTimer::new("构建买入交易指令"); + let timer = TradeTimer::new("构建买入交易指令"); // 验证参数 - 转换为BuyParams进行验证 let buy_params = BuyParams { @@ -95,7 +95,8 @@ impl TradeExecutor for GenericTradeExecutor { .instruction_builder .build_buy_instructions(&buy_params) .await?; - timer.stage("买入交易指令"); + + timer.finish(); // 并行执行交易 parallel_execute_with_tips( @@ -110,7 +111,6 @@ impl TradeExecutor for GenericTradeExecutor { ) .await?; - timer.finish(); Ok(()) } @@ -147,7 +147,7 @@ impl TradeExecutor for GenericTradeExecutor { } async fn sell_with_tip(&self, params: SellWithTipParams) -> Result<()> { - let mut timer = TradeTimer::new("构建卖出交易指令"); + let timer = TradeTimer::new("构建卖出交易指令"); // 转换为SellParams进行指令构建 let sell_params = SellParams { @@ -168,7 +168,8 @@ impl TradeExecutor for GenericTradeExecutor { .instruction_builder .build_sell_instructions(&sell_params) .await?; - timer.stage("卖出交易指令"); + + timer.finish(); // 并行执行交易 parallel_execute_with_tips( @@ -183,7 +184,6 @@ impl TradeExecutor for GenericTradeExecutor { ) .await?; - timer.finish(); Ok(()) } diff --git a/src/trading/core/parallel.rs b/src/trading/core/parallel.rs index 9f378ad..057a742 100755 --- a/src/trading/core/parallel.rs +++ b/src/trading/core/parallel.rs @@ -7,6 +7,7 @@ use tokio::task::JoinHandle; use crate::{ common::PriorityFee, swqos::{SwqosType, SwqosClient, TradeType}, + trading::core::timer::TradeTimer, trading::common::{ build_rpc_transaction, build_sell_tip_transaction_with_priority_fee, build_sell_transaction, build_tip_transaction_with_priority_fee, @@ -36,6 +37,9 @@ pub async fn parallel_execute_with_tips( let handle = tokio::spawn(async move { core_affinity::set_for_current(core_id); + + let mut timer = TradeTimer::new(format!("构建交易指令: {:?}", swqos_client.get_swqos_type())); + let transaction = if matches!(trade_type, TradeType::Sell) && swqos_client.get_swqos_type() == SwqosType::Default { @@ -88,9 +92,13 @@ pub async fn parallel_execute_with_tips( .await? }; + timer.stage(format!("提交交易指令: {:?}", swqos_client.get_swqos_type())); + swqos_client .send_transaction(trade_type, &transaction) .await?; + + timer.finish(); Ok::<(), anyhow::Error>(()) }); diff --git a/src/trading/core/timer.rs b/src/trading/core/timer.rs index 7ab481c..3841fe8 100755 --- a/src/trading/core/timer.rs +++ b/src/trading/core/timer.rs @@ -1,6 +1,7 @@ use std::time::Instant; /// 交易时间测量器 +#[derive(Clone)] pub struct TradeTimer { start_time: Instant, stage: String, @@ -25,9 +26,10 @@ impl TradeTimer { } /// 完成计时并输出最终耗时 - pub fn finish(self) { + pub fn finish(mut self) { let elapsed = self.start_time.elapsed(); println!(" {} 耗时: {:?}", self.stage, elapsed); + self.stage.clear(); // 清空stage,避免Drop时重复打印 } /// 获取当前阶段的耗时(不重置计时器)