mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Economic calendar event impact
This commit is contained in:
@@ -59,3 +59,6 @@ PATH_TO_SELENIUM_DRIVER = None # Replace with "PATH"
|
||||
|
||||
# https://coinmarketcap.com/api/
|
||||
COINMARKETCAP_KEY = os.getenv("GT_CMC_API_KEY") or "REPLACE_ME"
|
||||
|
||||
# https://finnhub.io
|
||||
API_FINNHUB_KEY = os.getenv("GT_API_FINNHUB_KEY") or "REPLACE_ME"
|
||||
@@ -9,6 +9,7 @@ from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.econ import fred_view
|
||||
from gamestonk_terminal.econ import finnhub_view
|
||||
|
||||
|
||||
class EconController:
|
||||
@@ -19,6 +20,7 @@ class EconController:
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
"events",
|
||||
"fred",
|
||||
"vixcls",
|
||||
"gdp",
|
||||
@@ -50,6 +52,7 @@ class EconController:
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print(" ")
|
||||
print(" events economic events [Finnhub]")
|
||||
print(
|
||||
" fred display customized FRED data from https://fred.stlouisfed.org"
|
||||
)
|
||||
@@ -95,6 +98,10 @@ class EconController:
|
||||
"""Process Quit command - quit the program"""
|
||||
return True
|
||||
|
||||
def call_events(self, other_args: List[str]):
|
||||
"""Process events command"""
|
||||
finnhub_view.economy_calendar_events(other_args)
|
||||
|
||||
def call_fred(self, other_args: List[str]):
|
||||
"""Process fred command"""
|
||||
fred_view.display_fred(other_args, "")
|
||||
|
||||
136
gamestonk_terminal/econ/finnhub_view.py
Normal file
136
gamestonk_terminal/econ/finnhub_view.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import argparse
|
||||
from typing import List
|
||||
import math
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import yfinance as yf
|
||||
import mplfinance as mpf
|
||||
import pandas as pd
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
plot_autoscale,
|
||||
check_positive,
|
||||
)
|
||||
|
||||
|
||||
def get_economy_calendar_events() -> pd.DataFrame:
|
||||
"""Get economic calendar events
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Get dataframe with economic calendar events
|
||||
"""
|
||||
response = requests.get(
|
||||
f"https://finnhub.io/api/v1/calendar/economic?token={cfg.API_FINNHUB_KEY}"
|
||||
)
|
||||
if response.status_code == 200:
|
||||
d_data = response.json()
|
||||
if "economicCalendar" in d_data:
|
||||
return pd.DataFrame(d_data["economicCalendar"])
|
||||
|
||||
return pd.DataFrame()
|
||||
|
||||
|
||||
def economy_calendar_events(other_args: List[str]):
|
||||
"""Output economy calendar events
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="events",
|
||||
description="""
|
||||
Output economy calendar events. [Source: https://finnhub.io]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--country",
|
||||
action="store",
|
||||
dest="country",
|
||||
type=str,
|
||||
default="US",
|
||||
choices=["NZ", "AU", "ERL", "CA", "EU", "US", "JP", "CN", "GB", "CH"],
|
||||
help="Country from where to get economic calendar events",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--num",
|
||||
action="store",
|
||||
dest="num",
|
||||
type=check_positive,
|
||||
default=10,
|
||||
help="Number economic calendar events to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--impact",
|
||||
action="store",
|
||||
dest="impact",
|
||||
type=str,
|
||||
default="all",
|
||||
choices=["low", "medium", "high", "all"],
|
||||
help="Country from where to get economic calendar events",
|
||||
)
|
||||
|
||||
try:
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-c")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
df_events = get_economy_calendar_events()
|
||||
|
||||
if df_events.empty:
|
||||
print("No latest economy calendar events found\n")
|
||||
return
|
||||
|
||||
df_econ_calendar = df_events[
|
||||
df_events["country"] == ns_parser.country
|
||||
].sort_values("time", ascending=False)
|
||||
|
||||
if df_econ_calendar.empty:
|
||||
print("No latet economy calendar events found in the specified country\n")
|
||||
return
|
||||
|
||||
if ns_parser.impact != "all":
|
||||
df_econ_calendar = df_econ_calendar[
|
||||
df_econ_calendar["impact"] == ns_parser.impact
|
||||
]
|
||||
|
||||
if df_econ_calendar.empty:
|
||||
print(
|
||||
"No latet economy calendar events found in the specified country with this impact\n"
|
||||
)
|
||||
return
|
||||
|
||||
df_econ_calendar = df_econ_calendar.fillna("---").head(n=ns_parser.num)
|
||||
|
||||
d_econ_calendar_map = {
|
||||
"actual": "Actual release",
|
||||
"prev": "Previous release",
|
||||
"country": "Country",
|
||||
"unit": "Unit",
|
||||
"estimate": "Estimate",
|
||||
"event": "Event",
|
||||
"impact": "Impact Level",
|
||||
"time": "Release time",
|
||||
}
|
||||
|
||||
df_econ_calendar = df_econ_calendar[
|
||||
["time", "event", "impact", "prev", "estimate", "actual", "unit"]
|
||||
].rename(columns=d_econ_calendar_map)
|
||||
|
||||
print(df_econ_calendar.to_string(index=False))
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
@@ -55,7 +55,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
" > scr screener stocks, \t\t e.g. overview/performance, using preset filters"
|
||||
)
|
||||
print(" > mill papermill menu, \t\t menu to generate notebook reports")
|
||||
print(" > econ economic data, \t\t from: FRED, VIX")
|
||||
print(" > econ economic data, \t\t e.g.: FRED, events")
|
||||
print(
|
||||
" > pa portfolio analysis, \t\t supports: robinhood, alpaca, ally "
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user