1
0

Kraken now supports double registers

This commit is contained in:
Jon Michael Aanes 2024-12-22 04:48:31 +01:00
parent a909d662ca
commit e4f73342a1
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 72 additions and 9 deletions

View File

@ -3,11 +3,13 @@
import datetime import datetime
import logging import logging
from decimal import Decimal from decimal import Decimal
from collections.abc import Iterator
import fin_defs import fin_defs
import krakenex import krakenex
from .data import ( from .data import (
Depo,
DepoFetcher, DepoFetcher,
DepoSingle, DepoSingle,
DepositDetails, DepositDetails,
@ -64,13 +66,47 @@ class KrakenDepoFetcher(DepoFetcher):
def _get_withdrawals(self) -> list[WithdrawalDetails]: 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]: 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]: 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]: def _get_double_registers(self) -> list[DoubleRegister]:
double_registers: list[DoubleRegister] = [] double_registers: list[DoubleRegister] = []

View File

@ -9,13 +9,40 @@ needs_secrets = pytest.mark.skipif(
reason='Secret kraken_USERNAME required', reason='Secret kraken_USERNAME required',
) )
def get_fetcher():
@needs_secrets return fin_depo.defi_kraken.KrakenDepoFetcher(
def test_get_depo():
fetcher = fin_depo.defi_kraken.KrakenDepoFetcher(
secrets.KRAKEN_KEY, secrets.KRAKEN_KEY,
secrets.KRAKEN_SECRET, 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) 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

View File

@ -28,7 +28,7 @@ def get_fetcher() -> fin_depo.defi_kucoin.KucoinDepoFetcher:
@needs_secrets @needs_secrets
def test_get_depo(): def test_get_depo():
"""Can inspect kucoin depository.""" """Can inspect depository."""
depo = get_fetcher().get_depo() depo = get_fetcher().get_depo()
assert isinstance(depo, fin_depo.data.DepoGroup) assert isinstance(depo, fin_depo.data.DepoGroup)