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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# ----------------------------------------
|
| 7 |
+
# Backend Variables (Not Exposed to Frontend)
|
| 8 |
+
# ----------------------------------------
|
| 9 |
+
API_KEY = os.getenv("FMP_API_KEY")
|
| 10 |
+
DEFAULT_RSS_PAGE = 0
|
| 11 |
+
DEFAULT_SEARCH_NAME = "NJOY"
|
| 12 |
+
DEFAULT_CIK = "0001547416"
|
| 13 |
+
|
| 14 |
+
# ----------------------------------------
|
| 15 |
+
# Initialize Session State Variables
|
| 16 |
+
# ----------------------------------------
|
| 17 |
+
if "run_rss" not in st.session_state:
|
| 18 |
+
st.session_state.run_rss = False
|
| 19 |
+
if "run_search" not in st.session_state:
|
| 20 |
+
st.session_state.run_search = False
|
| 21 |
+
if "run_cik" not in st.session_state:
|
| 22 |
+
st.session_state.run_cik = False
|
| 23 |
+
|
| 24 |
+
if "rss_page" not in st.session_state:
|
| 25 |
+
st.session_state.rss_page = DEFAULT_RSS_PAGE
|
| 26 |
+
if "search_name" not in st.session_state:
|
| 27 |
+
st.session_state.search_name = DEFAULT_SEARCH_NAME
|
| 28 |
+
if "cik_value" not in st.session_state:
|
| 29 |
+
st.session_state.cik_value = DEFAULT_CIK
|
| 30 |
+
|
| 31 |
+
# ----------------------------------------
|
| 32 |
+
# Cached API Functions
|
| 33 |
+
# ----------------------------------------
|
| 34 |
+
@st.cache_data(show_spinner=False)
|
| 35 |
+
def fetch_equity_rss(rss_page: int) -> pd.DataFrame:
|
| 36 |
+
"""
|
| 37 |
+
Fetch Equity Offering data from the RSS feed endpoint.
|
| 38 |
+
"""
|
| 39 |
+
url = f"https://financialmodelingprep.com/api/v4/fundraising-rss-feed?page={rss_page}&apikey={API_KEY}"
|
| 40 |
+
response = requests.get(url)
|
| 41 |
+
response.raise_for_status()
|
| 42 |
+
data = response.json()
|
| 43 |
+
if not data:
|
| 44 |
+
return pd.DataFrame()
|
| 45 |
+
return pd.DataFrame(data)
|
| 46 |
+
|
| 47 |
+
@st.cache_data(show_spinner=False)
|
| 48 |
+
def fetch_equity_search(name: str) -> pd.DataFrame:
|
| 49 |
+
"""
|
| 50 |
+
Search for equity offerings by company/offering name.
|
| 51 |
+
"""
|
| 52 |
+
url = f"https://financialmodelingprep.com/api/v4/fundraising/search?name={name}&apikey={API_KEY}"
|
| 53 |
+
response = requests.get(url)
|
| 54 |
+
response.raise_for_status()
|
| 55 |
+
data = response.json()
|
| 56 |
+
if not data:
|
| 57 |
+
return pd.DataFrame()
|
| 58 |
+
return pd.DataFrame(data)
|
| 59 |
+
|
| 60 |
+
@st.cache_data(show_spinner=False)
|
| 61 |
+
def fetch_equity_by_cik(cik: str) -> pd.DataFrame:
|
| 62 |
+
"""
|
| 63 |
+
Fetch all equity offerings for a company identified by its CIK.
|
| 64 |
+
"""
|
| 65 |
+
url = f"https://financialmodelingprep.com/api/v4/fundraising?cik={cik}&apikey={API_KEY}"
|
| 66 |
+
response = requests.get(url)
|
| 67 |
+
response.raise_for_status()
|
| 68 |
+
data = response.json()
|
| 69 |
+
if not data:
|
| 70 |
+
return pd.DataFrame()
|
| 71 |
+
return pd.DataFrame(data)
|
| 72 |
+
|
| 73 |
+
# ----------------------------------------
|
| 74 |
+
# MAIN APP
|
| 75 |
+
# ----------------------------------------
|
| 76 |
+
def main():
|
| 77 |
+
st.set_page_config(page_title="Equity Offerings Dashboard", layout="wide")
|
| 78 |
+
st.title("Equity Offerings Dashboard")
|
| 79 |
+
st.write(
|
| 80 |
+
"This dashboard provides access to equity offering announcements. "
|
| 81 |
+
"Use the sidebar below to choose one of the three pages. Each page shows the raw data in a table format with details fetched from Financial Modeling Prep."
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
# Sidebar: Navigation and Options inside an expander
|
| 85 |
+
with st.sidebar.expander("Navigation and Options", expanded=True):
|
| 86 |
+
page = st.radio(
|
| 87 |
+
"Select Page",
|
| 88 |
+
("Equity Offering RSS Feed", "Equity Offering Search", "Equity Offering By CIK"),
|
| 89 |
+
help="Choose a page: the RSS Feed shows the live feed; Search allows searching by name; By CIK shows offerings for a company."
|
| 90 |
+
)
|
| 91 |
+
if page == "Equity Offering RSS Feed":
|
| 92 |
+
rss_page = st.number_input(
|
| 93 |
+
"RSS Feed Page",
|
| 94 |
+
min_value=0,
|
| 95 |
+
value=DEFAULT_RSS_PAGE,
|
| 96 |
+
help="Enter the page number to fetch the RSS feed data."
|
| 97 |
+
)
|
| 98 |
+
st.session_state.rss_page = rss_page
|
| 99 |
+
if st.button("Run Equity Offering RSS Feed"):
|
| 100 |
+
st.session_state.run_rss = True
|
| 101 |
+
elif page == "Equity Offering Search":
|
| 102 |
+
search_name = st.text_input(
|
| 103 |
+
"Search Name",
|
| 104 |
+
value=DEFAULT_SEARCH_NAME,
|
| 105 |
+
help="Enter the name to search for equity offerings (e.g., NJOY)."
|
| 106 |
+
)
|
| 107 |
+
st.session_state.search_name = search_name
|
| 108 |
+
if st.button("Run Equity Offering Search"):
|
| 109 |
+
st.session_state.run_search = True
|
| 110 |
+
else: # Equity Offering By CIK
|
| 111 |
+
cik_value = st.text_input(
|
| 112 |
+
"Company CIK",
|
| 113 |
+
value=DEFAULT_CIK,
|
| 114 |
+
help="Enter the CIK of the company to view its equity offerings."
|
| 115 |
+
)
|
| 116 |
+
st.session_state.cik_value = cik_value
|
| 117 |
+
if st.button("Run Equity Offering By CIK"):
|
| 118 |
+
st.session_state.run_cik = True
|
| 119 |
+
|
| 120 |
+
# ----------------------------------------
|
| 121 |
+
# Page Output
|
| 122 |
+
# ----------------------------------------
|
| 123 |
+
if page == "Equity Offering RSS Feed":
|
| 124 |
+
st.header("Equity Offering RSS Feed")
|
| 125 |
+
st.write(
|
| 126 |
+
"This page displays the live RSS feed of equity offering announcements. "
|
| 127 |
+
"The table below shows details such as company name, form type, offering date, and URL."
|
| 128 |
+
)
|
| 129 |
+
if st.session_state.run_rss:
|
| 130 |
+
df_rss = fetch_equity_rss(st.session_state.rss_page)
|
| 131 |
+
if df_rss.empty:
|
| 132 |
+
st.error("No data returned from the Equity Offering RSS Feed.")
|
| 133 |
+
else:
|
| 134 |
+
st.dataframe(df_rss, use_container_width=True)
|
| 135 |
+
else:
|
| 136 |
+
st.info("Enter a page number in the sidebar and click 'Run Equity Offering RSS Feed'.")
|
| 137 |
+
|
| 138 |
+
elif page == "Equity Offering Search":
|
| 139 |
+
st.header("Equity Offering Search")
|
| 140 |
+
st.write(
|
| 141 |
+
"This page allows you to search for equity offering announcements by company or offering name. "
|
| 142 |
+
"The table below shows the matching offerings along with key details."
|
| 143 |
+
)
|
| 144 |
+
if st.session_state.run_search:
|
| 145 |
+
df_search = fetch_equity_search(st.session_state.search_name)
|
| 146 |
+
if df_search.empty:
|
| 147 |
+
st.error("No equity offerings found for the specified search name.")
|
| 148 |
+
else:
|
| 149 |
+
st.dataframe(df_search, use_container_width=True)
|
| 150 |
+
else:
|
| 151 |
+
st.info("Enter a name in the sidebar and click 'Run Equity Offering Search'.")
|
| 152 |
+
|
| 153 |
+
else: # Equity Offering By CIK
|
| 154 |
+
st.header("Equity Offering By CIK")
|
| 155 |
+
st.write(
|
| 156 |
+
"This page displays all equity offering announcements made by a company, identified by its CIK. "
|
| 157 |
+
"The table below lists detailed information for each offering."
|
| 158 |
+
)
|
| 159 |
+
if st.session_state.run_cik:
|
| 160 |
+
df_cik = fetch_equity_by_cik(st.session_state.cik_value)
|
| 161 |
+
if df_cik.empty:
|
| 162 |
+
st.error("No equity offerings found for the specified CIK.")
|
| 163 |
+
else:
|
| 164 |
+
st.dataframe(df_cik, use_container_width=True)
|
| 165 |
+
else:
|
| 166 |
+
st.info("Enter a CIK in the sidebar and click 'Run Equity Offering By CIK'.")
|
| 167 |
+
|
| 168 |
+
if __name__ == "__main__":
|
| 169 |
+
main()
|
| 170 |
+
|
| 171 |
+
hide_streamlit_style = """
|
| 172 |
+
<style>
|
| 173 |
+
#MainMenu {visibility: hidden;}
|
| 174 |
+
footer {visibility: hidden;}
|
| 175 |
+
</style>
|
| 176 |
+
"""
|
| 177 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|