From 63bffd9c6382b44296957f4405b1852eff15f531 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 17 May 2024 00:24:01 +0200 Subject: [PATCH] Kucoin account information --- README.md | 2 +- personal_data/fetchers/kucoin.py | 51 +++++++++++++++++++ personal_data/fetchers/partisia_blockchain.py | 1 + personal_data/main.py | 1 + personal_data/secrets.py | 5 ++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 personal_data/fetchers/kucoin.py diff --git a/README.md b/README.md index 2272ca6..139d5f6 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Supported fetchers: - FFXIV Lodestone achivement history - Partisia Blockchain BYOC and MPC trackers - Playstation achievements by way of PSN Profiles. +- [Kraken Account Balances](https://docs.kraken.com/rest/#tag/Account-Data/operation/getAccountBalance) ## Usage @@ -22,7 +23,6 @@ python -m personal_data - [ ] fredagscafeen.dk - [ ] [WaniKani](https://docs.api.wanikani.com) - [ ] Ledger (Live?) Account Balances -- [ ] Kraken Account Balances: https://docs.kraken.com/rest/#tag/Account-Data/operation/getAccountBalance - [ ] Kucoin Account Balances: https://www.kucoin.com/docs/rest/account/basic-info/get-account-list-spot-margin-trade_hf ## License diff --git a/personal_data/fetchers/kucoin.py b/personal_data/fetchers/kucoin.py new file mode 100644 index 0000000..64be6f7 --- /dev/null +++ b/personal_data/fetchers/kucoin.py @@ -0,0 +1,51 @@ +import dataclasses +import datetime +import email.utils +import json +from frozendict import frozendict +import logging +from collections.abc import Iterator, Mapping +from decimal import Decimal + +from frozendict import frozendict + +from personal_data.data import DeduplicateMode, Scraper + +from .. import secrets + +import kucoin.client + +logger = logging.getLogger(__name__) + + +HOSTNAME = 'api.kucoin.com' +URL_ACCOUNTS = 'https://{hostname}/api/v1/accounts' + +# TODO: Move these into secrets! +client = kucoin.client.Client( + secrets.KUCOIN_KEY, + secrets.KUCOIN_SECRET, + secrets.KUCOIN_PASS, +) + + +@dataclasses.dataclass(frozen=True) +class KucoinAccountBalances(Scraper): + dataset_name = 'defi_kucoin_balance' + deduplicate_mode = DeduplicateMode.ONLY_LATEST + deduplicate_ignore_columns = ['account.update_time'] + + def scrape(self) -> Iterator[Mapping[str, object]]: + time = datetime.datetime.now() + for account in client.get_accounts(): + print(account) + + data_point = { + 'account.id': account['id'], + 'account.currency': account['currency'], + 'account.type': account['type'], + 'account.balance': account['balance'], + 'account.update_time': time, + } + + yield frozendict(data_point) diff --git a/personal_data/fetchers/partisia_blockchain.py b/personal_data/fetchers/partisia_blockchain.py index 25a1fd8..fa5d43f 100644 --- a/personal_data/fetchers/partisia_blockchain.py +++ b/personal_data/fetchers/partisia_blockchain.py @@ -26,6 +26,7 @@ URL_ACCOUNT_PLUGIN_GLOBAL = 'https://{hostname}/{shard}blockchain/accountPlugin/ MPC_DECIMALS = 10000 + def shard_id_for_address(address: str) -> str: return 'shards/Shard2/' # TODO diff --git a/personal_data/main.py b/personal_data/main.py index 418b83e..817866c 100644 --- a/personal_data/main.py +++ b/personal_data/main.py @@ -29,6 +29,7 @@ import personal_data.fetchers.crunchyroll import personal_data.fetchers.ffxiv_lodestone import personal_data.fetchers.partisia_blockchain import personal_data.fetchers.psnprofiles +import personal_data.fetchers.kucoin from . import mailgun diff --git a/personal_data/secrets.py b/personal_data/secrets.py index 457a2b7..6bcd2c1 100644 --- a/personal_data/secrets.py +++ b/personal_data/secrets.py @@ -34,6 +34,11 @@ PLAYSTATION_PSN_ID = load_secret('PLAYSTATION_PSN_ID') # Partisia Blockchain PBC_ACCOUNT_ADDRESS = load_secret('PBC_ACCOUNT_ADDRESS') +# Kucoin +KUCOIN_KEY = load_secret('KUCOIN_KEY') +KUCOIN_SECRET = load_secret('KUCOIN_SECRET') +KUCOIN_PASS = load_secret('KUCOIN_PASS') + # Email configuration MAILGUN_API_KEY = load_secret('MAILGUN_API_KEY') MAILGUN_DOMAIN = load_secret('MAILGUN_DOMAIN')