Using Javascript, I’m able to successfully query Alpaca Market Data from ‘https://data.alpaca.markets/v1’ with fetch(). I’m now trying to implement websocket streaming using Socket.IO, but I keep getting 404 errors with whatever I try.
The code I’m using:
var url = 'wss://data.alpaca.markets/stream';
var params = {
'action': 'authenticate',
'data': {
'key_id': ALPACA_API_KEY_ID,
'secret_key': ALPACA_API_SECRET_KEY
}
}
For the actual connection event I’ve tried all of the following, because I’m not entirely sure how I’m supposed to be passing the handshake data. Each of the following returns a 404 error:
var socket = io(url);
var socket = io(url, { query: params });
var socket = io(url, { query: JSON.stringify(params) });
I’ve tried a number of other tweaks to various things in an attempt to get it to work, but every response I get is a 404. Any help on troubleshooting this is appreciated. I know there’s an Alpaca JS library that could be used, but I’d like to get this working without that, if possible.
Thanks