mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
* This change creates a PR * start moving stuff around * data_models/_category_.json * reference/_category_.json * moving some stuff around * Introduction * Documentation updates * few broken links, clean up sidebar titles for how-to * codespell * quickstart - new provider extension * add a comment * map provider interface * quickstart for new router extension * [Docs] diataxis refactor refactor (#6425) * Start refactor * Edits * [DOCS] Reorganize and edit. Fix sidebar navigation (#6445) * Reorganize and edit. Fix sidebar navigation * Fix broken linkages * Edit --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> * Fix links --------- Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com> * Fix broken links * Reword CLA part in the Licensing FAQ * change titles and order suggestion - cc @IgorWounds @piiq --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com> Co-authored-by: hjoaquim <henriquecjoaquim@gmail.com>
96 lines
3.0 KiB
Plaintext
Vendored
96 lines
3.0 KiB
Plaintext
Vendored
---
|
|
title: REST API Requests
|
|
sidebar_position: 8
|
|
description: How to send requests to the OpenBB Platform REST API.
|
|
keywords:
|
|
- tutorial
|
|
- OpenBB Platform
|
|
- Python client
|
|
- Fast API
|
|
- getting started
|
|
- requests
|
|
- data providers
|
|
---
|
|
|
|
|
|
Most REST API endpoints are for data retrieval and are defined as `GET` requests, but some [toolkit extensions](/platform/user_guides/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.
|
|
|
|
```bash
|
|
uvicorn openbb_core.api.rest_api:app --reload
|
|
```
|
|
|
|
This example will use Python and the `requests` library.
|
|
|
|
#### Fetch Some Data
|
|
|
|
```python
|
|
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]
|
|
```
|
|
|
|
```json
|
|
{'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.
|
|
|
|
```python
|
|
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()
|
|
```
|
|
|
|
| window | realized | min | lower_25% | median | upper_75% | max |
|
|
|---------:|-----------:|-----------:|------------:|---------:|------------:|--------:|
|
|
| 3 | 0.396165 | 0.00701638 | 0.444709 | 0.72414 | 1.11563 | 8.47636 |
|
|
| 10 | 0.623199 | 0.190188 | 0.665584 | 0.852915 | 1.15491 | 4.83264 |
|
|
| 30 | 0.988435 | 0.332913 | 0.750007 | 0.921482 | 1.17072 | 2.98404 |
|
|
| 60 | 0.932594 | 0.47639 | 0.792548 | 0.964617 | 1.20171 | 2.35563 |
|
|
| 90 | 0.915137 | 0.551011 | 0.815229 | 0.965553 | 1.2128 | 2.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.
|
|
|
|
```python
|
|
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()
|
|
```
|