-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportfolio-tracker.py
executable file
·55 lines (36 loc) · 1.38 KB
/
portfolio-tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
from dotenv import load_dotenv
import os
from botweb3lib import BlockchainAccess
# Load environment variables from the .env file
load_dotenv()
dry_run = True
wallet = os.getenv("WALLET")
print(f"Wallet: {wallet}")
# Load blockchain configuration
BlockchainAccess.load_config()
class TokenBalance:
def __init__(self, blockchain_access, token_name, wallet):
self._blockchain_access = blockchain_access
self.token_name = token_name
self.wallet = wallet
self.balance = self._fetch_balance()
def _fetch_balance(self):
"""Fetch the balance of the token for the given wallet."""
return self._blockchain_access.check_balance([self.token_name], self.wallet)[self.token_name]
def __str__(self):
return f"{self.token_name} @ {self._blockchain_access.get_chain()}: {self.balance}"
def __lt__(self, other):
"""Define sorting by balance value."""
return self.balance < other.balance
balances = []
def print_balances(chain):
for token_balance in balances:
print(token_balance)
# Iterate over supported chains
for chain in ["polygon", "optimism"]:
blockchain_access = BlockchainAccess(chain, dry_run)
tokens = blockchain_access.get_all_tokens()
balances += [TokenBalance(blockchain_access, token, wallet) for token in tokens]
balances.sort(reverse=True)
print_balances(chain)