Below is the c# code: dynamic json; var url = "https://api.kite.trade/margins/basket?consider_positions=false"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "token " + API + ":" + MyAccessToken; httpRequest.ContentType = "application/x-www-form-urlencoded"; var data = "[{\"exchange\": \"NFO\",\"tradingsymbol\": \"AMBUJACEM22JAN370PE\",\"transaction_type\": \"SELL\",\"variety\": \"regular\",\"product\": \"NRML\",\"order_type\": \"MARKET\",\"quantity\": 1500,\"price\": 0,\"trigger_price\": 0}]"; using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(data); } var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); // at this line getting this error System.Net.WebException: 'The remote server returned an error: (400) Bad Request.' string result; using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } json = JsonConvert.DeserializeObject(result);
Below is the c# code:
dynamic json;
var url = "https://api.kite.trade/margins/basket?consider_positions=false";
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.Headers["Authorization"] = "token " + API + ":" + MyAccessToken;
httpRequest.ContentType = "application/x-www-form-urlencoded";
var data = "[{\"exchange\": \"NFO\",\"tradingsymbol\": \"AMBUJACEM22JAN370PE\",\"transaction_type\": \"SELL\",\"variety\": \"regular\",\"product\": \"NRML\",\"order_type\": \"MARKET\",\"quantity\": 1500,\"price\": 0,\"trigger_price\": 0}]";
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
streamWriter.Write(data);
}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); // at this line getting this error System.Net.WebException: 'The remote server returned an error: (400) Bad Request.'
string result;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
json = JsonConvert.DeserializeObject(result);
The same was working before
application/json
, refer complete curl request params here.one more thing how to add consider_positions=false in kite 3.0.7.0 using below code
OrderMarginParams param = new OrderMarginParams();
param.Exchange = "NFO";
param.TradingSymbol = "AMBUJACEM22JAN370PE"
param.TransactionType = "SELL";
param.Quantity = 1500;
param.Price = 0m;
param.OrderType = "MARKET";
param.Product = "NRML";
List margins = kite.GetOrderMargins(new List() { param });