Hi All,
I am trying to fetch MCX:CRUDEOIL22DECFUT using the websocket connection.
I get an empty response : res {"s":"ok","d":{"7202":[],"7208":[],"31038":[]}}
I am able to get the quotes for the same symbol but it somehow does not work on the websocket
Below is my code
USING WEBSOCKET:const reqBody = {
symbol: ["MCX:CRUDEOIL22DECFUT"],
dataType: "symbolUpdate",
};
fyers.fyers_connect(reqBody, function (result) {
console.log("res", result);
});
Response: res {"s":"ok","d":{"7202":[],"7208":[],"31038":[]}
USING REST API TO GET QUOTES:async function getQuotes() {
const quotes = new fyers.quotes();
const result = await quotes.setSymbol("MCX:CRUDEOIL22DECFUT").getQuotes();
console.log(result.d[0].v);
}
getQuotes();
Response: {
ch: -286,
chp: -4.26,
lp: 6434,
spread: 1,
ask: 6436,
bid: 6435,
open_price: 6673,
high_price: 6734,
low_price: 6410,
prev_close_price: 6720,
volume: 39713,
short_name: 'CRUDEOIL22DECFUT',
exchange: 'MCX',
description: 'MCX:CRUDEOIL22DECFUT',
original_name: 'MCX:CRUDEOIL22DECFUT',
symbol: 'MCX:CRUDEOIL22DECFUT',
fyToken: '1120221219243301',
tt: 1669161600,
cmd: {
t: 1669214280,
o: 6438,
h: 6438,
l: 6433,
c: 6434,
v: 91,
tf: '20:8'
}
}
I am unable to figure out why does it work when getting quotes and why does it fail when using a websocket.
Can anyone help on this ?
Ok, I got it.
I got a new accessToken to make it work.
But I am still not sure why was I able to fetch the quotes if the token had expired.