diff --git a/fin_depo/data.py b/fin_depo/data.py index 4d68124..d0aed92 100644 --- a/fin_depo/data.py +++ b/fin_depo/data.py @@ -71,8 +71,10 @@ class DepoGroup(Depo): del nested_depo return summed + T = TypeVar('T') + class DepoFetcher(abc.ABC): """Base `Depo` fetcher interface. diff --git a/fin_depo/defi_kraken.py b/fin_depo/defi_kraken.py index d5335bd..2cedacc 100644 --- a/fin_depo/defi_kraken.py +++ b/fin_depo/defi_kraken.py @@ -7,7 +7,7 @@ from decimal import Decimal import fin_defs import krakenex -from .data import Depo, DepoSingle, DepoFetcher +from .data import Depo, DepoFetcher, DepoSingle logger = logging.getLogger(__name__) @@ -29,8 +29,6 @@ class KrakenDepoFetcher(DepoFetcher): def __init__(self, kraken_key: str, kraken_secret: str): self.assert_param('kraken_key', str, kraken_key) self.assert_param('kraken_secret', str, kraken_secret) - assert kraken_key is not None, 'Missing kraken_key' - assert kraken_secret is not None, 'Missing kraken_secret' self.client = krakenex.API( kraken_key, kraken_secret, @@ -42,13 +40,13 @@ class KrakenDepoFetcher(DepoFetcher): result = self.client.query_private('Balance') assets: dict[fin_defs.Asset, Decimal] = {} - for account, balance_str in result['result'].items(): - account = account.removesuffix('.HOLD') + for account_raw, balance_str in result['result'].items(): + account = account_raw.removesuffix('.HOLD') asset = fin_defs.WELL_KNOWN_SYMBOLS[account] balance = Decimal(balance_str) if balance != 0: assets[asset] = assets.get(asset, Decimal(0)) + balance - del account, balance_str, asset, balance + del account, account_raw, balance_str, asset, balance return DepoSingle( name='Kraken', diff --git a/fin_depo/defi_kucoin.py b/fin_depo/defi_kucoin.py index 5d6b976..da4f8df 100644 --- a/fin_depo/defi_kucoin.py +++ b/fin_depo/defi_kucoin.py @@ -7,7 +7,7 @@ from decimal import Decimal import fin_defs import kucoin.client -from .data import DepoGroup, DepoSingle, DepoFetcher +from .data import DepoFetcher, DepoGroup, DepoSingle logger = logging.getLogger(__name__) diff --git a/fin_depo/defi_partisia_blockchain.py b/fin_depo/defi_partisia_blockchain.py index 09b7aa4..337d904 100644 --- a/fin_depo/defi_partisia_blockchain.py +++ b/fin_depo/defi_partisia_blockchain.py @@ -2,7 +2,6 @@ import dataclasses import datetime -import requests import email.utils import json import logging @@ -13,7 +12,7 @@ import fin_defs import requests from frozendict import frozendict -from .data import DepoGroup, DepoSingle, DepoFetcher +from .data import DepoFetcher, DepoGroup, DepoSingle logger = logging.getLogger(__name__) diff --git a/fin_depo/investbank_nordnet.py b/fin_depo/investbank_nordnet.py index 8cadd6e..3dd12fd 100644 --- a/fin_depo/investbank_nordnet.py +++ b/fin_depo/investbank_nordnet.py @@ -11,13 +11,13 @@ I am grateful for his pioneering work. import datetime import logging -import requests from decimal import Decimal import fin_defs +import requests from frozendict import frozendict -from .data import Depo, DepoGroup, DepoSingle, DepoFetcher +from .data import Depo, DepoFetcher, DepoGroup, DepoSingle logger = logging.getLogger(__name__) @@ -40,7 +40,9 @@ 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() + +EMPTY_DICT: dict[str, str | int] = frozendict() + class NordnetDepoFetcher(DepoFetcher): """Depository fetcher for [Nordnet](https://nordnet.dk), the online investment bank. @@ -59,13 +61,12 @@ class NordnetDepoFetcher(DepoFetcher): """ def __init__(self, session: requests.Session, username: str, password: str): - self.session = self.assert_param('session', requests.Session, session) self.username: str = self.assert_param('username', str, username) self.password: str = self.assert_param('password', str, password) self.is_logged_in = False - def _get_json(self, url: str, params: dict[str, str | int] = EMPTY_DICT)-> 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)