|
| 1 | +import { MessariClient } from "@messari-kit/api"; |
| 2 | +import { printTable } from "console-table-printer"; |
| 3 | +import type { getAcquisitionDealsParameters, getFundingRoundsInvestorsParameters, getFundingRoundsParameters } from "@messari-kit/types"; |
| 4 | +import dotenv from "dotenv"; |
| 5 | + |
| 6 | +// Load environment variables from .env file |
| 7 | +dotenv.config(); |
| 8 | + |
| 9 | +// Get API key from environment variable |
| 10 | +const API_KEY = process.env.MESSARI_API_KEY; |
| 11 | + |
| 12 | +// Check if API key is available |
| 13 | +if (!API_KEY) { |
| 14 | + console.error("Error: MESSARI_API_KEY environment variable is not set."); |
| 15 | + console.error("Please create a .env file with your API key or set it in your environment."); |
| 16 | + process.exit(1); |
| 17 | +} |
| 18 | + |
| 19 | +// Initialize the Messari client |
| 20 | +const client = new MessariClient({ |
| 21 | + apiKey: API_KEY, |
| 22 | + // Optional: Override the base URL if needed |
| 23 | + // baseUrl: "https://api.messari.io", |
| 24 | +}); |
| 25 | + |
| 26 | +async function main() { |
| 27 | + const roundMap: Record<string, { entityName: string; type: string }> = {}; |
| 28 | + // Get the latest funding rounds filter by type and announcedAfter date |
| 29 | + try { |
| 30 | + const roundsParams: getFundingRoundsParameters = { page: 1, limit: 10, type: "Seed,Series A", announcedAfter: "2025-01-01T00:00:00Z" }; |
| 31 | + const resp = await client.fundraising.getFundingRounds(roundsParams); |
| 32 | + |
| 33 | + console.log("\n--------------------------------"); |
| 34 | + console.log("Funding Rounds"); |
| 35 | + console.log("--------------------------------"); |
| 36 | + const rounds = resp.data; |
| 37 | + if (rounds.length > 0) { |
| 38 | + for (const round of rounds) { |
| 39 | + if (round.id && round.fundedEntity?.name) { |
| 40 | + roundMap[round.id] = { entityName: round.fundedEntity?.name, type: round.type ?? "" }; |
| 41 | + } |
| 42 | + } |
| 43 | + const rows = rounds.map((r) => ({ |
| 44 | + "Id": r.id, |
| 45 | + "Date": r.announcementDate, |
| 46 | + "Entity": r.fundedEntity?.name, |
| 47 | + "Type": r.type, |
| 48 | + "Amount Raised": r.amountRaisedUSD, |
| 49 | + })); |
| 50 | + printTable(rows); |
| 51 | + } |
| 52 | + } catch (error) { |
| 53 | + console.error("Error calling getProjectRecap:", error); |
| 54 | + } |
| 55 | + |
| 56 | + // Get the funding round investors |
| 57 | + try { |
| 58 | + const investorsParams: getFundingRoundsInvestorsParameters = { page: 1, limit: 10, type: "Seed,Series A", announcedAfter: "2025-01-01T00:00:00Z" }; |
| 59 | + const resp = await client.fundraising.getFundingRoundsInvestors(investorsParams); |
| 60 | + |
| 61 | + console.log("\n--------------------------------"); |
| 62 | + console.log("Funding Round - Investors"); |
| 63 | + console.log("--------------------------------"); |
| 64 | + |
| 65 | + const rounds = resp.data; |
| 66 | + if (rounds.length > 0) { |
| 67 | + for (const round of rounds) { |
| 68 | + const roundName = roundMap[round.fundingRoundId ?? ""]; |
| 69 | + if (!roundName) { |
| 70 | + continue; |
| 71 | + } |
| 72 | + |
| 73 | + console.log("Round Id:", round.fundingRoundId); |
| 74 | + console.log(roundName.entityName, "-", roundName.type); |
| 75 | + if (round.organizations) { |
| 76 | + const rows = round.organizations.map((o) => ({ |
| 77 | + "Id": o.id, |
| 78 | + "Name": o.name, |
| 79 | + "Location": o.location, |
| 80 | + })); |
| 81 | + printTable(rows); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } catch (error) { |
| 86 | + console.error("Error calling getProjectRecap:", error); |
| 87 | + } |
| 88 | + |
| 89 | + // Get the acquisition deals |
| 90 | + try { |
| 91 | + const dealsParams: getAcquisitionDealsParameters = { page: 1, limit: 10 }; |
| 92 | + const resp = await client.fundraising.getAcquisitionDeals(dealsParams); |
| 93 | + |
| 94 | + console.log("\n--------------------------------"); |
| 95 | + console.log("M&A Deals"); |
| 96 | + console.log("--------------------------------"); |
| 97 | + |
| 98 | + const deals = resp.data; |
| 99 | + if (deals.length > 0) { |
| 100 | + const rows = deals.map((d) => ({ |
| 101 | + "Date": d.announcementDate, |
| 102 | + "Entity": d.acquiredEntity?.name, |
| 103 | + "Acquirer": d.acquiringEntity?.name, |
| 104 | + "Type": d.status, |
| 105 | + "Amount Raised": d.transactionAmountUSD, |
| 106 | + })); |
| 107 | + printTable(rows); |
| 108 | + } |
| 109 | + } catch (error) { |
| 110 | + console.error("Error calling getAcquisitionDeals:", error); |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +main().catch(console.error); |
0 commit comments