WebSocket connection to 'wss://stream.data.alpaca.markets/v1beta2/crypto' failed:

when i try to stream data though websocket Real-time Data | Alpaca Docs
WebSocket() - Web APIs | MDN

const url = “wss://stream.data.alpaca.markets/v1beta2/crypto”;

const socket = new WebSocket(url);

console.log(socket);

it not show success message but
it shows
WebSocket connection to 'wss://stream.data.alpaca.markets/v1beta2/crypto' failed: Error during WebSocket handshake: Unexpected response code: 403
what should i do ??

1 Like

I’m having the same issue. Did you ever get this resolved?

1 Like

Same here. Couldn’t find an answer to this problem anywhere. Works fine with wscat, but not in firefox browser.

1 Like

i just change url to wss://stream.data.sandbox.alpaca.markets/v2/{source}

it also work with crypto.

1 Like
const url = 'wss://stream.data.sandbox.alpaca.markets/v1beta2/crypto';
const socket = new WebSocket(url);

Still get a 403 forbidden error

Hi all,

You need to authenticate after opening the WS connection.

For the WebSocket example in JavaScript.

You can add these lines to send a message after opening the connection. The message contains the API keys in the format the API expects for an auth message.

socket.onopen = function(e) {
  socket.send( 
    {"action": "auth", "key": "{KEY_ID}", "secret": "{SECRET}"}
  );
};

Read the docs for more info:

1 Like

The connection is refused so it doesn’t get a “socket.onopen” message. It just fails on “new WebSocket(url);”.

Do you get the issue on the non-sandbox endpoint?

wss://stream.data.alpaca.markets/v1beta2/crypto

Yes, exactly the same

startfrom0.js:3 WebSocket connection to ‘wss://stream.data.alpaca.markets/v1beta1/crypto’ failed:

Some idea what is going on?
Was just going to buy the paid subscription but all my test started failing…

This issue has been fixed. It should work now :slight_smile:

1 Like

Yup! Seems to be working now. Thank you for the help.

I am having issues to with ‘auth failed’ when connecting to non-crypto streaming websocket… in python I am doing:

conn = Stream(ALPACA_API_KEY,
              ALPACA_SECRET_KEY,
              data_stream_url=URL(
              "wss://stream.data.sandbox.alpaca.markets"),
              data_feed='iex',
              websocket_params={'ping_interval': 5})

With the same credentials that work for live streaming but when changing data_stream_url to ‘sandbox’ I just get repeated ‘auth failed’. Otherwise it connect fine (with live url for data_streaming_url) without me sending any kind of auth action. What am I doing wrong?