Asset Sentiment Comparison

Track and compare sentiment metrics across multiple crypto assets to identify potential market trends and opportunities. IN THIS RECIPE
  1. Instantiate Client
  2. Fetch Sentiment Data
  3. Compare Results

Overview Code Example

This is the initial code snippet to get started:
import MessariSDK from "@messari/sdk-ts";

const client = new MessariSDK({
  apiKey: process.env.MESSARI_SDK_API_KEY,
});

async function compareSentiment() {
  const allSentiments = await client.signal.v0.sentiment.list({
    sort: "marketcap",
  });

  const assetsOfInterest = ["bitcoin", "ethereum", "solana"];
  const targetAssets = allSentiments.data.filter((asset) =>
    assetsOfInterest.includes(asset.name.toLowerCase())
  );

  console.log("ASSET SENTIMENT COMPARISON:");
  console.log("--------------------------");

  targetAssets.forEach((asset) => {
    console.log(`Asset ID: ${asset.id}`);
    console.log(`${asset.name}:`);
    console.log(`  Sentiment Score: ${asset.sentimentScore}/100`);
    console.log(
      `  Momentum: ${asset.sentimentMomentumScore > 0 ? "+" : ""}${
        asset.sentimentMomentumScore
      }`
    );
    console.log(`  Positive Posts: ${asset.positivePostPercent}%`);
    console.log(`  Negative Posts: ${asset.negativePostPercent}%`);
    console.log(`  Tweet Volume (7d): ${asset.tweetVolume}`);
    console.log("--------------------------");
  });

  const topMomentum = targetAssets.reduce((prev, current) =>
    prev.sentimentMomentumScore > current.sentimentMomentumScore
      ? prev
      : current
  );

  console.log(
    `Asset with strongest positive momentum: ${topMomentum.name} (${topMomentum.sentimentMomentumScore})`
  );
}

compareSentiment();

Example Output

When you run this code, you’ll see output similar to:
> tsx src/index.ts

ASSET SENTIMENT COMPARISON:
--------------------------
Asset ID: 1e31218a-e44e-4285-820c-8282ee222035
Bitcoin:
  Sentiment Score: 49.551945328629714/100
  Momentum: +0.9252608758659662
  Positive Posts: 0.483764%
  Negative Posts: 0.131403%
  Tweet Volume (7d): 18447
--------------------------
Asset ID: 21c795f5-1bfd-40c3-858e-e9d7e820c6d0
Ethereum:
  Sentiment Score: 50.29481604817771/100
  Momentum: -0.020164777946519052
  Positive Posts: 0.466686%
  Negative Posts: 0.17212%
  Tweet Volume (7d): 13508
--------------------------
Asset ID: b3d5d66c-26a2-404c-9325-91dc714a722b
Solana:
  Sentiment Score: 48.815104955204504/100
  Momentum: +0.7521656135294847
  Positive Posts: 0.484354%
  Negative Posts: 0.141168%
  Tweet Volume (7d): 9811
--------------------------
Asset with strongest positive momentum: Bitcoin (0.9252608758659662)
You can enhance this output with visualizations like radar charts to better compare the assets:
SENTIMENT RADAR CHART:
Bitcoin   : Sentiment[█████░░░░░] Momentum[██████████] Volume[██████████]
Ethereum  : Sentiment[█████░░░░░] Momentum[█████░░░░░] Volume[███████░░░]
Solana    : Sentiment[█████░░░░░] Momentum[█████████░] Volume[█████░░░░░]

Installation

For the latest version of the Messari SDK-TS, use:
npm install @messari/sdk-ts

Detailed Recipe Steps

1

1. Instantiate Client

First, instantiate the MessariSDK from@messari/sdk-ts. You’ll need to provide your API key during initialization or set it as an environment variable.

2

2. Fetch Sentiment Data

Next, use the client.signal.v0.sentiment.list() method to retrieve sentiment data for all tracked assets. You can sort the results by market cap, rank, or combined sentiment using the sort parameter.

For specific assets, you can either filter the results from the list endpoint or use the client.signal.v0.sentiment.assets.retrieve() method with a specific asset ID.

3

3. Compare Results

The response contains various sentiment metrics for each asset:

  • sentimentScore: Overall sentiment (0-100) compared to 20-day baseline
  • sentimentMomentumScore: Day-over-day change in sentiment
  • positivePostPercent/negativePostPercent: Percentage of positive/negative posts
  • tweetVolume: Total number of tweets about the asset in the last 7 days

You can compare these metrics across assets to identify opportunities, such as assets with improving sentiment despite stagnant prices, or extreme sentiment conditions that might signal potential market reversals.

For more details on available sentiment endpoints and metrics, see theSentiment API documentation.