Error of Input Exception for some orders while placing orders

rishabh1

We are facing issues placing orders via the API on Kite. The errors are random: Some orders are going through and some are not. There is no set pattern as to which order is going through and what is not.

One of the errors was the following:

I am getting this error {"status":"error","message":"Limit price should be greater than zero.","data":null,"error_type":"InputException"} while placing the order through Kite Api. This error message is coming for most of the contracts across all the asset classes and across different accounts as well. When I check the limit price, it is not null or 0 it has some value.



It was working properly until yesterday. This is the first time we have faced such an issue. Is there some systemic issue with the API today/ or was there some changes made on the Zerodha Kite API end?


@sujith Please help.
  • rakeshr
    rakeshr edited December 2021
    Can you please give a few of those order placement params(which are throwing above input exception)? As this error message is thrown only if the limit price field is send as zero.
  • rishabh1
    public static string Placezerodhaorder(string MyAPIKey, string accesstoken, string Exchange,
    string TradingSymbol,
    string TransactionType,
    string Quantity,
    string price = null,
    string Product = null,
    string OrderType = null,
    string Validity = null,
    string DisclosedQuantity = null,
    string TriggerPrice = null,
    string SquareOffValue = null,
    string StoplossValue = null,
    string TrailingStoploss = null,
    string Variety = Constants.VARIETY_REGULAR,
    string Tag = ""
    )
    {


    try
    {
    var client = new HttpClient();
    var pairs = new List>


    {
    new KeyValuePair("exchange", Exchange),
    new KeyValuePair("tradingsymbol", TradingSymbol),
    new KeyValuePair("transaction_type", TransactionType),
    new KeyValuePair("quantity", Quantity.ToString()),
    new KeyValuePair("price",price.ToString()),
    new KeyValuePair("product", Product),
    new KeyValuePair("order_type", OrderType),
    new KeyValuePair("validity", Validity),
    new KeyValuePair("disclosed_quantity", DisclosedQuantity.ToString()),
    new KeyValuePair("trigger_price", TriggerPrice.ToString()),
    new KeyValuePair("squareoff", SquareOffValue.ToString()),
    new KeyValuePair("stoploss", StoplossValue.ToString()),
    new KeyValuePair("trailing_stoploss", TrailingStoploss.ToString()),
    new KeyValuePair("variety", Variety),
    new KeyValuePair("tag", Tag)
    };


    var content = new FormUrlEncodedContent(pairs);
    client.DefaultRequestHeaders.Add("Authorization", "token " + MyAPIKey + ":" + accesstoken);
    var responsess = client.PostAsync("https://api.kite.trade/orders/" + Variety, content).Result;

    if (responsess.IsSuccessStatusCode)
    {
    var ss = responsess.Content.ReadAsStringAsync().Result;
    return ss;
    }
    else
    {
    var ss = responsess.Content.ReadAsStringAsync().Result;
    return ss;
    }

    }
    catch (WebException ex)
    {
    return ex.Message;
    }

    }


    This is code snippet... Price is throwing the exception. I am passing all the required variable to this function.
  • rakeshr
    new KeyValuePair("price",price.ToString()),
    price field should be float data type not string.
  • rishabh1
    Thank you Rakesh, Any Idea, why this error has come up now. We have been using this code since 1.5 years and sent out more than 10K orders in the last year using the same.

  • rishabh1
    Hi, Today all the orders went perfectly fine, we did not make any changes on our end. Why does the issue go and come?
  • rishabh1
    Hi, Now we are facing the same issue again today as above. For two days the orders went perfectly fine but the same orders with the same parameters are going sometimes and are being rejected sometimes with the error " {"status":"error","message":"Limit price should be greater than zero.","data":null,"error_type":"InputException"} ".

    We are placing orders from Visual Studio: dotnet C#. While placing same orders from python, postman the orders are going fine.

    Anyone facing a similar issue or would know why this would be happening?
  • sujith
    Can you let us know which library you are using and the version number and a bit about your setup?
  • rishabh1
    rishabh1 edited January 4
    Hi Sujith,

    We tried placing orders using two different libraries:

    1. Rest Sharp: The following is the code made by postman:

    var client = new RestClient("https://api.kite.trade/orders/regular");
    client.Timeout = -1;
    var request = new RestRequest(Method.POST);
    request.AddHeader("Authorization", "token XXXX:XXXXXXXXXXXXXX");
    request.AddHeader("ijqjp8eqygba1rw2", "t");
    request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
    request.AddParameter("tradingsymbol", "BHEL");
    request.AddParameter("exchange", "NSE");
    request.AddParameter("transaction_type", "SELL");
    request.AddParameter("order_type", "LIMIT");
    request.AddParameter("quantity", "1");
    request.AddParameter("product", "MIS");
    request.AddParameter("price", "62");
    request.AddParameter("validity", "DAY");
    IRestResponse response = client.Execute(request);
    Console.WriteLine(response.Content);



    2. Using http Client:
    string responseFromServer = string.Empty;
    var tt = "tradingsymbol=" + TradingSymbol + "&exchange=" + Exchange + "&transaction_type=" + TransactionType + "&order_type=" + OrderType + "&quantity=" + Quantity + "&product=" + Product + "&price=" + Price + "&trigger_price=" + TriggerPrice + "&disclosed_quantity=" + DisclosedQuantity + "&validity=" + Validity + "&tag=" + Tag + "&squareoff=" + SquareOffValue + "&stoploss=" + StoplossValue + "&trailing_stoploss=" + TrailingStoploss + "&variety=" + Variety;

    var content = new FormUrlEncodedContent(pairs);
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    // Create a request using a URL that can receive a post.
    WebRequest request = WebRequest.Create("https://api.kite.trade/orders/" + Variety);
    // Set the Method property of the request to POST.
    request.Method = "POST";
    // Create POST data and convert it to a byte array.
    byte[] byteArray = Encoding.UTF8.GetBytes(tt);
    request.Headers.Add("Authorization", "token " + MyAPIKey + ":" + accesstoken);
    // Set the ContentType property of the WebRequest.
    request.ContentType = "application/x-www-form-urlencoded";
    // Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length;

    // Get the request stream.
    Stream dataStream = request.GetRequestStream();
    // Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length);
    // Close the Stream object.
    dataStream.Close();

    // Get the response.
    WebResponse response = request.GetResponse();
    // Display the status.
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);

    // Get the stream containing content returned by the server.
    // The using block ensures the stream is automatically closed.
    using (dataStream = response.GetResponseStream())
    {
    // Open the stream using a StreamReader for easy access.
    StreamReader reader = new StreamReader(dataStream);
    // Read the content.
    responseFromServer = reader.ReadToEnd();
    // Display the content.
    Console.WriteLine(responseFromServer);
    }

    // Close the response.
    response.Close();
    return responseFromServer;
    }
    catch (WebException ex)
    {
    return ex.Message;
    }



    Both these methods were working yesterday and on Friday, they have been working since the last 1.5 years. But today again: the same codes work sometimes and the other times they are giving the same error of "Limit price being zero".

  • rishabh1
    The version for
    Rest Sharp Library: 106.15.0
    System.Net.http: 4.3.4
  • sujith
    Can you private message the api_key and client id?
  • rishabh1
    Hi Sujith, the issue seems to be resolved. The issue was in passing the values like: Disclosed qty,triggerprice, squareoffvalue. These values were being passed as null ("") . Some times it was being accepted and sometimes it was not being accepted. Have added a condition for this: If these values are empty then we do not pass the values ahead. In normal limit orders the "disclosed qty" and some other values are mostly empty . Sometimes it was being accepted and sometimes it wasnt. Now we have stopped passing these values in case they are empty.
  • rishabh1
    Really appreciate your support.
This discussion has been closed.