alpacahq / alpaca-ts

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
ISC License
154 stars 42 forks source link

Authentication issue #23

Closed drixie closed 3 years ago

drixie commented 3 years ago

There's something wrong with how the credentials object is being handled. i am not skilled enough to troubleshoot and debug. I am using the official SDK with no authentication issues.

drixie commented 3 years ago

Does not work for both AlpacaClient and AlpacaStream

117 commented 3 years ago

Can you show me an error or something to work with? Does this occur when trying a certain endpoint? I don't know where to begin without more information.

drixie commented 3 years ago

It occurs on all endpoints, since each endpoint requires authentication. I supplied the credentials and other parameters as outlined in the readme.

This is the error from AlpacaClient: { code: 40110000, message: 'access key verification failed : access key not found (Code = 40110000)' }

This is the error from AlpacaStream: Error: There was an error in authorizing your websocket connection. Object received: { "stream": "authorization", "data": { "action": "authenticate", "message": "must provide key_id and secret_key or oauth_token", "status": "unauthorized" } }

117 commented 3 years ago

Are you certain the paper: true/false field matches the key type you are using?

const client = new AlpacaClient({
  credentials: {
    key: 'PK8Z6I3DLEFDZR******',
    secret: 'QDDi0TSUCqT6WCnVluXEZyNB6FtITp3KqE******',
  },
  paper: true,
  rate_limit: true,
})

client
  .getAccount()
  .then((account) =>
    console.log(`account has $${account.buying_power} buying_power`)
  )

Console output:

account has $200418.44 buying_power

The above is working for me.

drixie commented 3 years ago

I got it resolved. It's not a bug in your lib. The issue came from the way my env vars was set up as I had my key and secret stored in .env.

Thanks for the support :)