Files
OpenBB/openbb_sdk
Igor Radovanovic 374dd96aed Feature/fetcher cleanup (#5330)
* Linting

* added extra params and file cleanup in yfinance

* `yfinance` Fetcher refactored

* `cboe` Fetcher refactored, pydocstyle pass and cleanup

* `yfinance` Fetcher cleanup and pydocstyle pass

* `cboe` Fetcher cleanup

* ruff + black

* Linting

* Fetcher cleanup and typing, bug fixes

Co-authored-by: montezdesousa

* Fix CPI

* Fix CBOE typing

* Fix yfinance typing

* MyPy improvements

* remove pass

* property reorder

* update get_data_many to return raw data and refactor treasury rates

* refactor stocksplits

* stockquote

* change data one and stock peers

* stock ownership

* stock news

* stock multiples

* insider trading

* stock eod

* share stats

* sec fillings

* risk premium

* revenue business line

* revenue geographic

* price target

* black

* treasury rates descriptions

* more descriptions

* remove The from descriptions

* remove The from descriptions

* price target consensus

* polygon forex pairs

* fix `Annotated is not defined` in static files

* cboe Fetcher relisted data and pyproject cleanup

* major indices eod

* yfinance relisted data

* major indixes const

* key metrics

* key executive

* institutional ownership

* forgot futures curve

* income statement

* income statement growth

* remove unecessary var

* black

* rename var

* change generic var names

* rename abstract fetcher inner properties

* remove unused provider helpers

* add class description

* import from ParamSpec regardless of version

* specific imports hub service & ruff

* remove useless inspect import

* update comment

* remove mypy comment

* fmp Fetcher refactor, pydocstyle pass and cleanup

* ruff

* query.Dict to query.dict and set dates to 1 year diff

* polygon date interval is 1 year

* typing

* mypy

---------

Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
2023-08-18 10:59:20 +01:00
..
2023-08-18 10:59:20 +01:00
2023-08-18 10:59:20 +01:00
2023-08-18 10:59:20 +01:00
2023-07-24 16:55:53 +02:00
2023-07-24 18:06:37 +01:00
2023-08-11 17:21:19 -04:00

Table of contents

Pre-requisites

To install and use the SDK you need:

  • A fresh virtual environment
  • Python 3.8 or higher
  • API keys for the APIs you want to use

For development you need:

  • Poetry 1.5.1 or higher
  • ruff 0.0.256
  • mypy 1.4.1
  • black

Installation

To install the SDK in a virtual environment from the repo root run:

pip install ./openbb_sdk

This will install the SDK and all its dependencies into the site-packages directory of the virtual environment.

API keys

To use your API keys you need to configure them. Here are the 3 options on how to do it:

  1. From local file
  2. At runtime
  3. From OpenBB Hub

1. From local file

You can specify the keys in the ~/.openbb_sdk/user_settings.json file.

Create this file using the following template and replace the values with your keys:

{
  "credentials": {
    "fmp_api_key": "REPLACE_ME",
    "polygon_api_key": "REPLACE_ME",
    "benzinga_api_key": "REPLACE_ME",
    "fred_api_key": "REPLACE_ME"
  }
}

2. From runtime

You can also specify your keys at runtime:

from openbb import obb
obb.settings.credentials.fmp_api_key = "REPLACE_ME"
obb.settings.credentials.polygon_api_key = "REPLACE_ME"

3. From OpenBB Hub

You can also load your the keys from the OpenBB Hub.

from openbb import obb
openbb.account.login(username="REPLACE_ME", password="REPLACE_ME")

Python Usage

Import and basic usage:

from openbb import obb
aapl = obb.stocks.load("AAPL")
df = aapl.to_dataframe()
df.head()

API Usage

Launch the API with:

uvicorn openbb_core.api.rest_api:app --host 0.0.0.0 --port 8000 --reload

Navigate to http://0.0.0.0:8000/docs to see the swagger API documentation.

Authorize with the developer credentials: openbb/openbb

Docker

You can use the API through Docker.

To build the image, from the repo root run:

docker build -f build/docker/api.dockerfile -t openbb-sdk:latest .

To run this newly-built image:

docker run --rm -p8000:8000 -v ~/.openbb_sdk:/root/.openbb_sdk openbb-sdk:latest

This will mount the local ~/.openbb_sdk directory into the Docker container so you can use the API keys from there and it will expose the API on port 8000.

Development

From the root of the OpenBB Terminal repo, run:

poetry install -C ./openbb_sdk

When developing a specific extension cd into the extension directory and run:

pip install -U -e .

While we're still developing, it is required to create the static python interface:

python -c "import openbb; openbb._rebuild_python_interface()"

Currently you need to do this before the first launch and every time you install or uninstall a new extension.