mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
add readme + linting
This commit is contained in:
40
gamestonk_terminal/portfolio/README.md
Normal file
40
gamestonk_terminal/portfolio/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
#PORTFOLIO
|
||||
|
||||
This was developed to interface with Robinhood.
|
||||
|
||||
Once this screen is accessed, the first command to be run is
|
||||
````
|
||||
login
|
||||
````
|
||||
Which will use your robinhood login infomation, which should be stored as environment variables or in the config_terminal.py
|
||||
|
||||
Currently there are 2 options:
|
||||
* [hold](#hold)
|
||||
* Look at current (stock only) holdings
|
||||
* [hist](#hist)
|
||||
* Get and plot historical portfolio
|
||||
|
||||
## hold <a name="hold"></a>
|
||||
|
||||
Displays current holdings to the console:
|
||||
|
||||
````
|
||||
usage: hold
|
||||
````
|
||||
There are no additional flags. This just prints all current stonks, their last price, previous close, your equity and
|
||||
the % change from previous close.
|
||||
|
||||
Example:
|
||||

|
||||
## hist <a name="hist"></a>
|
||||
Display your RH portfolio based on provided interval and span. Based on the API data availablility, plotted as a candlestick chart.
|
||||
````
|
||||
usage: hist [-s --span] [-i --interval]
|
||||
````
|
||||
* -s/--span : How long to look back. Defaults to the day. Options:
|
||||
* [day, week, month, 3month, year, 5year, all]
|
||||
* -i/--interval: Data resolution. Defaults to 10minute intervals. Options:
|
||||
* [5minute, 10minute, hour, day, week]
|
||||
|
||||
Example Default Output:
|
||||

|
||||
@@ -7,8 +7,6 @@ from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.portfolio import rh_api
|
||||
|
||||
|
||||
|
||||
|
||||
def print_port(show_login):
|
||||
|
||||
""" Print help """
|
||||
@@ -18,16 +16,16 @@ def print_port(show_login):
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print(" ")
|
||||
print("Robinhood:")
|
||||
print("")
|
||||
if show_login:
|
||||
print(" login login")
|
||||
print(" ")
|
||||
print(" hold look at current holdings")
|
||||
print(" hist look at historical portfolio")
|
||||
print(" ")
|
||||
|
||||
|
||||
|
||||
def rh_port_menu():
|
||||
def port_menu():
|
||||
plt.close("all")
|
||||
port_parser = argparse.ArgumentParser(prog="port", add_help=False)
|
||||
choices = ["help", "q", "quit", "hold", "hist", "login", "logoff"]
|
||||
@@ -60,11 +58,19 @@ def rh_port_menu():
|
||||
|
||||
elif ns_known_args.cmd == "q":
|
||||
# Leave the port menu + logout of robinhood
|
||||
rh_api.logoff()
|
||||
# logoff raises error if not logged in
|
||||
try:
|
||||
rh_api.logoff()
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
elif ns_known_args.cmd == "quit":
|
||||
rh_api.logoff()
|
||||
# Will raise exception if not logged in
|
||||
try:
|
||||
rh_api.logoff()
|
||||
except Exception:
|
||||
pass
|
||||
# Abandon the program
|
||||
return True
|
||||
|
||||
|
||||
@@ -43,21 +43,17 @@ def logoff():
|
||||
|
||||
def show_holdings():
|
||||
|
||||
r.login(user, pw)
|
||||
|
||||
holds = r.account.build_holdings()
|
||||
stocks = []
|
||||
quant = []
|
||||
equity = []
|
||||
for stock, data in holds.items():
|
||||
stocks.append(stock)
|
||||
quant.append(float(data["quantity"]))
|
||||
equity.append(round(float(data["equity"]), 2))
|
||||
|
||||
print("")
|
||||
print("Stonk\t last price \t prev close \t equity \t % Change")
|
||||
print("")
|
||||
for stonk, n, eq in zip(stocks, quant, equity):
|
||||
for stonk, eq in zip(stocks, equity):
|
||||
stonk_data = r.stocks.get_quotes(stonk)[0]
|
||||
prev_close = round(float(stonk_data["adjusted_previous_close"]), 2)
|
||||
last_price = round(float(stonk_data["last_trade_price"]), 2)
|
||||
@@ -105,13 +101,13 @@ def plot_historical(l_args):
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
if ns_parser.span not in valid_span:
|
||||
raise ValueError(
|
||||
"Invalid Span: Must be one of: '5minute','10minute','hour','day',or 'week'"
|
||||
)
|
||||
if ns_parser.interval not in valid_interval:
|
||||
raise ValueError(
|
||||
"Invalid Interval: Must be one of : 'day','week','month','3month','year', '5year' or 'all'"
|
||||
"Invalid Interval: Must be one of: 5minute, 10minute, hour, day, week"
|
||||
)
|
||||
if ns_parser.span not in valid_span:
|
||||
raise ValueError(
|
||||
"Invalid Span: Must be one of : day, week, month, 3month, year, 5year, all"
|
||||
)
|
||||
|
||||
hist = r.account.get_historical_portfolio(
|
||||
|
||||
Reference in New Issue
Block a user