This commit is contained in:
parent
71f767e2ed
commit
f74945d6bf
|
@ -1 +1 @@
|
||||||
__version__ = '0.1.2'
|
__version__ = '0.1.2'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import abc
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import datetime
|
import datetime
|
||||||
from collections.abc import Mapping
|
from collections.abc import Iterable, Mapping
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import enforce_typing
|
import enforce_typing
|
||||||
|
@ -9,18 +10,48 @@ from fin_defs import Asset
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Depo:
|
class Depo(abc.ABC):
|
||||||
name: str
|
name: str
|
||||||
updated_time: datetime.datetime
|
updated_time: datetime.datetime
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def assets(self) -> Iterable[Asset]:
|
||||||
|
"""Returns the different assets managed by this depo."""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_amount_of_asset(self, asset: Asset) -> Decimal:
|
||||||
|
"""Returns the amount of owned assets for all nested depos.
|
||||||
|
|
||||||
|
Must return 0 if depo does not contain the given asset.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class DepoSingle(Depo):
|
class DepoSingle(Depo):
|
||||||
assets: Mapping[Asset, Decimal]
|
_assets: Mapping[Asset, Decimal]
|
||||||
|
|
||||||
|
def assets(self) -> Iterable[Asset]:
|
||||||
|
return self._assets
|
||||||
|
|
||||||
|
def get_amount_of_asset(self, asset: Asset) -> Decimal:
|
||||||
|
return self._assets.get(asset, Decimal(0))
|
||||||
|
|
||||||
|
|
||||||
@enforce_typing.enforce_types
|
@enforce_typing.enforce_types
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class DepoGroup(Depo):
|
class DepoGroup(Depo):
|
||||||
nested: list[Depo]
|
nested: list[Depo]
|
||||||
|
|
||||||
|
def assets(self) -> Iterable[Asset]:
|
||||||
|
assets: list[Asset] = []
|
||||||
|
for nested_depo in self.nested:
|
||||||
|
assets.extend(nested_depo.assets())
|
||||||
|
return assets
|
||||||
|
|
||||||
|
def get_amount_of_asset(self, asset: Asset) -> Decimal:
|
||||||
|
summed: Decimal = Decimal(0)
|
||||||
|
for nested_depo in self.nested:
|
||||||
|
summed += nested_depo.get_amount_of_asset(asset)
|
||||||
|
del nested_depo
|
||||||
|
return summed
|
||||||
|
|
|
@ -25,7 +25,8 @@ class KucoinDepoFetcher:
|
||||||
asset = fin_defs.WELL_KNOWN_SYMBOLS[account_data['currency']]
|
asset = fin_defs.WELL_KNOWN_SYMBOLS[account_data['currency']]
|
||||||
balance = Decimal(account_data['balance'])
|
balance = Decimal(account_data['balance'])
|
||||||
assets_for_account_type = assets_by_account_type.get(
|
assets_for_account_type = assets_by_account_type.get(
|
||||||
account_data['type'], {},
|
account_data['type'],
|
||||||
|
{},
|
||||||
)
|
)
|
||||||
assets_for_account_type[asset] = (
|
assets_for_account_type[asset] = (
|
||||||
assets_for_account_type.get(asset, Decimal(0)) + balance
|
assets_for_account_type.get(asset, Decimal(0)) + balance
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -15,6 +15,7 @@ PACKAGE_NAME = 'fin_depo'
|
||||||
with open('README.md') as f:
|
with open('README.md') as f:
|
||||||
readme = f.read()
|
readme = f.read()
|
||||||
|
|
||||||
|
|
||||||
def parse_version_file(text: str) -> str:
|
def parse_version_file(text: str) -> str:
|
||||||
match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text)
|
match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text)
|
||||||
if match is None:
|
if match is None:
|
||||||
|
@ -22,9 +23,11 @@ def parse_version_file(text: str) -> str:
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
return match.group(2)
|
return match.group(2)
|
||||||
|
|
||||||
|
|
||||||
with open(PACKAGE_NAME + '/_version.py') as f:
|
with open(PACKAGE_NAME + '/_version.py') as f:
|
||||||
version = parse_version_file(f.read())
|
version = parse_version_file(f.read())
|
||||||
|
|
||||||
|
|
||||||
def parse_requirements(text: str) -> list[str]:
|
def parse_requirements(text: str) -> list[str]:
|
||||||
return text.strip().split('\n')
|
return text.strip().split('\n')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user