1
0

Kucoin use fin_depo

This commit is contained in:
Jon Michael Aanes 2024-06-02 17:42:16 +02:00
parent 9a1900b5d4
commit 526e5eee02
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 17 additions and 8 deletions

View File

@ -6,6 +6,7 @@ from decimal import Decimal
import kucoin.client import kucoin.client
from frozendict import frozendict from frozendict import frozendict
from fin_depo.defi_kucoin import KucoinDepoFetcher
from personal_data.data import DeduplicateMode, Scraper from personal_data.data import DeduplicateMode, Scraper
@ -21,7 +22,6 @@ client = kucoin.client.Client(
secrets.KUCOIN_PASS, secrets.KUCOIN_PASS,
) )
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class KucoinAccountBalances(Scraper): class KucoinAccountBalances(Scraper):
dataset_name = 'defi_kucoin_balance' dataset_name = 'defi_kucoin_balance'
@ -29,20 +29,28 @@ class KucoinAccountBalances(Scraper):
deduplicate_ignore_columns = ['account.update_time'] deduplicate_ignore_columns = ['account.update_time']
def scrape(self) -> Iterator[Mapping[str, object]]: 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 = { data_point = {
'account.update_time': datetime.datetime.now(tz=datetime.UTC), 'account.update_time': depo.updated_time,
} }
for account in client.get_accounts(): for asset in depo.assets():
key = f"balance.{account['currency']}" key = f"balance.{asset}"
data_point[key] = data_point.get(key, Decimal(0)) + Decimal( data_point[key] = depo.get_amount_of_asset(asset)
account['balance'],
) print(data_point)
yield frozendict(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 = {}
data_point['account.update_time'] = datetime.datetime.now(tz=datetime.UTC) data_point['account.update_time'] = datetime.datetime.now(tz=datetime.UTC)
data_point['account.num_deposit_addresses'] = len(addresses) data_point['account.num_deposit_addresses'] = len(addresses)

View File

@ -7,3 +7,4 @@ cfscrape
frozendict frozendict
python-kucoin python-kucoin
krakenex krakenex
fin-depo