-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
29 lines (21 loc) · 802 Bytes
/
api.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
import os
import requests
supported_currencies = ['usd', 'eur']
def fetch_wallet_balance(address, currency='usd'):
if currency not in supported_currencies:
raise Exception("Unsupported currency!")
api_url = 'https://api.covalenthq.com'
endpoint = f'/v1/1/address/{address}/balances_v2/'
url = api_url + endpoint
payload = {
"key": os.environ['COVALENT_API_KEY'],
"quote-currency": currency
}
r = requests.get(url, params=payload)
data = r.json()
# We don't need nft data right now
data['data']['items'] = [item for item in data['data']['items'] if item['type'] != 'nft' ]
portfolio_balance = 0.0
for item in data['data']['items']:
portfolio_balance += item['quote']
return data, portfolio_balance