sparkstartconsulting / IBKR-API-Rust

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

Issue with req_historical_data() #32

Closed virtualritz closed 2 years ago

virtualritz commented 2 years ago

I'm trying to use req_historical_data() with a future.

In test_helpers.rs, I replaced next_valid_id() with the code to generate the request to make this simpler to replicate:

    fn next_valid_id(&mut self, order_id: i32) {
        self.next_order_id = order_id;
        info!("next_valid_id -- order_id: {}", order_id);

        let order_id = self.next_order_id();
        let time_str = Utc::now().format("%Y%m%d %H:%M:%S");

        self.client
            .as_ref()
            .expect(CLIENT_IS_NONE)
            .lock()
            .expect(CLIENT_POISONED_MUTEX)
            .req_historical_data(
                order_id,
                &Contract {
                    symbol: "MNQ".to_string(),
                    sec_type: "FUT".to_string(),
                    exchange: "GLOBEX".to_string(),
                    last_trade_date_or_contract_month: "20211217".to_string(),
                    ..Default::default()
                },
                time_str.to_string().as_str(),
                "3 D",
                "30 secs",
                "TRADES",
                0,
                1,
                false,
                vec![],
            )
            .unwrap();
    }

The output I get is:

2021-10-11 19:14:10 twsapi_client src/bin/manual_tests.rs line: 32 INFO - getting connection...
2021-10-11 19:14:10 twsapi::core::client src/core/client.rs line: 118 INFO - Connecting
2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 171 INFO - Server version: 142
2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 186 INFO - Connected
2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 109 DEBUG - starting reader loop
2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 2598 INFO - Starting run...
2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1278 INFO - calling managed_accounts
2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3341 INFO - managed_accounts -- accounts_list: DF3987931,DU3987932,DU3987933,DU3987934,DU3987935,DU3987936,
2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1283 INFO - finished calling managed_accounts
2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3222 INFO - next_valid_id -- order_id: 1
2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2104 , error_string:Market data farm connection is OK:usfarm
2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2106 , error_string:HMDS data farm connection is OK:ushmds
2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed
2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed
2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed

The last message, more incoming packet(s) are needed, repeats infinitely.

sparkstartconsulting commented 2 years ago

I haven't had time to run this yet, but the

2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed

message is a normal message in debug mode. The reader thread is listening to the socket in a loop but is not getting any messages from IB. That will repeat forever until the connection is closed or a message from IB comes in through the socket

On Mon, Oct 11, 2021 at 1:19 PM Moritz Mœller @.***> wrote:

I'm trying to use req_historical_data() with a future.

In test_helpers.rs, I replaced next_valid_id() with the code to generate the request to make this simpler to replicate:

fn next_valid_id(&mut self, order_id: i32) {
    self.next_order_id = order_id;
    info!("next_valid_id -- order_id: {}", order_id);

    let order_id = self.next_order_id();
    let time_str = Utc::now().format("%Y%m%d %H:%M:%S");

    self.client
        .as_ref()
        .expect(CLIENT_IS_NONE)
        .lock()
        .expect(CLIENT_POISONED_MUTEX)
        .req_historical_data(
            order_id,
            &Contract {
                symbol: "MNQ".to_string(),
                sec_type: "FUT".to_string(),
                exchange: "GLOBEX".to_string(),
                last_trade_date_or_contract_month: "20211217".to_string(),
                ..Default::default()
            },
            time_str.to_string().as_str(),
            "3 D",
            "30 secs",
            "TRADES",
            0,
            1,
            false,
            vec![],
        )
        .unwrap();
}

The output I get is:

2021-10-11 19:14:10 twsapi_client src/bin/manual_tests.rs line: 32 INFO - getting connection... 2021-10-11 19:14:10 twsapi::core::client src/core/client.rs line: 118 INFO - Connecting 2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 171 INFO - Server version: 142 2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 186 INFO - Connected 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 109 DEBUG - starting reader loop 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 2598 INFO - Starting run... 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1278 INFO - calling managed_accounts 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3341 INFO - managed_accounts -- accounts_list: DF3987931,DU3987932,DU3987933,DU3987934,DU3987935,DU3987936, 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1283 INFO - finished calling managed_accounts 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3222 INFO - next_valid_id -- order_id: 1 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2104 , error_string:Market data farm connection is OK:usfarm 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2106 , error_string:HMDS data farm connection is OK:ushmds 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed

