Kraken account balance implemented
This commit is contained in:
parent
8a9f8bf5e8
commit
56a68b5119
44
personal_data/fetchers/defi_kraken.py
Normal file
44
personal_data/fetchers/defi_kraken.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import dataclasses
|
||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
from collections.abc import Iterator, Mapping
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
import krakenex
|
||||||
|
from frozendict import frozendict
|
||||||
|
|
||||||
|
from personal_data.data import DeduplicateMode, Scraper
|
||||||
|
|
||||||
|
from .. import secrets
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# TODO: Move these into secrets!
|
||||||
|
client = krakenex.API(
|
||||||
|
secrets.KRAKEN_KEY,
|
||||||
|
secrets.KRAKEN_SECRET,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass(frozen=True)
|
||||||
|
class KrakenAccountBalances(Scraper):
|
||||||
|
dataset_name = 'defi_kraken_balance'
|
||||||
|
deduplicate_mode = DeduplicateMode.ONLY_LATEST
|
||||||
|
deduplicate_ignore_columns = ['account.update_time']
|
||||||
|
|
||||||
|
def scrape(self) -> Iterator[Mapping[str, object]]:
|
||||||
|
data_point = {
|
||||||
|
'account.update_time': datetime.datetime.now(tz=datetime.UTC),
|
||||||
|
}
|
||||||
|
|
||||||
|
result = client.query_private('Balance')
|
||||||
|
|
||||||
|
for account, balance_str in result['result'].items():
|
||||||
|
key = f'balance.{account}'
|
||||||
|
balance = Decimal(balance_str)
|
||||||
|
balance = balance if balance != 0 else Decimal(0)
|
||||||
|
data_point[key] = data_point.get(key, Decimal(0)) + balance
|
||||||
|
del key, balance
|
||||||
|
|
||||||
|
yield frozendict(data_point)
|
||||||
|
|
|
@ -14,9 +14,6 @@ from .. import secrets
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
HOSTNAME = 'api.kucoin.com'
|
|
||||||
URL_ACCOUNTS = 'https://{hostname}/api/v1/accounts'
|
|
||||||
|
|
||||||
# TODO: Move these into secrets!
|
# TODO: Move these into secrets!
|
||||||
client = kucoin.client.Client(
|
client = kucoin.client.Client(
|
||||||
secrets.KUCOIN_KEY,
|
secrets.KUCOIN_KEY,
|
|
@ -39,6 +39,10 @@ KUCOIN_KEY = load_secret('KUCOIN_KEY')
|
||||||
KUCOIN_SECRET = load_secret('KUCOIN_SECRET')
|
KUCOIN_SECRET = load_secret('KUCOIN_SECRET')
|
||||||
KUCOIN_PASS = load_secret('KUCOIN_PASS')
|
KUCOIN_PASS = load_secret('KUCOIN_PASS')
|
||||||
|
|
||||||
|
# KRAKEN
|
||||||
|
KRAKEN_KEY = load_secret('KRAKEN_KEY')
|
||||||
|
KRAKEN_SECRET = load_secret('KRAKEN_SECRET')
|
||||||
|
|
||||||
# Email configuration
|
# Email configuration
|
||||||
MAILGUN_API_KEY = load_secret('MAILGUN_API_KEY')
|
MAILGUN_API_KEY = load_secret('MAILGUN_API_KEY')
|
||||||
MAILGUN_DOMAIN = load_secret('MAILGUN_DOMAIN')
|
MAILGUN_DOMAIN = load_secret('MAILGUN_DOMAIN')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user