Error due to fetchData function from WebSocketV2


  • When i use fetchData function from WebSocketV2 instance then it gives the error that i have provided in photo

    code :
    web_socket.fetchData({
    correlationID: "abcde12345",
    action: 1,
    params: {
    mode: 1,
    tokenList: [
    {
    exchangeType: 1,
    tokens: ["10626", "5290"],
    },
    {
    exchangeType: 5,
    tokens: ["234230", "234235", "234219"],
    },
    ],
    },
    });
    Screenshot 2024-03-10 155613.png

    I think this error is due to the way it's fetching in websocket2.0.js file,
    it's fetch value as const { correlationID, action, mode, exchangeType, tokens } = json_req; but in documentation it is written as {
    "correlationID": "abcde12345",
    "action": 1,
    "params": {
    "mode": 1,
    "tokenList": [
    {
    "exchangeType": 1,
    "tokens": [
    "10626",
    "5290"
    ]
    },
    {
    "exchangeType": 5,
    "tokens": [
    "234230",
    "234235",
    "234219"
    ]
    }
    ]
    }
    }

    I request you please provide appropriate solution.


  • Hi @greatworld

    Apologies for the delayed response.
    Kindly find below working code to fetch data. Please verify and let us know if this helps.

    Code Snippet:
    let web_socket = new WebSocketV2({
    jwttoken: 'jwt_token',
    apikey: 'api_key',
    clientcode: 'client_code',
    feedtype: 'feed_token',
    });

    web_socket.connect().then((res) => {
    let json_req = {
    correlationID: 'abcde12345',
    action: 1,
    mode : 1,
    exchangeType: 5,
    tokens: ["234230", "234235", "234219"],
    };
    web_socket.fetchData(json_req);
    web_socket.on('tick', receiveTick);
    function receiveTick(data) {
    console.log('receiveTick:::::', data);
    }
    });

    Regards,
    SmartAPI team