Julia API Call to Alpaca trading receives HTTP/1.1 401 Unauthorized
First time asking a question here. Hoping I do this right!
I've recently heard of Alpaca for algorithmic trading, and thought it would be a cool opportunity to learn Julia and try to get an algo working! Super excited, but running into some trouble getting the initial API call to work.
I'm hung up on the initial API HTTP request for authorization. My account is set up and approved. I've been able to get it to work with the Python library: alpaca-trade-api, but have not had luck with a simple Julia HTTP GET request. Same keys, same domain, but Julia gives an "unauthorized" error.
Link to API documentation:
https://docs.alpaca.markets/web-api/
Here's the code I'm using:
using HTTP
using JSON
key = Dict("APCA-API-KEY-ID" => "my_key")
secret_key = Dict("APCA-API-SECRET-KEY" => "my_secret_key")
params = merge(key,secret_key)
base_url = "https://paper-api.alpaca.markets"
endpoint = "/v1/account"
url = base_url * endpoint
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json"],
JSON.json(params)
)
And I get the error:
"code":40110000,"message":"access key verification failed : access key not found (Code = 40110000)
Unsure if it has to do with the format in which I'm submitting my keys, but I've tried just using the dictionary as the argument, or defining "headers=params" and that didn't work either. Same error.
Curious if anyone else has experience with getting Alpaca working with Julia, or has insight into why this wouldn't be working.
api http julia-lang unauthorized alpacajs
add a comment |
First time asking a question here. Hoping I do this right!
I've recently heard of Alpaca for algorithmic trading, and thought it would be a cool opportunity to learn Julia and try to get an algo working! Super excited, but running into some trouble getting the initial API call to work.
I'm hung up on the initial API HTTP request for authorization. My account is set up and approved. I've been able to get it to work with the Python library: alpaca-trade-api, but have not had luck with a simple Julia HTTP GET request. Same keys, same domain, but Julia gives an "unauthorized" error.
Link to API documentation:
https://docs.alpaca.markets/web-api/
Here's the code I'm using:
using HTTP
using JSON
key = Dict("APCA-API-KEY-ID" => "my_key")
secret_key = Dict("APCA-API-SECRET-KEY" => "my_secret_key")
params = merge(key,secret_key)
base_url = "https://paper-api.alpaca.markets"
endpoint = "/v1/account"
url = base_url * endpoint
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json"],
JSON.json(params)
)
And I get the error:
"code":40110000,"message":"access key verification failed : access key not found (Code = 40110000)
Unsure if it has to do with the format in which I'm submitting my keys, but I've tried just using the dictionary as the argument, or defining "headers=params" and that didn't work either. Same error.
Curious if anyone else has experience with getting Alpaca working with Julia, or has insight into why this wouldn't be working.
api http julia-lang unauthorized alpacajs
add a comment |
First time asking a question here. Hoping I do this right!
I've recently heard of Alpaca for algorithmic trading, and thought it would be a cool opportunity to learn Julia and try to get an algo working! Super excited, but running into some trouble getting the initial API call to work.
I'm hung up on the initial API HTTP request for authorization. My account is set up and approved. I've been able to get it to work with the Python library: alpaca-trade-api, but have not had luck with a simple Julia HTTP GET request. Same keys, same domain, but Julia gives an "unauthorized" error.
Link to API documentation:
https://docs.alpaca.markets/web-api/
Here's the code I'm using:
using HTTP
using JSON
key = Dict("APCA-API-KEY-ID" => "my_key")
secret_key = Dict("APCA-API-SECRET-KEY" => "my_secret_key")
params = merge(key,secret_key)
base_url = "https://paper-api.alpaca.markets"
endpoint = "/v1/account"
url = base_url * endpoint
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json"],
JSON.json(params)
)
And I get the error:
"code":40110000,"message":"access key verification failed : access key not found (Code = 40110000)
Unsure if it has to do with the format in which I'm submitting my keys, but I've tried just using the dictionary as the argument, or defining "headers=params" and that didn't work either. Same error.
Curious if anyone else has experience with getting Alpaca working with Julia, or has insight into why this wouldn't be working.
api http julia-lang unauthorized alpacajs
First time asking a question here. Hoping I do this right!
I've recently heard of Alpaca for algorithmic trading, and thought it would be a cool opportunity to learn Julia and try to get an algo working! Super excited, but running into some trouble getting the initial API call to work.
I'm hung up on the initial API HTTP request for authorization. My account is set up and approved. I've been able to get it to work with the Python library: alpaca-trade-api, but have not had luck with a simple Julia HTTP GET request. Same keys, same domain, but Julia gives an "unauthorized" error.
Link to API documentation:
https://docs.alpaca.markets/web-api/
Here's the code I'm using:
using HTTP
using JSON
key = Dict("APCA-API-KEY-ID" => "my_key")
secret_key = Dict("APCA-API-SECRET-KEY" => "my_secret_key")
params = merge(key,secret_key)
base_url = "https://paper-api.alpaca.markets"
endpoint = "/v1/account"
url = base_url * endpoint
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json"],
JSON.json(params)
)
And I get the error:
"code":40110000,"message":"access key verification failed : access key not found (Code = 40110000)
Unsure if it has to do with the format in which I'm submitting my keys, but I've tried just using the dictionary as the argument, or defining "headers=params" and that didn't work either. Same error.
Curious if anyone else has experience with getting Alpaca working with Julia, or has insight into why this wouldn't be working.
api http julia-lang unauthorized alpacajs
api http julia-lang unauthorized alpacajs
edited Nov 20 at 5:38
asked Nov 20 at 5:20
MJ F.
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I just resolved a similar issue using PyLiveTrader, although that uses a config.yaml for the API keys. I was able to solve it by using the proper syntax for yaml (four spaces after colon), as well as making sure that I was using the paper key when using the paper base_url (originally I had the regular base_url). Best of luck! (I'm very new to this, so sorry if this isn't helpful).
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
add a comment |
From the linked documentation, you see the corresponding curl command:
curl -X GET
-H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://{apiserver_domain}/v1/account
The option -H, means header. So the keys must go in the header, i.e. the 3rd parameter of HTTP.request
(https://juliaweb.github.io/HTTP.jl/stable/index.html#Requests-1):
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json",
"APCA-API-KEY-ID => "YOUR_API_KEY_ID",
"APCA-API-SECRET-KEY => "YOUR_API_SECRET_KEY" ]
)
You should replace YOUR_API_KEY_ID
and YOUR_API_SECRET_KEY
by your credientials.
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386668%2fjulia-api-call-to-alpaca-trading-receives-http-1-1-401-unauthorized%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I just resolved a similar issue using PyLiveTrader, although that uses a config.yaml for the API keys. I was able to solve it by using the proper syntax for yaml (four spaces after colon), as well as making sure that I was using the paper key when using the paper base_url (originally I had the regular base_url). Best of luck! (I'm very new to this, so sorry if this isn't helpful).
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
add a comment |
I just resolved a similar issue using PyLiveTrader, although that uses a config.yaml for the API keys. I was able to solve it by using the proper syntax for yaml (four spaces after colon), as well as making sure that I was using the paper key when using the paper base_url (originally I had the regular base_url). Best of luck! (I'm very new to this, so sorry if this isn't helpful).
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
add a comment |
I just resolved a similar issue using PyLiveTrader, although that uses a config.yaml for the API keys. I was able to solve it by using the proper syntax for yaml (four spaces after colon), as well as making sure that I was using the paper key when using the paper base_url (originally I had the regular base_url). Best of luck! (I'm very new to this, so sorry if this isn't helpful).
I just resolved a similar issue using PyLiveTrader, although that uses a config.yaml for the API keys. I was able to solve it by using the proper syntax for yaml (four spaces after colon), as well as making sure that I was using the paper key when using the paper base_url (originally I had the regular base_url). Best of luck! (I'm very new to this, so sorry if this isn't helpful).
answered Nov 20 at 8:28
user10678933
461
461
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
add a comment |
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
Thanks for your suggestions! At first I didn't know how applicable your response was because you were using a different config/content type. But turns out your paper-trading account comment turned out to be on the right track! I had to generate new keys for my paper account... dumb looking back on it. Should have read the instructions a bit more carefully. But thanks! You helped turn me onto the solution :)
– MJ F.
Nov 21 at 17:19
add a comment |
From the linked documentation, you see the corresponding curl command:
curl -X GET
-H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://{apiserver_domain}/v1/account
The option -H, means header. So the keys must go in the header, i.e. the 3rd parameter of HTTP.request
(https://juliaweb.github.io/HTTP.jl/stable/index.html#Requests-1):
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json",
"APCA-API-KEY-ID => "YOUR_API_KEY_ID",
"APCA-API-SECRET-KEY => "YOUR_API_SECRET_KEY" ]
)
You should replace YOUR_API_KEY_ID
and YOUR_API_SECRET_KEY
by your credientials.
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
add a comment |
From the linked documentation, you see the corresponding curl command:
curl -X GET
-H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://{apiserver_domain}/v1/account
The option -H, means header. So the keys must go in the header, i.e. the 3rd parameter of HTTP.request
(https://juliaweb.github.io/HTTP.jl/stable/index.html#Requests-1):
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json",
"APCA-API-KEY-ID => "YOUR_API_KEY_ID",
"APCA-API-SECRET-KEY => "YOUR_API_SECRET_KEY" ]
)
You should replace YOUR_API_KEY_ID
and YOUR_API_SECRET_KEY
by your credientials.
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
add a comment |
From the linked documentation, you see the corresponding curl command:
curl -X GET
-H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://{apiserver_domain}/v1/account
The option -H, means header. So the keys must go in the header, i.e. the 3rd parameter of HTTP.request
(https://juliaweb.github.io/HTTP.jl/stable/index.html#Requests-1):
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json",
"APCA-API-KEY-ID => "YOUR_API_KEY_ID",
"APCA-API-SECRET-KEY => "YOUR_API_SECRET_KEY" ]
)
You should replace YOUR_API_KEY_ID
and YOUR_API_SECRET_KEY
by your credientials.
From the linked documentation, you see the corresponding curl command:
curl -X GET
-H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://{apiserver_domain}/v1/account
The option -H, means header. So the keys must go in the header, i.e. the 3rd parameter of HTTP.request
(https://juliaweb.github.io/HTTP.jl/stable/index.html#Requests-1):
api = HTTP.request(
"GET",
url,
["Content-Type" => "application/json",
"APCA-API-KEY-ID => "YOUR_API_KEY_ID",
"APCA-API-SECRET-KEY => "YOUR_API_SECRET_KEY" ]
)
You should replace YOUR_API_KEY_ID
and YOUR_API_SECRET_KEY
by your credientials.
answered Nov 20 at 11:24
Alex338207
922510
922510
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
add a comment |
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
Thanks for your response! I gave that a shot and received the same error. At this point I'm incredibly confused as to why I can't figure out how to send this HTTP request via Julia, but it works in Python... I did also try using the "POST" method instead of "GET" and I receive a "404 Not Found" error. Any additional help would be super appreciated! I wonder if it has something to do with how Julia is formatting the headers dictionary as the first comment eludes to. I've tried converting to json and it hasn't worked.
– MJ F.
Nov 21 at 8:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386668%2fjulia-api-call-to-alpaca-trading-receives-http-1-1-401-unauthorized%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown