alienbrett / PyAlly

Ally Invest API Module for Python3
https://alienbrett.github.io/PyAlly/
MIT License
57 stars 28 forks source link

Error when cancelling an order #66

Closed carterjfulcher closed 2 years ago

carterjfulcher commented 3 years ago

I am trying to cancel an order by ID.

I have setup the order to be cancelled as such:

cxl = ally.Order.Order(
      orderid=order, 
      type_=ally.Order.OType.Cancel
)

I originally attempted to submit this by simply doing broker.submit(cxl, preview=False) , however this presented me with the following server error:

  File "/home/xxxx/xxxxx/env/lib/python3.8/site-packages/ally/Api.py", line 154, in request
    x.raise_for_status()
  File "/home/xxxx/xxxxx/env/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://api.tradeking.com/v1/accounts/my_account_number/orders.json

Afterwards, I checked the preview and received:

ally.exception.ExecutionException: We cannot process your request at this time. Please contact your account representative.

Lastly, I also checked str(cxl) and got:

(OType.Cancel) None 0 units of "None" None, None

I'm using v1.1.1 on Ubuntu. Does anyone have an ideas on this?

carterjfulcher commented 3 years ago

One solution to this problem is just to use the broker object directly retrieved from broker.orders(). It seems PyAlly does not support cancelling or creating/fetching an order object by ID. Which is unfortunate if you store your orders by id instead of the object.

LaikaN57 commented 3 years ago

The http 500 is most likely transient. Please retry. As for the the cancelling by order id. It looks like that is the current code path. Can you please explain more, give a reference to code, or show what you are trying to do?

LaikaN57 commented 3 years ago

@carterjfulcher bump

LaikaN57 commented 2 years ago

@carterjfulcher bump