-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcryptapi.py
More file actions
148 lines (100 loc) · 3.04 KB
/
Copy pathcryptapi.py
File metadata and controls
148 lines (100 loc) · 3.04 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import requests
CRYPTAPI_URL = 'https://api.cryptapi.io/'
BLOCKBEE_URL = 'https://api.blockbee.io/'
CRYPTAPI_HOST = 'api.cryptapi.io'
BLOCKBEE_HOST = 'api.blockbee.io'
def get_info(coin=''):
_info = process_request(coin, endpoint='info')
if _info:
return _info
return None
def get_supported_coins():
_info = get_info('')
_info.pop('fee_tiers', None)
_coins = {}
for ticker, coin_info in _info.items():
if 'coin' in coin_info.keys():
_coins[ticker] = coin_info['coin']
else:
for token, token_info in coin_info.items():
_coins[ticker + '_' + token] = token_info['coin'] + ' (' + ticker.upper() + ')'
return _coins
def get_logs(coin, callback_url):
if coin is None or callback_url is None:
return None
params = {
'callback': callback_url
}
_logs = process_request(coin, endpoint='logs', params=params)
if _logs:
return _logs
return None
def get_qrcode(coin, address, value='', size=300):
if coin is None:
return None
params = {
'address': address,
'size': size
}
if value:
params = {
'address': address,
'size': size,
'value': value
}
_qrcode = process_request(coin, endpoint='qrcode', params=params)
if _qrcode:
return _qrcode
return None
def get_conversion(origin, to, value):
params = {
'from': origin,
'to': to,
'value': value
}
_value = process_request('', endpoint='convert', params=params)
if _value:
return _value
return None
def get_estimate(coin):
params = {
'addresses': 1, # Change this according your number of addresses
'priority': 'default' # Change this according the priority you want to define
}
_estimate = process_request(coin, endpoint='estimate', params=params)
if _estimate:
return _estimate
return None
def get_address(coin, params):
_address = process_request(coin, endpoint='create', params=params)
if _address:
return _address
return None
def process_request(coin='', endpoint='', params=None):
if coin != '':
coin += '/'
if params is not None and 'apikey' in params:
response = requests.get(
url="{base_url}{coin}{endpoint}/".format(
base_url=BLOCKBEE_URL,
coin=coin.replace('_', '/'),
endpoint=endpoint,
),
params=params,
headers={'Host': BLOCKBEE_HOST},
)
else:
response = requests.get(
url="{base_url}{coin}{endpoint}/".format(
base_url=CRYPTAPI_URL,
coin=coin.replace('_', '/'),
endpoint=endpoint,
),
params=params,
headers={'Host': CRYPTAPI_HOST},
)
url = response.url
response = response.json()
if endpoint == 'create':
response['raw_request_url'] = url # For debugging purposes
return response