Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portfolio-Exportierung als CSV-Datei/Inhalt für private Anlagenverwaltung #1

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Pipfile
100755 → 100644
Empty file.
Empty file modified Pipfile.lock
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified src/OnVistaApi_test.py
100755 → 100644
Empty file.
Empty file modified src/config.py
100755 → 100644
Empty file.
Empty file modified src/main.py
100755 → 100644
Empty file.
Empty file modified src/onvistabank_api/OnVistaApi.py
100755 → 100644
Empty file.
Empty file modified src/onvistabank_api/OnVistaLowLevelApi.py
100755 → 100644
Empty file.
73 changes: 73 additions & 0 deletions src/portfolio-exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python3

# Exportiert das Portfolio des Nutzers als CSV-Datei mit ; als Spaltentrenner. Login erfordert ggf. TAN-Eingabe.

from operator import itemgetter,attrgetter
from config import get_allowed_user_ids, get_telegram_token
from onvistabank_api.OnVistaApi import OnVistaApiOTPRequiredException
from onvistabank_api.OnVistaLowLevelApi import OnVistaOTPIsWrongException
from datetime import timedelta
from loguru import logger
import sys
from onvistabank_api.OnVistaApi import OnVistaApi
from config import get_onvistabank_username, get_onvistabank_password
from typing import Optional

def format_number(number: float) -> str:
return (
"{:,.2f}".format(number).replace(",", " ").replace(".", ",").replace(" ", ".")
)

logger.remove(0)

logger.add(sys.stderr, level="ERROR")

api = None

api = OnVistaApi(
"cookies.txt", get_onvistabank_username(), get_onvistabank_password()
)

try:
api.login()
except OnVistaApiOTPRequiredException:
otp = input("Bitte OTP-Passwort eingeben: ")
api.enterOTP(otp)

# Die Konten dieses Logins abfragen
accounts_result = api.get_accounts()

print("accountNumber;iban;currentBalance;name;isin;quantity;buyingValue;lastValue;totalValue;actualValue;totalPerformance;performancePercentage")
for i, account in enumerate(accounts_result["accountsList"], start=1):
logger.info("Account: {}", account)

account_key = account["accountKey"]

# Die (Aktien-)Positionen für diesen Account abfragen
positions = sorted(api.trading_positions(account_key)["portfolio"]["positions"], key=itemgetter('isin'))

for position in positions:
message = ""
message += f'{account["accountNumber"]};'
message += f'{account["iban"]};'
message += f'{format_number(account["currentBalance"])};'

message += f'{position["name"]};'
message += f'{position["isin"]};'
message += f'{position["quantity"]};'

message += f"{format_number(position['buyingValue'])};"
message += f"{format_number(position['lastValue'])};"

message += f"{format_number(position['totalValue'])};"
message += f"{format_number(position['actualValue'])};"

message += f"{format_number(position['totalPerformance'])};"
message += f"{format_number(position['performancePercentage'])}"
#message += "\n"
print(message)

print(f"overall actualValue: {format_number(sum([position['actualValue'] for position in positions]))}\n")
print(f"overall totalPerformance: {format_number(sum([position['totalPerformance'] for position in positions]))}\n")


Loading