Order exit giving error "Invalid `api_key` or `access_token`"

pavvu_kk
All the calls work fine but the call to exit order fails with error "Invalid `api_key` or `access_token`"
I'm writing a script to exit all my CO positions at EOD. As mentioned else where, I'm getting all orders that have trigger pending and are 'CO' product type, looping through them and issuing an exit order. This same token and api_key work for all other preceding calls except this one. Pls help.

kite = KiteConnect(api_key=configuration.kite_api_key)
kite.set_access_token(cache.get_value('access_token'))
kite.exit_order(variety, order_id, parent_order_id)
  • sujith
    Can you give us complete request and response stacktrace?
  • pavvu_kk
    Will post tomorrow during market hours
  • __name__
    Hi,

    Im facing a similar issue.

    when i try to login with https://kite.zerodha.com/connect/login?api_key=XXXXXXXXX&v=3, i get the following response.
    {"status":"error","message":"Invalid `api_key`","data":null,"error_type":"InputException"}

    My api key is valid.
  • __name__
    This happens if I cancel the subscription before the expiry of subscription. Even though I have paid for a few more days, the app is being marked as inactive.

    I hope u would fix it.
  • sujith
    There is no issue here. If an app is expired or inactive then one can't log in to that app.

    Please write to kiteconnect(at)zerodha.com someone from the team will take a look at this.
  • pavvu_kk
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "DELETE /orders/CO/200417002036102?order_id=200417002036102&variety=CO&parent_order_id=200417002036100 HTTP/1.1" 307 0
    DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): api.kite.trade:80
    DEBUG:urllib3.connectionpool:http://api.kite.trade:80 "DELETE /orders/co/200417002036102?order_id=200417002036102&variety=CO&parent_order_id=200417002036100 HTTP/1.1" 301 None
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "DELETE /orders/co/200417002036102?order_id=200417002036102&variety=CO&parent_order_id=200417002036100 HTTP/1.1" 400 109
    INFO:root:Order exit failed: Invalid `api_key` or `access_token`.
  • pavvu_kk
    @sujith above is the error trace
  • __name__
    An app should become inactive when the paid period ends right. Canceling the renewal should not make it inactive.
  • sujith
    @pavvu_kk,
    Can you run pykiteconnect with debug logs on and paste the complete stack trace? You can private message the complete stack trace since it will contain your credentials as well.
  • sujith
    @__name__,
    One can cancel auto-renewal by going to the billing section and un-link the Zerodha account.
    You seem to have canceled your app.
  • pavvu_kk
    @sujith
    that is what I did and got that log. The call that precedes this call to fetch all orders goes through properly.
  • rakeshr
    @pavvu_kk
    order_id=200417002036102&variety=CO&parent_order_id=200417002036100
    You seems to be sending variety as CO instead of co.You need to send variety=co
    Check input params detail here.
  • pavvu_kk
    @rakeshr thanks for pointing out...will check that. Though this should ideally have no bearing on the api key/token.
  • pavvu_kk
    @sujith Is there any issue with the API?
  • pavvu_kk
    @rakeshr @sujith, wanted to let you guys know that changing 'co' to 'CO' actually worked.
    @sujith you should fix the incorrect error message
    @rakeshr thank you
  • pavvu_kk
    sorry...its the other way around...hanged 'CO' to 'co'
Sign In or Register to comment.