Ticker connection gets closed and it tries to reconnect after every 5 second as reconnect interval was 5, and error was unable to parse instrument token. My question is i haven't even added any new stock to list. if it was able to parse one time why not second time. Fine if was unable to parse also but which instrument token was unable to parse that also not clear. Please help me on this.
Please respond, today also after 15 mins means from 9:30 again it started giving error 'unable to parse instrument token', 'One or more errors occured'
private void Events_AskForStockSubscriptionEvent(string[] tradingSymbol, StockSubscribeMode mode, bool isSubscribe) { GetCode: try { if (isSubscribe) { var ltp = Kite.GetLTP(tradingSymbol); List tokens = new List(); foreach (var item in ltp) { var token = item.Value.InstrumentToken; _instrumentToken[token] = item.Key; tokens.Add(token); } var ar = tokens.ToArray(); ticker.Subscribe(ar); ticker.SetMode(ar, Mode: KiteConnect.Constants.MODE_LTP); } else {
List tokens = new List(); foreach (var item in tradingSymbol) { if (_instrumentToken.Any(s => s.Value.Equals(item))) { var first = _instrumentToken.FirstOrDefault(s => s.Value.Equals(tradingSymbol)); tokens.Add(first.Key); } } var ar = tokens.ToArray(); ticker.UnSubscribe(ar); } } catch (Exception) { goto GetCode; } }
The mentioned error happens when you send the instrument tokens as strings instead of integers. But your code looks fine. We need more data to debug this issue. Can you initialize ticker like below:
Ticker ticker = new Ticker(MyAPIKey, MyAccessToken, Debug: true);
This will print more data about the things happening behind the scenes in the debug console. Can you post the debug log you get when you subscribe and get the error?
I am also getting the same error, Socket is getting disconnected around 10:00 AM daily, after reconnecting success it is giving below error : Error parsing instrument tokens.
After error I am getting Lost ticker connection. Once it is getting disconnected it is not re-connecting. I also checked with the internet connectivity, not issues from internet provider. Internet connection is stable.
I am using KiteConnect.dll run time version v4.0.30319. Please respond ASAP. This is happening to me for more than a week.
@NaveenR Can you post the debug logs from ticker at that time frame?
Also, if your internet connection can deliver 10-20 KB/s that is enough for hundreds of tokens. The disconnections usually happen due to the proxies or firewalls at your end or at your ISP end. Some ISPs might disconnect long-standing connections after some time.
Please post the log, we will check what's going on. Thanks.
Are you building a console application or a GUI application? If it is a GUI application your logs will be in the Debug window or in the Output window. If it is a console application, by logs I meant whatever gets printed in the console. Can you post those logs at that time frame?
Also, can you confirm that this happens exactly at 10.00 AM?
I got something like this in my console at 9:40 AM Resubscribing {"a":"unsubscribe","v":[107265]} 30 {"a":"mode","v":["ltp", [107265]]} {"a":"mode","v":["quote", []]} {"a":"mode","v":["full", []]} Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
This is thrown from the UI. Can you double check the logic you are using? Also to isolate the source of bug maybe you should create a simple app with just ticker and try to reproduce this issue.
I changed the code, now there is reconnecting issues.
Below is my log from my console
The thread 0x29f0 has exited with code 0 (0x0). 4 No of packets: 2 No of bytes: 22 Packet Length 8 Packet Length 8 15/11/2018 13:37:23 Heartbeat No of packets: 2 No of bytes: 22 Packet Length 8 Packet Length 8 4 No of packets: 1 No of bytes: 12 Packet Length 8 4 The thread 0x170 has exited with code 0 (0x0). 3 The thread 0x2514 has exited with code 0 (0x0). 2 1 0 Resubscribing {"a":"unsubscribe","v":[7455745,1921537]} 39 {"a":"mode","v":["ltp", [7455745,1921537]]} {"a":"mode","v":["quote", []]} {"a":"mode","v":["full", []]} New interval 5 5 WebSocket Message: {"type":"error","data":"Error parsing instrument tokens."} WebSocket Message: {"type":"error","data":"Error parsing instrument tokens."}
if it goes like this it's horrible.
Can you post the code that creates and subscribes the ticker? We will try to run the same and reproduce the issue.
{
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: 1, Retries: 50);
ticker.Connect();
}
private void OnOrderUpdate(Order OrderData)
{
string symbol = string.Format("{0}:{1}", OrderData.Exchange, OrderData.Tradingsymbol);
Events.RaiseRevievedOrderInfoEvent(OrderData);
}
private void OnConnect()
{
}
private void OnClose()
{
}
private void OnError(string Message)
{
}
private void OnNoReconnect()
{
}
private void OnReconnect()
{
}
private void OnTick(Tick TickData)
{
try
{
Events.RaiseStockLTPChangedEvent(_instrumentToken[TickData.InstrumentToken], TickData.LastPrice);
}
catch (Exception)
{
}
}
private void Events_AskForStockSubscriptionEvent(string[] tradingSymbol, StockSubscribeMode mode, bool isSubscribe)
{
GetCode:
try
{
if (isSubscribe)
{
var ltp = Kite.GetLTP(tradingSymbol);
List tokens = new List();
foreach (var item in ltp)
{
var token = item.Value.InstrumentToken;
_instrumentToken[token] = item.Key;
tokens.Add(token);
}
var ar = tokens.ToArray();
ticker.Subscribe(ar);
ticker.SetMode(ar, Mode: KiteConnect.Constants.MODE_LTP);
}
else
{
List tokens = new List();
foreach (var item in tradingSymbol)
{
if (_instrumentToken.Any(s => s.Value.Equals(item)))
{
var first = _instrumentToken.FirstOrDefault(s => s.Value.Equals(tradingSymbol));
tokens.Add(first.Key);
}
}
var ar = tokens.ToArray();
ticker.UnSubscribe(ar);
}
}
catch (Exception)
{
goto GetCode;
}
}
The mentioned error happens when you send the instrument tokens as strings instead of integers. But your code looks fine. We need more data to debug this issue. Can you initialize ticker like below:
Ticker ticker = new Ticker(MyAPIKey, MyAccessToken, Debug: true);
This will print more data about the things happening behind the scenes in the debug console. Can you post the debug log you get when you subscribe and get the error?
{"a":"unsubscribe","v":[0]}
{"a":"unsubscribe","v":[0]}
{"a":"unsubscribe","v":[0]}
Getting this message while unsubscribing and that is where it is trying to reconnect and resubscribe.
Can you try to log "ar" used in this line of code?
ticker.UnSubscribe(ar);
I believe there is a token which is 0. And that is invalid.
After error I am getting Lost ticker connection. Once it is getting disconnected it is not re-connecting. I also checked with the internet connectivity, not issues from internet provider. Internet connection is stable.
I am using KiteConnect.dll run time version v4.0.30319. Please respond ASAP. This is happening to me for more than a week.
Also, if your internet connection can deliver 10-20 KB/s that is enough for hundreds of tokens. The disconnections usually happen due to the proxies or firewalls at your end or at your ISP end. Some ISPs might disconnect long-standing connections after some time.
Please post the log, we will check what's going on. Thanks.
in onError function I am getting - Error parsing instrument tokens and then Lost ticker connection.
Please suggest me if I am making any mistake in coding.
Regards.
Also, can you confirm that this happens exactly at 10.00 AM?
I am receiving only "Error parsing instrument tokens" and "Lost ticker connection" under my log.
private void onError(string Message)
{
Console.WriteLine(Message);
logFile.WriteLogToFile("Socket Connection error : " + Message + DateTime.Now);
}
This happens around 09:50 AM to 10:00 AM daily. I am able to fetch the data till 09:50 AM. Once it got disconnected, I am not able to connect again.
Is there any other kiteConnect.dll to find more information on debug mode?
Make sure you are passing instrument tokens as numbers, not as string/character.
Resubscribing
{"a":"unsubscribe","v":[107265]}
30
{"a":"mode","v":["ltp", [107265]]}
{"a":"mode","v":["quote", []]}
{"a":"mode","v":["full", []]}
Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
After disconnecting it is not reconnecting
Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll
This is thrown from the UI. Can you double check the logic you are using? Also to isolate the source of bug maybe you should create a simple app with just ticker and try to reproduce this issue.
Below is my log from my console
The thread 0x29f0 has exited with code 0 (0x0).
4
No of packets: 2
No of bytes: 22
Packet Length 8
Packet Length 8
15/11/2018 13:37:23 Heartbeat
No of packets: 2
No of bytes: 22
Packet Length 8
Packet Length 8
4
No of packets: 1
No of bytes: 12
Packet Length 8
4
The thread 0x170 has exited with code 0 (0x0).
3
The thread 0x2514 has exited with code 0 (0x0).
2
1
0
Resubscribing
{"a":"unsubscribe","v":[7455745,1921537]}
39
{"a":"mode","v":["ltp", [7455745,1921537]]}
{"a":"mode","v":["quote", []]}
{"a":"mode","v":["full", []]}
New interval 5
5
WebSocket Message: {"type":"error","data":"Error parsing instrument tokens."}
WebSocket Message: {"type":"error","data":"Error parsing instrument tokens."}
Version : 3.0.0.0