mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
degiro integration : apply black
This commit is contained in:
@@ -32,7 +32,7 @@ quotecast_api = None
|
||||
def fetch_additional_information(
|
||||
positions: pd.DataFrame,
|
||||
) -> pd.DataFrame:
|
||||
""" Fetch extra information about the positions like :
|
||||
"""Fetch extra information about the positions like :
|
||||
- name
|
||||
- isin
|
||||
- symbol
|
||||
@@ -47,7 +47,7 @@ def fetch_additional_information(
|
||||
"""
|
||||
|
||||
# EXTRACT POSITIONS IDS
|
||||
positions_ids = positions['id'].astype('int32').tolist()
|
||||
positions_ids = positions["id"].astype("int32").tolist()
|
||||
|
||||
# FETCH EXTRA DATA
|
||||
request = ProductsInfo.Request()
|
||||
@@ -63,10 +63,10 @@ def fetch_additional_information(
|
||||
)
|
||||
|
||||
# CONVERT TO DATAFRAME
|
||||
products_info = pd.DataFrame(products_info_dict['values'].values())
|
||||
products_info = pd.DataFrame(products_info_dict["values"].values())
|
||||
|
||||
# MERGE DATA WITH POSITIONS
|
||||
positions_full = pd.merge(positions, products_info, on='id')
|
||||
positions_full = pd.merge(positions, products_info, on="id")
|
||||
|
||||
return positions_full
|
||||
|
||||
@@ -74,9 +74,11 @@ def fetch_additional_information(
|
||||
def fetch_current_positions() -> pd.DataFrame:
|
||||
# FETCH HELD PRODUCTS
|
||||
request_list = Update.RequestList()
|
||||
request_list.values.extend([
|
||||
Update.Request(option=Update.Option.PORTFOLIO, last_updated=0),
|
||||
])
|
||||
request_list.values.extend(
|
||||
[
|
||||
Update.Request(option=Update.Option.PORTFOLIO, last_updated=0),
|
||||
]
|
||||
)
|
||||
|
||||
update_pb = trading_api.get_update(request_list=request_list, raw=False)
|
||||
positions_partial = filter_current_positions(portfolio=update_pb.portfolio)
|
||||
@@ -90,7 +92,7 @@ def fetch_current_positions() -> pd.DataFrame:
|
||||
def filter_current_positions(
|
||||
portfolio: Update.Portfolio,
|
||||
) -> pd.DataFrame:
|
||||
""" Filter the positions in order to keep only held ones.
|
||||
"""Filter the positions in order to keep only held ones.
|
||||
|
||||
Args:
|
||||
portfolio (Update.Portfolio):
|
||||
@@ -102,11 +104,11 @@ def filter_current_positions(
|
||||
|
||||
# CONVERT TO DATAFRAME
|
||||
portfolio_dict = pb_handler.message_to_dict(message=portfolio)
|
||||
positions = pd.DataFrame(portfolio_dict['values'])
|
||||
positions = pd.DataFrame(portfolio_dict["values"])
|
||||
|
||||
# SETUP MASK
|
||||
mask_product = positions['positionType'] == 'PRODUCT'
|
||||
mask_not_empty = positions['size'] > 0
|
||||
mask_product = positions["positionType"] == "PRODUCT"
|
||||
mask_not_empty = positions["size"] > 0
|
||||
mask_current_position = mask_product & mask_not_empty
|
||||
|
||||
# FILTER
|
||||
@@ -117,7 +119,7 @@ def filter_current_positions(
|
||||
|
||||
def login():
|
||||
"""
|
||||
Connect to Degiro's API.
|
||||
Connect to Degiro's API.
|
||||
"""
|
||||
|
||||
# CONNECT
|
||||
@@ -127,8 +129,8 @@ def login():
|
||||
client_details_table = trading_api.get_client_details()
|
||||
|
||||
# EXTRACT OPTIONAL CREDENTIALS
|
||||
int_account = client_details_table['data']['intAccount']
|
||||
user_token = client_details_table['data']['id']
|
||||
int_account = client_details_table["data"]["intAccount"]
|
||||
user_token = client_details_table["data"]["id"]
|
||||
|
||||
# SETUP OPTIONAL CREDENTIALS
|
||||
trading_api.credentials.int_account = int_account
|
||||
@@ -137,7 +139,7 @@ def login():
|
||||
|
||||
def logout():
|
||||
"""
|
||||
Log out from Degiro's API.
|
||||
Log out from Degiro's API.
|
||||
"""
|
||||
|
||||
trading_api.logout()
|
||||
@@ -145,7 +147,7 @@ def logout():
|
||||
|
||||
def show_holdings():
|
||||
"""
|
||||
Display held products.
|
||||
Display held products.
|
||||
"""
|
||||
|
||||
# FETCH HELD PRODUCTS
|
||||
@@ -153,26 +155,26 @@ def show_holdings():
|
||||
|
||||
# FORMAT DATAFRAME
|
||||
selected_columns = [
|
||||
'symbol',
|
||||
'size',
|
||||
'price',
|
||||
'closePrice',
|
||||
'breakEvenPrice',
|
||||
"symbol",
|
||||
"size",
|
||||
"price",
|
||||
"closePrice",
|
||||
"breakEvenPrice",
|
||||
]
|
||||
formatted_columns = [
|
||||
'Stonk',
|
||||
'Size',
|
||||
'Last Price',
|
||||
'Close Price',
|
||||
'Break Even Price',
|
||||
"Stonk",
|
||||
"Size",
|
||||
"Last Price",
|
||||
"Close Price",
|
||||
"Break Even Price",
|
||||
]
|
||||
fmt_positions = positions[selected_columns].copy(deep=True)
|
||||
fmt_positions.columns = formatted_columns
|
||||
|
||||
fmt_positions['% Change'] = positions['price']
|
||||
fmt_positions['% Change'] -= fmt_positions['Close Price']
|
||||
fmt_positions['% Change'] /= fmt_positions['Close Price']
|
||||
fmt_positions['% Change'] = fmt_positions['% Change'].round(3)
|
||||
fmt_positions["% Change"] = positions["price"]
|
||||
fmt_positions["% Change"] -= fmt_positions["Close Price"]
|
||||
fmt_positions["% Change"] /= fmt_positions["Close Price"]
|
||||
fmt_positions["% Change"] = fmt_positions["% Change"].round(3)
|
||||
|
||||
# DISPLAY DATAFRAME
|
||||
print(fmt_positions)
|
||||
@@ -184,40 +186,40 @@ def return_holdings() -> pd.DataFrame:
|
||||
|
||||
# FORMAT DATAFRAME
|
||||
selected_columns = [
|
||||
'symbol',
|
||||
'size',
|
||||
'price',
|
||||
'breakEvenPrice',
|
||||
"symbol",
|
||||
"size",
|
||||
"price",
|
||||
"breakEvenPrice",
|
||||
]
|
||||
formatted_columns = [
|
||||
'Symbol',
|
||||
'MarketValue',
|
||||
'Quantity',
|
||||
'CostBasis',
|
||||
"Symbol",
|
||||
"MarketValue",
|
||||
"Quantity",
|
||||
"CostBasis",
|
||||
]
|
||||
fmt_positions = positions[selected_columns].copy(deep=True)
|
||||
fmt_positions.columns = formatted_columns
|
||||
fmt_positions['Broker'] = 'dg'
|
||||
fmt_positions["Broker"] = "dg"
|
||||
|
||||
return fmt_positions
|
||||
|
||||
|
||||
def top_news_preview():
|
||||
"""
|
||||
Display pending orders.
|
||||
Display pending orders.
|
||||
"""
|
||||
|
||||
# FETCH DATA
|
||||
top_news_preview = trading_api.get_top_news_preview(raw=True)
|
||||
|
||||
# DISPLAY DATA
|
||||
for article in top_news_preview['data']['items']:
|
||||
print('date', article['date'])
|
||||
print('lastUpdated', article['lastUpdated'])
|
||||
print('category', article['category'])
|
||||
print('title', article['title'])
|
||||
print('brief', article['brief'])
|
||||
print('---')
|
||||
for article in top_news_preview["data"]["items"]:
|
||||
print("date", article["date"])
|
||||
print("lastUpdated", article["lastUpdated"])
|
||||
print("category", article["category"])
|
||||
print("title", article["title"])
|
||||
print("brief", article["brief"])
|
||||
print("---")
|
||||
|
||||
|
||||
def product_lookup(search_text: str):
|
||||
@@ -235,16 +237,18 @@ def product_lookup(search_text: str):
|
||||
)
|
||||
|
||||
# DISPLAY DATA
|
||||
products_df = pd.DataFrame(products['products'])
|
||||
products_selected = products_df[[
|
||||
'name',
|
||||
'isin',
|
||||
'symbol',
|
||||
'productType',
|
||||
'currency',
|
||||
'closePrice',
|
||||
'closePriceDate',
|
||||
]]
|
||||
products_df = pd.DataFrame(products["products"])
|
||||
products_selected = products_df[
|
||||
[
|
||||
"name",
|
||||
"isin",
|
||||
"symbol",
|
||||
"productType",
|
||||
"currency",
|
||||
"closePrice",
|
||||
"closePriceDate",
|
||||
]
|
||||
]
|
||||
|
||||
print(products_selected)
|
||||
|
||||
@@ -253,7 +257,7 @@ def latest_news():
|
||||
# SETUP REQUEST
|
||||
request = LatestNews.Request(
|
||||
offset=0,
|
||||
languages='en,fr',
|
||||
languages="en,fr",
|
||||
limit=20,
|
||||
)
|
||||
|
||||
@@ -261,11 +265,11 @@ def latest_news():
|
||||
latest_news = trading_api.get_latest_news(request=request, raw=True)
|
||||
|
||||
# DISPLAY DATA
|
||||
for article in latest_news['data']['items']:
|
||||
print('date', article['date'])
|
||||
print('title', article['title'])
|
||||
print('content', article['content'])
|
||||
print('---')
|
||||
for article in latest_news["data"]["items"]:
|
||||
print("date", article["date"])
|
||||
print("title", article["title"])
|
||||
print("content", article["content"])
|
||||
print("---")
|
||||
|
||||
|
||||
def news_by_company(isin: str):
|
||||
@@ -273,7 +277,7 @@ def news_by_company(isin: str):
|
||||
isin=isin,
|
||||
limit=10,
|
||||
offset=0,
|
||||
languages='en,fr',
|
||||
languages="en,fr",
|
||||
)
|
||||
|
||||
# FETCH DATA
|
||||
@@ -283,25 +287,27 @@ def news_by_company(isin: str):
|
||||
)
|
||||
|
||||
# DISPLAY DATA
|
||||
for article in news_by_company['data']['items']:
|
||||
print('date', article['date'])
|
||||
print('title', article['title'])
|
||||
print('content', article['content'])
|
||||
print('isins', article['isins'])
|
||||
print('---')
|
||||
for article in news_by_company["data"]["items"]:
|
||||
print("date", article["date"])
|
||||
print("title", article["title"])
|
||||
print("content", article["content"])
|
||||
print("isins", article["isins"])
|
||||
print("---")
|
||||
|
||||
|
||||
def pending_orders():
|
||||
request_list = Update.RequestList()
|
||||
request_list.values.extend([
|
||||
Update.Request(option=Update.Option.ORDERS, last_updated=0),
|
||||
])
|
||||
request_list.values.extend(
|
||||
[
|
||||
Update.Request(option=Update.Option.ORDERS, last_updated=0),
|
||||
]
|
||||
)
|
||||
|
||||
update = trading_api.get_update(request_list=request_list)
|
||||
update_dict = pb_handler.message_to_dict(message=update)
|
||||
orders_df = pd.DataFrame(update_dict['orders']['values'])
|
||||
orders_df = pd.DataFrame(update_dict["orders"]["values"])
|
||||
|
||||
if orders_df.shape[0] == 0:
|
||||
print('No pending orders.')
|
||||
print("No pending orders.")
|
||||
else:
|
||||
print(orders_df)
|
||||
|
||||
@@ -98,12 +98,12 @@ class PortfolioController:
|
||||
print("\nRobinhood:")
|
||||
print(" rhhold check holdings")
|
||||
print(" rhhist plot historical RH portfolio")
|
||||
print("\nAlpaca:")
|
||||
print("\nAlpaca:")
|
||||
print(" alphold view alpaca holdings")
|
||||
print(" alphist plot historical alpaca portfolio")
|
||||
print("\nAlly:")
|
||||
print("\nAlly:")
|
||||
print(" allyhold view ally holdings")
|
||||
print("\nDegiro:")
|
||||
print("\nDegiro:")
|
||||
print(" dghold view dg holdings")
|
||||
print(" dgtopnews view top news preview")
|
||||
print(" dglastnews view latest news")
|
||||
@@ -226,7 +226,7 @@ class PortfolioController:
|
||||
|
||||
def call_dglookup(self, search_text_list: List[str]):
|
||||
try:
|
||||
search_text = ' '.join(search_text_list)
|
||||
search_text = " ".join(search_text_list)
|
||||
dg_api.product_lookup(search_text=search_text)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
Reference in New Issue
Block a user