From 95445f8c5f361eb99aae84e86c05174fef10700c Mon Sep 17 00:00:00 2001 From: Wil Boayue Date: Thu, 7 Nov 2024 23:11:00 -0800 Subject: [PATCH 1/3] checkpoint --- src/client.rs | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 84c9bd6e..36bb0c94 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1569,10 +1569,42 @@ impl Debug for Client { } } -/// Server sends data until not required -/// Supports the handling of responses from TWS. -/// Cancelled with dropped if not already cancelled. +/// Subscriptions facilitate handling responses from TWS that may be delayed or delivered periodically. +/// +/// They offer both blocking and non-blocking methods for retrieving data. +/// +/// In the simplest case a subscription can be implicitly converted to blocking iterator +/// that cancels the subscription when it goes out of scope. /// +/// ```no_run +/// use ibapi::contracts::Contract; +/// use ibapi::market_data::realtime::{BarSize, WhatToShow}; +/// use ibapi::Client; +/// +/// fn main() { +/// let connection_url = "127.0.0.1:4002"; +/// let client = Client::connect(connection_url, 100).expect("connection to TWS failed!"); +/// +/// // Request real-time bars data for AAPL with 5-second intervals +/// let contract = Contract::stock("AAPL"); +/// let subscription = client +/// .realtime_bars(&contract, BarSize::Sec5, WhatToShow::Trades, false) +/// .expect("realtime bars request failed!"); +/// +/// // Use the subscription as a blocking iterator +/// for bar in subscription { +/// // Process each bar here (e.g., print or use in calculations) +/// println!("Received bar: {bar:?}"); +/// } +/// // The subscription is automatically cancelled when it goes out of scope +/// } +/// ``` +/// +/// Subscriptions can be explicitly canceled using the [cancel](Subscription::cancel) method. +/// +/// You can convert subscriptions into blocking or non-blocking iterators using the [iter](Subscription::iter), [try_iter](Subscription::try_iter) or [timeout_iter](Subscription::timeout_iter) methods. +/// +/// Alternatively, you may poll subscriptions in a blocking or non-blocking manner using the [next](Subscription::next), [try_next](Subscription::try_next) or [next_timeout](Subscription::next_timeout) methods. #[allow(private_bounds)] #[derive(Debug)] pub struct Subscription<'a, T: DataStream> { @@ -1746,10 +1778,6 @@ impl<'a, T: DataStream> Subscription<'a, T> { SubscriptionIter { subscription: self } } - pub fn into_iter(self) -> SubscriptionOwnedIter<'a, T> { - SubscriptionOwnedIter { subscription: self } - } - pub fn try_iter(&self) -> SubscriptionTryIter { SubscriptionTryIter { subscription: self } } From 45f543aa9cc69bad94f754f7665acbc9e08ef083 Mon Sep 17 00:00:00 2001 From: Wil Boayue Date: Thu, 7 Nov 2024 23:16:55 -0800 Subject: [PATCH 2/3] merge main --- src/client.rs | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/client.rs b/src/client.rs index eaa667e9..7559f455 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1570,9 +1570,9 @@ impl Debug for Client { } /// Subscriptions facilitate handling responses from TWS that may be delayed or delivered periodically. -/// +/// /// They offer both blocking and non-blocking methods for retrieving data. -/// +/// /// In the simplest case a subscription can be implicitly converted to blocking iterator /// that cancels the subscription when it goes out of scope. /// @@ -1580,30 +1580,28 @@ impl Debug for Client { /// use ibapi::contracts::Contract; /// use ibapi::market_data::realtime::{BarSize, WhatToShow}; /// use ibapi::Client; -/// -/// fn main() { -/// let connection_url = "127.0.0.1:4002"; -/// let client = Client::connect(connection_url, 100).expect("connection to TWS failed!"); -/// -/// // Request real-time bars data for AAPL with 5-second intervals -/// let contract = Contract::stock("AAPL"); -/// let subscription = client -/// .realtime_bars(&contract, BarSize::Sec5, WhatToShow::Trades, false) -/// .expect("realtime bars request failed!"); -/// -/// // Use the subscription as a blocking iterator -/// for bar in subscription { -/// // Process each bar here (e.g., print or use in calculations) -/// println!("Received bar: {bar:?}"); -/// } -/// // The subscription is automatically cancelled when it goes out of scope +/// +/// let connection_url = "127.0.0.1:4002"; +/// let client = Client::connect(connection_url, 100).expect("connection to TWS failed!"); +/// +/// // Request real-time bars data for AAPL with 5-second intervals +/// let contract = Contract::stock("AAPL"); +/// let subscription = client +/// .realtime_bars(&contract, BarSize::Sec5, WhatToShow::Trades, false) +/// .expect("realtime bars request failed!"); +/// +/// // Use the subscription as a blocking iterator +/// for bar in subscription { +/// // Process each bar here (e.g., print or use in calculations) +/// println!("Received bar: {bar:?}"); /// } +/// // The subscription is automatically cancelled when it goes out of scope /// ``` -/// +/// /// Subscriptions can be explicitly canceled using the [cancel](Subscription::cancel) method. -/// +/// /// You can convert subscriptions into blocking or non-blocking iterators using the [iter](Subscription::iter), [try_iter](Subscription::try_iter) or [timeout_iter](Subscription::timeout_iter) methods. -/// +/// /// Alternatively, you may poll subscriptions in a blocking or non-blocking manner using the [next](Subscription::next), [try_next](Subscription::try_next) or [next_timeout](Subscription::next_timeout) methods. #[allow(private_bounds)] #[derive(Debug)] From e56d7674211b675372f22ca80c3d95731bd43c7a Mon Sep 17 00:00:00 2001 From: Wil Boayue Date: Thu, 7 Nov 2024 23:20:21 -0800 Subject: [PATCH 3/3] fixed iter --- src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 7559f455..12d7a7ae 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1850,7 +1850,7 @@ impl<'a, T: DataStream + 'a> IntoIterator for Subscription<'a, T> { type IntoIter = SubscriptionOwnedIter<'a, T>; fn into_iter(self) -> Self::IntoIter { - self.into_iter() + SubscriptionOwnedIter { subscription: self } } }