td-ameritrade-python-api icon indicating copy to clipboard operation
td-ameritrade-python-api copied to clipboard

cancel_time argument to order_duration() breaks order submission

Open AndrewRoskamp opened this issue 4 years ago • 4 comments

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!

AndrewRoskamp avatar Dec 14 '20 19:12 AndrewRoskamp

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.

areed1192 avatar Dec 15 '20 16:12 areed1192

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')])

AndrewRoskamp avatar Dec 15 '20 17:12 AndrewRoskamp

Any news on this?

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

JimLynchCodes avatar Oct 14 '21 14:10 JimLynchCodes

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.

devintivie avatar Oct 20 '22 07:10 devintivie