A feasible and reliable way of attaining real-time options data
Disclaimer: All the content featured in this article is strictly for educational purposes and should not be taken as a form of investment advice
Introduction
In the rapid world of options trading, real-time data is such a crucial element as it helps traders to be spontaneous with their trade decisions and stay ahead in the market. But there’s a problem.
The process of obtaining real-time options data is such a frustrating task for a number of reasons like finding reliable sources, the cost of acquiring the data, and so on. Though there are a plethora of APIs available in the market, the ones that focus on real-time options data are very hard to find and ensuring their reliability is a whole different task.
But today, we are going to discuss a potential solution to all these problems. Introducing Intrinio’s Real-Time Options Data API. This is an easily accessible and reliable source for all your real-time data needs. In this article, we will dive deep into this API and explore the different endpoints offered for each type of data.
Setting up an Account & Acquiring Data
Before heading to start coding in Python, it is essential to first have an Intrinio account and then purchase the real-time options API endpoints. Firstly, to create an account, head over to Intrinio’s homepage and select the Sign Up button on the top-right corner which leads you to the user registration page.
After creating an account, you can purchase the API endpoints from this product page which contains all the details about the real-time data that comes with the API: https://intrinio.com/products/options-realtime
Intrinio Real-time Options Data Product details (Image by Author)
Now that you have an Intrinio account which allows you to have your own API keys (vital for extracting data) and ownership of the real-time options data, we can now proceed to coding in Python and get our hands dirty by extracting some interesting information from the APIs.
Importing Packages
The first and foremost step of setting up the coding environment is to import the required packages. In this article, we are going to use just two packages which include requests for making API calls and pandas for working with data. The following code will import all the mentioned packages into our Python environment:
# IMPORTING PACKAGES
import requests
import pandas as pd
If you haven’t installed any of the imported packages, make sure to do so using the pip command in your terminal.
Extracting Real-Time Options Data
This is the core section of the article where we are going to extract different types of real-time options data with the help of Python and several API endpoints.
1. Options Chain
Let’s start off with a common yet crucial type of options data which is the options chain. Any trader who is into options trading cannot neglect the options chain as it reveals a lot of important information which are extremely useful for making better trade decisions. The following code utilizes Intrinio’s Real-Time Options Chain API endpoint to extract the options chain of Microsoft options contracts expiring on Dec 1:
# REAL-TIME OPTIONS CHAIN DATA
url = 'https://api-v2.intrinio.com/options/chain/MSFT/2023-12-01/realtime'
headers = {'api_key':'YOUR API KEY'}
json = requests.get(url, headers = headers).json()
stats = []
option = []
price = []
for i in range(len(json['chain'])):
stats.append(json['chain'][i]['stats'])
option.append(json['chain'][i]['option'])
price.append(json['chain'][i]['price'])
stats_df, option_df, price_df = pd.DataFrame(stats), pd.DataFrame(option), pd.DataFrame(price)
stats_df.index, price_df.index = option_df['code'], option_df['code']
display(stats_df), display(option_df), display(price_df)
In the above code, we are first storing the API URL into the url variable. Speaking of the API URL, it involves two mandatory parameters which are the stock symbol and the expiration date (MSFT and 2023–12–01 respectively in our case). There are also other parameters like moneyness, option type, strike, and so on which can be helpful in filtering the data but here, our focus is only on the mandatory ones.
Then, we are making an API call, and each dictionary in the JSON response is sub-divided into three:
stats — which contains the option greeks figures along with implied volatility and underlying price of the contract
option — it comprises the basic information about the contract like the expiration date, option type, and the strike price.
price — it has every type of price-related information like the ask price, bid price, open interest, sizes of the asks and bids, volume, and so on.
After making the API call, we are using a for-loop to create three different dataframes for each of the dictionary fields to get a better view of the information we are extracting. These are the output dataframes from the above code:
Left: Stats Dataframe, Right: Option Dataframe
Price Dataframe
Almost every type of information a trader needs on a real-time basis is covered by this Options Chain API endpoint. Let’s move on to the next type of options data.
2. Option Stats
In the previous section when we extracted the options chain data, it did give some stats like the option greeks figures, implied volatility, and underlying price, but with the help of Intrinio’s Real-Time Option Stats API endpoint, we can extract even more detailed stats for a given options contract. Following is an example of using the API to extract the option stats for a particular contract:
# REAL-TIME OPTIONS STATS DATA
url = 'https://api-v2.intrinio.com/options/prices/MSFT231201P00345000/realtime/stats'
headers = {'api_key':'YOUR API KEY'}
stats_json = requests.get(url, headers = headers).json()
stats_json
The code is pretty straightforward. We are first storing the API URL into the url variable. Before moving on, a little analysis of the API URL: There is only one mandatory parameter which is identifier , nothing but the code of the options contract (MSFT231201P00345000 in our case). And there’s one optional parameter called source where we can specify whether we want real-time or delayed data.
After storing the API URL and the API key in their respective variables, we are making an API call and like the JSON response we got in the previous section, the output of this endpoint also contains three different fields. Here’s the output of the above code:
The first field is stats which contains the option greeks, implied volatility, and underlying price. The second one is factors which has price-related information along with other details like risk-free interest rate and dividend yield. The third and final field is option which contains some basic info about the options contract.
3. Unusual Activity
This is where things get interesting! In the previous two sections, the data we pulled were just fundamental options data which are used by most of the traders but in order to have an edge in the market, we need more than just fundamental data.
This is where Intrinio serves as a helping hand by offering a unique product called the Real-Time Options Unusual Activity API endpoint which, as the name suggests, tracks unusual activities happening in the trading arena like large trades, sweeps, and block trades. The following code tracks the unusual activities happening with Apple options contracts:
# REAL-TIME UNUSUAL ACTIVIY
url = 'https://api-v2.intrinio.com/options/unusual_activity/AAPL?source=realtime'
headers = {'api_key':'YOUR API KEY'}
json = requests.get(url, headers = headers).json()
unusual_activity = pd.DataFrame(json['trades']).drop(['symbol'], axis = 1)
unusual_activity.head()
The code is very simple and nothing much going on here in terms of complexity. As usual, we are first storing the API URL and the API key in their respective variables, and then, making the API call using the get function provided by the requests package.
Before discussing the output of the code, let’s take a minute to talk about the API URL. It has only one mandatory parameter which is the stock symbol and there is one additional parameter which is called source where we can specify whether we want real-time or delayed data. This is the output dataframe of the above code:
Out of all the columns in the dataframe, the most important ones are the type and sentiment columns. The type column is concerned about the type of unusual activity, whether it’s large trades, sweeps, or block trades. The sentiment column reveals the market sentiment of that particular options contract. These two columns of data can have a huge influence on traders’ decisions with regard to buying or selling a contract.
Conclusion
In this article, we explored the intricacies of the exciting Real-Time Options Data API provided by Intrinio and extracted various types of useful data with the help of several endpoints. There are still a lot of endpoints which are not discussed in this article and you can view them in their documentation here.
To summarise, I had a great experience using Intrinio’s real-time options data APIs. It was very easy to interact with their APIs and their greatly detailed documentation helped me in saving a ton of time. I recommend you guys to definitely give their APIs a try.
With that being said, you’ve reached the end of the article. Hope you learned something new and useful. If you’ve used Intrinio’s APIs for extracting data, let me know your user experience in the comments. Thank you very much for your time.