You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to get real time quote for a stock, I get this error :
/Users/vivien/Documents/tradingapp/node_modules/ws/lib/websocket.js:394
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
^
Error: WebSocket is not open: readyState 0 (CONNECTING)
at WebSocket.send (/Users/vivien/Documents/tradingapp/node_modules/ws/lib/websocket.js:394:13)
at AlpacaStocksClient.authenticate (/Users/vivien/Documents/tradingapp/node_modules/@alpacahq/alpaca-trade-api/dist/resources/datav2/websocket.js:171:19)
at WebSocket.<anonymous> (/Users/vivien/Documents/tradingapp/node_modules/@alpacahq/alpaca-trade-api/dist/resources/datav2/websocket.js:108:43)
at Object.onceWrapper (node:events:509:28)
at WebSocket.emit (node:events:390:28)
at WebSocket.setSocket (/Users/vivien/Documents/tradingapp/node_modules/ws/lib/websocket.js:225:10)
at ClientRequest.<anonymous> (/Users/vivien/Documents/tradingapp/node_modules/ws/lib/websocket.js:882:15)
at ClientRequest.emit (node:events:390:28)
at TLSSocket.socketOnData (node:_http_client:527:11)
at TLSSocket.emit (node:events:390:28)
Here is my code:
const http = require('http');
const server = http.createServer(app);
const io = require('socket.io')(server);
const Alpaca = require('@alpacahq/alpaca-trade-api');
const alpaca = new Alpaca({
keyId: process.env.ALPACA_API_KEY_ID,
secretKey: process.env.ALPACA_API_SECRET_KEY,
paper: true,
});
io.on('connection', (socket) => {
console.log(`Client connected with ID: ${socket.id}`);
let stream = null;
socket.on('subscribe', (ticker) => {
console.log(`Subscribing to data for ${ticker}`);
const stream = alpaca.data_stream_v2;
stream.onConnect(function () {
console.log("Connected");
stream.subscribeForQuotes([(ticker)]);
});
stream.onStockQuote((quote) => {
console.log(quote);
socket.emit('stockData', quote);
});
stream.connect();
});
socket.on('disconnect', () => {
console.log(`Client disconnected with ID: ${socket.id}`);
if (stream) {
console.log(`Unsubscribing from data for ${stream.ticker}`);
stream.disconnect();
}
});
});
Expected Behavior
No response
SDK Version I encountered this issue in
"@alpacahq/alpaca-trade-api": "^2.16.1",
Steps To Reproduce
In nodejs, try to stream real time data from alpaca.
Filled out the Steps to Reproduce section?
I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current Behavior
When I try to get real time quote for a stock, I get this error :
Here is my code:
Expected Behavior
No response
SDK Version I encountered this issue in
Steps To Reproduce
Filled out the Steps to Reproduce section?
Anything else?
No response
The text was updated successfully, but these errors were encountered: