Skip to main content

REST API Requests

Most REST API endpoints are for data retrieval and are defined as GET requests, but some toolkit extensions require data to pass through the function. In these instances, it must be a POST request.

Example

This example will use a GET request to fetch daily VIX data from the Cboe data extension, and then make a POST request which passes through the data to a technical analysis function.

First, start a development server.

uvicorn openbb_core.api.rest_api:app --reload

This example will use Python and the requests library.

Fetch Some Data

import requests

get_url = "http://127.0.0.1:8000/api/v1/index/price/historical?provider=cboe&symbol=vix&interval=1d"
get_response = requests.get(get_url)
data_results = get_response.json()["results"]

data_results[-1]
{'date': '2023-11-17T00:00:00',
'open': 14.18,
'high': 14.19,
'low': 13.67,
'close': 13.79,
'volume': 0,
'calls_volume': None,
'puts_volume': None,
'total_options_volume': None}

Send a POST Request

Next, pass the data_results to a function, using the json field in the POST headers.

For this example, realized volatility cones, the default parameters assume the time series data is daily and that volatility should be annualized over 252 trading days.

import pandas as pd

post_url = "http://localhost:8000/api/v1/technical/cones"
post_response = requests.post(post_url, json=data_results)
ta_results = post_response.json()["results"]

pd.DataFrame.from_records(ta_results).head()
windowrealizedminlower_25%medianupper_75%max
30.3961650.007016380.4447090.724141.115638.47636
100.6231990.1901880.6655840.8529151.154914.83264
300.9884350.3329130.7500070.9214821.170722.98404
600.9325940.476390.7925480.9646171.201712.35563
900.9151370.5510110.8152290.9655531.21282.04104

The output from the Fast API is a serialized version of this object, and these methods are lost on conversion. OBBject can be reconstructed to recover the helpers by importing the model and validating the data.

import requests
from openbb_core.app.model.obbject import OBBject

data = []
symbol="SPY"
url = f"http://127.0.0.1:8000/api/v1/equity/price/historical?provider=polygon&symbol={symbol}"
headers = {"accept": "application/json"}

response = requests.get(url, headers=headers, timeout=3)

if response.status_code == 200:
data = OBBject.model_validate(response.json())

data.to_df()

On this page