Julia API Call to Alpaca trading receives HTTP/1.1 401 Unauthorized
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
up vote
2
down vote
accepted
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 |
up vote
2
down vote
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 |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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 |
up vote
2
down vote
accepted
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 |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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
361
361
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 |
up vote
2
down vote
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 |
up vote
2
down vote
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 |
up vote
2
down vote
up vote
2
down vote
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
912510
912510
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