Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to release/4.3.3
  • Loading branch information
deeleeramone committed Oct 8, 2024
2 parents 3b02961 + 45f060b commit f560986
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
64 changes: 28 additions & 36 deletions examples/streamlit/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime, timedelta

from openbb import obb
from openbb_biztoc.utils.helpers import get_all_tags, get_sources
from numpy import nan

import streamlit as st

Expand Down Expand Up @@ -59,21 +59,6 @@

if "news" not in st.session_state:
st.session_state.news = None
if "biztoc_tags" not in st.session_state:
st.session_state.biztoc_tags = []
try:
_all_tags = []
_biztoc_tags = get_all_tags(api_key=obb.user.credentials.biztoc_api_key.get_secret_value()) # type: ignore
for key, value in _biztoc_tags.items():
_all_tags.extend(_biztoc_tags[key])
st.session_state.biztoc_tags = _all_tags
except Exception:
st.session_state.biztoc_tags = []
try:
_sources = get_sources(api_key=obb.user.credentials.biztoc_api_key.get_secret_value()) # type: ignore
st.session_state.biztoc_sources = [d["id"] for d in _sources]
except Exception:
st.session_state.biztoc_sources = []

if "biztoc_sources" not in st.session_state:
st.session_state.biztoc_sources = []
Expand Down Expand Up @@ -145,7 +130,11 @@ def fetch_openbb():
kwargs["filter"] = "tag" if kwargs.get("tag") else None
if kwargs.get("filter") is None:
kwargs["filter"] = "latest"
kwargs["source"] = st.session_state.selected_biztoc_source
kwargs["source"] = (
st.session_state.selected_biztoc_source
if st.session_state.selected_biztoc_source
else None
)
kwargs["filter"] = "source" if kwargs.get("source") else kwargs.get("filter")
if kwargs.get("filter") == "source":
kwargs.pop("tag")
Expand Down Expand Up @@ -202,15 +191,10 @@ def update_data():
st.session_state.selected_tags = st.text_input(
label="Tag", value=st.session_state.selected_tags
)
old_biztoc_tags = st.session_state.biztoc_tags
old_biztoc_source = st.session_state.selected_biztoc_source
if st.session_state.selected_provider == "Biztoc":
st.session_state.selected_tags = st.selectbox(
label="Tag", options=[None] + old_biztoc_tags
)
st.session_state.selected_biztoc_source = st.selectbox(
label="Source", options=[None] + st.session_state.biztoc_sources
)

