import * as dotenv from 'dotenv'
import WebSocket from 'ws';
//setting up env
dotenv.config()
// setting up the websocket
const ws = new WebSocket(`wss://ws.twelvedata.com/v1?symbol=AAPL?apikey=${process.env.API_KEY_TWELVEDATA}`);
ws.on('subscribe', (stream) => {
console.log('stream ==>', stream);
})
I cannot emit subscribe event given by the twelvedata API. Also, I don't know how to pass the parameters as suggested by the twelvedata's documentation in node js.
For Example:-
{ "action": "subscribe",
"params": {
"symbols": [{
"symbol": "AAPL",
"exchange": "NASDAQ"
}, {
"symbol": "RY",
"mic_code": "XNYS"
}, {
"symbol": "DJI",
"type": "Index"
}
]
}
}
This object is used as a parameter to emit event to the twelvedata server and the server then responds with the data stream.
How can I emit the subscribe event through web-sockets as stated by the below screenshot (this is an example from the twelvedata website)
How can I pass the information regarding the subscribe event and the parameters to the web socket as shown in the screenshots