Trading View Automation
  • Introduction
  • Setting Up Local Server
    • Setting Up HashiCorp Vault + EthSigner
    • Setting Up HashiCorp Vault (dev) + EthSigner
  • Setting Up Google Cloud Run
    • Setting Up Google KMS
  • Setting Up Heroku
  • Setting Up Env Vars
  • Setting Up Trading View Alert
  • Testing With sendAlert.js
  • Setting Up Google Sheets
  • Setting Up Telegram Notifications
  • Using Tmux
  • Using Git
Powered by GitBook
On this page
  • Table of Contents
  • Introduction
  • Setup Ngrok
  • Setup NodeJS App
  • Setup Notifications (Google Sheet and Telegram)
  • Test Setup

Setting Up Local Server

PreviousIntroductionNextSetting Up HashiCorp Vault + EthSigner

Last updated 6 months ago

Table of Contents

Introduction

For your local server to receive webhooks from Trading View, it must have a SSL/TLS address. This can be done in three ways:

  1. Getting a static IP from your ISP and creating a TLS certificate

  2. Registering a domain

  3. Using a reverse proxy, such as Ngrok

Using a reverse proxy is the easiest and we'll detail the use of Ngrok in this documentation.

Ngrok Introduction

With Ngrok, you will be given a TLS-secured HTTPS URL, which can be entered into the "webhook URL" field in your Trading View alert. When the JSON message is sent to the Ngrok URL, it is forwarded to your local server through a continuously persistent, TLS-secured tunnel. If your server temporarily disconnects from the internet, the Ngrok tunnel should automatically re-establish when your internet reconnects.

(Optional) HashiCorp Vault + EthSigner Introduction

System Diagram

Setup Ngrok

  1. Install Ngrok agent and add Auth Token (do this once)

    1. In your Ngrok account, go to Setup & Installation (left menu)

    2. At the top of the page, select Linux and follow the on-screen instructions

      1. Install Ngrok via Apt with:

        curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
          | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
          | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
      2. Add auth token to ngrok.yml configuration file with: ngrok config add-authtoken <authToken>

        • Console should show "Authtoken saved to configuration file: /home/<user>/.config/ngrok/ngrok.yml"

  2. Run the Ngrok client in a new tmux window

    1. Create new tmux window named "ngrok" with tmux new -s ngrok

      • Should see a green bar on the bottom, indicating a tmux window

    2. Start ngrok tunnel with ngrok http http://localhost:8080

      • copy the HTTPS URL and use it as the webhook URL in your Trading View alert

    3. Leave tmux window with ctrl + b, then d

    4. When needed, re-enter tmux window with tmux attach -t ngrok

      • If you exit the tmux window (with ctrl + b, then x), the tunnel will close. To restart a new tunnel, run ngrok http http://localhost:8080. A new HTTPS URL will be given, so you will have to replace the old URL in all your Trading View alerts. This can be inconvenient, so do not close the tmux window (the terminal window can be closed). Alternatively, you can register for a static HTTPS URL on Ngrok (paid plan).

Setup NodeJS App

  1. Install Git and NodeJS on your local server (instructions below is for Linux Ubuntu)

    1. Install NVM and NodeJS

      1. sudo apt update // updates packages

      2. sudo apt install curl -y // installs curl if not yet installed

      3. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

        1. Check install with nvm -v

      4. nvm install --lts // install NodeJS "long-term support" version

        • Check install with node -v

    2. Install Git

      1. apt-get install git

        • Check install with git --version

  2. Create SSH link to Github (on your personal computer, your OS credential manager can help authentication, so the "https method" can be used; whereas, on Linux, we must use the "ssh method")

    1. Generate ssh public/private key

      1. In CLI, run ssh-keygen -t ed25519 -C "your_email@example.com"

        1. use your Gitub email

      2. press Enter to accept default location to generate files

      3. At prompt, enter a passphrase (can be anything)

        • You may need this to re-login every now and then, so note it down somewhere safe

      4. Reenter the passphrase

      5. Two files will be generated the ~/.ssh folder: "id_ed25519" (the private key) and "id_ed25519.pub" (the public key)

    2. Copy the public key

      1. cd into ~/.ssh folder and run cat id_ed25519.pub // this prints the key to console. Copy the entire key (including email)

    3. Log into Github > click profile icon (top right) > Settings > SSH and GPC Key (left menu) > New SSH key

      1. Give key a name

      2. Purpose is “Authentication Key"

      3. Paste copied public key into the key field (paste the entire string, including the email)

      4. Click “Add SSH Key”

    4. Verify setup

      1. In CLI, run ssh -vT git@github.com

      2. Enter passphrase (that you chose above) when prompted

  3. Download the NodeJS App from the Github repository

    1. cd into the folder where you want the “trading-view-automation” folder downloaded

    2. run git clone git@github.com:brianonchain/trading-view-automation.git

  4. Prepare the environment

    1. cd into “trading-view-automation” folder

    2. install modules listed in package.json with npm install

    3. Add environment variables

      1. create “.env” file and start editing it with touch .env , then vim .env

  5. Run server.js in tmux window

    1. cd into "trading-view-automation" folder

    2. tmux new -s nodejs // creates tmux window called "nodejs"

      1. new terminal interface with green line on bottom should appear

    3. node server.js

      1. It should say "listening on port 8080" or whatever PORT you input in the .env file

    4. ctrl + b, then d // leave tmux window

    5. Whenever you need to re-enter the window (for example, to view logs), run tmux attach -t nodejs

Setup Notifications (Google Sheet and Telegram)

Test Setup

If Ngrok is set up, use the Ngrok HTTPS URL as the webhook. If not, use http://localhost:8080.

With HashiCorp Vault + EthSigner, your private keys can reside in a software-protected environment, as opposed to residing in a .env file. See .

Create an Ngrok account ()

and read the

press i to start editing. Use the environment variables detailed in

Set up Telegram to see successful or failed trades (see )

Set up Google Sheets to see successful or failed trades (see )

The cloned Github repo above contains a "sendAlert.js" file that allows you to send a mock Trading View Alert JSON message the NodeJS App (see ).

Setting Up HashiCorp Vault + EthSigner
https://ngrok.com/
Install tmux
usage instructions
Setting Up Env Vars
Setting up Telegram
Setting Up Google Sheets
Test With sendAlert.js
Introduction
Setup Ngrok
Setup NodeJS App
Setup Notifications
Test Setup
System diagram for DEX trade. In a CEX trade, the NodeJS App creates orders using the ccxt library.