Skip to main content

ibapi/config/builder/
async_impl.rs

1//! Asynchronous `submit()` for the update-config builder.
2
3use super::update_config_builder::UpdateConfigBuilder;
4use crate::client::r#async::Client;
5use crate::common::request_helpers::{self, expect_proto};
6use crate::config::common::{decoders, encoders};
7use crate::config::UpdateConfigResponse;
8use crate::protocol::{check_version, Features};
9use crate::Error;
10
11impl UpdateConfigBuilder<'_, Client> {
12    /// Submit the configuration edit asynchronously.
13    ///
14    /// Returns the gateway's [`UpdateConfigResponse`]. If its `warnings` are
15    /// non-empty the edit was not applied — re-submit with each warning passed
16    /// to [`accept_warning`](UpdateConfigBuilder::accept_warning).
17    ///
18    /// # Examples
19    ///
20    /// ```no_run
21    /// use ibapi::prelude::*;
22    /// use ibapi::config::{ApiConfig, ApiSettings};
23    ///
24    /// #[tokio::main]
25    /// async fn main() {
26    ///     let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
27    ///
28    ///     let response = client
29    ///         .update_config()
30    ///         .api(ApiConfig {
31    ///             settings: Some(ApiSettings {
32    ///                 socket_port: Some(7497),
33    ///                 ..Default::default()
34    ///             }),
35    ///             ..Default::default()
36    ///         })
37    ///         .submit()
38    ///         .await
39    ///         .expect("update config failed");
40    ///     println!("{response:?}");
41    /// }
42    /// ```
43    pub async fn submit(self) -> Result<UpdateConfigResponse, Error> {
44        check_version(self.client.server_version(), Features::UPDATE_CONFIG)?;
45
46        request_helpers::one_shot_by_request_id(
47            self.client,
48            |request_id| encoders::encode_update_config(&self.to_proto(request_id)),
49            expect_proto(decoders::decode_update_config_proto),
50        )
51        .await
52    }
53}
54
55#[cfg(test)]
56#[path = "async_impl_tests.rs"]
57mod tests;