The Stock Price API provides access to real-time and historical stock market prices for companies in every major exchange around the world.
https://api.api-ninjas.com/v1/stockprice
Returns the current price information for any given ticker symbol. Want historical stock prices? Use the /v1/stockpricehistorical endpoint instead.
ticker
requiredStock ticker symbol (e.g., AAPL
).
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/stockprice?ticker=AAPL
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
7
8
{
"ticker": "AAPL",
"name": "Apple Inc.",
"price": 192.42,
"exchange": "NASDAQ",
"updated": 1706302801,
"currency": "USD"
}
1
2
3
4
5
6
7
8
import requests
symbol = 'AAPL'
api_url = 'https://api.api-ninjas.com/v1/stockprice?ticker={}'.format(symbol)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
https://api.api-ninjas.com/v1/stockpricehistorical
Returns historical price data in OHLCV (Open, High, Low, Close, Volume) format for any given ticker symbol.
To get the 'price' for a particular period, use the close
value from the response.
ticker
requiredStock ticker symbol (e.g., AAPL
).
period
optionalTime interval between data points. Valid values are: 1m
, 5m
, 15m
, 30m
, 1h
, 4h
. Default is 1h
.
start
optionalStart timestamp in Unix format. If not provided, defaults to 24 hours ago.
end
optionalEnd timestamp in Unix format. If not provided, defaults to current time.
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/stockpricehistorical?ticker=AAPL&period=1h&start=1706000000&end=1706302801
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[
{
"open": 192.425,
"low": 191.94,
"high": 192.59,
"close": 192.3,
"volume": 8363236,
"time": 1706283000
},
{
"open": 192.48,
"low": 192.34,
"high": 192.975,
"close": 192.425,
"volume": 3467330,
"time": 1706279400
},
{
"open": 192.66,
"low": 192.27,
"high": 192.73,
"close": 192.4751,
"volume": 3375199,
"time": 1706275800
},
"..."
]