From 71402d2fec36cc3ce091ad48dd5b31f9ddca5969 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 20 Jun 2024 23:43:45 +0200 Subject: [PATCH] Documentation --- fin_depo/data.py | 14 ++++++++++++++ fin_depo/defi_kraken.py | 15 +++++++++++++++ fin_depo/defi_kucoin.py | 15 +++++++++++++++ fin_depo/defi_partisia_blockchain.py | 13 +++++++++++++ fin_depo/investbank_nordnet.py | 17 ++++++++++++++++- 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/fin_depo/data.py b/fin_depo/data.py index ceef6c4..fc3ca96 100644 --- a/fin_depo/data.py +++ b/fin_depo/data.py @@ -11,6 +11,16 @@ from fin_defs import Asset @enforce_typing.enforce_types @dataclasses.dataclass class Depo(abc.ABC): + """A depository tracking some amount of assets. + + Depo can either be DepoSingle, which is the base layer of the depository + structure, or nested in DepoGroup, which allows for a complex hierarcy of + depositories. + + The depository structure exposed by each backend depends upon the logical + structure of the relevant service and the API of this service. + """ + name: str updated_time: datetime.datetime @@ -29,6 +39,8 @@ class Depo(abc.ABC): @enforce_typing.enforce_types @dataclasses.dataclass class DepoSingle(Depo): + """Base level of depository.""" + _assets: Mapping[Asset, Decimal] def assets(self) -> Iterable[Asset]: @@ -41,6 +53,8 @@ class DepoSingle(Depo): @enforce_typing.enforce_types @dataclasses.dataclass class DepoGroup(Depo): + """Nested depository.""" + nested: list[Depo] def assets(self) -> Iterable[Asset]: diff --git a/fin_depo/defi_kraken.py b/fin_depo/defi_kraken.py index cf7ff4d..acb77c9 100644 --- a/fin_depo/defi_kraken.py +++ b/fin_depo/defi_kraken.py @@ -1,3 +1,5 @@ +"""See `KrakenDepoFetcher` for documentation.""" + import datetime import logging from decimal import Decimal @@ -11,6 +13,19 @@ logger = logging.getLogger(__name__) class KrakenDepoFetcher: + """Depository fetcher for [Kraken](https://www.kraken.com), the online crypto currency exchange. + + Requirements for use: + - Account on [Kraken](https://www.kraken.com). + - Have performed Know Your Customer (KYC) for your account. + - Created API key from [Kraken Pro + settings](https://pro.kraken.com/app/settings/api). + API key must have the **Query Funds Permission**, and **should not have + any additional permissions**. Employ principle of least priviledge. + + Depository structure: A `DepoSingle`. No nesting. + """ + def __init__(self, kraken_key: str, kraken_secret: str): assert kraken_key is not None, 'Missing kraken_key' assert kraken_secret is not None, 'Missing kraken_secret' diff --git a/fin_depo/defi_kucoin.py b/fin_depo/defi_kucoin.py index 0db7bd6..90c566c 100644 --- a/fin_depo/defi_kucoin.py +++ b/fin_depo/defi_kucoin.py @@ -1,3 +1,5 @@ +"""See `KucoinDepoFetcher` for documentation.""" + import datetime import logging from decimal import Decimal @@ -11,6 +13,19 @@ logger = logging.getLogger(__name__) class KucoinDepoFetcher: + """Depository fetcher for [Kucoin](https://www.kucoin.com), the online crypto currency exchange. + + Requirements for use: + - Account on [Kucoin](https://www.kucoin.com). + - Have performed Know Your Customer (KYC) for your account. + - Created API key from [settings menu](https://www.kucoin.com/account/api). + API key must have the **General Permission**, and **should not have + any additional permissions**. Employ principle of least priviledge. + + Depository structure: An upper level depo split for each of the + sub-accounts (Funding, Trading, Margin, Futures...) + """ + def __init__(self, kucoin_key: str, kucoin_secret: str, kucoin_pass: str): assert kucoin_key is not None, 'Missing kucoin_key' assert kucoin_secret is not None, 'Missing kucoin_secret' diff --git a/fin_depo/defi_partisia_blockchain.py b/fin_depo/defi_partisia_blockchain.py index ab6f342..3883d01 100644 --- a/fin_depo/defi_partisia_blockchain.py +++ b/fin_depo/defi_partisia_blockchain.py @@ -1,3 +1,5 @@ +"""See `PartisiaBlockchainAccountDepoFetcher` for documentation.""" + import dataclasses import datetime import email.utils @@ -137,6 +139,17 @@ BYOC_ASSETS = { class PartisiaBlockchainAccountDepoFetcher: + """Depository fetcher for individual [Partisia + Blockchain](https://partisiablockchain.com/) accounts, including [MPC](https://partisiablockchain.gitlab.io/documentation/pbc-fundamentals/mpc-token-model-and-account-elements.html) and + [Bring-Your-Own-Coin](https://partisiablockchain.gitlab.io/documentation/pbc-fundamentals/byoc/introduction-to-byoc.html). + + Requirements for use: + - Account on Partisia Blockchain. + + Depository structure: A nested depo containing both a `Native` and a `BYOC` + depo. + """ + def __init__(self, session, blockchain_address: str): assert session is not None, 'missing session' assert blockchain_address is not None, 'missing blockchain_address' diff --git a/fin_depo/investbank_nordnet.py b/fin_depo/investbank_nordnet.py index 3e5a8f0..ca9020b 100644 --- a/fin_depo/investbank_nordnet.py +++ b/fin_depo/investbank_nordnet.py @@ -1,4 +1,4 @@ -"""Nordnet Depository fetching for Nordnet, the scandinavian investment bank. +"""Nordnet Depository fetching for [Nordnet](https://nordnet.dk), the online scandinavian investment bank. This fetcher uses the [Nordnet API](https://www.nordnet.dk/externalapi/docs/api), which requires a Nordnet @@ -40,6 +40,21 @@ def asset_from_instrument_json(json) -> fin_defs.Asset | None: class NordnetDepoFetcher: + """Depository fetcher for [Nordnet](https://nordnet.dk), the online investment bank. + + Requirements for use: + - Account on [Nordnet](https://nordnet.dk). This requires a MitID. + - Password login enabled from [settings](https://www.nordnet.dk/indstillinger/min-profil) + + **Warning**: This system uses an unofficial API which uses your normal + Nordnet username and password for login access, with full read/write + access! **This is dangerous**, and any potential leak would give an + attacker full access to your account. + + Depository structure: Each account you have access to will be given its own + `Depo`, with all of them nested under a "Nordnet" nested depository. + """ + def __init__(self, session, username: str, password: str): assert session is not None, 'missing session' self.session = session