forked from DarrenWestwood/greed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockonomics.py
32 lines (30 loc) · 1.09 KB
/
blockonomics.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
import configloader
import requests
# Define all the database tables using the sqlalchemy declarative base
class Blockonomics:
def fetch_new_btc_price():
url = 'https://www.blockonomics.co/api/price'
params = {'currency':configloader.config["Payments"]["currency"]}
r = requests.get(url,params)
if r.status_code == 200:
price = r.json()['price']
print ('Bitcoin price ' + str(price))
return price
else:
print(r.status_code, r.text)
def new_address(reset=False):
api_key = configloader.config["Bitcoin"]["api_key"]
secret = configloader.config["Bitcoin"]["secret"]
url = 'https://www.blockonomics.co/api/new_address'
if reset == True:
url += '?match_callback='+secret+'&reset=1'
else:
url += "?match_callback=" + secret
headers = {'Authorization': "Bearer " + api_key}
print(url)
r = requests.post(url, headers=headers)
if r.status_code == 200:
return r
else:
print(r.status_code, r.text)
return r