Merge pull request #766 from wozz/winkdex
Update exchange rate plugin for Winkdex
This commit is contained in:
commit
ab41c6f940
|
@ -48,7 +48,7 @@ class Exchanger(threading.Thread):
|
||||||
def get_json(self, site, get_string):
|
def get_json(self, site, get_string):
|
||||||
try:
|
try:
|
||||||
connection = httplib.HTTPSConnection(site)
|
connection = httplib.HTTPSConnection(site)
|
||||||
connection.request("GET", get_string)
|
connection.request("GET", get_string, headers={"User-Agent":"Electrum"})
|
||||||
except Exception:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
resp = connection.getresponse()
|
resp = connection.getresponse()
|
||||||
|
@ -123,16 +123,13 @@ class Exchanger(threading.Thread):
|
||||||
|
|
||||||
def update_wd(self):
|
def update_wd(self):
|
||||||
try:
|
try:
|
||||||
winkresp = self.get_json('winkdex.com', "/static/data/0_600_288.json")
|
winkresp = self.get_json('winkdex.com', "/api/v0/price")
|
||||||
####could need nonce value in GET, no Docs available
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"USD": 0.0}
|
quote_currencies = {"USD": 0.0}
|
||||||
####get y of highest x in "prices"
|
usdprice = decimal.Decimal(str(winkresp["price"]))/decimal.Decimal("100.0")
|
||||||
lenprices = len(winkresp["prices"])
|
|
||||||
usdprice = winkresp["prices"][lenprices-1]["y"]
|
|
||||||
try:
|
try:
|
||||||
quote_currencies["USD"] = decimal.Decimal(str(usdprice))
|
quote_currencies["USD"] = usdprice
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.quote_currencies = quote_currencies
|
self.quote_currencies = quote_currencies
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -426,7 +423,7 @@ class Plugin(BasePlugin):
|
||||||
return
|
return
|
||||||
elif cur_exchange == "Winkdex":
|
elif cur_exchange == "Winkdex":
|
||||||
try:
|
try:
|
||||||
resp_hist = self.exchanger.get_json('winkdex.com', "/static/data/0_86400_730.json")['prices']
|
resp_hist = self.exchanger.get_json('winkdex.com', "/api/v0/series?start_time=1342915200")['series'][0]['results']
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
elif cur_exchange == "BitcoinVenezuela":
|
elif cur_exchange == "BitcoinVenezuela":
|
||||||
|
@ -467,12 +464,14 @@ class Plugin(BasePlugin):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/100000000 , "USD")
|
tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/100000000 , "USD")
|
||||||
elif cur_exchange == "Winkdex":
|
elif cur_exchange == "Winkdex":
|
||||||
tx_time_str = int(tx_time) - (int(tx_time) % (60 * 60 * 24))
|
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') + "T16:00:00-04:00"
|
||||||
try:
|
try:
|
||||||
tx_rate = resp_hist[[x['x'] for x in resp_hist].index(tx_time_str)]['y']
|
tx_rate = resp_hist[[x['timestamp'] for x in resp_hist].index(tx_time_str)]['price']
|
||||||
tx_USD_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(tx_rate), "USD")
|
tx_USD_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(tx_rate)/Decimal("100.0"), "USD")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/100000000 , "USD")
|
tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/100000000 , "USD")
|
||||||
|
except KeyError:
|
||||||
|
tx_USD_val = _("No data")
|
||||||
elif cur_exchange == "BitcoinVenezuela":
|
elif cur_exchange == "BitcoinVenezuela":
|
||||||
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d')
|
tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d')
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue