It looks like you're new here. If you want to get involved, click one of these buttons!
using System;
using KiteConnect;
namespace ConsoleApp__data
{
class Program
{
static void Main(string[] args)
{
String MyAPIKey = "xxxxxxxx";
String MyAccessToken = "xxxxxxxxxx";
// Create a new Ticker instance
Ticker ticker = new Ticker(MyAPIKey, MyAccessToken);
// Add handlers to events
ticker.OnTick += onTick;
ticker.OnOrderUpdate += OnOrderUpdate;
ticker.OnReconnect += onReconnect;
ticker.OnNoReconnect += oNoReconnect;
ticker.OnError += onError;
ticker.OnClose += onClose;
ticker.OnConnect += onConnect;
// 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 UInt32[] { 738561 });
ticker.SetMode(Tokens: new UInt32[] { 738561 }, Mode: Constants.MODE_FULL);
// Disconnect ticker before closing the application
// ticker.Close();
}
private static void onConnect()
{
Console.WriteLine("Connected ticker");
}
private static void onError(string Message)
{
Console.WriteLine("Error: " + Message);
}
private static void onClose()
{
Console.WriteLine("Closed ticker");
}
private static void oNoReconnect()
{
Console.WriteLine("Not reconnecting");
}
private static void onReconnect()
{
Console.WriteLine("Reconnecting");
}
// Example onTick handler
private static void onTick(Tick TickData)
{
Console.WriteLine("LTP: " + TickData.LastPrice);
}
}
}
I am just trying websocket print to get the ltp, but there is no data, output as follows :
Also, copied even the example program from https://github.com/zerodhatech/dotnetkiteconnect/blob/master/KiteConnectSample/Program.cs for websocket method.
output of program -
Connected ticker
Closed ticker
program exit with 0.
does not make sense why ltp not printing, can you gave a example from your end
Sorry if i am wrong. but this is hilarious.
I apologize.
But you are having a couple month long problem.
because you forgot to put Console.ReadLine() or Read()
at the end of your program.
Of course your program terminates with just "Connected" message.
there is nothing to stop your program from running to its end.
this observation is based on the snippet you provide above.
if it is something else. i apologise.
Thanks
Regards
That being said you missed the critical part of that code to keep your program running so that ticker can function.
Console.ReadKey();
attached locals variable captured for reference @tonystark @trade_then, is there a problem with change in websocket
in above comments @sujith mentions that. in case you wonder why your code works even when you subscribe outside of onConnect.
The reason for that is this line.
because here websocket connection is waited and does not return untill connected.
otherwise ticker.Subscribe(Tokens: new UInt32[] { 738561 });
would not have worked outside OnConnect.
maybe it is different in other language bindings for kiteconnect. but C# one makes it work
for you because of that line.
Thanks
Regards.