0

I'm trying to write a rust program that interfaces with Binance's REST API. The link to the documentation is here. The problem is that I'm sending a POST request with reqwest, a rust crate, but simply receive {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."} as the response. The body's supposed to be empty, as per the documentation.

let final_url = "https://api.binance.com/api/v3/userDataStream".to_string(); 
            let client = reqwest::blocking::Client::new();
            let response: Value = client.post(&final_url)
                .body("")
                .header("X-MBX-APIKEY", api_key)
                .send().unwrap()
                .json().unwrap();
            println!("response: {}", response);

api_key in this case is just a string containing the key(which I'm sure is correct, but who knows). I've done everything from creating new API keys to just trying the secret key instead of the API key, but nothing's been giving.

user3167679
  • 51
  • 1
  • 7
  • Shouldn't the header come before the body? – Jmb Jun 24 '20 at 06:24
  • I'd get a command working with CURL on the command line first without Rust. Once you have that working, it should be more straightforward. – Ian Jun 24 '20 at 07:45
  • @Ian oddly, the command itself doesn't work on curl either. It's probably an issue with the key itself, so I'll try looking into it more. – user3167679 Jun 25 '20 at 01:07

1 Answers1

2

I'm in the United States, so the base endpoint that I had to be using was api.binance.us. The first line had to be:

let final_url = "https://api.binance.us/api/v3/userDataStream".to_string(); 
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user3167679
  • 51
  • 1
  • 7