API of TD Ameritrade

Discussion in 'Automated Trading' started by earth_imperator, Jul 8, 2022.

  1. Some years ago I had taken a look at the C/C++ API of TD Ameritrade, but it looked too complicated.
    Has the situation changed since then, the API become easier to use?
    IIRC, the authentication part was IMO made too complicated: instead of using username (or acctnumber) and password they used something else (OAuth or something else). One wonders why make things unnecessarily so complicated... :-()

    I now am in need for automation to update my offers (Bid, Ask) of my open orders in some time intervals (like every 10 minutes or so). Ie. not realtime. For this to function one of course needs to get the account data and the data of all positions, incl. open orders, as well get current quotes for all open positions and open orders. Then the feature to programmatically modify (update) a specific open order...

    Is here anybody with experience of the TD API and could give some info to a newcomer to the TD API? Thx.
     
    Last edited: Jul 8, 2022
  2. ET180

    ET180

  3. It's not super user friendly but it does work as advertised. I've got code that uses the TD API frequently but the IB/TWS API is much, much better. There's probably not much demand for the TD API since all orders go to a middle man and you think your trades are free. People doing automated trading through an API find out pretty fast how much those free trades are costing them. I wrote software to measure the cost by sending identical orders to TD and IB through their APIs.

    Summary: Open an IB account and use their API but if you absolutely must stay with TD you can get the job done.
     
  4. It looks like a fairly standard Rest service. The authentication follows the standard OAuth for Rest services. There are many examples online on how to retrieve a token, it shouldn't take you long to get it working.

    I also use IB but I cannot recommend it, it is a pain in the ass to get it to work. The only benefit you get from it, is their commissions but it looks like the implementation of TD's services are way better.
     
  5. TD Ameritrade API does require OAuth for login. In general the reason for that is so the credentials are not stored on the client and the broker controls the login process with whatever verification they want (including whatever changes).

    You have another option that does not require OAuth login and supports multiple brokers. Medved Trader software has a WebSocket API for market data and trading that supports most of the brokers and datafeeds that are integrated into Medved Trader. So you could write to that API and it will handle the logins for whatever broker you want, but you only need to write for one API. We've also added various alerting and other features to the API to make things more versatile :). Docs at https://medvedtrader.com/wsapi
     
  6. What do you mean by "all orders go to a middle man"? To a different company than TD Ameritrade?
     
  7. Oh man, I hate this OAuth shaet! Unfortunately I've to master this c-rap... :-(

    Thx everbody.
     
  8. What does the so called "Callback URL: http://localhost" do (under "App Details" in account web page)?
    Does it mean my PC has to be remotely accessible from the Internet, ie. do I need to open a port to the inside of my LAN in my router/firewall for this OAuth stuff to function?
     
  9. The call back url is a url that will handle the response, in case you set up any port to listen. If you specify a localhost url they won't be able to access it, so that will mean that you don't care about the response, and you are happy just checking that you got a token that isn't empty.
     
  10. Where does one associate the TD trading account with the API account?
    I mean I have both of them, but how does the API account know what my trading account is?
    There clearly something is missing in my setup. Is there a setting in the trading account to allow/disallow API usage?

    I'm following the instructions on the Simple Auth for Local Apps page
    with my own OAuth "Consumer key" (for this posting I afterwards changed it with XXXX in the address bar below), but I just get this error:
    OAuth-ERR.png
     
    Last edited: Jul 9, 2022
    #10     Jul 9, 2022