How to get the live data from market feed for different stocks ?



  • @admin

    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?


  • @Jeet-Pattani said in How to get the live data from market feed for different stocks ?:

    I entered the code given to login but it shows this error
    {"status":false,"message":"YOUR USER ID OR PASSWORD IS INVALID","errorcode":"AB1007","data":null}
    I tried it with both api key and secret key.
    Please tell me how to fix this.

    Have you migrated your account.


  • var axios = require('axios');
    var data = JSON.stringify({
        "clientcode": "jety2619@gmail.com",
        "password": "Info@money1411"
    });
    
    var config = {
        method: 'post',
        url: 'https://apiconnect.angelbroking.com//rest/auth/angelbroking/user/v1/loginByPassword',
    
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'X-UserType': 'USER',
            'X-SourceID': 'WEB',
            'X-ClientLocalIP': 'CLIENT_LOCAL_IP',
            'X-ClientPublicIP': 'CLIENT_PUBLIC_IP',
            'X-MACAddress': 'MAC_ADDRESS',
            'X-PrivateKey': 'vtJ7Ks0m'
        },
        data: data
    };
    
    axios(config)
        .then(function(response) {
            console.log(JSON.stringify(response.data));
        })
        .catch(function(error) {
            console.log(error);
        });
    

    I entered the code given to login but it shows this error

    {"status":false,"message":"YOUR USER ID OR PASSWORD IS INVALID","errorcode":"AB1007","data":null}

    I tried it with both api key and secret key.

    Please tell me how to fix this.


  • Hi @Jeet-Pattani You need to call login api to get the tokens.


  • @admin please tell how to get bearer Authorization token and also it is showing error in data : data

    var axios = require('axios');
    var data = JSON.stringify({
        "exchange":"NSE",
        "tradingsymbol":"SBIN-EQ",
        "symboltoken":"3045"
    });
    
    var config = {
      method: 'post',
      url: 'https://apiconnect.angelbroking.com/ 
      rest/secure/angelbroking/order/
      v1/getLtpData',
    
      headers: { 
        'Authorization': 'Bearer AUTHORIZATION_TOKEN', 
        'Content-Type': 'application/json', 
        'Accept': 'application/json', 
        'X-UserType': 'USER', 
        'X-SourceID': 'WEB', 
        'X-ClientLocalIP': 'CLIENT_LOCAL_IP', 
        'X-ClientPublicIP': 'CLIENT_PUBLIC_IP', 
        'X-MACAddress': 'MAC_ADDRESS', 
        'X-PrivateKey': 'API_KEY'
      },
      data : data
    };
    
    axios(config)
    .then(function (response) {
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });
    ```var axios = require('axios');
    var data = JSON.stringify({
        "exchange":"NSE",
        "tradingsymbol":"SBIN-EQ",
        "symboltoken":"3045"
    });
    
    var config = {
      method: 'post',
      url: 'https://apiconnect.angelbroking.com/ 
      rest/secure/angelbroking/order/
      v1/getLtpData',
    
      headers: { 
        'Authorization': 'Bearer AUTHORIZATION_TOKEN', 
        'Content-Type': 'application/json', 
        'Accept': 'application/json', 
        'X-UserType': 'USER', 
        'X-SourceID': 'WEB', 
        'X-ClientLocalIP': 'CLIENT_LOCAL_IP', 
        'X-ClientPublicIP': 'CLIENT_PUBLIC_IP', 
        'X-MACAddress': 'MAC_ADDRESS', 
        'X-PrivateKey': 'API_KEY'
      },
      data : data
    };
    
    axios(config)
    .then(function (response) {
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });

  • @admin said in How to get the live data from market feed for different stocks ?:

    n use get ltp data api() or

    I tried to used the code snippets in the github page but got errors. I could not find how to use the get ltp data api() function to get the data. Please help. It would be great if you could show me a sample code to fetch the data.

    //The code I copy pasted from github page of angelbroking
    let web_socket = new WebSocketClient({
    clientcode: "CLIENT_CODE",
    jwttoken: "jwt_token",
    apikey: "Wz5XQb5r",
    feedtype: "order_feed",
    });

    web_socket.connect()
    .then(() => {
    web_socket.fetchData("ACTION_TYPE", "FEED_TYPE"); // 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);
    }

    let { SmartAPI, WebSocket } = require("smartapi-javascript");

    let smart_api = new SmartAPI({
    api_key: "Wz5XQb5r", // PROVIDE YOUR API KEY HERE
    // OPTIONAL : If user has valid access token and refresh token then it can be directly passed to the constructor.
    // access_token: "YOUR_ACCESS_TOKEN",
    // refresh_token: "YOUR_REFRESH_TOKEN"
    });

    return smart_api.getCandleData({
    "exchange": "NSE",
    "symboltoken": "3045",
    "interval": "ONE_MINUTE",
    "fromdate": "2021-02-10 09:00",
    "todate": "2021-02-10 09:20"
    })

    //Errors I got

    ReferenceError: WebSocketClient is not defined
    at Object.<anonymous> (d:\Web development\practice js\tempCodeRunnerFile.js:1:18)
    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)
    at node:internal/main/run_main_module:17:47


  • HI @Jeet-Pattani You need to coordinate with your own software dev team to built this.


  • @admin thank you very much. I want to learn how to implement it and use it to display in a stock ticker. Can you guide me?

    I want to display data like in this image which uses marquee.

    Screenshot_2021-11-02-22-13-34-58_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

    https://in.tradingview.com/widget/ticker-tape/


  • HI @Jeet-Pattani You can use get ltp data api() or get candle data api() get the prices.