How to get the live data from market feed for different stocks ?
-
var websocket = require(WebSocket); let web_socket = new WebSocketClient({ clientcode: "P529774", jwttoken: "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6IlA1Mjk3NzQiLCJyb2xlcyI6MCwidXNlcnR5cGUiOiJVU0VSIiwiaWF0IjoxNjM4ODUyODY1LCJleHAiOjE3MjUyNTI4NjV9.ExqXu3cKYv2xh1hAlbI2xZHknfF1ZwfbPDu7cIKM0ljRQM5nUn1wmCOFdirEwLRzQxM-G6CsfmlDYkaMED_uIg", apikey: "erZDHFHD", feedtype: "order_feed", }); web_socket.connect() .then(() => { web_socket.fetchData("subscribe", "order_feed"); // ACTION_TYPE: subscribe | unsubscribe FEED_TYPE: order_feed setTimeout(function() { web_socket.close() }, 60000) }); web_socket.on('tick', receiveTick); function receiveTick(data) { console.log("receiveTick:::::", data); }
I am not able to connect to websocket. I am getting the error as below.
node:internal/validators:119 throw new ERR_INVALID_ARG_TYPE(name, 'string', value); ^ TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received function WebSocket at new NodeError (node:internal/errors:371:5) at validateString (node:internal/validators:119:11) at Module.require (node:internal/modules/cjs/loader:998:3) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (d:\home page\smart api\test.js:35:17) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'ERR_INVALID_ARG_TYPE' }
Is there a requirement to get any other websocket client?
-
@jety_22 please go through below doc
https://smartapi.angelbroking.com/docs/WebSocketStreaming -
@admin There is no clear mention on how to connect to the websocket.
-
@admin I also used the wss url but it still showed error.
-
@Jeet-Pattani said in How to get the live data from market feed for different stocks ?:
@admin There is no clear mention on how to connect to the websocket.
post your client id here our team will connect you.
-
@admin CLIENT ID P529774
PHONE 8460920114
PLEASE CONTACT ASAP -
This post is deleted! -
Hi @jety_22 Dont expose your password publicly.
-
@jety_22 as cordinated with the team our team is working on web socket we will update you on this.
-
@admin I connected using websocket.
let { SmartAPI, WebSocket } = require("smartapi-javascript"); let web_socket = new WebSocket({ client_code: "P529774", feed_token: "097948399" }); web_socket.connect() .then(() => { web_socket.runScript("nse_cm|2885", "cn")// SCRIPT: nse_cm|2885, mcx_fo|222900 TASK: mw|sfi|dp web_socket.runScript("nse_cm|2885", "mw") setTimeout(function() { web_socket.close() }, 3000) }) web_socket.on('tick', receiveTick) function receiveTick(data) { console.log("receiveTick:::::", data) }
But I am getting the following response.
receiveTick::::: [ { ak: 'ok', task: 'cn', msg: 'connected' } ] receiveTick::::: [] receiveTick::::: [ { tvalue: '07/12/2021 16:19:25', name: 'tm' } ] receiveTick::::: [ { tvalue: '07/12/2021 16:19:26', name: 'tm' } ] receiveTick::::: [ { tvalue: '07/12/2021 16:19:27', name: 'tm' } ] Socket closed
will it send response during market hours only?