You want to track your crypto portfolio but don't want to build an entire backend or deal with CoinGecko rate limits. Here's how to build a working portfolio tracker in under 50 lines of JavaScript.
No API key needed. No signup. Just code.
What We're Building
A command-line portfolio tracker that:
- Fetches live prices for any coins you hold
- Calculates your total portfolio value in USD
- Shows profit/loss per coin
- Runs with a single
node portfolio.jscommand
The API
We'll use the Frostbyte API — it returns real-time prices for 500+ coins with no authentication required.
Quick test:
curl -s https://agent-gateway-kappa.vercel.app/prices | python3 -m json.tool | head -20
Response:
{
"count": 527,
"prices": {
"BTC": "71312.5",
"ETH": "2080.95",
"SOL": "88.80",
"DOGE": "0.094",
"XMR": "363.8"
}
}
527 coins, updated in real time, zero authentication.
Step 1: Define Your Holdings
Create portfolio.js:
const HOLDINGS = [
{ coin: 'BTC', amount: 0.5, buyPrice: 42000 },
{ coin: 'ETH', amount: 10, buyPrice: 2200 },
{ coin: 'SOL', amount: 100, buyPrice: 25 },
];
Replace with your actual holdings and buy prices.
Step 2: Fetch Live Prices
async function getPrices() {
const res = await fetch('https://agent-gateway-kappa.vercel.app/prices');
const data = await res.json();
return data.prices;
}
That's it. No headers, no API keys, no OAuth dance.
Step 3: Calculate Portfolio Value
async function showPortfolio() {
const prices = await getPrices();
let totalValue = 0, totalCost = 0;
console.log('\n COIN | QTY | PRICE | VALUE | P/L');
console.log(' -------|----------|-------------|-------------|--------');
for (const h of HOLDINGS) {
const price = parseFloat(prices[h.coin]);
if (!price) { console.log(` ${h.coin}: not found`); continue; }
const value = h.amount * price;
const cost = h.amount * h.buyPrice;
const pl = ((price - h.buyPrice) / h.buyPrice * 100).toFixed(1);
const sign = price >= h.buyPrice ? '+' : '';
totalValue += value;
totalCost += cost;
console.log(
` ${h.coin.padEnd(6)} | ${String(h.amount).padEnd(8)} | $${price.toLocaleString().padStart(10)} | $${value.toLocaleString().padStart(10)} | ${sign}${pl}%`
);
}
const totalPL = ((totalValue - totalCost) / totalCost * 100).toFixed(1);
console.log(' -------|----------|-------------|-------------|--------');
console.log(` TOTAL | | | $${totalValue.toLocaleString().padStart(10)} | ${totalValue >= totalCost ? '+' : ''}${totalPL}%\n`);
}
showPortfolio();
Full Code (44 Lines)
Here's the complete portfolio.js:
const HOLDINGS = [
{ coin: 'BTC', amount: 0.5, buyPrice: 42000 },
{ coin: 'ETH', amount: 10, buyPrice: 2200 },
{ coin: 'SOL', amount: 100, buyPrice: 25 },
];
async function getPrices() {
const res = await fetch('https://agent-gateway-kappa.vercel.app/prices');
const data = await res.json();
return data.prices;
}
async function showPortfolio() {
const prices = await getPrices();
let totalValue = 0, totalCost = 0;
console.log('\n COIN | QTY | PRICE | VALUE | P/L');
console.log(' -------|----------|-------------|-------------|--------');
for (const h of HOLDINGS) {
const price = parseFloat(prices[h.coin]);
if (!price) { console.log(` ${h.coin}: not found`); continue; }
const value = h.amount * price;
const cost = h.amount * h.buyPrice;
const pl = ((price - h.buyPrice) / h.buyPrice * 100).toFixed(1);
const sign = price >= h.buyPrice ? '+' : '';
totalValue += value;
totalCost += cost;
console.log(
` ${h.coin.padEnd(6)} | ${String(h.amount).padEnd(8)} | $${price.toLocaleString().padStart(10)} | $${value.toLocaleString().padStart(10)} | ${sign}${pl}%`
);
}
const totalPL = ((totalValue - totalCost) / totalCost * 100).toFixed(1);
console.log(' -------|----------|-------------|-------------|--------');
console.log(` TOTAL | | | $${totalValue.toLocaleString().padStart(10)} | ${totalValue >= totalCost ? '+' : ''}${totalPL}%\n`);
}
showPortfolio();
Run it:
node portfolio.js
Add Auto-Refresh
Want a live dashboard? Add one line:
setInterval(showPortfolio, 30000); // refresh every 30s
showPortfolio();
Other Free Endpoints
The same API has more tools you can use without an API key:
Your public IP:
curl https://agent-gateway-kappa.vercel.app/ip
IP geolocation (city, country, ISP):
curl https://agent-gateway-kappa.vercel.app/ip/json
Get an API key for 40+ additional endpoints (200 free credits):
curl -X POST https://agent-gateway-kappa.vercel.app/api/keys/create
This unlocks DNS lookups, website screenshots, code execution, web scraping, and more. Full docs at the API catalog.
Built with Frostbyte API — free crypto, geo, and developer APIs.
Top comments (0)