Not able to fetch positions using python client

SZM059
i have been using this request to fetch positions in python for last 2 years, which uses api key and access_token. I started giving me error today. what changes has been done ? what's the new request i have to send now in python.

requests.get("https://api.kite.trade/portfolio/positions?api_key=********&access_token=******
response - {'status': 'error', 'message': 'Invalid `api_key` or `access_token`.', 'data': None, 'error_type': 'InputException'}
  • SZM059
    @sujith
    I have resolved the issue now from the suggestion retrieved on another thread.

    But i want to know how would someone know all these changes in advance instead facing bugs in market realtime.
  • yeshwanth
    @SZM059 Other APIs are working after moving to header auth, but placing order is not working for me.. Any Idea?

    Its giving error as

    {'data': None,
    'error_type': 'InputException',
    'message': 'Missing or empty field `exchange`',
    'status': 'error'}

    I am passing the exchange in data as below

    {'exchange': 'NFO',
    'order_type': 'LIMIT',
    'price': 0.75,
    'product': 'NRML',
    'quantity': 4200,
    'tradingsymbol': 'MIDCPNIFTY23O099125CE',
    'transaction_type': 'BUY',
    'validity': 'DAY'}

    The code is as below:

    url = "https://api.kite.trade/orders/regular"
    payload = { "tradingsymbol":tradingsymbol,
    "exchange":exchange,
    "order_type":"LIMIT",
    "product":"NRML",
    "validity":"DAY",
    "quantity":quantity,
    "transaction_type":transaction_type,
    "price":limit_price}
    auth_header = api_key + ":" + access_token
    headers["Authorization"] = "token {}".format(auth_header)
    res = requests.post(url, data=payload, headers=headers)


  • yeshwanth
    Got resolved after using form request "application/x-www-form-urlencoded"
  • sujith
    @SZM059,
    We have always mentioned to use authentication on request headers and not on query params. The query param way of authentication was always for legacy reasons. Users were directed to use auth headers from the very beginning.
Sign In or Register to comment.