1
0
This commit is contained in:
Jon Michael Aanes 2024-06-02 16:14:46 +02:00
parent a4be3e49ed
commit e68b3b539d
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
6 changed files with 39 additions and 32 deletions

View File

@ -1,4 +1,3 @@
__all__ = ['defi_kraken', 'defi_kucoin'] __all__ = ['defi_kraken', 'defi_kucoin']
from . import defi_kraken from . import defi_kraken, defi_kucoin
from . import defi_kucoin

View File

@ -1,10 +1,11 @@
import dataclasses
import datetime
from collections.abc import Mapping
from decimal import Decimal
import enforce_typing import enforce_typing
import dataclasses
from decimal import Decimal
from collections.abc import Mapping
from fin_defs import Asset from fin_defs import Asset
import datetime
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass @dataclasses.dataclass
@ -12,11 +13,13 @@ class Depo:
name: str name: str
updated_time: datetime.datetime updated_time: datetime.datetime
@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]
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass @dataclasses.dataclass
class DepoGroup(Depo): class DepoGroup(Depo):

View File

@ -1,14 +1,16 @@
from .data import Depo, DepoSingle
from decimal import Decimal
import fin_defs
import datetime import datetime
import krakenex
import logging import logging
from decimal import Decimal
import fin_defs
import krakenex
from .data import Depo, DepoSingle
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class KrakenDepoFetcher:
class KrakenDepoFetcher:
def __init__(self, kraken_key: str, kraken_secret: str): def __init__(self, kraken_key: str, kraken_secret: str):
self.client = krakenex.API( self.client = krakenex.API(
kraken_key, kraken_key,

View File

@ -1,20 +1,16 @@
from .data import DepoSingle, DepoGroup
import dataclasses
import datetime import datetime
import fin_defs
import logging import logging
from collections.abc import Iterator, Mapping
from decimal import Decimal from decimal import Decimal
import fin_defs
import kucoin.client import kucoin.client
from frozendict import frozendict
from personal_data.data import DeduplicateMode, Scraper from .data import DepoGroup, DepoSingle
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class KucoinDepoFetcher:
class KucoinDepoFetcher:
def __init__(self, kucoin_key: str, kucoin_secret: str, kucoin_pass: str): def __init__(self, kucoin_key: str, kucoin_secret: str, kucoin_pass: str):
self.client = kucoin.client.Client( self.client = kucoin.client.Client(
kucoin_key, kucoin_key,
@ -28,10 +24,18 @@ class KucoinDepoFetcher:
for account_data in self.client.get_accounts(): for account_data in self.client.get_accounts():
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(account_data['type'], {}) assets_for_account_type = assets_by_account_type.get(
assets_for_account_type[asset] = assets_for_account_type.get(asset, Decimal(0)) +balance account_data['type'], {},
)
assets_for_account_type[asset] = (
assets_for_account_type.get(asset, Decimal(0)) + balance
)
del account_data, asset, balance del account_data, asset, balance
return DepoGroup("Kucoin", now, [ return DepoGroup(
DepoSingle("Kucoin " + account_type, now, assets) for account_type, 'Kucoin',
assets in assets_by_account_type.items() now,
]) [
DepoSingle('Kucoin ' + account_type, now, assets)
for account_type, assets in assets_by_account_type.items()
],
)

View File

@ -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')

View File

@ -1,6 +1,2 @@
import pytest
import fin_depo
def test_nothing(): def test_nothing():
pass pass