mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
* update Terminal about URLs and some other broken links
* ruff
* intro
* changing the heading levels
* dependency management sections
* structure
* developer guides
* structure
* contributor guides
* keywords and descriptions
* broken urls
* cool cards
* Cool cards (#5727)
* tidy up terminal/content
* some more tidy up
* fix styling for platform that was missing
* more tidy up
* improve color for dark and light mode
* create new reference card for more basic cards
* rename back to menus
* implement all index.md for terminal, except reference
* improve bot title
* more refactoring
* fix remaining index
* header styling
* more styling
* heheheheheheeh
* Revert "heheheheheheeh"
This reverts commit 7d095fcfd2.
* Ccards (#5733)
* links
* more links
* improved styling and chevron aligned to title
* fix index.mdx urls for Terminal
* update package.json
* update index.mdx
* fix generation
* spelling
* toolkit_extensions
* update data extensions
* couple of links
* add tiingo to data extensions list
---------
Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
210 lines
7.8 KiB
Markdown
Vendored
210 lines
7.8 KiB
Markdown
Vendored
---
|
|
title: Basic Syntax
|
|
sidebar_position: 2
|
|
description: This page provides comprehensive information about standardized command
|
|
syntax for an open-source platform. Topics discussed include the structure of command
|
|
syntax, use of standardized parameters, usage of provider and symbol parameters,
|
|
handling of date and limit parameters, and more. Also explored, are the methods
|
|
for selecting data sources, handling different list and ticker symbol formats, and
|
|
dealing with command responses and warnings.
|
|
keywords:
|
|
- command syntax
|
|
- standardized parameters
|
|
- date format
|
|
- provider parameter
|
|
- data source selection
|
|
- symbol parameter
|
|
- list formats
|
|
- ticker symbols
|
|
- date parameter
|
|
- time series
|
|
- limit parameter
|
|
- keyword arguments
|
|
- endpoint parameters
|
|
- command response
|
|
- data models
|
|
---
|
|
|
|
import HeadTitle from '@site/src/components/General/HeadTitle.tsx';
|
|
|
|
<HeadTitle title="Basic Syntax - Usage | OpenBB Platform Docs" />
|
|
|
|
The structure of command syntax is standardized across common fields. This ensures that a `date` is always a `date` and the format remains consistent throughout. Standardized parameters include, but are not limited to:
|
|
|
|
- [provider](#provider)
|
|
- [symbol](#symbol)
|
|
- [start_date](#dates)
|
|
- [end_date](#dates)
|
|
- [date](#dates)
|
|
- [limit](#limit)
|
|
|
|
When looking at a function's docstring, the standard parameters (shared across multiple providers) are positioned first. Provider-specific parameters positionally follow the `provider` argument. The example below is from, `obb.equity.price.quote`:
|
|
|
|
```console
|
|
Parameters
|
|
----------
|
|
symbol : str
|
|
Symbol to get data for. In this case, the comma separated list of symbols.
|
|
provider : Optional[Literal['fmp', 'intrinio']]
|
|
The provider to use for the query, by default None.
|
|
If None, the provider specified in defaults is selected or 'fmp' if there is
|
|
no default.
|
|
source : Literal['iex', 'bats', 'bats_delayed', 'utp_delayed', 'cta_a_delayed', 'cta_b_delayed', 'intrinio_mx', 'intrinio_mx_plus', 'delayed_sip']
|
|
Source of the data. (provider: intrinio)
|
|
```
|
|
|
|
:::note
|
|
Examples below assume that the Python interface has been imported in the current session, and/or the Fast API has been started.
|
|
|
|
```python
|
|
from openbb import obb
|
|
```
|
|
|
|
```python
|
|
uvicorn openbb_core.api.rest_api:app
|
|
```
|
|
|
|
:::
|
|
|
|
## Provider
|
|
|
|
The `provider` parameter is the way to select the specific source of the data from the endpoint. If a [preference for the default provider](/platform/usage#user-settings) has not been defined, the default will be the first, alphabetically, installed provider. Provider values are entered in lower-case, with an underscore for multiple words - for example:
|
|
|
|
```python
|
|
historical_prices = obb.equity.price.historical("aapl", provider="alpha_vantage")
|
|
```
|
|
|
|
Provider coverage can be ascertained with the command below:
|
|
|
|
```python
|
|
obb.coverage.providers
|
|
```
|
|
|
|
Refer to, [Data Providers](/platform/extensions/data_extensions), for instructions on installing data provider extensions.
|
|
|
|
## Symbol
|
|
|
|
Symbols are not case-sensitive, and where the function allows, can be entered as a `string`, `List[str]`, or a comma-separated `string`. The exact format of the symbol may vary between providers - for example, share classes, exchange suffixes, and global composities. An example of this difference is shown below:
|
|
|
|
```python
|
|
obb.equity.price.historical("brk.b", provider="polygon")
|
|
```
|
|
|
|
```python
|
|
obb.equity.price.historical("brk-b", provider="fmp")
|
|
```
|
|
|
|
While some providers handle the different formats on their end, others do not. This is something to consider when no results are returned from one source.
|
|
|
|
With providers supporting market data from multiple jurisdictions, the most common method for requesting data outside of US-listings is to append a suffix to the ticker symbol (e.g., `RELIANCE.NS`). Formats may be unique to a provider, so it is best to review the source's documentation for an overview of their specific conventions. [This page](https://help.yahoo.com/kb/SLN2310.html) on Yahoo describes how they format symbols, which many others follow to some degree.
|
|
|
|
### One Symbol
|
|
|
|
```python
|
|
quote = obb.equity.price.quote(symbol="td", provider="fmp")
|
|
```
|
|
|
|
### Multiple Symbols
|
|
|
|
The OpenBB Provider module enforces REST-compliant lists that can be entered in either format through the Python interface.
|
|
|
|
#### Comma-Separated String
|
|
|
|
This is the format required by the Fast API, when creating new data endpoints, it is important that the Python interface is able to accept both formats.
|
|
|
|
```python
|
|
quotes = obb.equity.price.quote("td,schw,jpm,ms", provider="fmp")
|
|
```
|
|
|
|
```python
|
|
import requests
|
|
r = requests.get("http://127.0.0.1:8000/api/v1/equity/price/quote?provider=fmp&symbol=td,schw,ms,jpm")
|
|
r.json()
|
|
```
|
|
|
|
#### Python List
|
|
|
|
Entering a list will provide the same outcome as above.
|
|
|
|
```python
|
|
quotes = obb.equity.price.quote(["td","schw","jpm","ms"], provider="fmp")
|
|
```
|
|
|
|
Lists of symbols can be generated from the results of other functions, and then passed to the input.
|
|
|
|
```python
|
|
symbol="spgi"
|
|
symbols = obb.equity.compare.peers(symbol).results.peers_list+[symbol]
|
|
quotes = obb.equity.price.quote(symbols)
|
|
```
|
|
|
|
:::note
|
|
To accomplish this same task through the Fast API, convert the list to a comma-separated string.
|
|
:::
|
|
|
|
```python
|
|
import requests
|
|
symbol="spgi"
|
|
r = requests.get(f"http://127.0.0.1:8000/api/v1/equity/compare/peers?provider=fmp&symbol={symbol}")
|
|
symbols_list = r.json()["results"]["peers_list"]+[symbol]
|
|
symbols = ",".join(symbols_list)
|
|
response = requests.get(f"http://127.0.0.1:8000/api/v1/equity/price/quote?provider=fmp&symbol={symbols}")
|
|
response.json()
|
|
```
|
|
|
|
## Dates
|
|
|
|
Dates are entered everywhere as a string, formatted as, "YYYY-MM-DD". If the function has only the `date` parameter, the data will be a snapshot instead of a time series.
|
|
|
|
```python
|
|
historical_prices = obb.equity.price.historical(symbol="qqq", start_date="2023-01-10", end_date="2023-01-31", provider="fmp")
|
|
```
|
|
|
|
For flexibility and programmatic purposes, a `datetime` object is also accepted.
|
|
|
|
```python
|
|
from datetime import datetime
|
|
symbol="qqq"
|
|
start = datetime.strptime("100123", "%d%m%y")
|
|
end = datetime.strptime("2023-01-31","%Y-%m-%d")
|
|
historical_prices = obb.equity.price.historical(symbol, start_date=start, end_date=end, provider="fmp")
|
|
```
|
|
|
|
```python
|
|
import requests
|
|
response = requests.get(f"http://127.0.0.1:8000/api/v1/equity/price/historical?provider=fmp&symbol={symbol}&start_date={start}&end_date={end}")
|
|
response.json()
|
|
```
|
|
|
|
## Limit
|
|
|
|
Where, optional, `limit` parameters are supplied, they are likely to have sensible default states that return N results starting from the most recent entry or the `start_date`. Enter these values as an integer.
|
|
|
|
```python
|
|
income = obb.equity.fa.income("AAPL", period="quarter", provider="fmp", limit=4)
|
|
```
|
|
|
|
## **kwargs
|
|
|
|
All endpoints accept additional keyword arguments, but non-existent parameters will be ignored. Invalid parameters are communicated via the `warnings` field in the command response. Parameters can be stored as a dictionary and fed to the command as `**kwargs`. If a provider, or function, has an undocumented parameter it can still be accessed by supplying the additional kwargs.
|
|
|
|
```python
|
|
kwargs = {"symbol":"msft","start_date":"2023-01-01","provider":"polygon"}
|
|
historical_prices = obb.equity.price.historical(**kwargs)
|
|
```
|
|
|
|
```python
|
|
data = obb.equity.price.quote("brk-b", provider="fmp", source="bats")
|
|
data.warnings
|
|
```
|
|
|
|
```console
|
|
[Warning_(category='OpenBBWarning', message="Parameter 'source' is not supported by fmp. Available for: intrinio.")]
|
|
```
|
|
|
|
## References
|
|
|
|
All functions, parameters, and responses are detailed under the [Reference pages](/platform/reference/fixedincome/ycrv). The data models for each provider source are described within the [Data Models](/platform/data_models/StockHistorical) pages.
|
|
|
|
These pages are a quick way to cross-reference differences between providers. The same information is provided in a function's signature and docstring.
|