This Node.js application is designed to monitor the Relative Strength Index (RSI) of stocks, alerting users via email when RSI values indicate significant trading opportunities. It automatically checks stocks listed in a tickers.txt
file against RSI thresholds and sends notifications using Gmail with OAuth2 authentication.
- Automated RSI Monitoring: Automatically checks the RSI for stocks at scheduled intervals.
- Email Alerts: Sends emails when RSI values are below 30 or above 70, which often indicate oversold and overbought conditions respectively.
- Secure Email Transmission: Uses OAuth2 for secure email transmission through Gmail.
Before running this application, you will need:
- Node.js installed on your machine.
- A Gmail account configured with OAuth2 credentials for sending emails.
- An accessible HTTP endpoint for RSI calculation.
To get started with this application, follow these steps:
-
Clone the repository:
git clone https://github.com/rsabh/RSIStockTrigger.git cd RSIStockTrigger
-
Install dependencies:
npm install
-
Set up environment variables:
Create a .env file in the root directory with the following content:
EMAIL_USER=your-email@gmail.com CLIENT_ID=your-client-id CLIENT_SECRET=your-client-secret REFRESH_TOKEN=your-refresh-token RECIPIENT_EMAIL_USER=recipient-email@gmail.com
- Prepare the ticker list: Populate the tickers.txt file with the stock symbols you wish to monitor, one per line.
- Start the server:
node app.js
- The script will execute based on the cron schedule set to monitor the RSI values at the desired frequency.
-
Modify the cron job setup in app.js to adjust the frequency of checks:
cron.schedule('* * * * *', async () => { // This sets the job to run every minute. Adjust as necessary. });
- Authorization Errors: Double-check your OAuth2 credentials if you encounter authorization errors. -Email Delivery Issues: Ensure that the Gmail API is enabled and the quota is not exceeded.
Follow these steps to configure OAuth2 credentials to enable your application to send emails using the Gmail API.
-
Access the Google Cloud Console
- Visit Google Cloud Console.
-
Create or Select a Project
- Create a new project or select an existing project from the project dropdown in the header.
-
Enable the Gmail API
- Navigate to APIs & Services > Library.
- Search for "Gmail API" and select it from the results.
- Click Enable to activate the Gmail API for your project.
-
Configure Consent Screen
- Go to APIs & Services > Credentials.
- Click on Configure Consent Screen and provide the necessary information.
- Save the settings.
-
Create Credentials
- In the Credentials tab, click Create Credentials and select OAuth 2.0 Client IDs.
- Fill out the form. For application type, choose Web application.
- Add
https://developers.google.com/oauthplayground
as a redirect URI if you plan to use the OAuth 2.0 Playground to obtain the refresh token.
-
Visit OAuth 2.0 Playground
- Go to the OAuth 2.0 Playground.
-
Configure the Playground
- Click on the gear icon (Settings) and check Use your own OAuth credentials.
- Enter your Client ID and Client Secret.
-
Select & Authorize APIs
- In the Step 1 section of the Playground, scroll or search for the Gmail API scopes you need, such as
https://mail.google.com/
. - Authorize the APIs by authenticating with your Google account and consenting to the access.
- In the Step 1 section of the Playground, scroll or search for the Gmail API scopes you need, such as
-
Exchange Authorization Code for Tokens
- In Step 2, click Exchange authorization code for tokens.
- The refresh token and access token will be displayed. Copy the refresh token for use in your application.
Remember to secure your credentials and never commit them directly into your version control system.