I am trying to subscribe to channel using native WebSocket in vanilla javascript (without using any library) [as I have just read it's possible but I am not sure - please correct me if I'm wrong].
I am trying to get the latest price of bitcoin
let ws = new WebSocket('wss://ws-feed.gdax.com');
var params = {
"type": "subscribe",
"channels": [{"name": "ticker", "product_ids": ["BTC-USD"]}]
}
ws.onmessage = function(msg) {
console.log(msg);
}
I am trying to connect to this channel, however I couldn't manage to do it. I am not getting any outputs in the console.
How do I give the parameters into the channel and start listening to it?