Building a Cryptocurrency Alert System

Using Node.js, Google Cloud Pub/Sub and Slack to Create an Alert System
profile photo
oliver rimmer

Introduction

Cryptocurrency trading is all about timing and staying informed about market movements. To help traders keep track of significant price movements, we've built an automated alert system using Node.js, Google Cloud Pub/Sub, and Slack. This system fetches data from CoinMarketCap and GeckoTerminal, filters cryptocurrency pairs based on specific criteria, and sends alerts to Slack when certain conditions are met. In this blog post, we'll walk you through how this project works and how you can set up your own cryptocurrency alert system.

Project Overview

Our alert system performs the following tasks:
  1. Trigger: It is activated by a message on a Google Cloud Pub/Sub topic.
  1. Fetch Data: It retrieves cryptocurrency pair data from CoinMarketCap.
  1. Filter: It filters the pairs based on liquidity, valuation, and transaction volume criteria.
  1. Analyze: It compares current prices with historical highs using GeckoTerminal data.
  1. Notify: It sends a Slack message if the current price exceeds the highest historical price.

Prerequisites

Before you get started, ensure you have the following:
  • A Google Cloud account.
  • A Pub/Sub topic set up in Google Cloud.
  • A Slack workspace and an incoming webhook URL.
  • Node.js installed on your local machine.

Setting Up the Project

Step 1: Initialize the Node.js Project

Create a new directory for your project and navigate into it:
shell
mkdir crypto-alert-system cd crypto-alert-system
Initialize a new Node.js project:
shell
npm init -y
Install the required dependencies:
shell
npm install @slack/webhook node-fetch

Step 2: Write the Code

Create a file named index.js and add the following code:
javascript
const { IncomingWebhook } = require('@slack/webhook'); const fetch = require('node-fetch'); const slackUrl = 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK'; const coinMarketCapUrl = 'https://api.coinmarketcap.com/dexer/v3/platformpage/pair-pages?platform-id=1&dexer-id=1069&sort-field=volumeUsd24h&verify=1&category=spot&page=1'; const geckoTerminalBaseUrl = 'https://api.geckoterminal.com/api/v2/networks/eth/pools'; const liquidityThreshold = 30000; const fdvThreshold = 3000000; const txns24hThreshold = 500; exports.entryPoint = async (event, context) => { const postSlackMessage = async () => { const webhook = new IncomingWebhook(slackUrl); try { const response = await fetch(coinMarketCapUrl); const data = await response.json(); const filteredCoins = data.data.pageList.filter(coin => coin.liquidity > liquidityThreshold && coin.fdv < fdvThreshold && coin.txns24h > txns24hThreshold ).map(coin => coin.pairContractAddress); console.log('Number of coins passed filter:', filteredCoins.length); for (const pairAddress of filteredCoins) { try { const req = await fetch(`${geckoTerminalBaseUrl}/${pairAddress}/ohlcv/hour?aggregate=1&limit=1000`); const geckoData = await req.json(); const ohlcvList = geckoData.data.attributes.ohlcv_list; if (ohlcvList.length < 20) continue; const highest = ohlcvList.reduce((max, candle) => Math.max(max, candle[2]), 0); const currentPrice = ohlcvList[0][4]; if (currentPrice > highest) { await webhook.send({ text: `Current Candle Higher than Previous ATH: ${pairAddress}`, }); } } catch (error) { console.error(`Error fetching data for pair ${pairAddress}:`, error); } } } catch (error) { console.error('Error fetching initial data:', error); } }; await postSlackMessage(); };
Replace YOUR/SLACK/WEBHOOK with your actual Slack webhook URL.

Step 3: Deploy to Google Cloud Functions

Deploy your function to Google Cloud Functions:
shell
gcloud functions deploy cryptoAlertSystem --runtime nodejs16 --trigger-topic YOUR_PUBSUB_TOPIC --entry-point entryPoint
Replace YOUR_PUBSUB_TOPIC with your actual Pub/Sub topic name.

Conclusion

By following these steps, you've set up a cryptocurrency alert system that fetches market data, filters it based on specific criteria, and sends alerts to Slack when significant price movements occur. This system helps traders stay informed and make timely decisions. Feel free to customize the filtering criteria and extend the functionality to suit your needs. Happy trading!
Related posts
post image
In this blog, we'll explore how to set up an automated trading bot using TradingView's custom Pine Script alerts and AWS Lambda. This bot will execute trades on the KuCoin Futures market based on the alerts generated from TradingV...
post image
Renko charts are a unique tool in technical analysis, focusing on price changes rather than time. Originating from Japan, these charts help traders identify trends and significant price movements by filtering out noise....
post image
In the world of technical analysis, recognizing patterns is crucial for making informed trading decisions. Among the most reliable and popular patterns are bull and bear flags. These patterns help traders identify potential contin...
Powered by Notaku