Files
OpenBB/website/content/api/_index.md
jmaslek b71abcfbf4 Updating some names (#1575)
* quick econ fix

* black

* keys and feature flags

* terminal name 👀

* some more replacements

* some more replacements

* edit pyproject

* gst -> openbb

* add example portfolios back to git

* Update api from gst

* sorry.  skipping some tests

* another round of names

* another round of test edits

* Missed some .gst refs and update timezone

* water mark stuff

* Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS

* fix more GST to OpenBB Terminal

* Logging : merge conflicts with main

* Revert wrong files

Co-authored-by: Andrew <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2022-03-29 09:46:26 -04:00

3.6 KiB
Vendored

geekdocCollapseSection
geekdocCollapseSection
true

{{< toc-tree >}}

image

GST python API

The GST python API was created to enable usage of the terminal functionality in python scripts and IPython Notebooks (Jupyter). The API wraps the functionality of the terminal in a way that the python commands follow the same convention as the terminal.

For example stocks/load aapl becomes openbb.stocks.load("aapl").


Python environment setup

Import the GST API into your python script or notebook with

from openbb_terminal import api as openbb

Understanding the API functions

To understand the parameters of an API function the simplest way is to refer to the docstring. Docstrings can be viewed using the code introspection tools of your text/notebook editor or the built-in python help command. Docstrings contain both the description of the functionality and the overview of the parameters.

As an example this is the docstring of openbb.economy.bigmac:

Display Big Mac Index for given countries

Parameters
----------
country_codes : List[str]
    List of country codes to get for
raw : bool, optional
    Flag to display raw data, by default False
export : str, optional
    Format data, by default ""
external_axes : Optional[List[plt.Axes]], optional
    External axes (3 axes are expected in the list), by default None

Usage examples

Load stock data into a dataframe:

aapl_data = openbb.stocks.load(
    ticker="aapl",
    start="2021-06-10",
)
aapl_data = openbb.stocks.process_candle(aapl_data)

Plot candle chart

openbb.stocks.candle("AAPL", aapl_data, True)

Call the "What if" command of the backtesting menu

openbb.stocks.bt.whatif("aapl", 10, datetime.strptime("2012-03-03", "%Y-%m-%d"))

Get sentiment for a list of tickers

openbb.stocks.ca.models.finbrain.get_sentiments(tickers=["aapl"])

Print key fundamental metrics for past 2 years

openbb.stocks.fa.fmp.metrics(ticker="AAPL", number=2)

Get fundamental metrics for past 3 years as a pandas dataframe

openbb.stocks.fa.fmp.models.fmp.get_key_metrics(ticker="AAPL", number=3)

Perform an OLS regression on multiple custom datasets

openbb.econometrics.ols(
    regression_variables=[
    'close-tsla', 'volume-aapl'
    ],
    data={"aapl":aapl_data,"tsla":tsla_data},
    datasets={
        "close-tsla":{"Close": None, "tsla": None},
        "volume-aapl":{"Volume": None, "aapl": None}
    }
)

External matplotlib axes support

Most of the functions of the terminal that generate matplotlib charts support passing external axes into them. This is very handy when you want a chart that is generated by GST to appear in another chart that you are creating in a notebook.

Example:

# Load stock data
ticker = "AAPL"
stock_data = openbb.stocks.load(ticker="aapl")

# Create a matplotlib figure
fig, axes = plt.subplots(3, 1, figsize=(10, 7))

# Use GST to add charts to the axes of the created figure
openbb.stocks.ta.macd(s_ticker=ticker, series=aapl["Close"], external_axes=axes[0:2])
openbb.stocks.options.voi_yf(
    ticker=ticker,
    expiry="2022-03-11",
    min_sp=110,
    max_sp=210,
    min_vol=0.3,
    external_axes=[axes[2]],
)

# Show the figure with charts
fig.show()