From a72bc5a44ada945bb5fe9a0239829018e2bea8d4 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Tue, 22 Jul 2014 17:06:23 -0400 Subject: [PATCH 1/2] Update exchange rate plugin for Winkdex updated exchange rate BTC price for Winkdex API that was officially published --- plugins/exchange_rate.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index f8713a78..68db2304 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -48,7 +48,7 @@ class Exchanger(threading.Thread): def get_json(self, site, get_string): try: connection = httplib.HTTPSConnection(site) - connection.request("GET", get_string) + connection.request("GET", get_string, headers={"User-Agent":"Electrum"}) except Exception: raise resp = connection.getresponse() @@ -123,16 +123,13 @@ class Exchanger(threading.Thread): def update_wd(self): try: - winkresp = self.get_json('winkdex.com', "/static/data/0_600_288.json") - ####could need nonce value in GET, no Docs available + winkresp = self.get_json('winkdex.com', "/api/v0/price") except Exception: return quote_currencies = {"USD": 0.0} - ####get y of highest x in "prices" - lenprices = len(winkresp["prices"]) - usdprice = winkresp["prices"][lenprices-1]["y"] + usdprice = decimal.Decimal(str(winkresp["price"]))/decimal.Decimal("100.0") try: - quote_currencies["USD"] = decimal.Decimal(str(usdprice)) + quote_currencies["USD"] = usdprice with self.lock: self.quote_currencies = quote_currencies except KeyError: From 9ae30533ca77849a213a28378f4c467d9dc68ec0 Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Tue, 22 Jul 2014 17:28:37 -0400 Subject: [PATCH 2/2] update historical winkdex api --- plugins/exchange_rate.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 68db2304..5c227e95 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -423,7 +423,7 @@ class Plugin(BasePlugin): return elif cur_exchange == "Winkdex": 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: return elif cur_exchange == "BitcoinVenezuela": @@ -464,12 +464,14 @@ class Plugin(BasePlugin): except KeyError: tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(str(tx_info['value']))/100000000 , "USD") 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: - tx_rate = resp_hist[[x['x'] for x in resp_hist].index(tx_time_str)]['y'] - tx_USD_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(tx_rate), "USD") + 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)/Decimal("100.0"), "USD") except ValueError: 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": tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') try: