-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: throw new Error('WebSocket is not open: readyState 0 (CONNECTING)'); #229
Comments
Can you add a code snippet on how you connect the WebSocket and also when/how you subscribe to stuff ? function initAlpaca() {
// Setup alpaca
let alpaca = new Alpaca({
keyId: 'PK...',
secretKey: 'EQ...',
paper: true,
})
// Get websocket for stock data
const stockStream = alpaca.data_stream_v2;
// Log errors
stockStream.onError(e => console.log(e))
// Run this function to execute stuff once connected, for instance subscribe to bars etc.
stockStream.onConnect(() => {
console.log("Alpaca connected!")
stockStream.subscribeForBars(["TSLA"])
})
// Process streamed data
stockStream.onStockBar(bar => console.log(bar))
// Trigger the websocket to connect
stockStream.connect()
} |
Also have the same error which is crash my application every day. Error log:
My code:
|
I'm just messing around with the node_modules right now, it looks like changing this code (from Old:
New:
It seems like, somehow, the socket has disconnected between emission of the I think there's a better way of doing this which doesn't involve constantly checking the websocket state, and instead just properly handling the disconnect instead by cancelling any pending authorization or pings or whatever else. However, I know next to nothing about this project's internals, so this is the best I have. |
Is there an existing issue for this?
Current Behavior
when i run node datav2.js
i got error
C:\Users\User\alpaca-trade-api-js\node_modules\ws\lib\websocket.js:394
Expected Behavior
can get data stream
SDK Version I encountered this issue in
2.16.1
Steps To Reproduce
Filled out the Steps to Reproduce section?
Anything else?
No response
The text was updated successfully, but these errors were encountered: