Mar 2, 2023
Summary
This project is a comprehensive REST API developed using FastAPI, aimed at storing and managing over 5TB of daily options data, including contract and price information. It features an extensive API that supports various endpoints for accessing historical data related to options trading. These endpoints include fetching historical expiries, strikes, prices, quotes, implied volatility (IV) rank, volatility cones, earnings, and IV information.
Github Repo.
Entity relationship diagram (ERD) between the tables in the database.
GET /stocks/tickers
Params: apiKey
Returns: List of unique tickers.
Request: /stocks/tickers?apiKey=test
Response: {
"message": "ok",
"data": [
"A",
"AA",
"AAAP",
"AABA",
...
]
}
GET /stocks/ticker-info
Params: apiKey, ticker
Returns: Ticker information including type, name, sector, industry, exchange, region, start and end date of data.
Request: /stocks/ticker-info?apiKey=test&ticker=aapl
Response: {
"message": "ok",
"data": {
"ticker": "AAPL",
"type": "STOCK",
"company_name": "Apple Inc.",
"sector": "Technology",
"industry": "Consumer Electronics",
"exchange": "NASDAQ",
"region": "US",
"start_date": "2008-02-04",
"end_date": "2024-01-09"
}
}
GET /stocks/hist/price
Params: apiKey, ticker, from (optional), to (optional)
Returns: Daily end-of-day price data for the specified date range or the entire history if no dates are specified.
Request: /stocks/hist/price?apiKey=test&ticker=aapl&from=2015-02-04
Response: {
"message": "ok",
"data": [
{
"ticker": "AAPL",
"date": "2008-02-04",
"unadj_open": 134.21,
"unadj_high": 135.9,
"unadj_low": 131.42,
"unadj_close": 131.65,
"open": 33.55,
"high": 33.98,
"low": 32.86,
"close": 32.91,
"volume": 32115400
},
{
"ticker": "AAPL",
"date": "2008-02-05",
"unadj_open": 130.43,
"unadj_high": 134,
"unadj_low": 128.9,
"unadj_close": 129.36,
"open": 32.61,
"high": 33.5,
"low": 32.22,
"close": 32.34,
"volume": 40751400
},
...
]
}
GET /stocks/hist/splits
Params: apiKey, ticker
Returns: Historical split data and split ratios for the specified ticker.
Request: /stocks/hist/splits?apiKey=test&ticker=aapl
Response: {
"message": "ok",
"data": [
{
"ticker": "AAPL",
"date": "2014-06-09",
"numerator": 7,
"denominator": 1
},
{
"ticker": "AAPL",
"date": "2020-08-31",
"numerator": 4,
"denominator": 1
}
]
}
GET /stocks/hist/divs
Params: apiKey, ticker
Returns: Historical dividend data for the specified ticker.
Request: /stocks/hist/divs?apiKey=test&ticker=msft
Response: {
"message": "ok",
"data": [
{
"ticker": "MSFT",
"ex_date": "2008-02-19",
"amount": 0.11,
"declared_date": "2007-12-19",
"payment_date": "2008-03-13",
"frequency": 4
},
{
"ticker": "MSFT",
"ex_date": "2008-08-19",
"amount": 0.11,
"declared_date": "2008-06-11",
"payment_date": "2008-09-11",
"frequency": 4
},
...
]
}
GET /stocks/hist/earnings
Params: apiKey, ticker
Returns: Historical earnings data for the specified ticker.
Request: /stocks/hist/earnings?apiKey=test&ticker=msft
Response: {
"message": "ok",
"data": [
{
"ticker": "MSFT",
"date": "2008-04-24",
"time": "amc",
"eps_est": 0.44,
"revenue_est": 13531404255.319149
},
{
"ticker": "MSFT",
"date": "2008-07-17",
"time": "amc",
"eps_est": 0.47,
"revenue_est": 16181282608.69565
},
...
]
}
GET /options/hist/expiries
Params: apiKey, ticker, tradeDate
Returns: A list of available option expiry dates for a given ticker and trade date.
Request: /options/hist/expiries?apiKey=test&ticker=msft&tradeDate=2012-09-11
Response: {
"message": "ok",
"data": [
"2012-09-14",
"2012-09-22",
"2012-10-20",
"2012-11-17",
"2012-12-22",
"2013-01-19",
"2013-04-20",
"2014-01-18"
]
}
GET /options/hist/strikes
Params: apiKey, ticker, tradeDate, expiry (optional)
Returns: Available strike prices for the specified expiry and trade date.
Request: /options/hist/strikes?apiKey=test&ticker=msft&tradeDate=2012-09-12&expiry=2012-09-22
Response: {
"message": "ok",
"data": {
"2012-09-22": [
15.0,
16.0,
17.0,
18.0,
19.0,
20.0,
21.0,
22.0,
23.0,
24.0,
25.0,
26.0,
27.0,
28.0,
29.0,
30.0,
31.0,
32.0,
33.0,
34.0,
35.0,
36.0,
37.0,
38.0,
39.0
]
}
}
GET /options/hist/price
Params: apiKey, ticker, tradeDate, expiry (optional), strike (optional), type (optional)
Returns: Pricing data, Greeks, and implied volatility for all options on the trade date.
Request: /options/hist/price?apiKey=test&ticker=msft&tradeDate=2012-09-12&expiry=2012-09-22&strike=25
Response: {
"message": "ok",
"data": {
"2012-09-22": {
"C": [
{
"strike": 25.0,
"type": "C",
"num_shares": 100,
"mid_price": 5.8,
"ivol": 0.6062812139267412,
"delta": 0.983123557251709,
"gamma": 0.013564147732578063,
"vega": 0.0021345728892685325,
"theta": -0.006531070880502779,
"rho": 0.0067015186553993425
}
],
"P": [
{
"strike": 25.0,
"type": "P",
"num_shares": 100,
"mid_price": 0.02,
"ivol": 0.6091400533522116,
"delta": -0.017278150157290062,
"gamma": 0.013774675466661486,
"vega": 0.0021779248948346473,
"theta": -0.006631945777524099,
"rho": -0.0001511839621483251
}
]
}
}
}
GET /options/hist/quotes
Params: apiKey, ticker, tradeDate, expiry (optional), strike (optional), type (optional)
Returns: Full quotes including bid/ask prices, open interest, and volume for the option chain.
Request: /options/hist/quotes?apiKey=test&ticker=msft&tradeDate=2012-09-12&expiry=2012-09-22&strike=25
Response: {
"message": "ok",
"data": {
"2012-09-22": {
"C": [
{
"strike": 25.0,
"type": "C",
"num_shares": 100,
"bid_price": 5.75,
"bid_ivol": 0.0,
"bid_delta": 1.0,
"bid_gamma": null,
"bid_vega": 0.0,
"bid_theta": -6.164231565018994e-05,
"bid_rho": 0.006849146183354438,
"mid_price": 5.8,
"mid_ivol": 0.6062812139267412,
"mid_delta": 0.983123557251709,
"mid_gamma": 0.013564147732578063,
"mid_vega": 0.0021345728892685325,
"mid_theta": -0.006531070880502779,
"mid_rho": 0.0067015186553993425,
"ask_price": 5.85,
"ask_ivol": 0.7558719368768753,
"ask_delta": 0.9577513617286223,
"ask_gamma": 0.02339189212784329,
"ask_vega": 0.004589421445916751,
"ask_theta": -0.017403339122203276,
"ask_rho": 0.006473859428495067
}
],
"P": [
{
"strike": 25.0,
"type": "P",
"num_shares": 100,
"bid_price": 0.0,
"bid_ivol": 0.0,
"bid_delta": 0.0,
"bid_gamma": null,
"bid_vega": 0.0,
"bid_theta": 0.0,
"bid_rho": -0.0,
"mid_price": 0.02,
"mid_ivol": 0.6091400533522116,
"mid_delta": -0.017278150157290062,
"mid_gamma": 0.013774675466661486,
"mid_vega": 0.0021779248948346473,
"mid_theta": -0.006631945777524099,
"mid_rho": -0.0001511839621483251,
"ask_price": 0.02,
"ask_ivol": 0.6091400533522116,
"ask_delta": -0.017278150157290062,
"ask_gamma": 0.013774675466661486,
"ask_vega": 0.0021779248948346473,
"ask_theta": -0.006631945777524099,
"ask_rho": -0.0001511839621483251
}
]
}
}
}
GET /options/hist/iv-rank
Params: apiKey, ticker, tradeDate, period (optional = 30)
Returns: The ATM implied volatility rank and percentile for the specified period of days.
Request: /options/hist/iv-rank?apiKey=test&ticker=msft&tradeDate=2012-09-12
Response: {
"message": "ok",
"data": {
"iv_rank": 15.8734,
"iv_percentile": 16.2055
}
}
GET /options/hist/vol-cone
Params: apiKey, ticker, tradeDate, period (optional = 30)
Returns: A volatility cone showing the distribution of realized volatility over a period of days.
Request: /options/hist/vol-cone?apiKey=test&ticker=msft&tradeDate=2012-09-12
Response: {
"message": "ok",
"data": {
"current_iv": 0.1978,
"stdev": 0.0438,
"mean": 0.2411,
"0%": 0.1565,
"10%": 0.1938,
"20%": 0.2065,
"30%": 0.2162,
"40%": 0.2263,
"50%": 0.2342,
"60%": 0.2444,
"70%": 0.2555,
"80%": 0.2671,
"90%": 0.2906,
"100%": 0.4546
}
}
GET /options/hist/iv-info
Params: apiKey, ticker, tradeDate, expiration (optional = 'all')
Returns: Detailed IV metrics, including skew and term structure slopes, as well as relevant earnings metrics.
Request: /options/hist/iv-info?apiKey=test&ticker=msft&tradeDate=2012-09-12
Response: {
"message": "ok",
"data": {
"expiries": {
"2012-09-14": {
"dte": 2,
"iv0": 0.2735906624904701,
"iv10": 0.2735906624904701,
"iv20": 0.2601562445154988,
"iv30": 0.24663216187260517,
"iv40": 0.23930285770722953,
"iv50": 0.2322725938991993,
"iv60": 0.2252423300911691,
"iv70": 0.2214868427359606,
"iv80": 0.22395749703406273,
"iv90": 0.22642815133216482,
"iv100": 0.2267851608782406,
"0_100_skew": 1.206386967431961,
"25_75_skew": 1.1377143250933481,
"25_50_skew": 1.0909345736416023,
"0_50_skew": 1.1778861117347397,
"50_75_skew": 1.0428804371792821,
"50_100_skew": 1.0241966140981547,
"implied_daily_move": 0.014631798091266184,
"iv_earnings_removed": 0.2322725938991993
},
...
},
"next_earnings_date": "2012-10-18",
"next_earnings_dte": 36,
"next_earnings_implied_move": 0.050390489900586866,
"term_structure_slope": 0.7691073595187886
}
}
GET /options/hist/earnings
Params: apiKey, ticker, tradeDate
Returns: Historical earnings data including implied moves, actual moves, and P&L analysis of ATM straddles.
Request: /hist/earnings?apiKey=test&ticker=msft&tradeDate=2012-09-12
Response: {
"message": "ok",
"data": {
"earnings": [
{
"earnings_date": "2007-01-25",
"earnings_time": "amc",
"realized_jump": 0.02576197387518142,
"realized_move": 0.0047169811320754715,
"abs_implied_move": 0.05558295402704342,
"straddle_return": -0.3612205391783913
},
{
"earnings_date": "2007-04-26",
"earnings_time": "amc",
"realized_jump": 0.03679817905918058,
"realized_move": 0.03566009104704097,
"abs_implied_move": 0.06014685424413794,
"straddle_return": -0.23169696226795422
},
{
"earnings_date": "2007-07-19",
"earnings_time": "amc",
"realized_jump": -0.012216404886561954,
"realized_move": -0.0118673647469459,
"abs_implied_move": 0.03935209602256577,
"straddle_return": -0.5939513115130355
},
...
]
"avg_abs_realized_move": 0.035443822974169585,
"avg_abs_realized_jump": 0.03459666608851649,
"avg_abs_implied_move": 0.0542817023259795,
"avg_straddle_return": -0.06968438576718343,
"cumulative_straddle_return": -1.602740872645219
}
}