areed1192 / td-ameritrade-python-api

Unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard API and allows users to build data pipelines for the Streaming API.
MIT License
684 stars 252 forks source link

cancel_time argument to order_duration() breaks order submission #139

Open AndrewRoskamp opened 3 years ago

AndrewRoskamp commented 3 years ago

Hi! It seems like specifying a cancel_time to order_duration will prevent the order from being submitted (unless I can't figure out what datetime format TDA expects). Whatever I put in that field will cause Ameritrade to issue a "A validation error occurred while processing the request." response. I am able to successfully submit orders without specifying a cancel_time.

order.order_duration(td.enums.DURATION.GOOD_TILL_CANCEL) # This works when later calling place_order()
order.order_duration(td.enums.DURATION.GOOD_TILL_CANCEL, cancel_time.date().isoformat() ) # This Doesn't
order.order_duration(td.enums.DURATION.GOOD_TILL_CANCEL, cancel_time.isoformat() ) # This Doesn't

Thanks!

areed1192 commented 3 years ago

Could be that it's missing an additional key. When I read the documentation, it looks like if you do just the date then you need to specify an additional key. Here is what they are:

"cancelTime": {
   "date": "string",
   "shortFormat": false
}

Can you print out the raw JSON and see if those keys are both in there.

AndrewRoskamp commented 3 years ago

It does look like those fields are present - you add them in the Order class. fwiw, I also tried changing that code to put 'false' in lieu of the actual bool value, and that didn't work either.

>>> json
OrderedDict([('cancelTime', {'date': '2020-12-14T14:30:00', 'shortFormat': False}), ('duration', 'GOOD_TILL_CANCEL'), ('orderLegCollection', [{...}]), ('orderStrategyType', 'SINGLE'), ('orderType', 'LIMIT'), ('price', 20.0), ('session', 'NORMAL')])
JimLynchCodes commented 2 years ago

Any news on this?

@areed1192 what is the format for cancelTime dates???

devintivie commented 1 year ago

Not sure if anyone else is still looking for this. The TDAmeritrade documentation is incorrect. cancelTime : string is the correct answer. It uses uses 'yyyy-MM-dd' format and is not an object as documented. Hopefully this helps. I did not try setting any shortFormat.