Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

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

    Bugs
    3
    19
    295
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jeet Pattani @admin last edited by

      @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/

      A 1 Reply Last reply Reply Quote 0
      • A
        admin @Jeet Pattani last edited by

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

        1 Reply Last reply Reply Quote 0
        • J
          Jeet Pattani @admin last edited by

          @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

          1 Reply Last reply Reply Quote 0
          • J
            Jeet Pattani @admin last edited by

            @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);
            });
            A 1 Reply Last reply Reply Quote 0
            • A
              admin @Jeet Pattani last edited by

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

              1 Reply Last reply Reply Quote 0
              • J
                Jeet Pattani last edited by

                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.

                A 1 Reply Last reply Reply Quote 0
                • A
                  admin @Jeet Pattani last edited by

                  @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.

                  J 1 Reply Last reply Reply Quote 0
                  • J
                    jety_22 @admin last edited by

                    @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?

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      admin @jety_22 last edited by

                      @jety_22 please go through below doc
                      https://smartapi.angelbroking.com/docs/WebSocketStreaming

                      J 2 Replies Last reply Reply Quote 0
                      • J
                        Jeet Pattani @admin last edited by

                        @admin There is no clear mention on how to connect to the websocket.

                        A 1 Reply Last reply Reply Quote 0
                        • J
                          Jeet Pattani @admin last edited by

                          @admin I also used the wss url but it still showed error.

                          1 Reply Last reply Reply Quote 0
                          • A
                            admin @Jeet Pattani last edited by

                            @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.

                            J 1 Reply Last reply Reply Quote 0
                            • J
                              jety_22 @admin last edited by

                              @admin CLIENT ID P529774
                              PHONE 8460920114
                              PLEASE CONTACT ASAP

                              1 Reply Last reply Reply Quote 0
                              • J
                                jety_22 last edited by

                                This post is deleted!
                                A 2 Replies Last reply Reply Quote 0
                                • A
                                  admin @jety_22 last edited by

                                  Hi @jety_22 Dont expose your password publicly.

                                  J 1 Reply Last reply Reply Quote 0
                                  • A
                                    admin @jety_22 last edited by

                                    @jety_22 as cordinated with the team our team is working on web socket we will update you on this.

                                    1 Reply Last reply Reply Quote 0
                                    • J
                                      jety_22 @admin last edited by

                                      @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?

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post