Alpaca Authentication with Qt Issue

I’m developing a desktop trading app and am targeting Alpaca first. Specifically, I’m having issues creating the proper HTTP GET header request to do authentication using the Qt framework. Anyone with Qt experience?

Here’s the a few examples I’ve tried and am getting code 40110000.

// 1
QUrl res(ALPACA_AUTH);
QNetworkRequest req(res);
req.setHeader(QNetworkRequest::ContentTypeHeader, “APCA-API-KEY-ID: BLAH”);
req.setHeader(QNetworkRequest::ContentTypeHeader, “APCA-API-SECRET-KEY: BLAHBLAH”);
man->executeAuthentication(req);

// 2
QUrl res(ALPACA_AUTH);
QNetworkRequest req(res);
req.setRawHeader("APCA-API-KEY-ID: ", “BLAH”);
req.setRawHeader("APCA-API-SECRET-KEY: ", “BLAHBLAH”);
man->executeAuthentication(req);

I’ve looked at This Stack Overflow Post and This Other Stack Overflow Post, but I’m still not getting it.

Thanks for any help!

Josh

1 Like

what endpoint url?..

https://paper-api.alpaca.markets/v2/account is the endpoint I’m testing with, so I’m using my paper account API key pairs.

Josh

I was able to use the curl -H option with my key pairs to successfully authenticate and get a return via terminal. Did that on my mac.

Not very familiar with Qt, but is there any way to dump the raw HTTP request in text for debug purpose?

I’ve been trying that, but it’s not been that helpful since I can’t print out everything like you’d think. I can print out the URL and Raw headers fine and they look like what I set.

One thing I’ve notices is that with cURL, there is no header name specified, but Qt does want you to provide that each time I call setRawHeader().

I got it finally, used the curl -v option to have curl print out all its details which gave me some clues.

Here’s the final solution:

QUrl res(ALPACA_AUTH);
QNetworkRequest req(res);
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setRawHeader("APCA-API-KEY-ID",  "BLAH");
req.setRawHeader("APCA-API-SECRET-KEY", "BLAHBLAH");

What actually really did it was removing the colon from the “APCA-API-KEY-ID” parts!

2 Likes