sparkstartconsulting / IBKR-API-Rust

Port of Interactive Broker's trading API written in Rust
MIT License
126 stars 39 forks source link

Write request in initial connect method, breaks on read-only mode #24

Closed zakpatterson closed 3 years ago

zakpatterson commented 3 years ago

I'm working through your code now, thanks for making this project, so sorry if I just haven't found the right way to construct a client yet that can do this.

  let wrapper: Arc<Mutex<TestWrapper<TcpStreamer>>> = Arc::new(Mutex::new(TestWrapper::new()));
  let app = Arc::new(Mutex::new(EClient::new(wrapper.clone())));

  println!("getting connection...");

  wrapper.lock().expect("Wrapper mutex was poisoned").client = Option::from(app.clone());

  app
    .lock()
    .expect("EClient mutex was poisoned")
    .connect("192.168.0.118", 7555, 0)?;

That connect call throws a bunch of errors if the API is in read-only mode:


["4", "2", "-1", "2104", "Market data farm connection is OK:usfarm.nj"]["4", "2", "-1", "2104", "Market data farm connection is OK:cashfarm"]["4", "2", "-1", "2104", "Market data farm connection is OK:usfarm"]["4", "2", "-1", "2106", "HMDS data farm connection is OK:euhmds"]["4", "2", "-1", "2106", "HMDS data farm connection is OK:cashhmds"]["4", "2", "-1", "2106", "HMDS data farm connection is OK:fundfarm"]["4", "2", "-1", "2106", "HMDS data farm connection is OK:ushmds"]["4", "2", "-1", "2158", "Sec-def data farm connection is OK:secdefnj"]["4", "2", "2147483647", "321", "Error validating request.-\'cB\' : cause - The API interface is currently in Read-Only mode."]...

It is unexpected that the initial connect call would require write access. Happy to work on this if desired.

sparkstartconsulting commented 3 years ago

Yes, that is expected if you are using the TestWrapper. It starts sending a lot of test requests upon connecting. You can use TestWrapper as a starting point, and just send the requests you are interested in when connecting (ones that are ok to send in read-only mode). Edit the start_requests method in TestWrapper to change the requests being sent, for your own testing.

And, what you really want to do is just have your own code be responsible for sending any requests, instead of automatically sending requests immediately upon connecting, through your own implementation of the Wrapper trait (you can use TestWrapper as a guide there).

zakpatterson commented 3 years ago

You know, that makes sense, sorry. Didn't mean to make a support question. Appreciate that, I'll close thanks.

sparkstartconsulting commented 3 years ago

By the way, all the data farm messages are ok. TWS Api reports status in addition to actual errors through their error apis

zakpatterson commented 3 years ago

By the way, all the data farm messages are ok. TWS Api reports status in addition to actual errors through their error apis

Yeah, the main error was ["4", "2", "2", "321", "Error validating request.-\'bO\' : cause - The API interface is currently in Read-Only mode."], which came in 50 times or so. I'll proceed with implementing my own Wrapper