From c79aad7f3ae3fb049e1fa28a7a9ca9c6a046e2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Sat, 18 Nov 2023 14:19:51 -0800 Subject: [PATCH] Cancel orders concurrently Currently the cancellation of all open orders is done serially. However, there is no reason not to do so concurrently. With this change we use the try_for_each_concurrent() combinator to accomplish the same. --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 199d19c..b537be6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,6 +103,10 @@ use crate::args::Updates; type Str = Cow<'static, str>; +/// The maximum concurrency to use when issuing requests. +const MAX_CONCURRENCY: usize = 32; + + // A replacement of the standard println!() macro that does not panic // when encountering an EPIPE. macro_rules! println { @@ -1068,7 +1072,7 @@ async fn order_cancel(client: Client, cancel: CancelOrder) -> Result<()> { }) }) .collect::>() - .try_for_each(|()| ready(Ok(()))) + .try_for_each_concurrent(Some(MAX_CONCURRENCY), |()| ready(Ok(()))) .await }, }