Node JS WebSocketV2
-
while using fetchdata function from WebSocketV2
code :
web_socket.fetchData({
correlationID: "abcde12345",
action: 1,
params: {
mode: 1,
tokenList: [
{
exchangeType: 1,
tokens: ["10626", "5290"],
},
],
},
});gives an error
error :
⨯ node_modules\smartapi-javascript\lib\websocket2.0.js (137:0) @ WebSocketV2.fetchData
⨯ Error: Invalid Mode value passed
at page (./src/app/page.jsx:63:16)
null
Error: Invalid Mode value passed
at WebSocketV2.fetchData (webpack-internal:///(rsc)/./node_modules/smartapi-javascript/lib/websocket2.0.js:137:11)
at eval (webpack-internal:///(rsc)/./node_modules/smartapi-javascript/lib/websocket2.0.js:52:14)
at Array.map (<anonymous>)
at WebSocket.onOpen (webpack-internal:///(rsc)/./node_modules/smartapi-javascript/lib/websocket2.0.js:51:20)
at callListener (webpack-internal:///(rsc)/./node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onOpen (webpack-internal:///(rsc)/./node_modules/ws/lib/event-target.js:237:9)
at WebSocket.emit (node:events:518:28)
at WebSocket.setSocket (webpack-internal:///(rsc)/./node_modules/ws/lib/websocket.js:244:10)
at ClientRequest.eval (webpack-internal:///(rsc)/./node_modules/ws/lib/websocket.js:1009:15)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketOnData (node:_http_client:575:11)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)I think this error is due to the structure of passing parameter in fetchData function.
-
@Moderator_2
"next": "14.1.3",
I am using next js instead of node js to connect with WebSocketV2 directly from fronend.It got connected and worked very fine with all the function defined in WebSocketV2 leaving WebSocketV2.fetchData function in smartapi-javascript\lib\websocket2.0.js which is upload in your github repo https://github.com/angel-one/smartapi-javascript/blob/main/lib/websocket2.0.js.
In documentation it said to pass parameter like :
{
"correlationID": "abcde12345",
"action": 1,
"params": {
"mode": 1,
"tokenList": [
{
"exchangeType": 1,
"tokens": [
"10626",
"5290"
]
},
{
"exchangeType": 5,
"tokens": [
"234230",
"234235",
"234219"
]
}
]
}
}but while retriving in WebSocketV2.fetchData function which is in line number 127 of https://github.com/angel-one/smartapi-javascript/blob/main/lib/websocket2.0.js file is like
const { correlationID, action, mode, exchangeType, tokens } = json_req;
but i am passing data in different structure , so as to retrive the data i pass it has to be like :
const { correlationID, action, params : {mode, tokenList :{exchangeType, tokens} }} = json_req;
I request please provide the solution as soon as possible.
Thank you -
"next": "14.1.3",
I am using next js instead of node js to conncect directly with WebSocketV2 from frontend and it's working fine for other functions define in WebSocketV2.
The only problem I see is in fetchdata function defined in smartapi-javascript\lib\websocket2.0.js file which is upload in your github https://github.com/angel-one/smartapi-javascript/blob/main/lib/websocket2.0.js
The structure of sending the data to websocket2.0 is describe as
{
"correlationID": "abcde12345",
"action": 1,
"params": {
"mode": 1,
"tokenList": [
{
"exchangeType": 1,
"tokens": [
"10626",
"5290"
]
},
{
"exchangeType": 5,
"tokens": [
"234230",
"234235",
"234219"
]
}
]
}
}
whereas at receiving end of fetchData function which is
const { correlationID, action, mode, exchangeType, tokens } = json_req;
couldn't fetch request data because it is not in fromat of
{ correlationID, action, mode, exchangeType, tokens }It should be
const {
correlationID,
action,
params :
{
mode,
tokenList :{
exchangeType, tokens
}
}
} = json_req;Please solve the issue as soon as possible.
Thank you -