1
0
fin-depo/fin_depo/__init__.py

101 lines
3.3 KiB
Python
Raw Normal View History

2024-07-08 17:05:49 +00:00
"""# Financial Depository Fetchers.
2024-07-21 12:32:46 +00:00
Python library for programmating downloads of asset position information from
personal depository accounts.
This library is a core part of my personal financial applications, as it allows
me to monitor my investments on financial markets and web3 investments.
A lot can be said (mostly negative) about web3, but at least they are serious
about API access, which the modern banking system is not great at providing.
Even in The European Union, where GDPR is law and OpenBanking is a requirement,
it is hugely difficult for people to access and control their own personal
financial information.
This is a library; if you want a simple program for downloading the information
exposed by one of the supported services, try [my personal-data-fetchers
program](https://gitfub.space/Jmaa/personal-data-fetchers).
2024-07-08 17:05:49 +00:00
2024-07-20 20:11:59 +00:00
## Supported websites/services
- [**Kraken**](https://www.kraken.com/) crypto-currency exchange
(`KrakenDepoFetcher`):
Uses their [publicly documented API](https://docs.kraken.com/rest/). This
provides the same data as the homepage.
- [**Kucoin**](https://www.kucoin.com/) crypto-currency exchange
(`KucoinDepoFetcher`):
Uses their [publicly documented
2024-07-20 20:03:50 +00:00
API](https://www.kucoin.com/docs/beginners/introduction). This provides the
same data as is available on the Assets Overview Page. This fetcher also
allows for placing market orders, but be careful with this functionality.
2024-07-20 20:11:59 +00:00
- [**Partisia Blockchain**](https://browser.partisiablockchain.com/) wallet
balances (`PartisiaBlockchainAccountDepoFetcher`):
Uses a public reader node to check the account state. This is the same data as
can be found in the Partisia Browser Assets page.
- [**Nordnet**](https://www.nordnet.dk) nordic investment bank
(`NordnetDepoFetcher`):
Uses their [API](https://www.nordnet.dk/externalapi/docs/api). Thanks to
[Morten Helmstedt](https://helmstedt.dk/) for sharing his [Nordnet
2024-07-20 20:03:50 +00:00
utilities](https://github.com/helmstedt/nordnet-utilities), which helped with
implementing this functionality. Exposes the same data as the home page.
## Future extension
2024-07-08 17:05:49 +00:00
- [ ] Investment Bank: Saxo Bank OpenAPI
- [ ] Personal Bank: Personal Bank Account (Open Banking) Maybe use AIIA?
2024-11-01 10:30:18 +00:00
- [ ] Partisia Blockchain: Implement sharding routing correctly.
2024-07-08 17:05:49 +00:00
"""
2024-11-01 10:30:18 +00:00
BACKEND_MODULE_NAMES = [
2024-07-16 19:54:13 +00:00
'defi_kraken',
'defi_kucoin',
2024-11-01 10:30:18 +00:00
'investbank_nordnet',
2024-07-16 19:54:13 +00:00
'defi_partisia_blockchain',
2024-11-01 10:30:18 +00:00
]
__all__ = [
'defi_kraken',
'defi_kucoin',
2024-07-16 19:54:13 +00:00
'investbank_nordnet',
2024-11-01 10:30:18 +00:00
'defi_partisia_blockchain',
2024-07-20 18:21:50 +00:00
'__version__',
2024-07-21 09:09:49 +00:00
'data',
'static',
2024-07-16 19:54:13 +00:00
]
2024-06-02 14:14:17 +00:00
import importlib
2024-08-08 16:14:01 +00:00
import logging
2024-08-08 15:54:50 +00:00
import sys
2024-07-21 09:09:49 +00:00
from . import (
data,
static,
2024-07-21 09:09:49 +00:00
)
2024-07-20 18:21:50 +00:00
from ._version import __version__
logger = logging.getLogger(__name__)
2024-11-01 10:30:18 +00:00
def load_backend(root_module, name: str) -> object | None:
"""Initializes the backend with the given name.
2024-08-08 15:54:50 +00:00
2024-11-01 10:30:18 +00:00
Module is assigned as an attribute to the root module.
"""
try:
2024-08-08 15:54:50 +00:00
imported_module = importlib.import_module(f'{__name__}.{name}')
except Exception:
logger.exception(
2024-08-08 15:56:14 +00:00
'Backend "%s" could not be imported. Are all module dependencies installed?',
name,
)
return None
2024-11-01 10:30:18 +00:00
setattr(root_module, name, imported_module)
2024-08-09 14:20:13 +00:00
return imported_module
2024-08-08 15:56:14 +00:00
# Import modules
2024-11-01 10:30:18 +00:00
for m in BACKEND_MODULE_NAMES:
load_backend(sys.modules[__name__], m)
2024-08-08 15:54:50 +00:00
del m