tdameritrade
tdameritrade copied to clipboard
placeOrder returning 415 response
I'm not able to post a pace order request - getting a 415 response code ("unsupported media type"). I'm using the commented out test as reference. Is this not currently working?
c = td.TDClient()
order = '''
{
"orderType": "MARKET",
"session": "NORMAL",
"duration": "DAY",
"orderStrategyType": "SINGLE",
"orderLegCollection": [
{
"instruction": "Buy",
"quantity": 1,
"instrument": {
"symbol": "IMRN",
"assetType": "EQUITY"
}
}
]
}
'''
print(c.accounts())
c.placeOrder(<accountId>, order)
EDIT: I tried adding extra header info for things like Content-Type
and Accept
with no luck. And yet hitting this API from https://developer.tdameritrade.com/ does work.
Correction, the snipped above is sending the raw string to the placeOrders API, but it's expecting a json value. Still, converting the string with j = json.loads(order)
yields the same 415 response.
Tim changed the order API, it broke mine as well and I haven't gotten around to updating it. I suggest going back to a previous version of the code. I reverted to https://github.com/timkpaine/tdameritrade/commit/bbf113c1ac296c69a2534a85c0d68c0c111e19ce.
(Use git checkout bbf113
from your terminal.)
Ah that would explain it, thanks! I reverted to bbf113c
and installed with python setup.py install
but I'm not able to authenticate from this commit. I'm still able to authenticate and get account info from master.
I've got the same environment variables set up. Are you aware of any other setup that's needed for this commit?
EDIT: Never mind, my env variable was set to AMERITRADE_CLIENT_ID
instead of TDAMERITRADE_CLIENT_ID
order
should be pass as json=order
in placeOrder
I am having this same error. I'm using the pip installed version, so I'm not sure how to specify a git version.
Is there a workaround?
Just follow https://github.com/timkpaine/tdameritrade/blob/master/general.ipynb. However, I don't see manually configure content type as best practice.