Skip to content
Back to the Guavy Blog
Blog

Building a JavaScript Program with the Guavy Trend History API

3 min read
Share

The cryptocurrency market is fast-paced, and to keep up, you need quick insights on trend shifts. With Guavy’s Trend History API, you can pull daily trend data for a coin over any window you choose.

In this tutorial, we’ll show you how to connect to the Trend History API and build a JavaScript program that fetches, displays, and works with trend data.

Overview of the Trend History API

The Trend History API returns a daily trend time series for one coin, up to a limit you set. For example, you could retrieve the last 7 days for Bitcoin, giving you actionable insights on market directions.

Step 1: Set Up Your Environment

Ensure you have Node.js installed if you plan to run this program from a local environment. You’ll also need an API key from Guavy for authentication.

Step 2: Making a Basic API Request

Let’s start by making a simple API request to get trend changes from the last 7 days.

  1. Set up your API URL
    Guavy’s API endpoint for retrieving trend history looks like this:

    https://guavy.com/api/v1/trades/get-trend-history/<SYMBOL>/<LIMIT>

    Replace <SYMBOL> with the coin you’re interested in and <LIMIT> with the maximum number of days to return. For example, /get-trend-history/btc/7 retrieves the last 7 days of trend data for Bitcoin.

  2. Add Your API Key
    You’ll need to include your Bearer token in the request header for authentication.

    const url = "https://guavy.com/api/v1/trades/get-trend-history/btc/7";
    const options = {
      method: "GET",
      headers: {
        Authorization: "Bearer YOUR-API-KEY",
      },
    };
  3. Fetch the Data

    Now, let’s fetch the data using JavaScript’s fetch function.

    fetch(url, options)
      .then((response) => response.json())
      .then((data) => console.log("Trend Data:", data))
      .catch((error) => console.error("Error fetching data:", error));

When executed, this code will print the trend data to the console. The response will look something like this:

{
  "trends": [
    {
      "date": "2026-08-10",
      "price": 64056.71028653909,
      "strength": "Weak",
      "timestamp": 1786397400000,
      "trend": "Neutral"
    }
  ]
}

Step 3: Parsing the Data

To make this data useful, let’s parse the response and display specific trend details, like the date, trend direction, and strength.

Add this code after the fetch call to display each trend change in a readable format.

fetch(url, options)
  .then((response) => response.json())
  .then((data) => {
    if (data.trends) {
      data.trends.forEach((point) => {
        console.log(`Date: ${point.date}`);
        console.log(`Trend: ${point.trend}`);
        console.log(`Strength: ${point.strength}`);
        console.log(`Price: $${point.price}\n`);
      });
    }
  })
  .catch((error) => console.error("Error fetching data:", error));

This code extracts each point in the series and displays its key details.

Conclusion

With just a few lines of JavaScript, we’ve successfully used the Guavy Trend History API to retrieve and display trend data for a cryptocurrency. Now you can leverage this API to keep tabs on the latest market movements, helping you make informed trading decisions.

Happy coding, and good luck navigating the crypto markets with Guavy!

Scored market news for you and your AI

Guavy reads and scores market news and commentary around the clock. Connect it to Claude or ChatGPT with no code, or build on it over REST and native MCP. No card required.

More from the blog