example5.ts

Example 5: Fetch and Analyze Market Cap Data

import { fetchMarketcap } from "../src/interactAgent";

async function example5() {
  const term = "QHLP";
  const count = 10;

  try {
    console.log("Fetching market cap data...");
    const marketCapData = await fetchMarketcap(term, count);
    console.log("Market cap data:", marketCapData);

    console.log("Analyzing market cap data...");
    // Example analysis
    const averageMarketCap = marketCapData.reduce(
      (sum: number, data: any) => sum + parseFloat(data.marketCap),
      0
    ) / marketCapData.length;
    console.log("Average Market Cap:", averageMarketCap);
  } catch (error) {
    console.error("Error fetching market cap data:", error);
  }
}

example5();

Last updated