TypeError when calling https order API via Python

tahseen
tahseen edited November 2017 in API clients
Please help. Am trying to place place a bracket order and I am doing below as per the Kite Connect Documentation

Please note access_token and api_key is correct they are working with requests for historical data

Bracket Order payload created. 

payload = {
'access_token=XXXXXX', 
'api_key=XXXXXX',
'exchange=NSE',
'order_type=LIMIT',
'order_variety=bo',
'price=1680.0',
'product=MIS',
'quantity=1',
'squareoff_value=1.0',
'stoploss_value=1.0','
'tradingsymbol=ACC',
'transaction_type=SELL',
'validity=DAY'
}

response = requests.post("https://api.kite.trade/orders/regular", data=payload)

throw this errorTypeError: 'set' object has no attribute '__getitem__'
  • sujith
    I think you missed adding trailing_stoploss.
    You can refer to example here.
  • tahseen
    trailing_stoploss is an optional parameter and it is mentioned also in the API Document on the website
  • sujith
    Can you give us the error message and status code, maybe that will help to narrow down the issue?
  • tahseen
    tahseen edited November 2017
    I found the reason. On your Kite Connect page you have incorrectly written how the post data is submitted via requests.post function of requests module in Python

    Default payload is JSON format. Your documentation on site is incorrect. Please correct it. It should be like this

    CORRECT STYLE
    payload = {
    "param1" : data1,
    "param2" : data2,
    }

    INCORRECT STYLE (Mentioned on Kite Connect Website Documentation)

    payload = {
    "param1=data1",
    "param2=data2"
    }
Sign In or Register to comment.