It looks like you're new here. If you want to get involved, click one of these buttons!
private const string MyAPIKey = "sfgsgsg";
private const string MySecret = "xfvcvv";
static string MyUserId = "cbxhb";
Kite kite = new Kite(MyAPIKey, Debug: true);
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["request_token"] != null)
{
string RequestToken = Convert.ToString(Request.QueryString["request_token"]);
User user = kite.GenerateSession(RequestToken, MySecret);
string MyAccessToken = user.AccessToken;
string MyPublicToken = user.PublicToken;
string UserId = "ZG6149";
Ticker ticker = new Ticker(MyAPIKey, UserId, MyPublicToken);
ticker.OnTick += OnTick;
ticker.OnOrderUpdate += OnOrderUpdate;
ticker.OnReconnect += OnReconnect;
ticker.OnNoReconnect += OnNoReconnect;
ticker.OnError += OnError;
ticker.OnClose += OnClose;
ticker.OnConnect += OnConnect;
ticker.EnableReconnect(Interval: 5, Retries: 50);
ticker.Connect();
ticker.Subscribe(Tokens: new UInt32[] { 256265 });
ticker.SetMode(Tokens: new UInt32[] { 256265 }, Mode: Constants.MODE_LTP);
LblResult.Text = Utils.JsonSerialize(ticker);
}
}
private static void initSession()
{
string RequestToken = Convert.ToString(HttpContext.Current.Session["REQUEST_TOKEN"]);
Kite kite = new Kite(MyAPIKey, Debug: true);
User user = kite.GenerateSession(RequestToken, MySecret);
Console.WriteLine(Utils.JsonSerialize(user));
}
private static void initTicker()
{
string RequestToken = Convert.ToString(HttpContext.Current.Session["REQUEST_TOKEN"]);
Kite kite = new Kite(MyAPIKey, Debug: true);
string MyAccessToken = Convert.ToString(HttpContext.Current.Session["ACCESS_TOKEN"]);
string MyPublicToken = Convert.ToString(HttpContext.Current.Session["PUBLIC_TOKEN"]);
string UserId = "ZG6149";
kite.SetAccessToken(MyAccessToken);
Ticker ticker = new Ticker(MyAPIKey, UserId, MyPublicToken);
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();
ticker.Subscribe(Tokens: new UInt32[] { 256265 });
ticker.SetMode(Tokens: new UInt32[] { 256265 }, Mode: Constants.MODE_LTP);
}
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));
}
Also, you are creating a ticker object inside a function like this:
Ticker ticker = new Ticker(MyAPIKey, UserId, MyPublicToken);
This ticker instance will get disposed immediately after the function execution is completed.
If you want a ticker running continuously in the server then you have to create a command line application. The example code given in the github repository is for that. Or you have to create a service that is not depended on page events.
PS: Do not post your App's credentials(api key, secret, tokens etc.) on the forum publicly. This may lead to unauthorised access.