All Projects → knicola → tdameritradejs

knicola / tdameritradejs

Licence: MIT license
TD Ameritrade Library for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language
Handlebars
879 projects

Projects that are alternatives of or similar to tdameritradejs

TradeAlgo
Stock trading algorithm written in Python for TD Ameritrade.
Stars: ✭ 147 (+297.3%)
Mutual labels:  stocks, tdameritrade
intrinio-realtime-java-sdk
Intrinio Java SDK for Real-Time Stock Prices
Stars: ✭ 22 (-40.54%)
Mutual labels:  stocks
Robinhood On Rails
A web dashboard for the free trading platform Robinhood using Ruby on Rails and a private API
Stars: ✭ 134 (+262.16%)
Mutual labels:  stocks
Reddit Hyped Stocks
A web application to explore currently hyped stocks on Reddit
Stars: ✭ 173 (+367.57%)
Mutual labels:  stocks
Sec Edgar Downloader
Download SEC filings from the EDGAR database using Python
Stars: ✭ 146 (+294.59%)
Mutual labels:  stocks
Investments
Helps you with managing your investments
Stars: ✭ 213 (+475.68%)
Mutual labels:  stocks
Pytse Client
work with Tehran stock exchange data in Python
Stars: ✭ 130 (+251.35%)
Mutual labels:  stocks
STOCK-RETURN-PREDICTION-USING-KNN-SVM-GUASSIAN-PROCESS-ADABOOST-TREE-REGRESSION-AND-QDA
Forecast stock prices using machine learning approach. A time series analysis. Employ the Use of Predictive Modeling in Machine Learning to Forecast Stock Return. Approach Used by Hedge Funds to Select Tradeable Stocks
Stars: ✭ 94 (+154.05%)
Mutual labels:  stocks
capm shiny
Demo project of creating an interactive analytical tool for stock market using CAPM.
Stars: ✭ 31 (-16.22%)
Mutual labels:  stocks
Finance
Here you can find all the quantitative finance algorithms that I've worked on and refined over the past year!
Stars: ✭ 194 (+424.32%)
Mutual labels:  stocks
Graphvega
Open Source Options Analytics Platform.
Stars: ✭ 189 (+410.81%)
Mutual labels:  stocks
Tiingo Python
Python REST Client for interacting with the Tiingo Financial Data API
Stars: ✭ 152 (+310.81%)
Mutual labels:  stocks
Python Trading Robot
A trading robot, that can submit basic orders in an automated fashion using the TD API.
Stars: ✭ 235 (+535.14%)
Mutual labels:  stocks
Revolut Stocks
A tax calculator for stocks and dividends activities.
Stars: ✭ 134 (+262.16%)
Mutual labels:  stocks
NSE-Stock-Scanner
National Stock Exchange (NSE), India based Stock screener program. Supports Live Data, Swing / Momentum Trading, Intraday Trading, Connect to online brokers as Zerodha Kite, Risk Management, Emotion Control, Screening, Strategies, Backtesting, Automatic Stock Downloading after closing, live free day trading data and much more
Stars: ✭ 78 (+110.81%)
Mutual labels:  stocks
Turingtrader
The Open-Source Backtesting Engine/ Market Simulator by Bertram Solutions.
Stars: ✭ 132 (+256.76%)
Mutual labels:  stocks
Yahoo Finance Api
PHP client for Yahoo Finance API 📈
Stars: ✭ 179 (+383.78%)
Mutual labels:  stocks
Dolibarr
Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). It is open source software (written in PHP) and designed for small and medium businesses, foundations and freelancers. You can freely install, use and distribute it as a standalon…
Stars: ✭ 2,877 (+7675.68%)
Mutual labels:  stocks
pr-www
Portfolio Report Website - the data source for Portfolio Performance
Stars: ✭ 50 (+35.14%)
Mutual labels:  stocks
pair-trading-view
Pair Trading View - .NET application for visual analysis of synthetic financial instruments based on statistical models.
Stars: ✭ 45 (+21.62%)
Mutual labels:  stocks

