jessecooper / pyetrade

Python E-Trade API Wrapper
GNU General Public License v3.0
205 stars 96 forks source link

cancel_order producing error - 400 Client Error: Bad Request for url #42

Closed rickbricker closed 3 years ago

rickbricker commented 3 years ago

Hello,

Generally having success with this really nice package. I am running into an issue when attempting to cancel an order I've placed previously. Here is a test I'm trying to run:

orderID = random.randint(100000, 999999)
orders.place_equity_order(accountId=ACCOUNTIDKEY, symbol=symbol, orderAction="BUY", clientOrderId=orderID, priceType="LIMIT", limitPrice=thePrice, quantity=shareSize, orderTerm="GOOD_UNTIL_CANCEL", marketSession="REGULAR")

time.sleep(2)

cancelResponse = orders.cancel_order(account_id=ACCOUNTIDKEY, order_num=orderID, resp_format='json')
print(cancelResponse)

The above code successfully places an order, but when it tries to cancel it I receive this error: requests.exceptions.HTTPError: 400 Client Error: Bad Request for url

According to the Etrade docs this means the AccountID key is incorrect. But I'm 100% sure it is correct. Does anyone have an idea of how to fix this?

Thanks!

rickbricker commented 3 years ago

Looks like I was using the order Id when I should have been using the order number. Resolved.