☰
Login
Signup
Home
›
Mobile and Desktop apps
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Register
Categories
Recent Discussions
Activity
Categories
13.8K
All Categories
0
Incidents
153
Node JS client
40
Go client
793
.Net API client
378
Kite Publisher
537
.Net / VBA / Excel (3rd party)
457
Algorithms and Strategies
993
Java client
1.1K
API clients
404
PHP client
4K
Python client
346
Mobile and Desktop apps
1.4K
Market data (WebSockets)
3.3K
General
In this Discussion
September 2016
Vivek
September 2016
cdesai1987
September 2016
Kailash
Below code is not working ."The remote server returned an error: (400) Bad Request "" Please Help
cdesai1987
September 2016
in
Mobile and Desktop apps
try
{
string url5 = "
https://api.kite.trade/orders/regular
";
var R1 = (HttpWebRequest)WebRequest.Create(url5);
R1.ContentType = "application/json; charset=UTF-8";
R1.Method = "POST";
using (var streamWriter = new StreamWriter(R1.GetRequestStream()))
{
string loginjson1 = new JavaScriptSerializer().Serialize(new
{
api_key = "XXXXX",
access_token = "XXXXX",
tradingsymbol="ACC",
exchange="NSE" ,
transaction_type="BUY" ,
order_type="MARKET" ,
quantity="1" ,
product="MIS" ,
validity="DAY"
});
streamWriter.Write(loginjson1);
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)R1.GetResponse();
}
catch (Exception ex)
{
Response.Write(ex);
}
Kailash
September 2016
You are sending a JSON payload, but the API only accepts standard form encoded POST parameters.
cdesai1987
September 2016
edited September 2016
Even the below code which is non Json code is not working... Please Help
System.Net.WebRequest req = System.Net.WebRequest.Create("
https://api.kite.trade/orders/regular
");
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("api_key=xxx&access_token=" + accesstoken + "&tradingsymbol=ACC&exchange=NSE&transaction_type=BUY&order_type=Market&quantity=1&product=MIS&validity=DAY");
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr =
new System.IO.StreamReader(resp.GetResponseStream());
Response.Write(sr.ReadToEnd().Trim());
Kailash
September 2016
What's the error message that you are getting?
cdesai1987
September 2016
edited September 2016
The remote server returned an error: (400) Bad Request
cdesai1987
September 2016
I am sending it from local https url. I am getting the access token from here but cannot execute the trades
Vivek
September 2016
edited September 2016
@cdesai1987
Please check for error message in response. You might get a meaningful error message which will help you to debug it. Generally 400 means you are sending invalid data or not sending required params.
cdesai1987
September 2016
It works now thanks
This discussion has been closed.
System.Net.WebRequest req = System.Net.WebRequest.Create("https://api.kite.trade/orders/regular");
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("api_key=xxx&access_token=" + accesstoken + "&tradingsymbol=ACC&exchange=NSE&transaction_type=BUY&order_type=Market&quantity=1&product=MIS&validity=DAY");
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr =
new System.IO.StreamReader(resp.GetResponseStream());
Response.Write(sr.ReadToEnd().Trim());