Getting error while trying to place basket order using kite publisher

tarunprasadoff
basket = {

"api_key": API_KEY,

"data": [
{
"exchange": "NFO",
"tradingsymbol": "NIFTY21DEC17000PE",
"transaction_type": "SELL",
"variety": "regular",
"product": "NRML",
"order_type": "LIMIT",
"quantity": 50,
"price": 97
},
{
"exchange": "NFO",
"tradingsymbol": "NIFTY21DEC17000CE",
"transaction_type": "BUY",
"variety": "regular",
"product": "NRML",
"order_type": "LIMIT",
"quantity": 50,
"price": 143
},
{
"exchange": "NFO",
"tradingsymbol": "NIFTY21DECFUT",
"transaction_type": "SELL",
"variety": "regular",
"product": "NRML",
"order_type": "LIMIT",
"quantity": 50,
"price": 17055
}
]
}

requests.post("https://kite.zerodha.com/connect/basket", json=basket)

By running this I am getting the following response:

{
"status": "error",
"message": "Invalid JSON payload in `data`.",
"data": null,
"error_type": "InputException"
}

I was getting the above error initially. Now for the same code, I am getting the following response:

{
"status":"error",
"message":"Missing or empty field `api_key`",
"data":null,
"error_type":"InputException"
}

I don't know what is going wrong
  • rakeshr
    "message": "Invalid JSON payload in `data`.",
    You need to post basket as form post. Check an example for the same here.
  • tarunprasadoff
    I did that too still getting the same error. I used the following code in an HTML file:

    <!DOCTYPE html>

    Kite Connect Basket Order Test







    document.getElementById("basket").value = [{
    "variety": "regular",
    "tradingsymbol": "INFY",
    "exchange": "NSE",
    "transaction_type": "BUY",
    "order_type": "MARKET",
    "quantity": 10,
    "readonly": false
    }, {
    "variety": "regular",
    "tradingsymbol": "NIFTY21DECFUT",
    "exchange": "NFO",
    "transaction_type": "SELL",
    "order_type": "LIMIT",
    "price": 7845,
    "quantity": 1,
    "readonly": false
    },
    {
    "variety": "bo",
    "tradingsymbol": "RELIANCE",
    "exchange": "NSE",
    "transaction_type": "BUY",
    "order_type": "LIMIT",
    "product": "MIS",
    "price": 915.15,
    "quantity": 1,
    "stoploss": 5,
    "squareoff": 7,
    "trailing_stoploss": 1.5,
    "readonly": true
    }]
    document.getElementById("basket-form").submit();





    I am getting the same following error:

    {"status":"error","message":"Invalid JSON payload in `data`.","data":null,"error_type":"InputException"}
  • rakeshr
    I tried the same order param at my end, it's working fine. Are you including basket form?
    this section:
    <form method="post" id="basket-form" action="https://kite.zerodha.com/connect/basket">
    <input type="hidden" name="api_key" value="xxx" />
    <input type="hidden" id="basket" name="data" value="" />
    </form>
  • tarunprasadoff
    I am doing the exact same thing. I am using the basket form. It is not working. Kindly suggest a solution
  • rakeshr
    Please paste here or DM your complete publisher code.
Sign In or Register to comment.