Get A Quote
Code Example
#!/usr/bin/env python3
import json
import requests
import sys
API_KEY = <TOKEN>
SINGLE = "AAPL"
TOP_FEW = "AAPL,MSFT,NVDA,AMZN,META,GGOGL,GOOG,BRK.B,LLY,AVGO,TSLA,JPM,UNH,XOM,V"
response = requests.post('https://api.tradier.com/v1/markets/quotes',
data={'symbols': SINGLE, 'greeks':'true'},
headers={'Authorization': f'Bearer {API_KEY}', 'Accept': 'application/json'}
)
try:
result = response.json()
except Exception as e:
print(f"Error: {response.status_code}")
print (e)
print(response.text)
sys.exit(1)
json_formatted_str = json.dumps(result, indent=2)
print(response.status_code)
print(json_formatted_str)
Response Example
200
{
"quotes": {
"quote": {
"symbol": "AAPL",
"description": "Apple Inc",
"exch": "Q",
"type": "stock",
"last": 253.24,
"change": 0.93,
"volume": 21640078,
"open": 253.205,
"high": 254.32,
"low": 251.712,
"close": null,
"bid": 253.22,
"ask": 253.25,
"change_percentage": 0.37,
"average_volume": 57388452,
"last_volume": 100,
"trade_date": 1758819401268,
"prevclose": 252.31,
"week_52_high": 260.1,
"week_52_low": 169.2101,
"bidsize": 2,
"bidexch": "Q",
"bid_date": 1758819401000,
"asksize": 1,
"askexch": "Z",
"ask_date": 1758819401000,
"root_symbols": "AAPL"
}
}
}
Step-by-Step Explainer
Imports
We'll want the ability to make an HTTP request and interpret the JSON response, so we will need libraries or built-in functionality in our script.
API token
You'll need your API Token from your account (https://web.tradier.com/user/api) to authorize the API call
Symbols
You can get a quote for a single financial instrument, such as a single equity or option, or you can gather several quotes at once by putting everything in a single string with commas separating the different elements.
Request
The request is a GET or POST call to the quotes endpoint. Make sure to have the symbols or OCC symbols instantiated correctly for the symbols parameter, and similarly for the API_KEY; make sure the Authorization parameter includes 'Bearer ' and your token correctly or you will get a 401.
Error Handling
We expect to get a JSON response of one or more quotes, so by attempting to store JSON in a variable, we verify if the call was successful or not. If there is an exception, we print the status code and error message so we know what went wrong.
Output
If the call is successful, we can do a bit of formatting to prettify the response and then print it out.
On this page
- Get A Quote