-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchGecko.py
102 lines (57 loc) · 2.19 KB
/
fetchGecko.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
from time import *
import datetime
import json
from geckoFuncz import *
import math
import dateparser
#lambda functions for rounding
ro1, ro2, ro6, ro8 = lambda x : round(x, 1), lambda x : round(x, 2), lambda x : round(x, 6), lambda x : round(x, 8)
# ---
# gecko API request section
# ---
time = datetime.now()
dtRn = str(strftime("%x") + " " + strftime("%X"))
justTime, justDate = strftime("%X"), strftime("%x")
print("\nStarted fetching coin data on: " + str(justDate) + " at: " + str(justTime))
# import symbolName data
symbolNamesInAddr = 'data/symbolNames.json'
with open(symbolNamesInAddr, 'r') as r:
symbolNameDict = json.load(r)
geckoData = getAllTokens(symbolNameDict)
time = datetime.now()
dtRn = str(strftime("%x") + " " + strftime("%X"))
justTime, justDate = strftime("%X"), strftime("%x")
print("\nCompleted fetching coin data on: " + str(justDate) + " at: " + str(justTime))
# ---
# sample stats section
# ---
time = datetime.now()
dtRn = str(strftime("%x") + " " + strftime("%X"))
justTime, justDate = strftime("%X"), strftime("%x")
print("\nStarted creating sample stats on: " + str(justDate) + " at: " + str(justTime))
geckoKeys = list(geckoData.keys())
analyzeAll = analyzeAllTokens(geckoData)
for aDict in analyzeAll:
aDictPair = aDict['pair']
baseKeys = geckoData.keys()
for baseKey in baseKeys:
currentGeckoDict = geckoData[baseKey]
currentGekkoQuote = currentGeckoDict['quote']
currentGekkoBase = currentGeckoDict['base']
currentGekkoPair = str(currentGekkoQuote).capitalize() + str(currentGekkoBase).capitalize()
if aDictPair == currentGekkoPair:
currentGeckoDict.update(aDict)
for geckoKey in geckoKeys:
currentGdict = geckoData[geckoKey]
stdDev = stdDevFunc(currentGdict)
currentGdict.update({'stdDev': stdDev})
time = datetime.now()
dtRn = str(strftime("%x") + " " + strftime("%X"))
justTime, justDate = strftime("%X"), strftime("%x")
print("\nCompleted creating sample stats on: " + str(justDate) + " at: " + str(justTime))
jsonOutAddr = 'data/geckoAnalysis.json'
try:
with open(jsonOutAddr, 'w') as fp1: json.dump(geckoData, fp1)
print("\nSuccess saving JSON file at: " + str(jsonOutAddr) + '\n')
except Exception as e: print(e)