ibtwsapi/
lib.rs

1//! Lib for sending requests to and processing responses from Interactive Broker's Trader Workstation or IB Gateway
2//!
3//! For usage of this library, please see the example implementation in [src/examples/test_helpers/manual_tests.rs](https://github.com/sparkstartconsulting/IBKR-API-Rust/blob/fix_docs_add_tests/src/examples/test_helpers/manual_tests.rs)
4//!
5//! The main structs and traits that clients will use are [**EClient**](https://github.com/sparkstartconsulting/IBKR-API-Rust/blob/fix_docs_add_tests/src/core/client.rs) , a struct that is responsible for
6//! connecting to TWS or IB Gateway and sending requests,  and [**Wrapper**](https://github.com/sparkstartconsulting/IBKR-API-Rust/blob/fix_docs_add_tests/src/core/wrapper.rs), a trait that clients will implement that declares callback functions
7//! that get called when the application receives messages from the server.
8//!
9//! In the example below, TWS will send the next valid order ID when the sample application connects.  This will cause the ***Wrapper*** callback method
10//! ***next_valid_id*** to be called, which will start sending test requests to TWS (see the
11//! ***start_requests*** method in ***TestWrapper*** which is called by ***next_valid_id***).
12//!
13//! ```no_run        
14//! use log::*;
15//! use std::thread;
16//! use std::time::Duration;
17//! use ibtwsapi::core::errors::*;
18//! use ibtwsapi::examples::example_wrapper::ExampleWrapper;
19//!
20//! /// Example of using client and wrapper.
21//! /// Requires a running instance of TWS or IB Gateway connected to the port in main.
22//! /// Upon connecting, TWS will send the next valid order ID which will cause the wrapper callback method
23//! /// next_valid_id to be called, which will start sending tests requests to TWS (see the
24//! /// start_requests function in ExampleWrapper which is called by next_valid_id
25//! //==================================================================================================
26//!pub fn main() -> Result<(), IBKRApiLibError> {
27//!    match log4rs::init_file("./log_config.yml", Default::default()) {
28//!        Ok(_) => (),
29//!        Err(e) => {
30//!            println!("Error: {}", e.to_string());
31//!            return Err(IBKRApiLibError::ApiError(TwsApiReportableError::new(
32//!                -1,
33//!                "-1".to_string(),
34//!                "Failed to create logger!!".to_string(),
35//!            )))
36//!        }
37//!    };
38//!
39//!    let mut app = ExampleWrapper::new();
40//!
41//!    info!("getting connection...");
42//!
43//!    //use port 7497 for TWS or 4002 for IB Gateway, depending on the port you have set
44//!    app.client.connect("127.0.0.1", 4002, 0)?;
45//!    loop {
46//!        match app.process_event() {
47//!            Ok(_) => continue,
48//!            Err(e) =>
49//!            {
50//!                error!("{}", e.to_string());
51//!                break ();
52//!            },
53//!        };
54//!    }
55//!    thread::sleep(Duration::new(2, 0));
56//!
57//!    Ok(())
58//!}
59//! ```     
60pub mod core;
61pub mod examples;
62mod tests;