Python API problem with Modify and Cancel order
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.
@Venkat please don't wrap the order ID in quotes. use
@shrini-viswanath today I tried even without quotes
with open order_id 170712000032130 as below,
it still pops up same error
@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 *
code='ZZZZZZZZZZZZZZZZZZZZ' #created using loginurl and pasted it here after authentication
s = Session (api_key)
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
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
@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
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+,
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