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

MJ F.

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.

user10678933

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Postman Google API request gives "401: Unauthorized"

Using Google Calendar API returns 401 (unauthorized)

Call web api with basic authentication always get 401 unauthorized from IIS

Web API 2: Random 401 unauthorized on POST

JHipster: Receive 401 Unauthorized when making API call to microservice

401 Unauthorized on Google Photos API with API Key

401 unauthorized github api

Google API with GoogleSignIn - Error 401 - unauthorized

401 Unauthorized error Binance API in r

401 Unauthorized For the Post Method in WooCommerce API

OAuth1 reject_token 401 unauthorized

Partner Central rest api 401 unauthorized access

jQuery Ajax Web API call returns 401 unauthorized error when set only Windows authentication in IIS

jBPM Business Central rest api 401 unauthorized

Reactjs how to call magento 2 api with bearer (the server responded with a status of 401 (unauthorized))

Getting error 401 - unauthorized with google API

Kubernetes client python API error 401 - Unauthorized

401 Unauthorized Request Discord API with OAuth

Python Linkedin API OAuth2 HTTP Error 401: Unauthorized

401 Unauthorized on dropbox API

Solr HTTP error: Unauthorized (401)

"HTTP Error 401: Unauthorized" when querying youtube api for playlist with python

getting HTTP Status 401 - unauthorized user error for ebayclassifeids Api

Unauthorized (HTTP 401) R omdbapi

Jujucharms API error 401 unauthorized

Axios with OMDB API, getting 401 Unauthorized

I receive a status 401 error: Unauthorized when i attempt to call my Secured API by keycloak

Angular Rest API call returning 401 Unauthorized

Getting 401 unauthorized status in an API