when I'm trying to pull the data for the LTP and OHLC facing an issue of the Input data exception like below even though I passed the data as suggested format DEBUG: GET https://api.kite.trade/quote/ltp?i=NSE:INFY&api_key=7sfgfgsmd9aca57du DEBUG: User-Agent: KiteConnect.Net/3.0.4.0 DEBUG: X-Kite-Version: 3 DEBUG: Authorization: token 7sfgfgsmd9aca57du DEBUG: 400 {"status":"error","message":"empty `api_key` or `access_token`","data":null,"error_type":"InputException"}
thank you rakeshr we captured the access token and have set it in the code but still it is giving the input exception . We are using the .NET platfrom to build or app I will give you more detailed explanation on the error so that it will be easy for you to help us 1.caputred the APIkey,secretkey,access token,publictoken. and set them in code.
below piece of code is not working even though we pass the request token User user = kite.GenerateSession(requestToken, MySecret); public User GenerateSession(string RequestToken, string AppSecret) { string checksum = Utils.SHA256(_apiKey + RequestToken + AppSecret);
var param = new Dictionary { {"api_key", _apiKey}, {"request_token", RequestToken}, {"checksum", checksum} };
var userData = Post("api.token", param);
return new User(userData); }
and here while performing the below get it is throwing the input data exception Dictionary ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY" }); Console.WriteLine(Utils.JsonSerialize(ltps));
@sujith thanks for the suggestion I have referred already this we have captured the access_token and public_token and stored in our code like below and I understand that request token is generated during everylogin. static string MyAPIKey = "7oq0bsmd9aca85du"; static string MySecret = "o41du1myizhzmxu91g9dqw5nn0uo9an5"; static string MyUserId = "WRxx85"; static string MyPublicToken = "0vmd7GX0528JzaEuoreYxTo6l0PwxHew"; static string MyAccessToken = "TDG6Tb73mu1Cuh1qMLwGbUMSs97Gd7oL" which but while passing the request to get the market.ltp data we are getting the data input exception and we are getting the issue like api_key or access_tkoen empty.
But it appears to me that you are not initiating Kite properly. you say you are using C# but it appears you are trying to send direct requests via web./curl etc. Again i could be wrong. market.ltp is tackled by GetLTP itself. or were you trying to refer internals of GetLTP.
From the looks of it. i am pretty sure you are not setting access token within kite instance. either you are not sending access token in the constructor of kite. or you are not setting access token later.
thank you for the response I'm setting the accesstoken and publictoken in the kite constructor only but when I'm running the code. I'm getting the input data exception
class Program { // instances of Kite and Ticker static Ticker ticker; static Kite kite;
// Initialize key and secret of your app static string MyAPIKey = "7oq0bsmd9ira57du"; static string MySecret = "o41du1myizhzmxu91g9dqw5nn0uq7an5"; static string MyUserId = "WR9819";
// persist these data in settings or db or file below keys are capture and stored in the static variable during the first logon and will be used for the furhter execution.
kite = new Kite(MyAPIKey, Debug: true); // For handling 403 errors kite.SetSessionExpiryHook(OnTokenExpire); // Initializes the login flow try { initSession();
// below code is not executed and it is going to the exception block and throwing an input data exception Dictionary ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY" }); Console.WriteLine(Utils.JsonSerialize(ltps)); } catch (Exception e) { // Cannot continue without proper authentication Console.WriteLine(e.Message); Console.ReadKey(); Environment.Exit(0); }
below is the Initsession code private static void initSession() { Console.WriteLine("Goto " + kite.GetLoginURL()); Console.WriteLine("Enter request token: "); string requestToken = Console.ReadLine();//here request token is passed everytime we login int i = 32; User user = kite.GenerateSession(requestToken, MySecret);
//generate session code this part is not at all executed public User GenerateSession(string RequestToken, string AppSecret) { string checksum = Utils.SHA256(_apiKey + RequestToken + AppSecret);
var param = new Dictionary { {"api_key", _apiKey}, {"request_token", RequestToken}, {"checksum", checksum} };
if this is your real code then, tell me on which line did you set the access token in kite instance. I don`t see it anywhere and are these secret key and api key real. if so remove them immediately . You should not post your secret information on public forums.
Either show me on which line you set the access token in or write those lines you are actually coding to insert access token into kite instance.
in your code above kite instance is getting your APIKey and command to print Debug information. Inside initSession() MyAccessToken = user.AccessToken; is setting global variable of Program class. that does not mean it will automatically be available to kite instance variable.
No they aren't original keys I have altered them so you want me to set the MyAccessToken = user.AccessToken; in the initSession() or in try block using kite.SetAccessToken(MyAccessToken); then will it execute. private static void initSession() { Console.WriteLine("Goto " + kite.GetLoginURL()); Console.WriteLine("Enter request token: "); string requestToken = Console.ReadLine(); kite.SetAccessToken(MyAccessToken); User user = kite.GenerateSession(requestToken, MySecret);
Console.WriteLine(Utils.JsonSerialize(user));
MyAccessToken = user.AccessToken; MyPublicToken = user.PublicToken; } this code changes will work ? as I'm instantiating all the keys.
call kite.SetAccessToken( MyAccessToken ) ; based on above two criterias in the above code again you are calling kite.SetAccessToken( MyAccessToken ) ; before generating it. so your call would have failed again.
the way you are going about it you can set it below Line 395 as the last line of the function.
You need to send access_token as well in
Authorization
header. Go through this documentation.1.caputred the APIkey,secretkey,access token,publictoken. and set them in code.
below piece of code is not working even though we pass the request token
User user = kite.GenerateSession(requestToken, MySecret);
public User GenerateSession(string RequestToken, string AppSecret)
{
string checksum = Utils.SHA256(_apiKey + RequestToken + AppSecret);
var param = new Dictionary
{
{"api_key", _apiKey},
{"request_token", RequestToken},
{"checksum", checksum}
};
var userData = Post("api.token", param);
return new User(userData);
}
and here while performing the below get it is throwing the input data exception
Dictionary ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY" });
Console.WriteLine(Utils.JsonSerialize(ltps));
You can refer to this thread.
we have captured the access_token and public_token and stored in our code like below and I understand that request token is generated during everylogin.
static string MyAPIKey = "7oq0bsmd9aca85du";
static string MySecret = "o41du1myizhzmxu91g9dqw5nn0uo9an5";
static string MyUserId = "WRxx85";
static string MyPublicToken = "0vmd7GX0528JzaEuoreYxTo6l0PwxHew";
static string MyAccessToken = "TDG6Tb73mu1Cuh1qMLwGbUMSs97Gd7oL"
which but while passing the request to get the market.ltp data we are getting the data input exception and we are getting the issue like api_key or access_tkoen empty.
But it appears to me that you are not initiating Kite properly.
you say you are using C# but it appears you are trying to send direct requests via web./curl etc.
Again i could be wrong.
market.ltp is tackled by GetLTP itself. or were you trying to refer internals of GetLTP.
From the looks of it. i am pretty sure you are not setting access token within kite instance. either you are not sending access token in the constructor of kite.
or you are not setting access token later.
Thanks
Regards
class Program
{
// instances of Kite and Ticker
static Ticker ticker;
static Kite kite;
// Initialize key and secret of your app
static string MyAPIKey = "7oq0bsmd9ira57du";
static string MySecret = "o41du1myizhzmxu91g9dqw5nn0uq7an5";
static string MyUserId = "WR9819";
// persist these data in settings or db or file below keys are capture and stored in the static variable during the first logon and will be used for the furhter execution.
static string MyPublicToken = "0vmd7GX0528JzaEuoreYxTo6l0PwxHew";
static string MyAccessToken = "TDG6Tb73mu1Cuh1qMLwGbUMSs97Gd7oL";
static void Main(string[] args)
{
kite = new Kite(MyAPIKey, Debug: true);
// For handling 403 errors
kite.SetSessionExpiryHook(OnTokenExpire);
// Initializes the login flow
try
{
initSession();
// below code is not executed and it is going to the exception block and throwing an input data exception
Dictionary ltps = kite.GetLTP(InstrumentId: new string[] { "NSE:INFY" });
Console.WriteLine(Utils.JsonSerialize(ltps));
}
catch (Exception e)
{
// Cannot continue without proper authentication
Console.WriteLine(e.Message);
Console.ReadKey();
Environment.Exit(0);
}
below is the Initsession code
private static void initSession()
{
Console.WriteLine("Goto " + kite.GetLoginURL());
Console.WriteLine("Enter request token: ");
string requestToken = Console.ReadLine();//here request token is passed everytime we login
int i = 32;
User user = kite.GenerateSession(requestToken, MySecret);
Console.WriteLine(Utils.JsonSerialize(user));
MyAccessToken = user.AccessToken;
MyPublicToken = user.PublicToken;
}
//generate session code this part is not at all executed
public User GenerateSession(string RequestToken, string AppSecret)
{
string checksum = Utils.SHA256(_apiKey + RequestToken + AppSecret);
var param = new Dictionary
{
{"api_key", _apiKey},
{"request_token", RequestToken},
{"checksum", checksum}
};
var userData = Post("api.token", param);
return new User(userData);
}
I don`t see it anywhere and are these secret key and api key real. if so remove them immediately .
You should not post your secret information on public forums.
Either show me on which line you set the access token in or write those lines you are actually coding to insert access token into kite instance.
in your code above kite instance is getting your APIKey and command to print Debug information.
Inside initSession()
MyAccessToken = user.AccessToken;
is setting global variable of Program class. that does not mean it will
automatically be available to kite instance variable.
Thanks
Regards
{
Console.WriteLine("Goto " + kite.GetLoginURL());
Console.WriteLine("Enter request token: ");
string requestToken = Console.ReadLine();
kite.SetAccessToken(MyAccessToken);
User user = kite.GenerateSession(requestToken, MySecret);
Console.WriteLine(Utils.JsonSerialize(user));
MyAccessToken = user.AccessToken;
MyPublicToken = user.PublicToken;
}
this code changes will work ? as I'm instantiating all the keys.
in the above code again you are calling kite.SetAccessToken( MyAccessToken ) ; before
generating it. so your call would have failed again.
the way you are going about it you can set it below Line 395 as the last line of the function.
Thanks
Regards