From 342b4f07952b5934a9a1dca32320ea9352ecf429 Mon Sep 17 00:00:00 2001 From: Kai Eberl Date: Sat, 30 May 2026 19:58:58 +0200 Subject: [PATCH] Add account listing endpoint --- README.md | 9 ++++- comdirect_api/service/account_service.py | 14 +++++++ tests/test_comdirect_client.py | 47 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41c9667..2a18f5f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is an unofficial python wrapper for the comdirect API for private consumers This package currently supports the following operations: -* Read balances and transactions +* Read account information, balances and transactions * Read depot information * Read and download Documents * Read and update orders @@ -59,6 +59,13 @@ balances = client.get_all_balances() print(balances['values']) ``` +You can fetch account master data separately: + +```python +accounts = client.get_accounts() +print(accounts['values']) +``` + It is also possible to send a GET request to a self defined endpoint, for example: ```python diff --git a/comdirect_api/service/account_service.py b/comdirect_api/service/account_service.py index 5ca56f3..77cd632 100644 --- a/comdirect_api/service/account_service.py +++ b/comdirect_api/service/account_service.py @@ -2,6 +2,20 @@ class AccountService: + def get_accounts(self, without_account: bool = False) -> Any: + """4.1.0. Request for account information for all accounts. + + Args: + without_account (bool, optional): Suppresses the master data of the accounts. Defaults to False. + + Returns: + Any: Response object + """ + url = "{0}/banking/clients/user/v2/accounts".format(self.api_url) + params = {"without-attr": "account"} if without_account else None + response = self.session.get(url, params=params).json() + return response + def get_all_balances(self, without_account: bool = False) -> Any: """4.1.1. Request for account information, including cash balance and buying power, for all accounts. diff --git a/tests/test_comdirect_client.py b/tests/test_comdirect_client.py index 144b546..3a48a56 100644 --- a/tests/test_comdirect_client.py +++ b/tests/test_comdirect_client.py @@ -3,6 +3,24 @@ from comdirect_api.comdirect_client import ComdirectClient +class DummyResponse: + def __init__(self, payload): + self.payload = payload + + def json(self): + return self.payload + + +class DummySession: + def __init__(self, payload): + self.payload = payload + self.requests = [] + + def get(self, url, params=None): + self.requests.append((url, params)) + return DummyResponse(self.payload) + + def test_comdirect_client_fresh_init(): client_id = "dummy_id" client_secret = "dummy_secret" @@ -37,3 +55,32 @@ def test_comdirect_client_import_session(tmp_path): assert new_client.auth_service.client_id == client_id assert new_client.auth_service.client_secret == client_secret + + +def test_get_accounts(): + client = ComdirectClient("dummy_id", "dummy_secret") + payload = {"values": [{"accountId": "account-id"}]} + client.session = DummySession(payload) + + response = client.get_accounts() + + assert response == payload + assert client.session.requests == [ + ("https://api.comdirect.de/api/banking/clients/user/v2/accounts", None) + ] + + +def test_get_accounts_without_account(): + client = ComdirectClient("dummy_id", "dummy_secret") + payload = {"values": []} + client.session = DummySession(payload) + + response = client.get_accounts(without_account=True) + + assert response == payload + assert client.session.requests == [ + ( + "https://api.comdirect.de/api/banking/clients/user/v2/accounts", + {"without-attr": "account"}, + ) + ]