-
Notifications
You must be signed in to change notification settings - Fork 6
/
cmc.py
30 lines (23 loc) · 775 Bytes
/
cmc.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
import urllib
import json
from utils import utils
from decimal import *
grlcpriceurl = 'https://api.coinmarketcap.com/v1/ticker/garlicoin/'
dashpriceurl = 'https://api.coinmarketcap.com/v1/ticker/dash/'
utils = utils()
cursor = utils.get_mysql_cursor()
sql = "TRUNCATE TABLE rates"
cursor.execute(sql)
response = urllib.urlopen(grlcpriceurl)
data = json.loads(response.read())
grlcprice = round(Decimal(data[0]['price_usd']),8)
response = urllib.urlopen(dashpriceurl)
data = json.loads(response.read())
dashprice = round(Decimal(data[0]['price_usd']),8)
sql = "INSERT INTO rates (pair,rate) VALUES (%s, %s)"
pair = "GRLC/DASH"
rate = grlcprice/dashprice
cursor.execute(sql, (pair,rate,))
pair = "DASH/GRLC"
rate = dashprice/grlcprice
cursor.execute(sql, (pair,rate,))