Websocket Streaming and Missing Tick Data

Rajkumarj
so i have built an simple .NET console to receive Tick Data by subscribing to one instrument and have been trying to form 1 min Candles with the recieved tick data.Mnay a times i can see a lot of tick data is missing .See below image(did a simple Console.Write to print for a min ).This leads to inconsistent 1 min candle formation i havealso attached the ping speed test to make sure there are no latency with my ISP..May i know why this is happening ??




the code used is shown below FYI

static void Main(string[] args)
{
// Read API key and access token from configuration
string apiKey = AppConfig.GetApiKey();
string requestToken = AppConfig.GetRequestToken();
string accessToken = AppConfig.GetAccessToken();
string apiSecret = AppConfig.GetApiSecret();
KiteConnectApi kiteConnect = new KiteConnectApi(apiKey, apiSecret,accessToken);


try
{


// Create a new Ticker instance
ticker = new Ticker(apiKey, accessToken);

// Add handlers to events
ticker.OnTick += OnTick;
ticker.OnOrderUpdate += OnOrderUpdate;
ticker.OnReconnect += OnReconnect;
ticker.OnNoReconnect += OnNoReconnect;
ticker.OnError += OnError;
ticker.OnClose += OnClose;
ticker.OnConnect += OnConnect;

// Engage reconnection mechanism and connect to ticker
ticker.EnableReconnect(Interval: 5, Retries: 50);
ticker.Connect();

UInt32[] tokens = { 5181953 }; // Oberoi Reality
ticker.Subscribe(tokens);
ticker.SetMode(tokens, Constants.MODE_FULL);

// Keep the application running to receive live updates
Console.WriteLine("Press any key to exit...");
//onsole.ReadKey();
Thread.Sleep(TimeSpan.FromMinutes(2));
// Disconnect ticker before closing the application
ticker.Close();

}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}


private static void OnTick(Tick TickData)
{
// Print Last Traded Price (LTP) to the console
Console.WriteLine("LP: " + TickData.LastPrice + " TimeStamp: " + TickData.Timestamp.ToString() );
}

private static void OnOrderUpdate(Order OrderData)
{
Console.WriteLine("OrderUpdate " + Utils.JsonSerialize(OrderData));
}

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

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

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

private static void OnClose()
{
Console.WriteLine("Connection closed.");
}

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


  • sujith
    You can refer to the tick frequency on FAQs.
  • Rajkumarj
    Thanks @sujith for the response. I just wanted to know whether there is a latency issue on my end or this is normal behaviour in websocket to miss out on few ticks in between ? . From what i read , the missing data in Kite charts are readjusted later when all the information is received.
  • sujith
    You can go through this thread to know more about how to convert ticks to candle.
    There is no adjustment, you just need first, last tick of the minute, high and low of the minute to form the candle.
  • Rajkumarj
    Yes @sujith i am doing that already. i am getting consistent results but for few candles , the tick that needs to come in at the 1st sec for example- 10:00:00 i get it at 10:00:02 so the open price is not correct for that candle and similarly the tick which is supposed to come in at 10:00:59 gets missed and the close price also becomes incorrect. So this is affecting my calculations leading to losses.
  • sujith
    I don't think you should compare other charts. The idea is to capture the trend. The live market data on Websocket API is only a snapshot data. It is not a tick by tick data. There can be hundreds of ticks every second at the exchange but exchange streams only one or two ticks a second on the internet. You can know more here.
Sign In or Register to comment.