diff --git a/fin_depo/defi_kraken.py b/fin_depo/defi_kraken.py index 71a3d86..c430c7e 100644 --- a/fin_depo/defi_kraken.py +++ b/fin_depo/defi_kraken.py @@ -3,11 +3,13 @@ import datetime import logging from decimal import Decimal +from collections.abc import Iterator import fin_defs import krakenex from .data import ( + Depo, DepoFetcher, DepoSingle, DepositDetails, @@ -64,13 +66,47 @@ class KrakenDepoFetcher(DepoFetcher): def _get_withdrawals(self) -> list[WithdrawalDetails]: - raise NotImplementedError("_get_withdrawals is a work in progress") + json = self.client.query_private('WithdrawStatus') + results = [] + for v in json['result']: + asset = parse_asset_from_ticker(v['asset']) + results.append(WithdrawalDetails( + withdrawn=fin_defs.AssetAmount(asset, Decimal(v['amount'])), + fee=fin_defs.AssetAmount(asset, Decimal(v['fee'])), + executed_time = datetime.datetime.fromtimestamp(v['time'],tz=datetime.UTC), + raw_details = v, + )) + return results def _get_deposits(self) -> list[DepositDetails]: - raise NotImplementedError("_get_deposits is a work in progress") + json = self.client.query_private('DepositStatus') + results = [] + for v in json['result']: + asset = parse_asset_from_ticker(v['asset']) + results.append(DepositDetails( + deposit=fin_defs.AssetAmount(asset, Decimal(v['amount'])), + fee=fin_defs.AssetAmount(asset, Decimal(v['fee'])), + executed_time = datetime.datetime.fromtimestamp(v['time'],tz=datetime.UTC), + raw_details = v, + )) + return results def _get_historic_spot_orders(self) -> Iterator[TradeOrderDetails]: - raise NotImplementedError("_get_historic_spot_orders is a work in progress") + json = self.client.query_private('ClosedOrders') + for order_id, v in json['result']['closed'].items(): + assert v['descr']['pair'] == 'USDTEUR', 'Only sell USDT for EUR is supported' + assert v['descr']['type'] == 'sell', 'Only sell USDT for EUR is supported' + asset_input = fin_defs.USDT + asset_output = fin_defs.EUR + yield TradeOrderDetails( + input =fin_defs.AssetAmount(asset_input, Decimal(v['vol_exec'])), + output =fin_defs.AssetAmount(asset_output, Decimal(v['cost'])), + fee = fin_defs.AssetAmount(asset_output, Decimal(v['fee'])), + executed_time = datetime.datetime.fromtimestamp(v['closetm'],tz=datetime.UTC), + order_id=order_id, + raw_order_details= v, + ) + del order_id, v def _get_double_registers(self) -> list[DoubleRegister]: double_registers: list[DoubleRegister] = [] diff --git a/test/test_kraken.py b/test/test_kraken.py index abe325b..31795b9 100644 --- a/test/test_kraken.py +++ b/test/test_kraken.py @@ -9,13 +9,40 @@ needs_secrets = pytest.mark.skipif( reason='Secret kraken_USERNAME required', ) - -@needs_secrets -def test_get_depo(): - fetcher = fin_depo.defi_kraken.KrakenDepoFetcher( +def get_fetcher(): + return fin_depo.defi_kraken.KrakenDepoFetcher( secrets.KRAKEN_KEY, secrets.KRAKEN_SECRET, ) - depo = fetcher.get_depo() + +@needs_secrets +def test_get_depo(): + """Can inspect depository.""" + depo = get_fetcher().get_depo() + assert isinstance(depo, fin_depo.data.DepoSingle) + + +@needs_secrets +def test_get_withdrawals(): + withdrawals = get_fetcher()._get_withdrawals() + assert len(withdrawals) > 0 + + +@needs_secrets +def test_get_deposits(): + deposits = get_fetcher()._get_deposits() + assert len(deposits) > 0 + + +@needs_secrets +def test_get_historic_spot_orders(): + orders = get_fetcher()._get_historic_spot_orders() + assert next(orders) + + +@needs_secrets +def test_get_double_registers(): + double_registers = get_fetcher()._get_double_registers() + assert len(double_registers) > 0 diff --git a/test/test_kucoin.py b/test/test_kucoin.py index 4a42eaa..046de14 100644 --- a/test/test_kucoin.py +++ b/test/test_kucoin.py @@ -28,7 +28,7 @@ def get_fetcher() -> fin_depo.defi_kucoin.KucoinDepoFetcher: @needs_secrets def test_get_depo(): - """Can inspect kucoin depository.""" + """Can inspect depository.""" depo = get_fetcher().get_depo() assert isinstance(depo, fin_depo.data.DepoGroup)