Building an Automated Alternative Data Analysis Pipeline for Cryptocurrency Trading using n8n, Polygon, and Messari APIs: Integrating On-chain Data, Social Media Sentiment Analysis, and Market Indicators

In the complex cryptocurrency market, real-time data analysis is essential to gain a competitive edge. By integrating n8n, Polygon, and Messari APIs, we build an automated analysis pipeline that combines on-chain data, social media sentiment, and market indicators, helping you make better data-driven trading decisions.

1. The Challenge / Context

Cryptocurrency trading is a battle of information. The market is extremely volatile and changes at a breathtaking pace. Simply analyzing past price charts is not enough. Various factors such as on-chain transactions, social media sentiment, and macroeconomic indicators influence prices. Manually collecting and analyzing this data is time-consuming and inefficient. There is a desperate need for an automated solution that integrates and analyzes this data in real-time to incorporate it into trading strategies.

2. Deep Dive: n8n, Polygon, Messari API

We utilize three key tools to build the automation pipeline.

  • n8n: A powerful no-code workflow automation platform. It allows you to visually configure and automate data flows by connecting various APIs and services. Even without extensive coding knowledge, you can perform complex data processing tasks.
  • Polygon API: Provides on-chain data from the Polygon network. You can obtain various information in real-time, such as token transfers, smart contract interactions, and trading volume. On-chain data plays a crucial role in understanding market sentiment and predicting potential price movements.
  • Messari API: An API that provides cryptocurrency market data. It offers various information such as prices, trading volumes, market capitalization, news, and analyst reports. Additionally, you can gain deep insights into projects, including asset profiles, governance information, and team details.

3. Step-by-Step Guide / Implementation

The following is a step-by-step guide to building an automated cryptocurrency data analysis pipeline using n8n, Polygon API, and Messari API.

Step 1: n8n Installation and Setup

Install n8n in your local or cloud environment. Using Docker is the simplest way.

docker run -d -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

Access the n8n UI (http://localhost:5678) and create a new workflow.

Step 2: Integrating Polygon API

Add a Polygon API node to your n8n workflow. Generate a Polygon API key and enter it in the node settings. Select the required endpoint and extract the desired data. For example, you can retrieve recent transaction history for a specific token.

// Example: Get recent transaction history for a specific token (assuming Polygon API v2 is used)
    {
      "nodes": [
        {
          "parameters": {
            "operation": "get",
            "url": "https://api.polygon.io/v2/last/trade/{ticker}?apiKey={YOUR_POLYGON_API_KEY}",
            "requestMethod": "GET",
            "options": {}
          },
          "name": "HTTP Request",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            200,
            200
          ]
        }
      ],
      "connections": []
    }
    

Here, {ticker} should be replaced with the token ticker (e.g., MATIC), and {YOUR_POLYGON_API_KEY} with your issued Polygon API key. Use the HTTP Request node to send a request to the Polygon API.

Step 3: Integrating Messari API

Add a Messari API node to your n8n workflow. Generate a Messari API key and enter it in the node settings. The Messari API offers various endpoints, so select and extract the data you need. For example, you can retrieve market indicators (price, trading volume, market capitalization, etc.) for a specific cryptocurrency.

// Example: Get market indicators for a specific cryptocurrency (assuming Messari API is used)
    {
      "nodes": [
        {
          "parameters": {
            "operation": "get",
            "url": "https://data.messari.io/api/v1/assets/{asset}/metrics",
            "requestMethod": "GET",
            "options": {},
            "headerParametersUi": {
              "parameter": [
                {
                  "name": "x-messari-api-key",
                  "value": "{YOUR_MESSARI_API_KEY}"
                }
              ]
            }
          },
          "name": "HTTP Request",
          "type": "n8n-nodes-base.httpRequest",
          "position": [
            200,
            400
          ]
        }
      ],
      "connections": []
    }
    

Here, {asset} should be replaced with the cryptocurrency name (e.g., bitcoin), and {YOUR_MESSARI_API_KEY} with your issued Messari API key. The API Key must be included in the Header of the HTTP Request node.

Step 4: Integrating Social Media Sentiment Analysis (Optional)

You can integrate social media APIs like Twitter API or Reddit API to analyze sentiment for specific cryptocurrencies. Use text analysis libraries (e.g., Python's NLTK or spaCy) to analyze the sentiment of tweets or posts and calculate positive/negative/neutral scores. n8n's Function node can be used to integrate such text analysis logic.

// Example: Running Python code for sentiment analysis in an n8n Function node (requires additional setup and library installation for actual operation)
    // Note: The ability to run Python code directly in n8n requires separate configuration.
    //      Generally, calling external APIs or using n8n's built-in JavaScript engine is more efficient.
    //      The code below is an example and may not work in a real environment.

    // const text = $json.text; // Social media text (e.g., tweet content)
    //
    // async function analyzeSentiment(text) {
    //   // Call external API (e.g., Google Cloud Natural Language API)
    //   const response = await fetch('https://language.googleapis.com/v1/documents:analyzeSentiment?key={YOUR_GOOGLE_API_KEY}', {
    //     method: 'POST',
    //     headers: {
    //       'Content-Type': 'application/json'
    //     },
    //     body: JSON.stringify({
    //       document: {
    //         type: 'PLAIN_TEXT',
    //         content: text
    //       }
    //     })
    //   });
    //
    //   const data = await response.json();
    //   return data.documentSentiment.score; // Return sentiment score
    // }
    //
    // const sentimentScore = await analyzeSentiment(text);
    //
    // return {
    //   sentimentScore: sentimentScore
    // };

    // Instead of calling an external API in n8n's JavaScript environment, a simpler example is shown below.
    const text = $input.item.json.text; // Text data passed from the previous node
    const positiveKeywords = ['good', 'great', 'amazing', 'bullish'];
    let sentimentScore = 0;

    positiveKeywords.forEach(keyword => {
      if (text.toLowerCase().includes(keyword)) {
        sentimentScore += 1;
      }
    });

    return [{json: {sentimentScore: sentimentScore}}];
    

Step 5: Data Integration and Analysis

Use n8n's Merge node to integrate the results from Polygon API, Messari API, and social media sentiment analysis. Perform necessary calculations using Function nodes or Math Formula nodes. For example, if an increase in on-chain trading volume, positive social media sentiment, and an upward price trend are all detected, a buy signal can be generated.

Step 6: Notification Setup

Use n8n's Email node, Slack node, or Telegram node to set up notifications for trading signals or significant market movements. You can configure it to automatically send alerts when specific conditions are met.

Step 7: Automation Scheduling

Use n8n's Cron node to schedule the workflow to run periodically. For example, you can run the workflow every minute, every hour, or at a specific time each day.

4. Real-world Use Case / Example

I use this pipeline to detect potential pump and dump schemes in DeFi tokens early. I detect a surge in trading volume for a specific token via the Polygon API and simultaneously verify the token's fundamental aspects through the Messari API. If I observe a rapid increase in positive mentions through social media sentiment analysis, I conclude that a pump and dump is likely and adjust my trading strategy. Thanks to this pipeline, I am not swayed by misinformation and can make rational, data-driven trading decisions.

5. Pros & Cons / Critical Analysis

  • Pros:
    • Data-driven trading decisions possible
    • Automated data collection and analysis
    • Integration of various data sources
    • Real-time notification feature
    • Easy workflow building with a no-code interface
  • Cons:
    • API usage limits (varies depending on API provider's policy)
    • Data quality issues (results may vary depending on the reliability of data sources)
    • Potential for performance degradation when building complex workflows
    • Accuracy issues with social media sentiment analysis (limitations of natural language processing technology)