Skip to content

An autonomous trading bot in Typescript with web access which allows running, scheduling and building algorithms to trade efficiently!

License

Notifications You must be signed in to change notification settings

gitter-badger/tradingbotx

 
 

Repository files navigation

TradingBot Typescript

This is an autonomous trading bot in Typescript with web access! It allows users to run algorithms and create and deploy new algorithms very quickly and easily. It allows paper trading as well as live trading (live pending approval).

It is just the beginning but my vision for this repo is as follows:

See it in action - https://tradingbotx.com

Vision

  • Build a community driven strong open source algorithm base in Typescript for trading efficiently
  • Make these available to users for free forever so anyone can benefit from these algorithms
  • Take a list of ticker symbols and algorithm(s), and find the best deals in the market from within that list.
  • Able to schedule algorithms based on user's preference
  • Provide a rating mechanism for Algorithms, so users can see the popular/highly rated algorithms
  • Seamlessly integrate with all popular brokerages and crypto exchanges

Let's see how it goes! It's only the start.

Roadmap

  • 🧹 Rewrite the project in typescript
  • 🆕 ✨ OAuth Support (https://alpaca.markets/docs/build-apps_services-with-alpaca/oauth-guide/)
  • 🆕 ✨ Trade with watchlists
  • 🆕 ✨ Watchlist
  • 🆕 ✨ SSL
  • 🧹 Transaction Type in the Trade Table
  • 🆕 ✨ Premium API support
  • 🧹 Skip orders that are not tradable fractionally
  • 🆕 ✨ Responsive Trade table for mobile
  • 🧹 Fix list selector styling on the trading page
  • 🆕 ✨ Support for live account (https://alpaca.markets/docs/api-documentation/api-v2/#paper-trading) - not exposed to public yet
  • 🧹 Error handling layer for both sync & async
  • 🐛 Timezone fix (changed to EST)
  • 🆕 ✨ Intraday price support for stocks (confidence is now realtime)
  • 🧹 Generic Algo Execution interfaces
  • 🆕 ✨ Multiple Algo Support - Buy & Sell basic
  • 🧹 README documentation for open sources, code clean up etc.
  • 🆕 ✨ Basic Backtest feature - allows you to look up algorithm's output b/w any timeframe
  • 🆕 ✨ Dark Mode Toggle 😍
  • 🐛 Fix algo selection based on query params on Quick Analysis page
  • 🆕 ✨ Algorithms page to describe what each algorithm does
  • 🆕 ✨ Account's page
  • 🆕 ✨ Account's positions page
  • 🆕 ✨ List Orders page
  • 🆕 ✨ Cloud based trade schedule
  • 🆕 ✨ Advanced Backtest feature - allows you to simulate the trading using multiple algorithms on a list of stocks
  • 🚧 API key/secret input for trade schedule
  • Strong Validations (https://wanago.io/2018/12/17/typescript-express-error-handling-validation/)
  • Generic algorithm parameters support
  • Expose a mechanism to configure algorithms from the interface
  • Expose API based live money trading for people who are looking to live trade (since OAuth isn't available for live trading yet)
  • Live money trading approval by Alpaca
  • Delete watchlist support
  • Watchlist detail page
  • Trade link on watchlist page
  • Cancel Order
  • Update Order

Contribution

After you fork and checkout the repo in your local box:

npm install
npm run compile

To start the website, you'll need a couple of APIs:

  1. Get AlphaVantage Free API here. AlphaVantage is used to pull historical Stock Prices data. We use OAuth, so you'll need to get the clientId and secret from the Alpaca's account dashboard.
  2. (optional) Get Alpaca Free API here. Alpaca is used as a brokerage to make trades, manage watchlists etc for Stocks.
  3. (optional) Get Free Crypto Compare API here. Crypto Compare API is used to pull price information for Cryptos.

Once you have these, you can follow next steps to get up and running locally:

You need to set following environment variables. You can do so by creating a .env file in the root folder of this project locally and copy pasting the following in it:

# AlphaVantage - API KEY (need for Stock's historical prices)
AV_API_KEY=<your-alphavantage-key>

# (optional) Crypto Compare Key (only needed for Crypto history prices)
CRYPTO_API_KEY=<your-crypto-compare-key>

# (optional) Alpaca Configuration
# Note: You only need these if you're planning to
# 1. Make Trades from local
# 2. Manage/view watchlists
# OAuth Configuration
# Guide: https://alpaca.markets/docs/build-apps_services-with-alpaca/oauth-guide/
ALP_CLIENT_ID=<your-alpaca-client-id>
ALP_CLIENT_SECRET=<your-alpaca-client-secret>
# for oauth redirect, you can use the staging end point
ALP_REDIRECT_URI=<redirect-uri>
# (optional) You can also hardcode your personal access token for local development
ALP_HARDCODED_ACCESS_TOKEN=...

# Server Configuration
ENV=dev
PORT=3000

and then, simply:

npm start

Hit http://localhost:3000/ from your browser.

Creating and deploying a new algorithm

First we need to understand the how algorithms are represented in this repo and their interfaces.

Understanding Algorithm Interface

An Algorithm in this repo has an input and an output. The input takes an object that contains prices as timeseries. You don't need to worry about pulling prices from an API yourself, it comes out of the box for you!

export interface AlgoInput {
  prices: number[];
}

The output of an Algo is a timeseries list of indicator values predicted/calculated by the algo. This is because some algorithms might output more than one indicators.

export interface AlgoOutput {
  indicators: number[][]; // [0][1] means 0th indicator's 1st timestamp value
}

And lastly, algorithms have an actionType i.e. whether it is predicting a buy action or a sell action for the users. Algorithms also have a name and unique id. Name will be visible on the website. Here's how to implement a very basic algorithm:

Create Algorithm

Let's create a Diamond Hands algorithm which returns 100% buy confidence always. :) Create diamond-hands.ts file in the ./src/algo folder and then copy paste the code below:

import {Algo, AlgoInput, AlgoOutput, AlgoActionType} from './algo';

export class DiamondHandsAlgo implements Algo {
  async run(algoInput: AlgoInput): Promise<AlgoOutput> {
    // This algo always recommends 100% buy confidence :)
    const indicatorA = algoInput.prices.map(p => 100);
    return {
      indicators: [indicatorA],
    };
  }

  actionType(): AlgoActionType {
    return 'buy';
  }

  name() {
    return 'Diamond Hands';
  }

  id() {
    return 'DiamondHands';
  }
}

Last thing we need to do is to add this algo in the registry ./src/algo/algoresitry.ts:

...
import {DiamondHandsAlgo} from './diamond-hands';
export const ALGO_REGISTRY = [
  new BuyLowAlgo(),
  new SellHighAlgo(),
  new DiamondHandsAlgo(), // add your new algo here
  /**
   * Add your new Algo here
   */
];

And, that's it! 💯

npm run compile && npm start

Go to http://localhost:3000 and see it in action:

DiamondHands

Note: Do not forget to create a documentation of your algorithm before submitting the pull request so community can understand how to use it. You can find documentation README at ./src/algo/README.md.

After you are ready to deploy, feel free to submit a pull request.

Current Algorithms Repository

Check out the current algorithms here.


Copyright Kevindra Singh © 2021. All rights reserved.

About

An autonomous trading bot in Typescript with web access which allows running, scheduling and building algorithms to trade efficiently!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 47.0%
  • Pug 35.4%
  • JavaScript 9.8%
  • CSS 7.8%