HomeGuidesHow to get stock prices in Python
How to get stock prices in Python
Get stock prices in Python with the requests library and one API key: the latest price, up to 50 prices in one request, and daily history adjusted for splits and dividends.
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 Python with the requests library. The whole script is below, and the sections after it explain each part.
import os
import requests
API = "https://api.dino.markets/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['DINO_API_KEY']}"}
def get(path, params=None):
response = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=30)
response.raise_for_status()
return response.json()
quote = get("/equities/XNAS:MSFT/price")
print(f"{quote['symbol']} {quote['price']} {quote['currency']}")
history = get("/equities/XNAS:MSFT/bars", {"start": "2026-11-03", "end": "2026-11-06"})
for bar in history["bars"]:
print(bar["date"], bar["close"])
Before you start
- Python 3.8 or newer.
- The requests library.
- A dino.markets API key.
- Each successful request counts against your plan’s monthly limit. Failed requests do not count.
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.
Install requests
Install the requests library with pip.
pip install requests
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.
import os
import requests
API = "https://api.dino.markets/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['DINO_API_KEY']}"}
response = requests.get(
f"{API}/equities/XNAS:MSFT/price",
headers=HEADERS,
timeout=30,
)
response.raise_for_status()
quote = 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%.
print(f"{quote['symbol']} {quote['price']} {quote['currency']}")
print(f"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.
data = get("/equities/prices", {"ids": "XNAS:MSFT,XNAS:NVDA"})
for item in data["prices"]:
print(item["symbol"], item["price"])
for item in data["errors"]:
print("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.
response = requests.get(
f"{API}/equities/XNAS:MSFT/bars",
params={"start": "2026-11-03", "end": "2026-11-06"},
headers=HEADERS,
timeout=30,
)
response.raise_for_status()
for bar in response.json()["bars"]:
print(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.
import time
def get_with_retry(path, params=None, tries=3):
for attempt in range(tries):
try:
response = requests.get(f"{API}{path}", params=params, headers=HEADERS, timeout=10)
except (requests.Timeout, requests.ConnectionError):
if attempt == tries - 1:
raise
time.sleep(2 ** attempt)
continue
if response.status_code >= 500 and attempt < tries - 1:
time.sleep(2 ** attempt)
continue
response.raise_for_status()
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.
cache = {}
def cached_price(stock_id, seconds=60):
hit = cache.get(stock_id)
if hit and time.time() - hit[0] < seconds:
return hit[1]
data = get_with_retry(f"/equities/{stock_id}/price")
cache[stock_id] = (time.time(), 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. Wrap them in Python's Decimal if you need to do sums.
How do I find a stock's id
Call GET /v1/equities/search?q=micro. Each result has an id such as XNAS:MSFT. For a US stock, the bare ticker also works.
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
Start with a free key
3,000 requests a month, no card needed.