add readme + linting

This commit is contained in:
Jamie
2021-03-18 15:29:48 -04:00
parent 3f33a557b3
commit 8650ba4e5f
3 changed files with 59 additions and 17 deletions

View 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:
![hold](https://user-images.githubusercontent.com/18151143/111685384-3c6ab080-87fe-11eb-80ce-9b256c396bf2.png)
## 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:
![hist](https://user-images.githubusercontent.com/18151143/111685390-3d9bdd80-87fe-11eb-90f9-7ca8b0c1e7f8.png)

View File

@@ -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

View File

@@ -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(