• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wboayue / rust-ibapi / 18546784772

16 Oct 2025 12:48AM UTC coverage: 80.487% (+0.002%) from 80.485%
18546784772

push

github

web-flow
feat: allow blocking client alongside async (#321)

* feat: allow blocking client alongside async

* fix: align sync docs and news cancellation

* fix: isolate order update stream tracking

* docs: enforce all-feature documentation coverage

* docs: enable prelude doctests

91 of 136 new or added lines in 13 files covered. (66.91%)

4 existing lines in 1 file now uncovered.

6579 of 8174 relevant lines covered (80.49%)

101.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/orders/builder/sync_impl.rs
1
use super::{BracketOrderBuilder, BracketOrderIds, OrderBuilder, OrderId};
2
use crate::client::sync::Client;
3
use crate::contracts::Contract;
4
use crate::errors::Error;
5
use crate::orders;
6

7
#[cfg(test)]
8
mod tests;
9

10
impl<'a> OrderBuilder<'a, Client> {
11
    /// Submit the order synchronously
12
    /// Returns the order ID assigned to the submitted order
13
    pub fn submit(self) -> Result<OrderId, Error> {
×
14
        let client = self.client;
×
15
        let contract = self.contract;
×
16
        let order_id = client.next_order_id();
×
17
        let order = self.build()?;
×
NEW
18
        orders::blocking::submit_order(client, order_id, contract, &order)?;
×
19
        Ok(OrderId::new(order_id))
×
20
    }
21

22
    /// Build the order and return it without submitting
23
    /// Useful for batch operations or custom submission logic
24
    pub fn build_order(self) -> Result<crate::orders::Order, Error> {
×
25
        self.build().map_err(Into::into)
×
26
    }
27

28
    /// Analyze order for margin/commission (what-if)
29
    pub fn analyze(mut self) -> Result<crate::orders::OrderState, Error> {
×
30
        self.what_if = true;
×
31
        let client = self.client;
×
32
        let contract = self.contract;
×
33
        let order_id = client.next_order_id();
×
34
        let order = self.build()?;
×
35

36
        // Submit what-if order and get the response
NEW
37
        let responses = orders::blocking::place_order(client, order_id, contract, &order)?;
×
38

39
        // Look for the order state in the responses
40
        for response in responses {
×
41
            if let crate::orders::PlaceOrder::OpenOrder(order_data) = response {
×
42
                if order_data.order_id == order_id {
×
43
                    return Ok(order_data.order_state);
×
44
                }
45
            }
46
        }
47

48
        Err(Error::Simple("What-if analysis did not return order state".to_string()))
×
49
    }
50
}
51

52
impl<'a> BracketOrderBuilder<'a, Client> {
53
    /// Submit bracket orders synchronously
54
    /// Returns BracketOrderIds containing all three order IDs
55
    pub fn submit_all(self) -> Result<BracketOrderIds, Error> {
×
56
        let client = self.parent_builder.client;
×
57
        let contract = self.parent_builder.contract;
×
58
        let base_id = client.next_order_id();
×
59
        let orders = self.build()?;
×
60

61
        let mut order_ids = Vec::new();
×
62

63
        for (i, mut order) in orders.into_iter().enumerate() {
×
64
            let order_id = base_id + i as i32;
×
65
            order.order_id = order_id;
×
66
            order_ids.push(order_id);
×
67

68
            // Update parent_id for child orders
69
            if i > 0 {
×
70
                order.parent_id = base_id;
×
71
            }
72

73
            // Only transmit the last order
74
            if i == 2 {
×
75
                order.transmit = true;
×
76
            }
77

NEW
78
            orders::blocking::submit_order(client, order_id, contract, &order)?;
×
79
        }
80

81
        Ok(BracketOrderIds::new(order_ids[0], order_ids[1], order_ids[2]))
×
82
    }
83
}
84

85
/// Extension trait for submitting multiple OCA orders
86
impl Client {
87
    /// Submit multiple OCA (One-Cancels-All) orders
88
    ///
89
    /// When one order in the group is filled, all others are automatically cancelled.
90
    ///
91
    /// # Example
92
    /// ```no_run
93
    /// use ibapi::client::blocking::Client;
94
    /// use ibapi::contracts::Contract;
95
    ///
96
    /// let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
97
    ///
98
    /// let contract1 = Contract::stock("AAPL").build();
99
    /// let contract2 = Contract::stock("MSFT").build();
100
    ///
101
    /// let order1 = client.order(&contract1)
102
    ///     .buy(100)
103
    ///     .limit(50.0)
104
    ///     .oca_group("MyOCA", 1)
105
    ///     .build_order().expect("order build failed");
106
    ///     
107
    /// let order2 = client.order(&contract2)
108
    ///     .buy(100)
109
    ///     .limit(45.0)
110
    ///     .oca_group("MyOCA", 1)
111
    ///     .build_order().expect("order build failed");
112
    ///
113
    /// let order_ids = client.submit_oca_orders(
114
    ///     vec![(contract1, order1), (contract2, order2)]
115
    /// ).expect("OCA submission failed");
116
    /// ```
117
    pub fn submit_oca_orders(&self, orders: Vec<(Contract, crate::orders::Order)>) -> Result<Vec<OrderId>, Error> {
×
118
        let mut order_ids = Vec::new();
×
119
        let base_id = self.next_order_id();
×
120

121
        for (i, (contract, mut order)) in orders.into_iter().enumerate() {
×
122
            let order_id = base_id + i as i32;
×
123
            order.order_id = order_id;
×
124
            order_ids.push(OrderId::new(order_id));
×
NEW
125
            orders::blocking::submit_order(self, order_id, &contract, &order)?;
×
126
        }
127

128
        Ok(order_ids)
×
129
    }
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc