-
Notifications
You must be signed in to change notification settings - Fork 4
/
resolvers.py
79 lines (55 loc) · 2.06 KB
/
resolvers.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
# import packages
import pandas as pd
from typing import Dict, Any, Union
class RESOLVERS:
"""
A class used to resolve (format) GraphQL API responses into a Python list
or Pandas DataFrame from HashrateIndex API.
Methods
-------
""
"""
def __init__(self, df: bool = False):
"""
Parameters
----------
df : boolean
A boolean flag that determines the output of each method. Default = True.
"""
self.df = df
def resolve_get_bitcoin_overview(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['bitcoinOverviews']['nodes']
if self.df:
return pd.DataFrame(data)
else:
return data
def resolve_get_hashprice(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['getHashprice']['nodes']
if self.df:
return pd.DataFrame(data)
else:
return data
def resolve_get_network_hashrate(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['getNetworkHashrate']['nodes']
if self.df:
return pd.DataFrame(data)
else:
return data
def resolve_get_network_difficulty(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['getChartBySlug']['data']
if self.df:
return pd.DataFrame(data)
else:
return data
def resolve_get_ohlc_prices(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['getChartBySlug']['data']
if self.df:
return pd.DataFrame(data)
else:
return data
def resolve_get_asic_price_index(self, json: Dict[str, Any]) -> Union[list, pd.DataFrame]:
data = json['data']['getChartBySlug']['data']
if self.df:
return pd.DataFrame(data)
else:
return data