ibapi/config/async.rs
1//! Asynchronous implementation of configuration retrieval.
2
3use crate::{
4 common::request_helpers::{self, expect_proto},
5 protocol::{check_version, Features},
6 Client, Error,
7};
8
9use super::builder::UpdateConfigBuilder;
10use super::{common::decoders, encoders, Config};
11
12impl Client {
13 /// Reads the TWS/Gateway configuration (API, precautions, orders, and
14 /// lock-and-exit settings) the gateway is currently running with.
15 ///
16 /// This is a read-only snapshot; fields the gateway does not report are
17 /// left as `None`.
18 ///
19 /// # Examples
20 ///
21 /// ```no_run
22 /// use ibapi::prelude::*;
23 ///
24 /// #[tokio::main]
25 /// async fn main() {
26 /// let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
27 /// let config = client.config().await.expect("request config failed");
28 /// println!("{config:?}");
29 /// }
30 /// ```
31 pub async fn config(&self) -> Result<Config, Error> {
32 check_version(self.server_version(), Features::CONFIG)?;
33
34 request_helpers::one_shot_by_request_id(self, encoders::encode_request_config, expect_proto(decoders::decode_config_proto)).await
35 }
36
37 /// Begins a fluent [`UpdateConfigBuilder`] to edit the TWS/Gateway
38 /// configuration. Set only the groups you want to change and terminate with
39 /// [`submit`](UpdateConfigBuilder::submit).
40 ///
41 /// # Examples
42 ///
43 /// ```no_run
44 /// use ibapi::prelude::*;
45 /// use ibapi::config::{OrdersConfig, OrdersSmartRouting};
46 ///
47 /// #[tokio::main]
48 /// async fn main() {
49 /// let client = Client::connect("127.0.0.1:4002", 100).await.expect("connection failed");
50 ///
51 /// let response = client
52 /// .update_config()
53 /// .orders(OrdersConfig {
54 /// smart_routing: Some(OrdersSmartRouting {
55 /// seek_price_improvement: Some(true),
56 /// ..Default::default()
57 /// }),
58 /// })
59 /// .submit()
60 /// .await
61 /// .expect("update config failed");
62 /// println!("{response:?}");
63 /// }
64 /// ```
65 pub fn update_config(&self) -> UpdateConfigBuilder<'_, Client> {
66 UpdateConfigBuilder::new(self)
67 }
68}
69
70#[cfg(test)]
71#[path = "async_tests.rs"]
72mod tests;