From 526e5eee023b3c7aa08fcab4d41ccc18199efdc5 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 2 Jun 2024 17:42:16 +0200 Subject: [PATCH] Kucoin use fin_depo --- personal_data/fetchers/defi_kucoin.py | 24 ++++++++++++++++-------- requirements.txt | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/personal_data/fetchers/defi_kucoin.py b/personal_data/fetchers/defi_kucoin.py index b88b1d9..15f7fe1 100644 --- a/personal_data/fetchers/defi_kucoin.py +++ b/personal_data/fetchers/defi_kucoin.py @@ -6,6 +6,7 @@ from decimal import Decimal import kucoin.client from frozendict import frozendict +from fin_depo.defi_kucoin import KucoinDepoFetcher from personal_data.data import DeduplicateMode, Scraper @@ -21,7 +22,6 @@ client = kucoin.client.Client( secrets.KUCOIN_PASS, ) - @dataclasses.dataclass(frozen=True) class KucoinAccountBalances(Scraper): dataset_name = 'defi_kucoin_balance' @@ -29,20 +29,28 @@ class KucoinAccountBalances(Scraper): deduplicate_ignore_columns = ['account.update_time'] def scrape(self) -> Iterator[Mapping[str, object]]: + fetcher = KucoinDepoFetcher( + kucoin_key = secrets.KUCOIN_KEY, + kucoin_secret = secrets.KUCOIN_SECRET, + kucoin_pass = secrets.KUCOIN_PASS, + ) + + depo = fetcher.get_depo() + data_point = { - 'account.update_time': datetime.datetime.now(tz=datetime.UTC), + 'account.update_time': depo.updated_time, } - for account in client.get_accounts(): - key = f"balance.{account['currency']}" - data_point[key] = data_point.get(key, Decimal(0)) + Decimal( - account['balance'], - ) + for asset in depo.assets(): + key = f"balance.{asset}" + data_point[key] = depo.get_amount_of_asset(asset) + + print(data_point) yield frozendict(data_point) -def addresses_to_data_points(addresses) -> frozendict: +def addresses_to_data_points(addresses: list[dict[str,str]]) -> frozendict: data_point = {} data_point['account.update_time'] = datetime.datetime.now(tz=datetime.UTC) data_point['account.num_deposit_addresses'] = len(addresses) diff --git a/requirements.txt b/requirements.txt index c1784cd..d5d6cc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ cfscrape frozendict python-kucoin krakenex +fin-depo