Accessing Tick Data in Full Mode

DA1077
Hi,

I want to get the Bids and Offers from tick data in FULL mode. I am using below code to access that but I am getting error. The code and error are as below. Please let me know the code I should use to access the Bids and Offers from Tick in FULL Mode.

Code Used:
===========
My.Computer.FileSystem.WriteAllText("C:\Users\nandy\Desktop\OGGN-New\TickData2.txt", Now.ToString("hh:mm:ss.fff") & " " & tickdata.InstrumentToken & " " & tickdata.Open & " " & tickdata.High & " " & tickdata.Low & " " & tickdata.LastPrice & " " & tickdata.Volume & " " & CStr(tickdata.Bids(0).Orders) & " " & CStr(tickdata.Offers(0).Orders) & " " & vbCrLf, True)


Error Received:
==============
System.NullReferenceException: 'Object reference not set to an instance of an object.'

Thanks,
Amitabha
  • tonystark
    tonystark edited November 2017
    Hi @DA1077,

    You can try splitting that string concatenation into different lines to narrow down the cause

    I believe this is due to unavailability of bids and orders in that array. So when you subscribe to a token server immediately sends a quote tick. This is due to the network delay in reaching the mode change request to the server. So it is better to check if bids and orders array length before accessing the first element inside it.

    Just add a check like:
    If tickdata.Bids.Length > 0 And tickdata.Offers.Length > 0 Then
    DoSomething()
    Else
    'No depth in the current tick. Check the next one.'
    End If
  • DA1077
    Hi ajinasokan,

    I have tried do the array length checking before writing but still the same exception as before is coming. It's coming only when I am trying to access bids or offers and NOT on others (like volume / open / high etc.). Please check an let me know the format through which I can access bids and offers.
  • tonystark
    Hi @DA1077,

    The format you have written is correct. I think the way you check the array length is wrong. Can you post the code snippet?
  • DA1077
    DA1077 edited November 2017
    Code snippet is as below -
    If tickdata.Bids.Length > 0 And tickdata.Offers.Length > 0 Then

    My.Computer.FileSystem.WriteAllText("C:\Users\nandy\Desktop\OGGN-New\TickData2.txt", Now.ToString("hh:mm:ss.fff") & " " & tickdata.InstrumentToken & " " & tickdata.Open & " " & tickdata.High & " " & tickdata.Low & " " & tickdata.LastPrice & " " & tickdata.Volume & " " & CStr(tickdata.Bids(0).Orders) & " " & CStr(tickdata.Offers(0).Orders) & " " & vbCrLf, True)

    End If
  • tonystark
    Hi @DA1077,

    Can you post complete code? This part of the code looks fine.
  • DA1077
    DA1077 edited November 2017
    Here it is -
    Imports System.ComponentModel
    Imports System
    Imports System.IO
    Imports KiteConnect

    Dim user As User
    Public WithEvents tickerPredefined As Ticker
    Public kite As Kite

    Private Sub btnTestTicker_Click(sender As Object, e As EventArgs) Handles btnTestTicker.Click
    tickerPredefined = New Ticker(tbxAPIKey.Text, tbxUserID.Text, tbxPublicToken.Text)
    tickerPredefined.Connect()
    tickerPredefined.Subscribe(Tokens:={"53471751", "53466887", "53474823", "53372423", "53499143"})
    tickerPredefined.SetMode(Tokens:={"53471751", "53466887", "53474823", "53372423", "53499143"}, Mode:="full")
    End Sub


    Private Sub Ontick(tickdata As Tick) Handles tickerPredefined.OnTick

    If tickdata.Bids.Length > 0 And tickdata.Offers.Length > 0 Then

    My.Computer.FileSystem.WriteAllText("C:\Users\nandy\Desktop\OGGN-New\TickData2.txt", Now.ToString("hh:mm:ss.fff") & " " & tickdata.InstrumentToken & " " & tickdata.Open & " " & tickdata.High & " " & tickdata.Low & " " & tickdata.LastPrice & " " & tickdata.Volume & " " & CStr(tickdata.Bids(0).Orders) & " " & CStr(tickdata.Offers(0).Orders) & " " & vbCrLf, True)

    End If

    Private Sub Onconnect() Handles tickerPredefined.OnConnect
    ConnectionStatus = tickerPredefined.IsConnected
    If ConnectionStatus = True Then
    MsgBox("Connection established")
    Else
    MsgBox("No connection established")
    End If
    End Sub
  • tonystark
    Hi @DA1077,

    This code is running fine at our end without any issues. I would suggest you to double check whether other parts of your program is interfering with it.
Sign In or Register to comment.