TD Ameritrade Library for Node.js

Free, open-source Node.js client for the TD Ameritrade Trading Platform.


WARNING This library is still in its early stages of development and thus far from ready for production use.


Status

For details concerning the latest update please read the CHANGELOG.

The API client is very close to being complete. All documented API methods have been implemented.

The data streamer implements most of what the documentation talks about except Actives, Level 1 Options and Level 2 order book. Documentation also mentions services NEWS_STORY and NEWS_HEADLINE_LIST but does not provide any information.

An attempt to provide typescript definitions is also in progress.

Installing

Using npm:

$ npm install @knicola/tdameritrade

Using yarn:

$ yarn add @knicola/tdameritrade

API

See API Docs file.

Usage

In order to use TD Ameritrade's API services you will need a Consumer Key (also called Client ID and API Key). To get one first create a developer account and add a new app. The key will be listed under the newly created app.

Node.js

SSL certificate is required for oauth2 authorization.

const { TDAmeritrade } = require('@knicola/tdameritrade')

const td = new TDAmeritrade({
    apiKey: 'your-consumer-key',
    redirectUri: 'https://localhost:8443',
    sslKey: 'path/to/selfsigned.key',
    sslCert: 'path/to/selfsigned.crt',
})

// event will fire once the local web server
// is ready for the oauth2 authorization.
td.on('login', url => {
    // use this to print the td oauth2 url to console
    // or to open the url directly in the browser.
    console.log(url)
})

// event will fire every time the token is renewed.
td.on('token', token => {
    // use this to know when a new access token is
    // issued or to save the token to a file.
    console.log(token)
})

// an all-in-one entry point which will determine
// whether authorization is required or, if the
// access token expired, whether to renew it.
td.login().then(async () => {
    const { candles } = await td.getPriceHistory('SPY')
    console.log(candles)

    // the websocket interface will be instantiated automatically.
    // for now, it will choose the first available account.
    const streamer = await td.streamer()
    // you could also choose to instantiate it
    // manually with `new td.TDStreamer(...)`

    // event will trigger once the streaming client is
    // connected *and* authenticated to the server.
    streamer.on('authenticated', () => {
        // we can now interact with the server
        streamer.subsChartEquity('SPY')
    })

    // event will trigger everytime the streaming server
    // sends us a new candle (that is every minute).
    streamer.on('chart', data => {
        console.log(data)
        // choose to save the data or determine
        // whether to place a buy/sell order.
        td.placeOrder({ ... }).then(res => {
            // ...
        })
    })

    // connect to the streaming server
    streamer.connect()
})

Browser

The .login() and .authorize() methods are not available in the browser since they depend on Node.js specific modules. Either the authorization code or the issued access and refresh token will have to be provided by the server hosting the website.

Authorization code:

const { TDAmeritrade } = require('@knicola/tdameritrade')
const td = new TDAmeritrade()
const authCode = 'provided by the server'

// the config will update automatically
// with the access and refresh token.
await td.getAccessToken(authCode)

const { candles } = await td.getPriceHistory('SPY')

Access and Refresh token:

const { TDAmeritrade } = require('@knicola/tdameritrade')

// provided by the server
const token = {
    apiKey: 'your-consumer-key',
    accessToken: 'your-access-token',
    refreshToken: 'your-refresh_token',
    accessTokenExpiresAt: '2020-01-01T01:31:01.000Z',
    refreshTokenExpiresAt: '2020-03-31T01:01:01.000Z',
}

const td = new TDAmeritrade(token)

const { candles } = await td.getPriceHistory('SPY')

Generate SSL Certificate

In most cases, a self-signed certificate will be enough. You can generate one using openssl:

$ openssl req -x509 -nodes -newkey rsa:2048 -keyout selfsigned.key -out selfsigned.crt -batch

# OR

$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -out selfsigned.crt -keyout selfsigned.key \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

License

This project is open-sourced software licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].