mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
added basic func for degiro broker
This commit is contained in:
@@ -36,5 +36,8 @@ API_NEWS_TOKEN = os.getenv("GT_API_NEWS_TOKEN") or "REPLACE_ME"
|
||||
RH_USERNAME = os.getenv("GT_RH_USERNAME") or "REPLACE_ME"
|
||||
RH_PASSWORD = os.getenv("GT_RH_PASSWORD") or "REPLACE_ME"
|
||||
|
||||
# Degiro
|
||||
DG_USERNAME = os.getenv("GT_DG_USERNAME") or "REPLACE_ME"
|
||||
DG_PASSWORD = os.getenv("GT_DG_PASSWORD") or "REPLACE_ME"
|
||||
# https://tradier.com/products/market-data-api
|
||||
TRADIER_TOKEN = os.getenv("GT_TRADIER_TOKEN") or "REPLACE_ME"
|
||||
|
||||
56
gamestonk_terminal/portfolio/dg_api.py
Normal file
56
gamestonk_terminal/portfolio/dg_api.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import degiroapi
|
||||
from termcolor import colored
|
||||
from gamestonk_terminal.config_terminal import DG_USERNAME as user, DG_PASSWORD as pw
|
||||
|
||||
degiro = degiroapi.DeGiro()
|
||||
|
||||
|
||||
def login():
|
||||
while True:
|
||||
login_prefr = input("Do you have 2FA activated? - y/n> ")
|
||||
if login_prefr == "q":
|
||||
break
|
||||
elif login_prefr == "y":
|
||||
topt = input("Enter TOPT> ")
|
||||
degiro.login(user, pw, topt)
|
||||
break
|
||||
elif login_prefr == "n":
|
||||
degiro.login(user, pw)
|
||||
break
|
||||
else:
|
||||
print("Invalid input. Try again.")
|
||||
input("Press enter to continue...")
|
||||
|
||||
|
||||
def logout():
|
||||
degiro.logout()
|
||||
|
||||
|
||||
def show_holdings():
|
||||
# Fetch current portfolio
|
||||
portfolio = degiro.getdata(degiroapi.Data.Type.PORTFOLIO, True)
|
||||
|
||||
stock_info = []
|
||||
# Loop to get stock info based on id provided in portfolio
|
||||
for stock in portfolio:
|
||||
if stock["positionType"] == "PRODUCT":
|
||||
stock_info.append(
|
||||
degiro.real_time_price(stock["id"], degiroapi.Interval.Type.One_Day)
|
||||
)
|
||||
|
||||
# showcase portfolio
|
||||
print("")
|
||||
print("Stonk\t last price \t prev close \t equity \t % Change")
|
||||
print("")
|
||||
for info in stock_info:
|
||||
stonk = info[0]["data"]["alfa"]
|
||||
last_price = info[0]["data"]["lastPrice"]
|
||||
prev_close = info[0]["data"]["previousClosePrice"]
|
||||
eq = "N/A"
|
||||
pct_change = round((last_price - prev_close) / prev_close, 3)
|
||||
to_print = f"{stonk}\t {last_price}\t\t {prev_close}\t\t {eq}\t\t {pct_change}"
|
||||
if last_price >= prev_close:
|
||||
print(colored(to_print, "green"))
|
||||
else:
|
||||
print(colored(to_print, "red"))
|
||||
print("")
|
||||
@@ -7,7 +7,7 @@ from prompt_toolkit.completion import NestedCompleter
|
||||
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.portfolio import rh_api, alp_api, ally_api
|
||||
from gamestonk_terminal.portfolio import rh_api, alp_api, ally_api, dg_api
|
||||
from gamestonk_terminal.portfolio.portfolio_helpers import (
|
||||
merge_portfolios,
|
||||
print_portfolio,
|
||||
@@ -26,6 +26,7 @@ class PortfolioController:
|
||||
"alphold",
|
||||
"alphist",
|
||||
"allyhold",
|
||||
"dghold",
|
||||
"hold",
|
||||
]
|
||||
|
||||
@@ -33,6 +34,7 @@ class PortfolioController:
|
||||
"rh",
|
||||
"alp",
|
||||
"ally",
|
||||
"dg",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@@ -48,6 +50,7 @@ class PortfolioController:
|
||||
print("\nBrokers Supported: rh - Robinhood")
|
||||
print(" alp - Alpaca")
|
||||
print(" ally - Ally Invest")
|
||||
print(" dg - Degiro")
|
||||
print("\nPortfolio:")
|
||||
print(" help show this menu again")
|
||||
print(
|
||||
@@ -69,6 +72,8 @@ class PortfolioController:
|
||||
print(" alphist view alp portfolio history")
|
||||
print("Ally:")
|
||||
print(" allyhold view ally holdings")
|
||||
print("Degiro:")
|
||||
print(" dghold view dg holdings")
|
||||
print("\nMerge:")
|
||||
print(" hold view net holdings across all logins")
|
||||
print("")
|
||||
@@ -86,6 +91,8 @@ class PortfolioController:
|
||||
print(" alphist plot historical alpaca portfolio")
|
||||
print("\nAlly:")
|
||||
print(" allyhold view ally holdings")
|
||||
print("\nDegiro:")
|
||||
print(" dghold view dg holdings")
|
||||
print("\nMerge:")
|
||||
print(" hold view net holdings across all logins")
|
||||
print("")
|
||||
@@ -171,6 +178,13 @@ class PortfolioController:
|
||||
print(e)
|
||||
print("")
|
||||
|
||||
def call_dghold(self, _):
|
||||
try:
|
||||
dg_api.show_holdings()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
|
||||
def call_hold(self, _):
|
||||
holdings = pd.DataFrame(
|
||||
columns=["Symbol", "MarketValue", "Quantity", "CostBasis"]
|
||||
|
||||
Reference in New Issue
Block a user