1
0
fin-depo/fin_depo/defi_kraken.py
Jon Michael Aanes 58b5a204f4
Some checks failed
Test Python / Test (push) Failing after 20s
Kraken and Kucoin depos
2024-05-29 22:29:44 +02:00

36 lines
998 B
Python

from .data import Depo, DepoSingle
from decimal import Decimal
import fin_defs
import datetime
import krakenex
import logging
logger = logging.getLogger(__name__)
class KrakenDepoFetcher:
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(
name = 'Kraken',
assets = assets,
updated_time = now,
)