Live Data feed using websocket in C#


  • @admin @administrators Please suggest how to get live feed using C# through websocket. I tried GitHub example code but not able get any response in messagerecieve event of websocket.


  • Hi @LKS Our team is working on websocket we will update you once we finish it.we appreciate your patience


  • @admin @administrators
    PLz suggest what do, to get live feed for any token from nse_fo in C#..

    I m not getting any response from WriteResult function and program remains there for no output...

    Attached Code Below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using AngelBroking;

    namespace ConsoleApp_WS_Test2
    {
    class Program
    {
    static void Main(string[] args)
    {
    string Client_code = ""; //YOUR CLIENT CODE
    string Password = ""; //YOUR PAS SWORD
    string api_key = "";
    string JWTToken = ""; //optional
    string RefreshToken = ""; //optional

            SmartApi connect = new SmartApi(api_key, JWTToken, RefreshToken);
    
            OutputBaseClass obj = new OutputBaseClass();
    
            //Login by client code and password
            obj = connect.GenerateSession(Client_code, Password);
            AngelToken sagr = obj.TokenResponse;
    
            //Get Token
            obj = connect.GenerateToken();
            sagr = obj.TokenResponse;
    
            AngelBroking.WebSocket _WS = new AngelBroking.WebSocket();
            var exitEvent = new ManualResetEvent(false);
    
            _WS.ConnectforStockQuote(sagr.feedToken, Client_code);
    
            Console.WriteLine("WS Created");
    
            if (_WS.IsConnected())
            {
                Console.WriteLine("IsConnected : In");
    
                string script = "nse_fo|49364", TASK = "mw";  // SCRIPT: nse_cm|2885, mcx_fo|222900  TASK: mw|sfi|dp
                
                Console.WriteLine("TASK : Market Watch mw");
                _WS.RunScript(sagr.feedToken, Client_code, script, TASK);
    
                _WS.MessageReceived += WriteResult;
                
    
                //_WS.Close(true); //to stop and close socket connection
            }
    
            Console.WriteLine("IsConnected : Out");
            exitEvent.WaitOne();
           
        }
    
        static void WriteResult(object sender, MessageEventArgs e)
        {
            Console.WriteLine("Tick Received : " + e.Message);
        }
    }
    

    }


  • @admin Now a new error :

    System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx' or one of its dependencies. The system cannot find the file specified.'

    coming while debugging... plz tell how to resolve this also..


  • @admin

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using AngelBroking;
    using Websocket.Client;

    namespace ConsoleApp3_WS_Feed
    {
    class Program
    {
    static void Main(string[] args)
    {
    string Client_code = ""; //YOUR CLIENT CODE
    string Password = ""; //YOUR PASSWORD
    string api_key = "";
    string JWTToken = ""; // optional
    string RefreshToken = ""; // optional

            SmartApi connect = null;
            OutputBaseClass obj = null;
            AngelBroking.WebSocket _WS = null;
    
            connect = new SmartApi(api_key, JWTToken, RefreshToken);
    
            obj = new OutputBaseClass();
    
            //Login by client code and password
            obj = connect.GenerateSession(Client_code, Password);
            AngelToken sagr = obj.TokenResponse;
    
            //Get Token
            obj = connect.GenerateToken();
            sagr = obj.TokenResponse;
    
            _WS = new AngelBroking.WebSocket();
            var exitEvent = new ManualResetEvent(false);
    
            Console.WriteLine("Connect Socket ");
            _WS.ConnectforStockQuote(sagr.feedToken, Client_code);
    
            if (_WS.IsConnected())
            {
                Console.WriteLine("If Connected");
                //string script = "", TASK = "";  // SCRIPT: nse_cm|2885, mcx_fo|222900  TASK: mw|sfi|dp
                string script = "nse_fo|49157&nse_fo|49122&nse_fo|49080&nse_fo|49304";
                //string script = "mcx_fo|230184&mcx_fo|229427&mcx_fo|229414&mcx_fo|229417";
                string TASK = "mw";
    
                _WS.RunScript(sagr.feedToken, Client_code, script, TASK);
                _WS.MessageReceived += WriteResult;
                
                Console.WriteLine("Feed Request");
                //_WS.Close(true); // to stop and close socket connection
                //Console.WriteLine("Close");
    
            }
    
            Console.WriteLine("Wait for Signal");
    
            exitEvent.WaitOne();
    
            Console.WriteLine("Main loop Over");
    
        }
    
    
        static void WriteResult(object sender, MessageEventArgs e)
         {
                    Console.WriteLine("Tick Received");
                    Console.WriteLine("Tick Received : " + e.Message);
        }
    }
    

    }


  • HI @LKS Can you post your code and response which you are getting.