st.session_state.selected_biztoc_source = st.text_input(label="Source")
old_benzinga_tickers = st.session_state.benzinga_tickers
if st.session_state.selected_provider == "Benzinga":
st.session_state.benzinga_tickers = st.text_input(
Expand Down Expand Up @@ -284,11 +268,10 @@ def update_data():
def main():
with st.session_state.news_container.container():
st.markdown(
" <style> div[class^='block-container'] { padding-top: 1rem; } h1 { margin-bottom: -50px; } </style> "
" <style> div[class^='block-container'] { padding-top: 1rem; } h1 { margin-bottom: -10px; } </style> "
"<h1 style='text-align: center;'>Headlines and Stories</h1> ",
unsafe_allow_html=True,
)
st.divider()
if st.session_state.news is not None:
story = -1
expanded = False
Expand All @@ -303,7 +286,7 @@ def main():
src = st.session_state.news.loc[i].url
date = str(st.session_state.news.loc[i].date)
title = st.session_state.news.loc[i].title
if text != "":
if text and text is not nan and text != "":
with st.expander(label=f"{date} - {title}", expanded=expanded):
st.markdown(
f"""
Expand Down Expand Up @@ -348,7 +331,7 @@ def main():
""",
unsafe_allow_html=True,
)
if _images:
if _images and _images is not nan:
img = _images[0].get("url")
if img is not None:
st.markdown(
Expand All @@ -363,16 +346,19 @@ def main():
st.markdown(
f"##### Tags for this story: \n {_tags} \n"
)
if _stocks:
if _stocks and _stocks is not nan:
st.markdown(f"##### Stocks mentioned:\n {_stocks} \n")
if _channels:
st.markdown(
f"##### Channels for this story: \n {_channels} \n"
)

if st.session_state.selected_provider == "Biztoc":
if st.session_state.news.loc[i].get("images"):
img = st.session_state.news.loc[i].images.get("s")
if st.session_state.news.loc[i].get("images") not in [
None,
nan,
]:
img = st.session_state.news.loc[i].images[0].get("s")
img = (
st.session_state.news.loc[i].images.get("o")
if img is None
Expand Down Expand Up @@ -406,14 +392,19 @@ def main():
st.markdown(text, unsafe_allow_html=True)
if _url:
st.write(_url)
if _stocks:
if _stocks and _stocks is not nan:
st.divider()
st.markdown(f"##### Stocks mentioned:\n {_stocks} \n")

if st.session_state.selected_provider == "FMP":
_url = st.session_state.news.loc[i].get("url")
_images = st.session_state.news.loc[i].get("images")
img = _images[0].get("o") if _images else None
_symbols = st.session_state.news.loc[i].get("symbols")
img = (
_images[0].get("o") or _images[0].get("url")
if _images
else None
)
if img is not None:
st.markdown(
f"""
Expand All @@ -424,9 +415,10 @@ def main():
""",
unsafe_allow_html=True,
)
if text:
st.markdown(text, unsafe_allow_html=True)
if _url:
st.write(_url)
if _url:
st.write(_url)

if st.session_state.selected_provider == "Tiingo":
_url = st.session_state.news.loc[i].get("url")
Expand All @@ -439,7 +431,7 @@ def main():
st.markdown(
f"##### Tags for this story: \n {_tags} \n"
)
if _stocks:
if _stocks and _stocks is not nan:
st.markdown(f"##### Stocks mentioned:\n {_stocks} \n")

st.divider()
Expand Down
2 changes: 1 addition & 1 deletion examples/usdLiquidityIndex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7076,7 +7076,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you just want to visualize the results, this is a fast way of doing it. However, titles are other customizatons clean things up."
"If you just want to visualize the results, this is a fast way of doing it. However, titles and other customizatons clean things up."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion openbb_platform/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ Data(open=1, high=2, low=3, close=4, volume=5, date=2020-01-01)

```

This means that the `Data` class is cleaver enough to understand that you are passing a dictionary and it will try to validate it for you.
This means that the `Data` class is clever enough to understand that you are passing a dictionary and it will try to validate it for you.
In other words, if you're using data that doesn't come from the OpenBBPlatform, you only need to ensure it's parsable by the `Data` class and you'll be able to use the data processing commands.
In other words, imagine you have a dataframe that you want to use with the `ta` menu. You can do the following:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def extract_data(
query.term = query.term.replace(" ", "%20")
url = base_url + f"search?q={query.term}"
response = make_request(url, headers=headers).json()
if query.source is not None:
elif query.source is not None:
sources_response = make_request(
"https://biztoc.p.rapidapi.com/sources",
headers=headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class FMPEtfHoldingsData(EtfHoldingsData):
value: Optional[float] = Field(
description="The value of the holding, in dollars.",
default=None,
json_schema_extra={"x-unit_measurement": "currency"},
)
weight: Optional[float] = Field(
description="The weight of the holding, as a normalized percent.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class IntrinioEtfHoldingsData(EtfHoldingsData):
coupon: Optional[float] = Field(
default=None,
description="The coupon rate of the debt security, if available.",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
balance: Optional[Union[int, float]] = Field(
default=None,
Expand All @@ -107,18 +108,22 @@ class IntrinioEtfHoldingsData(EtfHoldingsData):
face_value: Optional[float] = Field(
default=None,
description="The face value of the debt security, if available.",
json_schema_extra={"x-unit_measurement": "currency"},
)
derivatives_value: Optional[float] = Field(
default=None,
description="The notional value of derivatives contracts held.",
json_schema_extra={"x-unit_measurement": "currency"},
)
value: Optional[float] = Field(
default=None,
description="The market value of the holding, on the 'as_of' date.",
json_schema_extra={"x-unit_measurement": "currency"},
)
weight: Optional[float] = Field(
default=None,
description="The weight of the holding, as a normalized percent.",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
updated: Optional[dateType] = Field(
default=None,
Expand Down Expand Up @@ -202,6 +207,8 @@ def transform_data(
for d in sorted(data, key=lambda x: x["weighting"], reverse=True):
# This field is deprecated and is dupilcated in the response.
_ = d.pop("composite_figi", None)
if d.get("coupon"):
d["coupon"] = d["coupon"] / 100
results.append(IntrinioEtfHoldingsData.model_validate(d))

return results
5 changes: 3 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ exclude = [
]

line-length = 122
target-version = "py38"
target-version = "py39"
fix = true

[lint]
select = [
Expand All @@ -27,7 +28,7 @@ select = [
"T20",
]
# These ignores should be seen as temporary solutions to problems that will NEED fixed
ignore = ["PLR2004", "PLR0913", "PLR0915"]
ignore = ["PLR2004", "PLR0913", "PLR0915", "UP035", "UP006"]

[lint.per-file-ignores]
"**/tests/*" = ["S101"]
Expand Down

0 comments on commit f560986

Please sign in to comment.