error while retrieving data object reference not set to an instance of object

sizzmht
it was working on thursday but not working today, getting error "error while retrieving data object reference not set to an instance of object"
  • sizzmht
    @sujith please advise
  • sizzmht
    i am getting message "connected ticket" under onconnect event handler but it looks like it goes straight after in to on error event handler
  • sujith
    Can you enable debug logs and post it here?
    Can you also give more information about your setup and library version?
  • sizzmht
    where to find log files

    static void Main(string[] args)
    {
    kite = new Kite(MyAPIKey, Debug: true);

    // For handling 403 errors

    kite.SetSessionExpiryHook(OnTokenExpire);

    // Initializes the login flow

    try
    {
    initSession();
    }
    catch (Exception e)
    {
    // Cannot continue without proper authentication
    Console.WriteLine(e.Message);
    Console.ReadKey();
    Environment.Exit(0);
    }

    kite.SetAccessToken(MyAccessToken);
    kite.EnableLogging(true);
    // Initialize ticker

    initTicker();

  • sizzmht
    this was working on friday, there has been no change, i have enabled log, please help, this seems to be waste of time, do you want me to post my key ?
  • sizzmht
    dll version 3.0.1.0
  • sizzmht
    windows 10
  • tonystark
    @sizzmht If you are building a console app, logs will be printed in the console. If you are building a WinForms application you can see logs in Debug -> Windows -> Output.

    To resolve issues faster you should provide us with more information like what were you trying to do, what are the instruments you were subscribing to, code example that can reproduce the problem, is there is any pattern in happening this error etc.

    The more you can communicate and give us details, the faster we can help. :smile:
  • sizzmht
    using System;
    using KiteConnect;
    using System.Collections.Generic;

    namespace KiteConnectSample
    {
    class Program
    {
    // instances of Kite and Ticker
    static Ticker ticker;
    static Kite kite;

    // Initialize key and secret of your app

    static string MyUserId = "ZM7819";

    // persist these data in settings or db or file
    static string MyPublicToken = "abcdefghijklmnopqrstuvwxyz";
    static string MyAccessToken = "abcdefghijklmnopqrstuvwxyz";

    static void Main(string[] args)
    {
    kite = new Kite(MyAPIKey, Debug: true);

    // For handling 403 errors

    kite.SetSessionExpiryHook(OnTokenExpire);

    // Initializes the login flow

    try
    {
    initSession();
    }
    catch (Exception e)
    {
    // Cannot continue without proper authentication
    Console.WriteLine(e.Message);
    Console.ReadKey();
    Environment.Exit(0);
    }

    kite.SetAccessToken(MyAccessToken);
    kite.EnableLogging(true);
    // Initialize ticker

    initTicker();


    Console.ReadLine();

    // Disconnect from ticker

    ticker.Close();
    }

    private static void initSession()
    {
    Console.WriteLine("Goto " + kite.GetLoginURL());
    Console.WriteLine("Enter request token: ");
    string requestToken = Console.ReadLine();
    User user = kite.GenerateSession(requestToken, MySecret);
    kite.EnableLogging(true);
    Console.WriteLine(Utils.JsonSerialize(user));

    MyAccessToken = user.AccessToken;
    MyPublicToken = user.PublicToken;
    }

    private static void initTicker()
    {
    ticker = new Ticker(MyAPIKey, MyAccessToken);

    //ticker.OnTick += OnTick;
    ticker.OnReconnect += OnReconnect;
    ticker.OnNoReconnect += OnNoReconnect;
    ticker.OnError += OnError;
    ticker.OnClose += OnClose;
    ticker.OnConnect += OnConnect;
    ticker.OnOrderUpdate += OnOrderUpdate;

    ticker.EnableReconnect(Interval: 5, Retries: 50);
    ticker.Connect();


    // Subscribing to NIFTY50 and setting mode to LTP
    ticker.Subscribe(Tokens: new UInt32[] { 1510401, 779521, 1270529, 341249, 492033, 1195009, 261889, 3050241, 1346049 });
    ticker.SetMode(Tokens: new UInt32[] { 1510401, 779521, 1270529, 341249, 492033, 1195009, 261889, 3050241, 1346049 }, Mode: Constants.MODE_FULL);
    }

    private static void OnTokenExpire()
    {
    Console.WriteLine("Need to login again");
    }

    private static void OnConnect()
    {
    Console.WriteLine("Connected ticker");
    }

    private static void OnClose()
    {
    Console.WriteLine("Closed ticker");
    }

    private static void OnError(string Message)
    {
    Console.WriteLine("Error: " + Message);
    }

    private static void OnNoReconnect()
    {
    Console.WriteLine("Not reconnecting");
    }

    private static void OnReconnect()
    {
    Console.WriteLine("Reconnecting");
    }

    private static void OnTick(Tick TickData)
    {

    Console.WriteLine("Tick " + Utils.JsonSerialize(TickData));
    }

    private static void OnOrderUpdate(Order OrderData)
    {
    Console.WriteLine("OrderUpdate " + Utils.JsonSerialize(OrderData));
    }
    }
    }
  • sizzmht
    @tonystark i have pasted entire code and console screenshot, let me know if you need anything else, i would appreciate your quick response. thanks. its the same code what is there on git hub i am just requesting banks tick data
  • tonystark
    @sizzmht Can you change the line to ticker = new Ticker(MyAPIKey, MyAccessToken, Debug: true); ?

    This will log more details about what is happening in ticker.
  • tonystark
    Also your code has //ticker.OnTick += OnTick;. All events in ticker are mandatory to have a handler. Try uncommenting it as well.
Sign In or Register to comment.