It looks like you're new here. If you want to get involved, click one of these buttons!
// Create a new Ticker instance
Ticker ticker = new Ticker(MyAPIKey, MyUserId, MyPublicToken);
// Add handlers to events
ticker.OnTick += onTick;
// Engage reconnection mechanism and connect to ticker
ticker.EnableReconnect(Interval: 5,Retries: 50);
ticker.Connect();
// Subscribing to NIFTY50 and setting mode to LTP
ticker.Subscribe(Tokens: new string[] { "256265" });
ticker.SetMode(Tokens: new string[] { "256265" }, Mode: "ltp");
// Example onTick handler
private static void onTick(Tick TickData)
{
Console.WriteLine("LTP: " + TickData.LastPrice);
}
// Disconnect ticker before closing the application
ticker.Close();
Vb equivalent of adding handler.
AddHandler ticker.OnTick, AddressOf OnTick
Request you to please provide your valuable input to my above code. I am unable to get the streaming data.
Thanks,
Amitabha
You can try http://converter.telerik.com/ to get a basic working VB code out of the C# code. This is not guaranteed to work but works most of the time.
Thanks for the response. After going through your response I tried to implement my tick receival in the main class itself. My logic is as below:
1. Automatically Get the access token/public token from the server and populate that in textboxes.(This part is working fine)
2. When the access token is available initiate the Ticket connection.( Facing problem in this part). If you see blow my code its executing the line "MsgBox("No connection established")" although I can see that Access token/Public Token/UserID is passed properly( Saw that in debug mode ). Please let me know where I a going wrong ?
My code is as below:
Public WithEvents tickerPredefined As Ticker
Dim ConnectionStatus As Boolean
Private Sub btnStartPredefinedProcess_Click(sender As Object, e As EventArgs) Handles btnStartPredefinedProcess.Click
Do Until AccessReceived = True
Loop
tickerPredefined = New Ticker(tbxAPIKey.Text, tbxUserID.Text, tbxPublicToken.Text)
tickerPredefined.Subscribe(Tokens:={"53461511"})
tickerPredefined.SetMode(Tokens:={"53461511"}, Mode:="ltp")
tickerPredefined.Connect()
ConnectionStatus = tickerPredefined.IsConnected
If ConnectionStatus = True Then
MsgBox("Connection established")
Else
MsgBox("No connection established")
End If
AddHandler tickerPredefined.OnTick, AddressOf Ontick
End Sub
Private Sub Ontick(tick As Tick) Handles tickerPredefined.OnTick
MsgBox(tick)
End Sub
Thanks,
Amitabha
Sorry for making another quick request for your attention to my earlier post. Above section of the code is actually the front section of the logic and until it gets sorted out I am not able to make further development on my application. You expedited response will be of great help.
Thanks,
Amitabha
Our .Net client Ticker implementation is completely non-blocking. It is asynchronous. This means every function call to Ticker will execute immediately and will not wait for the network to respond. If there are any issues they will be reported via OnError event. This is for not wasting time on waiting for the network to respond.
In your implementation
tickerPredefined.Connect()
will ask ticker to connect to the server which will take a few milliseconds. But the function execution will complete immediately and will go to the next line of your code which isConnectionStatus = tickerPredefined.IsConnected
. Until server connection is complete tickerPredefined.IsConnected will return False. That is why you are getting that message. Try attaching OnConnect event to your ticker object.I suggest you go through the example code once again. Also, since you are using Winforms you can create multiple buttons for Create Ticker, Connect, Subscribe, UnSubscribe, Close and do appropriate actions for understanding the event mechanism.
Also, I would like to mention that you are creating new Ticker connections in a loop which is a bad idea since this is based on events.
I followed as per your suggestion but still the connection is not getting active. I am struggling to get through this opening piece of code for last one week. Will you please recreate the scenario at your end using below code and let me know what's wrong here ? My current code is provided below. I have created a separate button Button1 to check if the connection is up or not. I am getting the message "No connection established" even when I click Button1. Note that the values in the textboxes tbxAPIKey.Text, tbxUserID.Text, tbxPublicToken.Text are correctly populated and no exception error is received at any step. Request you to please recreate this small scenario at your end and provide your expert advise on this.
Code:
====== Thanks,
Amitabha
Here is an example:
Please suggest is there is any compatibility issue here or something else.
Which OS are you using?
Unfortunately, WebSocket feature that comes with .Net framework is not supported on Windows 7 and earlier. And there is no update or patch for this in Windows 7 since Microsoft stopped the support for it.
If you have to use Win 7 you will have to use third-party client libraries for Kite Connect. But recommended approach is to use latest Windows version with updates.
Thanks for your time and the update. I will try on a different machine having Windows 10.
Thanks,
Amitabha