1
0
personal-data/personal_data/fetchers/defi_kucoin.py
Jon Michael Aanes fd8734b80a
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 34s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 30s
Fixed Kucoin address checker
2024-11-27 00:24:12 +01:00

45 lines
1.2 KiB
Python

import dataclasses
import datetime
import logging
from collections.abc import Iterator, Mapping
import kucoin.client
from frozendict import frozendict
from personal_data.data import DeduplicateMode, Scraper
from .. import secrets
logger = logging.getLogger(__name__)
def get_client():
return kucoin.client.Client(
secrets.kucoin_key(),
secrets.kucoin_secret(),
secrets.kucoin_pass(),
)
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)
if len(addresses) > 0:
for k, v in addresses[-1].items():
data_point[f'deposit.{k}'] = v
return frozendict(data_point)
@dataclasses.dataclass(frozen=True)
class KucoinDepositAddresses(Scraper):
dataset_name = 'defi_kucoin_deposit_address'
deduplicate_mode = DeduplicateMode.ONLY_LATEST
deduplicate_ignore_columns = ['account.update_time']
def scrape(self) -> Iterator[Mapping[str, object]]:
addresses = get_client().get_deposit_address('MPC')
yield addresses_to_data_points(addresses)