1
0

Code quality
Some checks failed
Test Python / Test (push) Failing after 25s

This commit is contained in:
Jon Michael Aanes 2024-07-16 22:00:28 +02:00
parent 2a563daf57
commit fa7c5c3c83
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -14,6 +14,7 @@ import logging
from decimal import Decimal
import fin_defs
from frozendict import frozendict
from .data import Depo, DepoGroup, DepoSingle
@ -38,6 +39,7 @@ def asset_from_instrument_json(json) -> fin_defs.Asset | None:
exchange_id = json['tradables'][0]['mic']
return fin_defs.Stock(symbol, fin_defs.EXCHANGES_BY_IDS[exchange_id])
EMPTY_DICT: dict[str,str | int] = frozendict()
class NordnetDepoFetcher:
"""Depository fetcher for [Nordnet](https://nordnet.dk), the online investment bank.
@ -56,16 +58,22 @@ class NordnetDepoFetcher:
"""
def __init__(self, session, username: str, password: str):
assert session is not None, 'missing session'
self.session = session
self.username = username
self.password = password
self.is_logged_in = False
assert self.username is not None, 'Username is missing'
assert self.password is not None, 'Password is missing'
if self.session is None:
msg = 'Session argument is missing'
raise TypeError(msg)
if self.username is not None:
msg = 'Username argument s missing'
raise TypeError(msg)
if self.password is not None:
msg = 'Password argument is missing'
raise TypeError(msg)
def get_json(self, url: str, params: dict[str, str | int] = {}) -> dict:
def get_json(self, url: str, params: dict[str, str | int] = EMPTY_DICT)-> dict:
if not url.startswith(API_ROOT):
msg = f'Given url must be located below API ROOT: {url}'
raise ValueError(msg)
@ -109,7 +117,7 @@ class NordnetDepoFetcher:
json_accounts = self.get_json(API_ACCOUNTS)
nested = []
nested: list[Depo] = []
for json_account in json_accounts:
account_id = json_account['accid']
@ -148,7 +156,7 @@ class NordnetDepoFetcher:
)
return DepoGroup(
name=f'Nordnet',
name='Nordnet',
updated_time=now,
nested=nested,
)