mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 23:12:21 +00:00
Merge pull request #432 from DidierRLopes/ipo
Add IPOs calendar to discovery menu
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
* [x] Add latest and trending news commands (@hinxx) - [PR #347](https://github.com/DidierRLopes/GamestonkTerminal/pull/347)
|
||||
* [x] Add top ratings updates (@hinxx) - [PR #357](https://github.com/DidierRLopes/GamestonkTerminal/pull/357)
|
||||
* [x] Add dark pool (ATS) data of tickers with growing trades activity (@didier) - [PR #372](https://github.com/DidierRLopes/GamestonkTerminal/pull/372)
|
||||
* [x] Past and future IPOs calendar (@didier) - [PR #432](https://github.com/DidierRLopes/GamestonkTerminal/pull/432)
|
||||
|
||||
|
||||
**NEXT**
|
||||
|
||||
@@ -68,6 +68,7 @@ export -f GNUS_data -F csv
|
||||
## Discover Stocks [»](discovery/README.md)
|
||||
Command|Description|Source
|
||||
---|---|---
|
||||
`ipo` |past and future IPOs |[Finnhub](https://finnhub.io)
|
||||
`map` |S&P500 index stocks map |[Finviz](https://finviz.com)
|
||||
`rtp_sectors` |real-time performance sectors |[Alpha Vantage](www.alphavantage.co)
|
||||
`gainers` |show latest top gainers |[Yahoo Finance](https://finance.yahoo.com/)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
This menu aims to discover new stocks, and the usage of the following commands along with an example will be exploited below.
|
||||
|
||||
* [ipo](#ipo)
|
||||
* past and future IPOs [Finnhub]
|
||||
* [map](#map)
|
||||
* S&P500 index stocks map [Finviz]
|
||||
* [rtp_sectors](#rtp_sectors)
|
||||
@@ -42,6 +44,20 @@ This menu aims to discover new stocks, and the usage of the following commands a
|
||||
* dark pool tickers with growing activity [FINRA]
|
||||
|
||||
|
||||
## ipo <a name="ipo"></a>
|
||||
|
||||
```shell
|
||||
usage: ipo [-p PAST_DAYS] [-f FUTURE_DAYS]
|
||||
```
|
||||
|
||||
Past and future IPOs. [Source: https://finnhub.io]
|
||||
|
||||
* -p : Number of past days to look for IPOs. Default 0.
|
||||
* -f : Number of future days to look for IPOs. Default 10.
|
||||
|
||||
<img width="1005" alt="Captura de ecrã 2021-05-03, às 12 54 44" src="https://user-images.githubusercontent.com/25267873/116873168-1e6ed900-ac0f-11eb-9d80-dddc8a754885.png">
|
||||
|
||||
|
||||
## map <a name="map"></a>
|
||||
|
||||
```shell
|
||||
|
||||
@@ -22,6 +22,7 @@ from gamestonk_terminal.discovery import (
|
||||
yahoo_finance_view,
|
||||
marketbeat_view,
|
||||
finra_ats_view,
|
||||
finnhub_view,
|
||||
)
|
||||
|
||||
|
||||
@@ -33,6 +34,7 @@ class DiscoveryController:
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
"ipo",
|
||||
"map",
|
||||
"rtp_sectors",
|
||||
"gainers",
|
||||
@@ -72,6 +74,7 @@ class DiscoveryController:
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print("")
|
||||
print(" ipo past and future IPOs [Finnhub]")
|
||||
print(" map S&P500 index stocks map [Finviz]")
|
||||
print(" rtp_sectors real-time performance sectors [Alpha Vantage]")
|
||||
print(" gainers show latest top gainers [Yahoo Finance]")
|
||||
@@ -135,6 +138,10 @@ class DiscoveryController:
|
||||
"""Process Quit command - quit the program"""
|
||||
return True
|
||||
|
||||
def call_ipo(self, other_args: List[str]):
|
||||
"""Process ipo command"""
|
||||
finnhub_view.ipo_calendar(other_args)
|
||||
|
||||
def call_map(self, other_args: List[str]):
|
||||
"""Process map command"""
|
||||
finviz_view.map_sp500_view(other_args)
|
||||
|
||||
122
gamestonk_terminal/discovery/finnhub_view.py
Normal file
122
gamestonk_terminal/discovery/finnhub_view.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import argparse
|
||||
from typing import List
|
||||
from datetime import datetime, timedelta
|
||||
import requests
|
||||
import pandas as pd
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
check_non_negative,
|
||||
)
|
||||
|
||||
|
||||
def get_ipo_calendar(from_date: str, to_date: str) -> pd.DataFrame:
|
||||
"""Get IPO calendar
|
||||
|
||||
Parameters
|
||||
----------
|
||||
from_date : str
|
||||
from date (%Y-%m-%d) to get IPO calendar
|
||||
to_date : str
|
||||
to date (%Y-%m-%d) to get IPO calendar
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Get dataframe with economic calendar events
|
||||
"""
|
||||
response = requests.get(
|
||||
f"https://finnhub.io/api/v1/calendar/ipo?from={from_date}&to={to_date}&token={cfg.API_FINNHUB_KEY}"
|
||||
)
|
||||
if response.status_code == 200:
|
||||
d_data = response.json()
|
||||
if "ipoCalendar" in d_data:
|
||||
d_refactor_columns = {
|
||||
"numberOfShares": "Number of Shares",
|
||||
"totalSharesValue": "Total Shares Value",
|
||||
"date": "Date",
|
||||
"exchange": "Exchange",
|
||||
"name": "Name",
|
||||
"price": "Price",
|
||||
"status": "Status",
|
||||
}
|
||||
return pd.DataFrame(d_data["ipoCalendar"]).rename(
|
||||
columns=d_refactor_columns
|
||||
)
|
||||
|
||||
return pd.DataFrame()
|
||||
|
||||
|
||||
def ipo_calendar(other_args: List[str]):
|
||||
"""Past and future IPOs calendar [Finnhub]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="ipo",
|
||||
description="""
|
||||
Past and future IPOs. [Source: https://finnhub.io]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--past",
|
||||
action="store",
|
||||
dest="past_days",
|
||||
type=check_non_negative,
|
||||
default=0,
|
||||
help="Number of past days to look for IPOs.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
"--future",
|
||||
action="store",
|
||||
dest="future_days",
|
||||
type=check_non_negative,
|
||||
default=10,
|
||||
help="Number of future days to look for IPOs.",
|
||||
)
|
||||
|
||||
try:
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-f")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
today = datetime.now()
|
||||
|
||||
if ns_parser.future_days > 0:
|
||||
future_date = today + timedelta(days=ns_parser.future_days)
|
||||
|
||||
df_future_ipo = get_ipo_calendar(
|
||||
today.strftime("%Y-%m-%d"), future_date.strftime("%Y-%m-%d")
|
||||
).rename(columns={"Date": "Future"})
|
||||
|
||||
if df_future_ipo.empty:
|
||||
print(f"No IPOs found for the next {ns_parser.future_days} days")
|
||||
else:
|
||||
print(df_future_ipo.to_string(index=False))
|
||||
print("")
|
||||
|
||||
if ns_parser.past_days > 0:
|
||||
past_date = today - timedelta(days=ns_parser.past_days)
|
||||
|
||||
df_past_ipo = get_ipo_calendar(
|
||||
past_date.strftime("%Y-%m-%d"), today.strftime("%Y-%m-%d")
|
||||
).rename(columns={"Date": "Past"})
|
||||
|
||||
if df_past_ipo.empty:
|
||||
print(f"No IPOs found since the last {ns_parser.past_days} days")
|
||||
else:
|
||||
print(df_past_ipo.to_string(index=False))
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
Reference in New Issue
Block a user