sparkstartconsulting / IBKR-API-Rust

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

Error when using TSLA in historical_data_operations_req() #30

Open virtualritz opened 3 years ago

virtualritz commented 3 years ago

I changed the example contract_samples::simple_future() for TSLA in historical_data_operations_req() like so:

pub fn historical_data_operations_req(&self) -> Result<(), IBKRApiLibError> {
        // Requesting historical data

        let contract = Contract {
            symbol: "TSLA".to_string(),
            sec_type: "STK".to_string(),
            exchange: "SMART".to_string(),
            currency: "USD".to_string(),
            ..Default::default()
        };

        self.client
            .as_ref()
            .unwrap()
            .try_lock()
            .unwrap()
            .req_head_time_stamp(
                4101,
                &contract,
                "TRADES",
                0,
                1,
            )?;

        let dt = Utc::now();
        let query_time = dt.format("%Y%m%d %H:%M:%S").to_string();
        info!("Request Time:  {}", query_time);

        self.client
            .as_ref()
            .expect(CLIENT_IS_NONE)
            .lock()
            .expect(CLIENT_POISONED_MUTEX)
            .req_historical_data(
                4102,
                &contract,
                query_time.as_str(),
                "60 D",
                "1 day",
                "MIDPOINT",
                1,
                1,
                false,
                vec![],
            )?;

        self.client
            .as_ref()
            .expect(CLIENT_IS_NONE)
            .lock()
            .expect(CLIENT_POISONED_MUTEX)
            .req_historical_data(
                4103,
                &contract,
                query_time.as_str(),
                "10 D",
                "1 min",
                "TRADES",
                1,
                1,
                false,
                vec![],
            )?;

        self.client
            .as_ref()
            .expect(CLIENT_IS_NONE)
            .lock()
            .expect(CLIENT_POISONED_MUTEX)
            .req_historical_data(
                4104,
                &contract,
                "",
                "1 M",
                "1 day",
                "MIDPOINT",
                1,
                1,
                true,
                vec![],
            )?;

        Ok(())
    }

What I get is No market data permissions for ISLAND STK for each of the three req_historical_data() calls. Only the req_head_time_stamp() calls succeeds:

2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3403 INFO - fundamental_data -- req_id: 4101, delta_neutral_contract: 20100629  08:00:00
2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4102 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK
2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4103 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK
2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4104 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK

I tried the same from the Python ib sync API and it works. What am I missing here?

sparkstartconsulting commented 3 years ago

Hey Moritz,

I have some really aggressive deadlines in the projects I manage right now and have to put every waking hour into seeing those through. I hope to get to both your code review and questions soon. With a lot of your questions, I would need to investigate myself to see what is going on, and I just don't have the time right now, but I hope to soon, because I would like to keep this project alive.

Thanks for your patience

On Mon, Oct 4, 2021 at 12:15 PM Moritz Mœller @.***> wrote:

I changed the example contract_samples::simple_future() for TSLA in historical_data_operations_req() like so:

pub fn historical_data_operations_req(&self) -> Result<(), IBKRApiLibError> { // Requesting historical data

    let contract = Contract {
        symbol: "TSLA".to_string(),
        sec_type: "STK".to_string(),
        exchange: "SMART".to_string(),
        currency: "USD".to_string(),
        ..Default::default()
    };

    self.client
        .as_ref()
        .unwrap()
        .try_lock()
        .unwrap()
        .req_head_time_stamp(
            4101,
            &contract,
            "TRADES",
            0,
            1,
        )?;

    let dt = Utc::now();
    let query_time = dt.format("%Y%m%d %H:%M:%S").to_string();
    info!("Request Time:  {}", query_time);

    self.client
        .as_ref()
        .expect(CLIENT_IS_NONE)
        .lock()
        .expect(CLIENT_POISONED_MUTEX)
        .req_historical_data(
            4102,
            &contract,
            query_time.as_str(),
            "60 D",
            "1 day",
            "MIDPOINT",
            1,
            1,
            false,
            vec![],
        )?;

    self.client
        .as_ref()
        .expect(CLIENT_IS_NONE)
        .lock()
        .expect(CLIENT_POISONED_MUTEX)
        .req_historical_data(
            4103,
            &contract,
            query_time.as_str(),
            "10 D",
            "1 min",
            "TRADES",
            1,
            1,
            false,
            vec![],
        )?;

    self.client
        .as_ref()
        .expect(CLIENT_IS_NONE)
        .lock()
        .expect(CLIENT_POISONED_MUTEX)
        .req_historical_data(
            4104,
            &contract,
            "",
            "1 M",
            "1 day",
            "MIDPOINT",
            1,
            1,
            true,
            vec![],
        )?;

    Ok(())
}

What I get is No market data permissions for ISLAND STK for each of the three req_historical_data() calls. Only the req_head_time_stamp() calls succeeds:

2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3403 INFO - fundamental_data -- req_id: 4101, delta_neutral_contract: 20100629 08:00:00 2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4102 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK 2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4103 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK 2021-10-04 18:06:29 twsapi::examples::test_helpers src/examples/test_helpers.rs line: 3038 ERROR - req_id: 4104 ,error_code: 162 , error_string:Historical Market Data Service error message:No market data permissions for ISLAND STK

I tried the same from the Python ib sync API and it works. What am I missing here?

— 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/30, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSKV5FIHVSXO6GDC3W732LUFHHLDANCNFSM5FJXZODA . 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 3 years ago

Hey, no worries. I don't depend on the working atm. Just made a ticket so it doesn't fall through the cracks.