Requirements & Installation

Dependencies

API key

Begin by visiting the Getting Started page at developer.tdameritrade.com. From there, read under the subheadings Creating a Developer Account and Registering an App. Read the post, How to create a TD Ameritrade API key for automated trading, for more details. It includes screenshots to help you from start to finish.

Advanced Features

There are certain order types and features of the API that cannot be used without first contacting TD Ameritrade support. You MUST contact them and ask that they disable advanced features on your account. There is no public information that I can find regarding what that means exactly, but you will NOT be able to use the Trade For Me application unless you complete this step. If you find that there are features in TOS or otherwise that you will lose as a result, you may create another brokerage account with TD Ameritrade dedicated to your automated trading.

Node.js

If you’re not already familiar with Node.Js, it’s an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. Download and install Node.js to the environment on which you plan to run Trade For Me.

MySQL

If you made it past the dependencies list at the top of the page and you’re still reading, you are most certainly my people. The kind of folks that like to tinker with geek things. You may or may not have installed, or at least used, a database backend for another application. If you haven’t this will be tricky for your first run at it. You have options:

  • Install MySQL Community Server
    • It’s free to download, install, and use.
    • It’s available for a wide variety of operating systems
  • Use a hosted database server
    • Bluehost is an awesome hosting company. If you just need a database for this app, you could probably get away with just the basic plan.
  • Use Docker
    • I’m currently running my app inside a docker container, although, my database isn’t in it. There’s no reason it couldn’t be, though!
    • Here’s an example of a docker compose file that could potentially get you started. This one will mount a volume for the MySQL data so it will persist between restarts. Essential if you don’t want to lose your data.
version: '3'
services:
 mysql:
  image: mysql
  environment:
   MYSQL_DATABASE: 'tradeforme'
   MYSQL_USER: 'tradeforme_user'
   MYSQL_PASSWORD: 'tradeForMeuserPaSs!'
   MYSQL_ROOT_PASSWORD: 'tradeForMrootPasS!'
  ports:
   - "3306:3306"
  volumes:
   - mysql_volume:/var/lib/mysql
volumes:
 mysql_volume:

Regardless of the option you choose, you must create a database and database user with the appropriate permissions. Feel free to use this SQL. Just be sure you change MY_STRONG_PASSWORD with an actual strong password. If you’re unable to run SQL directly due to limitations by your host, you will need to use whichever mechanism they allow to create databases and users. The important bit is the GRANT statement. When creating your user, grant it the same permissions as listed here. These permissions are the minimum required to install and use the app.

CREATE SCHEMA `tradeforme` ;
CREATE USER 'tradeforme_user'@'%' IDENTIFIED BY 'MY_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON `tradeforme`.* TO 'tradeforme_user'@'%';

If you need to set mysql_native_password (because you got an error that the authentication method wasn’t supported)

ALTER USER 'tradeforme_user'@'%' IDENTIFIED WITH mysql_native_password BY 'MY_STRONG_PASSWORD';

If you see this error: You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)

Using SET in this way will not persist the global variable, however, you should only need to do this one time right before you initialize the application.

SET GLOBAL log_bin_trust_function_creators=1;

Installation [core application]

  • Extract zip package to a folder on your computer or server
  • Generate self-signed SSL certificates (read README.txt in resources/cert for detailed instructions)
    • OpenSSL is required
    • Windows users may wish to download Git Bash for this step. That will make it easer, although, if you know your way around OpenSSL and command line apps, you probably don’t need it.
  • cd to your project root and execute: npm install –production
  • Rename _db-example.conf to _db.conf and update with your database credentials
  • Execute: node tradeforme config init
  • Update values and execute: node tradeforme config set –acctNum=123 –tdConfig.apiKey=XYZ –tdConfig.redirectUri=https://localhost:3000 –tz=America/Chicago
  • Execute: node tradeforme config get [to verify config options]
  • Execute: node tradeforme login
    • View log/YYYY-MM-DD.log to find your login URL. It will be a URL to auth.tdameritrade.com with your redirect URL as a parameter. You will login with your TD Ameritrade credentials allowing the TD Ameritrade Developer API to interact with your brokerage account. Upon successful authentication, you’ll be redirected back to your redirect URL and Trade For Me will handle the auth/access tokens for future API calls.
  • Make $$$

Installation [strategy]

  • Extract zip package
  • Place the extracted file into /strategies directory within your application directory