1
0
fin-depo/fin_depo/__init__.py
takunomi-build-bot ef9aa91499
All checks were successful
Python Ruff Code Quality / ruff (push) Successful in 22s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 23s
Run Python tests (through Pytest) / Test (push) Successful in 27s
🤖 Repository layout updated to latest version
This commit was automatically generated by a script: https://gitfub.space/Jmaa/repo-manager
2024-11-29 01:27:46 +01:00

138 lines
4.7 KiB
Python

"""# Financial Depository Fetchers.
Python library for programmatic download 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 ordinary 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).
## Supported websites/services
| Service | Description | Read assets | Swap assets |
| :-: | --- | :-: | :-: |
| [**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 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. | ✅︎ | ✅︎ |
| [**Partisia Blockchain**](https://browser.partisiablockchain.com/) | Wallet balances on Partisia Blockchain (`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 utilities](https://github.com/helmstedt/nordnet-utilities), which helped with implementing this functionality. Exposes the same data as the home page. | ✅︎ | |
## Example Application
The library ships with an example application in the form of a CLI program that
can display a tree representation of assets in known depositories:
```bash
python -m fin_depo
```
Example output:
```
Aggregated
├─ Kraken
│ ├─ BTC 0.00871009
│ └─ EUR 200.5
└─ Kucoin
├─ Kucoin trade
│ ├─ BTC 0.00169297
│ └─ USDT 20
└─ Kucoin main
├─ BTC 0
└─ USDT 40
```
## Usage
Using the Kraken API as an example:
```python
depo_fetcher = fin_depo.defi_kraken.KrakenDepoFetcher(
KRAKEN_KEY, KRAKEN_SECRET,
)
depo = depo_fetcher.get_depo()
depo.assets()
> [BTC, USDT]
depo.get_amount_of_asset(BTC)
> 0.1
```
## Future extension
- [ ] Investment Bank: Saxo Bank OpenAPI
- [ ] Personal Bank: Personal Bank Account (Open Banking).
* Maybe using [Enable Banking](https://enablebanking.com/)? They seem to
allow developers to access their own accounts in a sort of half production
half demo environment.
* [AIIA](https://www.aiia.eu/) is also a possiblity?
- [ ] Partisia Blockchain: Implement sharding routing correctly.
- [ ] Depository history: Allow users to query both the state of their deposity
in the past, and to allow them to query the transactions.
* Most backends only support listing the transactions themselves, so the
depository history needs to be computed backwards from these.
"""
BACKEND_MODULE_NAMES = [
'defi_kraken',
'defi_kucoin',
'investbank_nordnet',
'defi_partisia_blockchain',
]
__all__ = [
'__version__',
'data',
'defi_kraken',
'defi_kucoin',
'defi_partisia_blockchain',
'investbank_nordnet',
'static',
]
import importlib
import logging
import sys
from . import (
data,
static,
)
from ._version import __version__
logger = logging.getLogger(__name__)
def load_backend(root_module, name: str) -> object | None:
"""Initializes the backend with the given name.
Module is assigned as an attribute to the root module.
"""
try:
imported_module = importlib.import_module(f'{__name__}.{name}')
except Exception:
logger.exception(
'Backend "%s" could not be imported. Are all module dependencies installed?',
name,
)
return None
setattr(root_module, name, imported_module)
return imported_module
# Import modules
for m in BACKEND_MODULE_NAMES:
load_backend(sys.modules[__name__], m)
del m