From 34253a1ba908cfa5c98e83c9af1a65c8dfe5eae1 Mon Sep 17 00:00:00 2001 From: Pontius Date: Thu, 3 Jan 2013 21:56:48 +0100 Subject: [PATCH 1/2] Use blockchain.info instead of intersango.com for exchange rates (quick hack) --- lib/exchange_rate.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py index 77cbf9b1..36e34fa6 100644 --- a/lib/exchange_rate.py +++ b/lib/exchange_rate.py @@ -28,21 +28,17 @@ class Exchanger(threading.Thread): self.discovery() def discovery(self): - connection = httplib.HTTPSConnection('intersango.com') - connection.request("GET", "/api/ticker.php") + connection = httplib.HTTPSConnection('blockchain.info') + connection.request("GET", "/ticker") response = connection.getresponse() if response.reason == httplib.responses[httplib.NOT_FOUND]: return response = json.loads(response.read()) - # 1 = BTC:GBP - # 2 = BTC:EUR - # 3 = BTC:USD - # 4 = BTC:PLN quote_currencies = {} try: - quote_currencies["GBP"] = self._lookup_rate(response, 1) - quote_currencies["EUR"] = self._lookup_rate(response, 2) - quote_currencies["USD"] = self._lookup_rate(response, 3) + quote_currencies["GBP"] = self._lookup_rate(response, "GBP") + quote_currencies["EUR"] = self._lookup_rate(response, "EUR") + quote_currencies["USD"] = self._lookup_rate(response, "USD") with self.lock: self.quote_currencies = quote_currencies self.parent.emit(SIGNAL("refresh_balance()")) @@ -50,7 +46,7 @@ class Exchanger(threading.Thread): pass def _lookup_rate(self, response, quote_id): - return decimal.Decimal(response[str(quote_id)]["last"]) + return decimal.Decimal(response[str(quote_id)]["24h"]) if __name__ == "__main__": exch = Exchanger(("EUR", "USD", "GBP")) From e590c1cb20b72ef7bd89a50640e8e9485d9d0967 Mon Sep 17 00:00:00 2001 From: Pontius Date: Fri, 4 Jan 2013 10:35:21 +0100 Subject: [PATCH 2/2] Adjusted quote lookup and added three more currencies (where we have translations for) --- lib/exchange_rate.py | 9 ++++----- lib/gui_lite.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py index 36e34fa6..a4137105 100644 --- a/lib/exchange_rate.py +++ b/lib/exchange_rate.py @@ -36,9 +36,8 @@ class Exchanger(threading.Thread): response = json.loads(response.read()) quote_currencies = {} try: - quote_currencies["GBP"] = self._lookup_rate(response, "GBP") - quote_currencies["EUR"] = self._lookup_rate(response, "EUR") - quote_currencies["USD"] = self._lookup_rate(response, "USD") + for r in response: + quote_currencies[r] = self._lookup_rate(response, r) with self.lock: self.quote_currencies = quote_currencies self.parent.emit(SIGNAL("refresh_balance()")) @@ -46,9 +45,9 @@ class Exchanger(threading.Thread): pass def _lookup_rate(self, response, quote_id): - return decimal.Decimal(response[str(quote_id)]["24h"]) + return decimal.Decimal(response[str(quote_id)]["15m"]) if __name__ == "__main__": - exch = Exchanger(("EUR", "USD", "GBP")) + exch = Exchanger(("BRL", "CNY", "EUR", "GBP", "RUB", "USD")) print exch.exchange(1, "EUR") diff --git a/lib/gui_lite.py b/lib/gui_lite.py index c9e06d6a..29897093 100644 --- a/lib/gui_lite.py +++ b/lib/gui_lite.py @@ -197,7 +197,7 @@ class MiniWindow(QDialog): self.actuator = actuator self.config = config self.btc_balance = None - self.quote_currencies = ["EUR", "USD", "GBP"] + self.quote_currencies = ["BRL", "CNY", "EUR", "GBP", "RUB", "USD"] self.actuator.set_configured_currency(self.set_quote_currency) self.exchanger = exchange_rate.Exchanger(self) # Needed because price discovery is done in a different thread