File size: 6,554 Bytes
894965e
 
 
 
 
 
d86e19e
894965e
 
f505f56
894965e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d86e19e
894965e
d86e19e
894965e
 
d86e19e
 
 
 
 
 
894965e
 
 
 
 
 
 
d86e19e
894965e
 
d86e19e
 
 
 
 
 
894965e
 
 
 
 
 
 
 
 
 
d86e19e
 
 
 
 
 
894965e
 
 
 
 
 
 
 
d86e19e
 
894965e
d86e19e
 
 
894965e
 
d86e19e
894965e
 
 
d86e19e
 
894965e
d86e19e
f505f56
d86e19e
894965e
 
 
 
f505f56
d86e19e
894965e
 
d86e19e
894965e
 
 
 
f505f56
d86e19e
894965e
 
d86e19e
894965e
 
 
 
 
d86e19e
 
894965e
d86e19e
 
894965e
 
d86e19e
894965e
d86e19e
894965e
 
 
f505f56
894965e
 
 
 
d86e19e
 
894965e
 
 
 
d86e19e
894965e
 
 
d86e19e
894965e
 
 
 
d86e19e
 
894965e
 
 
 
d86e19e
894965e
 
 
d86e19e
894965e
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import streamlit as st
import requests
import pandas as pd
import os

# ----------------------------------------
# Backend Variables
# ----------------------------------------
API_KEY = os.getenv("FMP_API_KEY")
DEFAULT_RSS_PAGE = 5  # Fixed at 5, not exposed to the user
DEFAULT_SEARCH_NAME = "NJOY"
DEFAULT_CIK = "0001547416"

# ----------------------------------------
# Initialize Session State Variables
# ----------------------------------------
if "run_rss" not in st.session_state:
    st.session_state.run_rss = False
if "run_search" not in st.session_state:
    st.session_state.run_search = False
if "run_cik" not in st.session_state:
    st.session_state.run_cik = False

if "rss_page" not in st.session_state:
    st.session_state.rss_page = DEFAULT_RSS_PAGE
if "search_name" not in st.session_state:
    st.session_state.search_name = DEFAULT_SEARCH_NAME
if "cik_value" not in st.session_state:
    st.session_state.cik_value = DEFAULT_CIK

# ----------------------------------------
# Cached API Functions
# ----------------------------------------
@st.cache_data(show_spinner=False)
def fetch_equity_live_feed(rss_page: int) -> pd.DataFrame:
    """
    Fetch equity offering data from the live feed endpoint for the specified page.
    """
    url = f"https://financialmodelingprep.com/api/v4/fundraising-rss-feed?page={rss_page}&apikey={API_KEY}"
    try:
        response = requests.get(url)
        response.raise_for_status()
        data = response.json()
    except:
        return pd.DataFrame()
    if not data:
        return pd.DataFrame()
    return pd.DataFrame(data)

@st.cache_data(show_spinner=False)
def fetch_equity_search(name: str) -> pd.DataFrame:
    """
    Search for equity offerings by company or offering name.
    """
    url = f"https://financialmodelingprep.com/api/v4/fundraising/search?name={name}&apikey={API_KEY}"
    try:
        response = requests.get(url)
        response.raise_for_status()
        data = response.json()
    except:
        return pd.DataFrame()
    if not data:
        return pd.DataFrame()
    return pd.DataFrame(data)

@st.cache_data(show_spinner=False)
def fetch_equity_by_cik(cik: str) -> pd.DataFrame:
    """
    Fetch all equity offerings for a company identified by its CIK.
    """
    url = f"https://financialmodelingprep.com/api/v4/fundraising?cik={cik}&apikey={API_KEY}"
    try:
        response = requests.get(url)
        response.raise_for_status()
        data = response.json()
    except:
        return pd.DataFrame()
    if not data:
        return pd.DataFrame()
    return pd.DataFrame(data)

# ----------------------------------------
# MAIN APP
# ----------------------------------------
def main():
    st.set_page_config(page_title="Equity Offerings", layout="wide")
    st.title("Equity Offerings")
    st.write(
        "Explore recent equity offering announcements. "
        "Use the sidebar to select one of three views. "
        "Each section provides a table with the raw data."
    )
    
    # Sidebar: Navigation and Options
    with st.sidebar.expander("Navigation and Options", expanded=True):
        page = st.radio(
            "Select Page",
            ("Equity Offering Live Feed", "Equity Offering Search", "Equity Offering By CIK"),
            help="Pick a live feed, do a search by name, or view offerings by CIK."
        )
        if page == "Equity Offering Live Feed":
            # Removed the user input for the page; using the fixed default of 5
            if st.button("Run"):
                st.session_state.run_rss = True
        elif page == "Equity Offering Search":
            search_name = st.text_input(
                "Search Name",
                value=st.session_state.search_name,
                help="Enter a name to search for equity offerings."
            )
            st.session_state.search_name = search_name
            if st.button("Run"):
                st.session_state.run_search = True
        else:  # Equity Offering By CIK
            cik_value = st.text_input(
                "Company CIK",
                value=st.session_state.cik_value,
                help="Enter a company's CIK to view its equity offerings."
            )
            st.session_state.cik_value = cik_value
            if st.button("Run"):
                st.session_state.run_cik = True

    # ----------------------------------------
    # Page Output
    # ----------------------------------------
    if page == "Equity Offering Live Feed":
        st.header("Equity Offering Live Feed")
        st.write(
            "Shows the most recent equity offering announcements. "
            "View details such as the company name, form type, date, and reference URL."
        )
        if st.session_state.run_rss:
            df_rss = fetch_equity_live_feed(st.session_state.rss_page)
            if df_rss.empty:
                st.error("No data found for this feed page.")
            else:
                st.dataframe(df_rss, use_container_width=True)
        else:
            st.info("Click 'Run' to fetch the live feed.")
    
    elif page == "Equity Offering Search":
        st.header("Equity Offering Search")
        st.write(
            "Search equity offerings by name. "
            "Matches are shown in the table with relevant offering details."
        )
        if st.session_state.run_search:
            df_search = fetch_equity_search(st.session_state.search_name)
            if df_search.empty:
                st.error("No equity offerings found for that search name.")
            else:
                st.dataframe(df_search, use_container_width=True)
        else:
            st.info("Enter a name in the sidebar and click 'Run'.")
    
    else:  # Equity Offering By CIK
        st.header("Equity Offering By CIK")
        st.write(
            "Displays equity offerings for a specific company, identified by its CIK. "
            "The table includes detailed information for each offering."
        )
        if st.session_state.run_cik:
            df_cik = fetch_equity_by_cik(st.session_state.cik_value)
            if df_cik.empty:
                st.error("No equity offerings found for that CIK.")
            else:
                st.dataframe(df_cik, use_container_width=True)
        else:
            st.info("Enter a CIK in the sidebar and click 'Run'.")

if __name__ == "__main__":
    main()

hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)