2024-06-02 14:14:46 +00:00
|
|
|
import datetime
|
|
|
|
import logging
|
2024-05-29 20:29:15 +00:00
|
|
|
from decimal import Decimal
|
2024-06-02 14:14:46 +00:00
|
|
|
|
2024-05-29 20:29:15 +00:00
|
|
|
import fin_defs
|
|
|
|
import krakenex
|
2024-06-02 14:14:46 +00:00
|
|
|
|
|
|
|
from .data import Depo, DepoSingle
|
2024-05-29 20:29:15 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2024-06-02 14:14:46 +00:00
|
|
|
class KrakenDepoFetcher:
|
2024-05-29 20:29:15 +00:00
|
|
|
def __init__(self, kraken_key: str, kraken_secret: str):
|
|
|
|
self.client = krakenex.API(
|
|
|
|
kraken_key,
|
|
|
|
kraken_secret,
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_depo(self) -> Depo:
|
|
|
|
now = datetime.datetime.now(tz=datetime.UTC)
|
|
|
|
|
|
|
|
result = self.client.query_private('Balance')
|
|
|
|
|
|
|
|
assets: dict[fin_defs.Asset, Decimal] = {}
|
|
|
|
for account, balance_str in result['result'].items():
|
|
|
|
asset = fin_defs.WELL_KNOWN_SYMBOLS[account]
|
|
|
|
balance = Decimal(balance_str)
|
|
|
|
if balance != 0:
|
|
|
|
assets[asset] = assets.get(asset, Decimal(0)) + balance
|
|
|
|
del account, balance_str, asset, balance
|
|
|
|
|
|
|
|
return DepoSingle(
|
2024-06-02 14:14:46 +00:00
|
|
|
name='Kraken',
|
|
|
|
assets=assets,
|
|
|
|
updated_time=now,
|
2024-05-29 20:29:15 +00:00
|
|
|
)
|