The last message, more incoming packet(s) are needed, repeats infinitely.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sparkstartconsulting/IBKR-API-Rust/issues/32, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSKV5HRC4WNSVY7C6G4CM3UGMMAPANCNFSM5FYWQ4TQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

virtualritz commented 2 years ago

Hmm, yeah. I just don't ever get any data with a contract like this. While the example calls to req_historical_data() in test_helper.rs seem to work just fine.

I thought there may be some issue related tp parsing that makes the reader thread believe it needs more packets to proceed.

sparkstartconsulting commented 2 years ago

Can you do this again and post simultaneous log messages from IB Gateway? It will be easier to diagnose if we know what is being done on the TWS side at the same time.

Sent from my iPhone

On Oct 14, 2021, at 12:37 AM, Brett Miller @.***> wrote:

 I haven't had time to run this yet, but the 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed

message is a normal message in debug mode. The reader thread is listening to the socket in a loop but is not getting any messages from IB. That will repeat forever until the connection is closed or a message from IB comes in through the socket

On Mon, Oct 11, 2021 at 1:19 PM Moritz Mœller @.***> wrote: I'm trying to use req_historical_data() with a future.

In test_helpers.rs, I replaced next_valid_id() with the code to generate the request to make this simpler to replicate:

fn next_valid_id(&mut self, order_id: i32) {
    self.next_order_id = order_id;
    info!("next_valid_id -- order_id: {}", order_id);

    let order_id = self.next_order_id();
    let time_str = Utc::now().format("%Y%m%d %H:%M:%S");

    self.client
        .as_ref()
        .expect(CLIENT_IS_NONE)
        .lock()
        .expect(CLIENT_POISONED_MUTEX)
        .req_historical_data(
            order_id,
            &Contract {
                symbol: "MNQ".to_string(),
                sec_type: "FUT".to_string(),
                exchange: "GLOBEX".to_string(),
                last_trade_date_or_contract_month: "20211217".to_string(),
                ..Default::default()
            },
            time_str.to_string().as_str(),
            "3 D",
            "30 secs",
            "TRADES",
            0,
            1,
            false,
            vec![],
        )
        .unwrap();
}

The output I get is:

2021-10-11 19:14:10 twsapi_client src/bin/manual_tests.rs line: 32 INFO - getting connection... 2021-10-11 19:14:10 twsapi::core::client src/core/client.rs line: 118 INFO - Connecting 2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 171 INFO - Server version: 142 2021-10-11 19:14:15 twsapi::core::client src/core/client.rs line: 186 INFO - Connected 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 109 DEBUG - starting reader loop 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 2598 INFO - Starting run... 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1278 INFO - calling managed_accounts 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3341 INFO - managed_accounts -- accounts_list: DF3987931,DU3987932,DU3987933,DU3987934,DU3987935,DU3987936, 2021-10-11 19:14:15 twsapi::core::decoder src/core/decoder.rs line: 1283 INFO - finished calling managed_accounts 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3222 INFO - next_valid_id -- order_id: 1 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2104 , error_string:Market data farm connection is OK:usfarm 2021-10-11 19:14:15 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3031 ERROR - req_id: -1 ,error_code: 2106 , error_string:HMDS data farm connection is OK:ushmds 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed 2021-10-11 19:14:15 twsapi::core::reader src/core/reader.rs line: 101 DEBUG - more incoming packet(s) are needed The last message, more incoming packet(s) are needed, repeats infinitely.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

virtualritz commented 2 years ago

There are no log messages from the gateway. I have Show API messages ticked but the only messages I see in my log during a run of the above are pings.

sparkstartconsulting commented 2 years ago

can you send the same thing through TWS and tell us the results?

On Thu, Oct 28, 2021 at 10:11 AM Moritz Mœller @.***> wrote:

There are no log messages from the gateway. I have Show API messages ticked but the only messages I see in my log during a run of the above are pings.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sparkstartconsulting/IBKR-API-Rust/issues/32#issuecomment-953886280, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSKV5C7UYOAHCLMZPWNK6TUJFRYRANCNFSM5FYWQ4TQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sparkstartconsulting commented 2 years ago

no further comments so closing.