Skip to content
dino.markets
DocsPricing
StocksSee the stocks API →CryptoSee the crypto API →CommoditiesSee the commodities API →EURUSDCurrenciesSee the currencies API →EconomicsSee the economics API →CoverageSee the coverage →
  • StocksStocks and ETFs on 42 exchanges, US funds and crypto
  • CryptoPrices and history for crypto pairs
  • CommoditiesGold in 31 currencies, other metals and oil in US dollars
  • CurrenciesHistory and conversion for 143 currencies
  • EconomicsInflation, GDP, jobs and yield curves
  • CoverageEvery country, currency, commodity and exchange the APIs cover
Build withDocsEndpointsMCPllms.txt
GuidesRead the guides →fxUse casesSee the use cases →dino.marketsCompareSee the comparisons →ChangelogSee what's new →
  • GuidesStep by step, with code you can run
  • Use casesThe calls each kind of app makes
  • CompareHow dino.markets sits against other data APIs
  • ChangelogNew data, countries and features
Build withDocsEndpointsMCPllms.txt
Sign inSign-ups paused

Home/Guides/How to get stock prices in JavaScript

How to get stock prices in JavaScript

Get stock prices in JavaScript with the fetch function in Node 18 or newer and one API key: the latest price, up to 50 prices in one request, and daily history.

dino.markets is a financial data API for apps and AI agents with stocks and ETFs on 42 exchanges, a free plan and paid plans from $29 a month (as of November 2026). This guide gets the latest price of Microsoft and its daily history in JavaScript, with the fetch function built into Node. The whole script is below, and the sections after it explain each part.

const API = "https://api.dino.markets/v1";
const HEADERS = { Authorization: `Bearer ${process.env.DINO_API_KEY}` };

async function get(path, params = {}) {
  const response = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
    headers: HEADERS,
    signal: AbortSignal.timeout(30_000),
  });
  if (!response.ok) {
    throw new Error(`Request failed: ${response.status} ${await response.text()}`);
  }
  return response.json();
}

const quote = await get("/equities/XNAS:MSFT/price");
console.log(`${quote.symbol} ${quote.price} ${quote.currency}`);

const history = await get("/equities/XNAS:MSFT/bars", { start: "2026-11-03", end: "2026-11-06" });
for (const bar of history.bars) {
  console.log(bar.date, bar.close);
}

Save it as stocks.mjs and run it with node stocks.mjs. The .mjs ending lets Node read it as an ES module, which is what allows await at the top of the file.

Before you start

  • Node 18 or newer. It has fetch built in, so you install nothing.
  • A dino.markets API key.
  • Each successful request counts against your plan’s monthly limit. Failed requests do not count.
  • Run this on a server. Keep the key out of browser code.

Get a key

Sign up for the Free plan, which needs no card. Then open keys in the dashboard, create a key and save it as the environment variable DINO_API_KEY.

Check your Node version

Print the version. If it is lower than 18, update Node first.

node --version

Request the latest price

Call GET /v1/equities/{id}/price. The id is the exchange code, a colon and the ticker, for example XNAS:MSFT for Microsoft on Nasdaq. A bare US ticker such as MSFT also works when it names one US listing. If you do not know the id, search for it with GET /v1/equities/search?q=micro.

