-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestManager.py
More file actions
37 lines (26 loc) · 1.06 KB
/
RequestManager.py
File metadata and controls
37 lines (26 loc) · 1.06 KB
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
import requests
import json
from datetime import datetime
from math import ceil
class RequestManager:
def getPrices(config):
key = config["key"]
symbols = list(sorted(config["crypto"].keys()))
params = ",".join(symbols)
url = ' https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=' + params
headers = {'Accepts': 'application/json', 'X-CMC_PRO_API_KEY': key}
request = requests.get(url, headers = headers)
data = json.loads(request.text)
total = 0
date = datetime.today().strftime("%m/%d/%y")
values = [date]
for symbol in symbols:
price = data["data"][symbol]["quote"]["USD"]["price"]
amount = config["crypto"][symbol]
value = ceil(amount * price * 100) / 100.0
total += amount * price #Don't want to round total until everything is added up
values += [value]
total = ceil(total * 100) / 100.0
values += [total]
titles = [""] + symbols + ["TOTAL"]
return (titles, values)