Welcome to this overview of some free python code that uses the Deribit API to pull in option open interest data, which is then used to calculate and display ‘max pain’ calculations for the chosen expiration.
The GitHub repository can be found here.
Max pain is a calculation that simply shows which underlying price would currently result in the lowest total intrinsic value of all currently held options. While simple to calculate, it is tedious to do by hand, so having it available at the click of a button is much more preferable.
For more information on max pain calculations, there is an article on this subject on the Deribit insights blog here.
The chart shows the open interest values for calls and puts, as well as the total intrinsic value calculation for each strike. The strike price at which the intrinsic value would be lowest, is labelled the max pain and is highlighted with a blue dashed line.
It’s possible to select a different expiry with the drop down menu, and also to change the currency by clicking the ‘change currency’ button. All three currencies that currently have tradable options are available (BTC, ETH, SOL). Sometimes currencies do not have options available to trade on all of the same expiry dates. When changing currencies, the code handles this automatically and populates the drop down menu with the correct dates for the selected currency.
Python UI libraries
Tkinter is used for the GUI, and Matplotlib is used to plot the charts. Both are very commonly used libraries in Python, so there is plenty of information available online if you want to edit things.
Deribit API endpoints
This program uses the following api endpoints:
Using the code
This code is free for all to use and edit as they wish. I hope each program is useful as it is, but they are also meant to be building blocks with which you can build your own more personalised applications. For example, even if you’re not too interested in the max pain calculation itself, displaying the current open interest by strike and option type may well be something useful you want to incorporate into your own code.