const response = await fetch("https://api.dino.markets/v1/equities/XNAS:MSFT/price", {
  headers: { Authorization: `Bearer ${process.env.DINO_API_KEY}` },
});
if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${await response.text()}`);
}
const quote = await response.json();

Example response from 13 November 2026. The price changes all day, the fields stay the same.

{
  "id": "XNAS:MSFT",
  "symbol": "MSFT",
  "currency": "USD",
  "price": "522.10",
  "previous_close": "523.00",
  "change": "-0.90",
  "change_percent": "-0.17",
  "volume": "128104",
  "market_session": "open",
  "timestamp": "2026-11-13T14:59:00Z",
  "stale": false,
  "delayed": true
}

delayed is present, as true, when the price is 15 minutes late. previous_close, change, change_percent and volume are left out when they are not known.

Print a price

The price is a decimal string in the listing’s currency. change_percent is in percent, so -0.17 means a fall of 0.17%.

console.log(`${quote.symbol} ${quote.price} ${quote.currency}`);
console.log(`Change today: ${quote.change_percent}%`);

Example output from 13 November 2026:

MSFT 522.10 USD
Change today: -0.17%

stale is true when the price is older than 15 minutes while the exchange is open. A closed market is never stale.

Get several prices at once

Call GET /v1/equities/prices with ids, a comma-separated list of up to 50 ids. It counts as one request, however many ids you send. Ids with no price come back in errors.

const data = await get("/equities/prices", { ids: "XNAS:MSFT,XNAS:NVDA" });
for (const item of data.prices) {
  console.log(item.symbol, item.price);
}
for (const item of data.errors) {
  console.log("No price for", item.id, item.code);
}

Get daily history

Call GET /v1/equities/{id}/bars. The default interval is 1d, one bar per session. start and end are dates written YYYY-MM-DD, both inclusive. Bars come oldest first, and prices are adjusted for splits and dividends.

const history = await get("/equities/XNAS:MSFT/bars", {
  start: "2026-11-03",
  end: "2026-11-06",
});
for (const bar of history.bars) {
  console.log(bar.date, bar.close);
}

Example output:

2026-11-03 520.99
2026-11-04 555.80
2026-11-05 535.93
2026-11-06 530.61

Example response, trimmed to two of the four bars:

{
  "id": "XNAS:MSFT",
  "currency": "USD",
  "adjusted": true,
  "bars": [
    {
      "date": "2026-11-03",
      "timestamp": "2026-11-03T14:30:00Z",
      "open": "509.01",
      "high": "523.44",
      "low": "507.82",
      "close": "520.99",
      "volume": "20010200"
    },
    {
      "date": "2026-11-04",
      "timestamp": "2026-11-04T14:30:00Z",
      "open": "543.70",
      "high": "559.15",
      "low": "542.30",
      "close": "555.80",
      "volume": "50807800"
    }
  ],
  "next_cursor": null
}

A page holds up to 5,000 bars. When next_cursor is not null, pass it as cursor with the same other parameters to get the next page. One-minute bars (interval=1m) cover at most 5 days per call and need a paid plan.

Handle errors

Errors come back as problem JSON with a code. Read the errors guide for the full list. These are the ones you will meet first.

Status Code What to do
401 unauthenticated The key is wrong or revoked. Replace it.
429 See code You reached the per-minute limit or the monthly limit of your plan. Wait, or change plan.

For a stock call you may also see 404 not_found for an id that matches no listing, 404 not_covered when an exchange has no prices yet, 403 plan_upgrade_required when the dates you ask for end before your plan’s history starts or you ask for one-minute bars on the Free plan, 400 invalid_interval for an interval other than 1d or 1m, and 409 cursor_expired when a split or dividend changed the history behind a cursor. Start the history again in that case.

Every 429 carries a Retry-After header. Do not retry a 401, since you need to fix the key first. Do retry timeouts and server errors, with a short wait that doubles each time.

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function getWithRetry(path, params = {}, tries = 3) {
  for (let attempt = 0; attempt < tries; attempt++) {
    const last = attempt === tries - 1;
    let response;
    try {
      response = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
        headers: HEADERS,
        signal: AbortSignal.timeout(10_000),
      });
    } catch (error) {
      if (last) throw error;
      await sleep(2 ** attempt * 1000);
      continue;
    }
    if (response.status >= 500 && !last) {
      await sleep(2 ** attempt * 1000);
      continue;
    }
    if (!response.ok) {
      throw new Error(`Request failed: ${response.status} ${await response.text()}`);
    }
    return response.json();
  }
}

A successful retry counts as one request.

Cache the result

Most pages and scripts do not need a fresh price on every request. Keep the last answer for a minute and reuse it, so repeat lookups use no requests.

const cache = new Map();

async function cachedPrice(stockId, seconds = 60) {
  const hit = cache.get(stockId);
  if (hit && Date.now() - hit.at < seconds * 1000) {
    return hit.price;
  }
  const data = await getWithRetry(`/equities/${stockId}/price`);
  cache.set(stockId, { at: Date.now(), price: data.price });
  return data.price;
}

Common questions

How many requests do I get

The Free plan has 3,000 successful requests a month. Starter has 20,000, Basic has 100,000 and Pro has 1,000,000. Failed requests do not count, and a batch request with up to 50 ids counts as one.

Can I try it before paying

Yes. Sign up for the Free plan, which needs no card.

Why are prices strings and not numbers

Prices are decimal strings, so no digits are lost on the way. Convert them with Number only for display, and use a decimal library if you need exact sums.

Can I call this from the browser

Do not. The key would be visible to anyone who opens the page. Call the API from your server and send the result to the browser.

How far back does the history go

The Free plan covers the last 12 months, Starter and Basic 5 years, and Pro the full history. A range that starts before your window is cut to the window. A range that ends before it is refused with 403 plan_upgrade_required.

Next steps

  • Browse every endpoint in the stocks reference.
  • Compare options in stock price APIs.
  • Read about plans and billing.

Next steps

  • DocumentationQuickstart: your first request→
  • API referenceEvery endpoint, parameter and response field→
  • PricingPlans and limits→
  • DocumentationErrors and limits→

Start with a free key

3,000 requests a month, no card needed.

Sign-ups paused ↗
  • Other MCP clientsServer address and key

Guides

How to get exchange rates in PythonHow to get stock prices in PythonHow to get stock prices in JavaScriptHow to get stock prices in ExcelHow to get stock prices in Google SheetsBeta and cost of equity in Excel
dino.markets

Stocks, currencies, commodities and economics through one API.

APIs

StocksCryptoCommoditiesCurrenciesEconomicsCoverage

Docs

QuickstartAPI referenceMCP serverllms.txtChangelog

Resources

GuidesUse casesCompareAll APIs

Support

PricingAboutSupport
© 2026 Nusantara Ventures, LLC
TermsAcceptable usePrivacy