Giter Club home page Giter Club logo

td-websocket-vue's Introduction

TD Ameritrade Auth and Websocket

What is this?

Auth with the TD Ameritrade API is a bit of a pain. This is a web app that allows you to authorize and authenticate yourself to use the TD Websocket API. A TD trading account is required.

Instructions

  1. Go to https://developer.tdameritrade.com and register an app. Use 'https://localhost:8080/td-login-redirect' as your redirect url.
  2. Copy your consumer key into the VUE_APP_TD_CONSUMER_KEY var in the .env.local file.
  3. npm install
  4. npm run serve
  5. Navigate to https://localhost:8080 (Yes, we are running https locally. The TD redirect requires https.)
  6. Click the td auth link at the top of the page and go through the log in process.

After logging in, a refresh token is stored locally for 90 days, so next time you run the app you won't have to log in again.


High level overview of the code

  1. A link is created allowing you to log in to your td account. After logging in, it returns an OAuth code to the redirect url.
    • If a refresh token exists in local storage, we use that to get an access token.
  2. Using the code, we retrieve an access token and store it in vuex. We also store the refresh token in local storage.
  3. Using the access token, we authenticate and connect to the websocket api.
  4. Requests are made to set the QOS to retrieve real time data and quotes on hot stock picks.

Notes

  • This was created with vue cli
  • We need to use history mode for the router instead of hash mode because td won't accept a redirect url with a hash. Since the redirect is a deep link back to localhost, historyApiFallback has to be set to true in vue.config.js

TD docs for the websocket api

https://developer.tdameritrade.com/content/streaming-data


If you find yourself making an abundance of money (or are planning on making an abundance of money) using this code, please show your support to a fellow dev.

paypal

td-websocket-vue's People

Contributors

itsdrew avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.