tdameritrade icon indicating copy to clipboard operation
tdameritrade copied to clipboard

placeOrder returning 415 response

Open rodrigobell opened this issue 4 years ago • 6 comments

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.

rodrigobell avatar Apr 21 '20 04:04 rodrigobell

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.

rodrigobell avatar Apr 21 '20 23:04 rodrigobell

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.)

dahifi avatar Apr 22 '20 12:04 dahifi

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

rodrigobell avatar Apr 22 '20 15:04 rodrigobell

order should be pass as json=order in placeOrder

wilfredcho avatar May 04 '20 02:05 wilfredcho

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?

JasonCrowe avatar Aug 31 '20 17:08 JasonCrowe

Just follow https://github.com/timkpaine/tdameritrade/blob/master/general.ipynb. However, I don't see manually configure content type as best practice.

j20120307 avatar Sep 08 '20 06:09 j20120307