Python API problem with Modify and Cancel order



  • Hi,
    I am trying to cancel an open order with the API, the following are the commands I am using to do that,
    imagine 170707000059603 is my order_id for my open order, to change the quantity I am using the modify order as below,

    u.modify_order('170707000059603',quantity=80) # not working

    u.cancel_order('170707000059603') # not working

    The error it pops up is "TypeError: Required parameter order_id not of type int"
    please someone help me the right way to do it.

    Thank you.


  • Global Moderator

    @Venkat please don't wrap the order ID in quotes. use

    u.cancel_order(170711000072877)
    


  • @shrini-viswanath today I tried even without quotes
    with open order_id 170712000032130 as below,

    u.cancel_order(170712000032130)

    it still pops up same error


  • Global Moderator

    @Venkat can you post some of your sample code while obfuscating any critical logic or personal keys?



  • @shrini-viswanath here is the sample code, I have created an open order manually in the web terminal for test purposes and trying to cancel it from code,

    sample code for cancellation of order

    from upstox_api.api import *

    api_key='YYYYYYYYYYYYYYYYY'
    your_redirect_uri='http://127.0.0.1'
    your_api_secret='XXXXXXXXXXXX'
    code='ZZZZZZZZZZZZZZZZZZZZ' #created using loginurl and pasted it here after authentication

    s = Session (api_key)
    s.set_redirect_uri (your_redirect_uri)
    s.set_api_secret (your_api_secret)

    s.set_code (code)

    access_token = s.retrieve_access_token()#
    print ('Received access_token: %s' % access_token)

    print 'Name= ',profile['name']
    print 'Available margin=',balance['equity']['available_margin']
    print 'Used margin=',balance['equity']['used_margin']
    u.get_master_contract('NSE_EQ') # get contracts for NSE EQ
    u.get_master_contract('NSE_FO') # get contracts for NSE FO

    Testing purposes, open order created manually using web terminal

    u.cancel_order(170712000032130)



  • Hi @venkat : I was able to cancel the order using u.cancel_order(orderid)
    If you are using cover order then the order id should be of the pending order and not the executed order.
    You can check what error you are getting using following code
    status=u.cancel_order(123123123123)
    print(status)



  • @ganesh I am not sure what is the issue I try to resolve but the problem still persists with the same error. I cannot modify or cancel the open order, but there is no problem while placing the order. If you have time can you connect to my laptop via teamviewer and check the problem why its happening



  • Pls share output of
    status=u.cancel_order(123123123123)
    print(status)



  • status=u.cancel_order(170713000075481)
    

    File "C:\Python27\lib\site-packages\upstox_api\api.py", line 487, in cancel_order
    raise TypeError("Required parameter order_id not of type int")
    TypeError: Required parameter order_id not of type int



  • @ganesh these are the libraries installed for python 2.7, Is it something to do with python 2.7 rather than 3+,

    upstox==1.5.1
    future==0.16.0
    websocket-client==0.44.0
    requests==2.18.1



  • @ganesh and @shrini-viswanath , atlast I figured it out what the problem is, the problem is with the python2.7, I tried with python 3.6 its working fine.

    I guess in python2.7 , for u.cancel_order(170713000075481) the orderid is not taking as integer inspite of trying different ways even tried int(orderid), there should be some import of future library to fix it.

    This error is occurring whenever there is an orderid sent, ex: cancel order, modify order, get_trades,etc.,,



  • Yes. I think please try python 3.5.
    I had issue in generating token with python 2.7 and it worked perfectly in 3.5


Log in to reply
 

Looks like your connection to Upstox Forum was lost, please wait while we try to reconnect.