Julia API Call to Alpaca trading receives HTTP/1.1 401 Unauthorized












1














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.










share|improve this question





























    1














    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.










    share|improve this question



























      1












      1








      1


      1





      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 5:38

























      asked Nov 20 at 5:20









      MJ F.

      83




      83
























          2 Answers
          2






          active

          oldest

          votes


















          3














          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).






          share|improve this answer





















          • 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



















          2














          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.






          share|improve this answer





















          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          3














          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).






          share|improve this answer





















          • 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
















          3














          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).






          share|improve this answer





















          • 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














          3












          3








          3






          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).






          share|improve this answer












          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).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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













          2














          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.






          share|improve this answer





















          • 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
















          2














          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.






          share|improve this answer





















          • 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














          2












          2








          2






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?