Use blockchain.info instead of intersango.com for exchange rates (quick hack)

This commit is contained in:
Pontius 2013-01-03 21:56:48 +01:00
parent e3fc19c48c
commit 34253a1ba9
1 changed files with 6 additions and 10 deletions

View File

@ -28,21 +28,17 @@ class Exchanger(threading.Thread):
self.discovery() self.discovery()
def discovery(self): def discovery(self):
connection = httplib.HTTPSConnection('intersango.com') connection = httplib.HTTPSConnection('blockchain.info')
connection.request("GET", "/api/ticker.php") connection.request("GET", "/ticker")
response = connection.getresponse() response = connection.getresponse()
if response.reason == httplib.responses[httplib.NOT_FOUND]: if response.reason == httplib.responses[httplib.NOT_FOUND]:
return return
response = json.loads(response.read()) response = json.loads(response.read())
# 1 = BTC:GBP
# 2 = BTC:EUR
# 3 = BTC:USD
# 4 = BTC:PLN
quote_currencies = {} quote_currencies = {}
try: try:
quote_currencies["GBP"] = self._lookup_rate(response, 1) quote_currencies["GBP"] = self._lookup_rate(response, "GBP")
quote_currencies["EUR"] = self._lookup_rate(response, 2) quote_currencies["EUR"] = self._lookup_rate(response, "EUR")
quote_currencies["USD"] = self._lookup_rate(response, 3) quote_currencies["USD"] = self._lookup_rate(response, "USD")
with self.lock: with self.lock:
self.quote_currencies = quote_currencies self.quote_currencies = quote_currencies
self.parent.emit(SIGNAL("refresh_balance()")) self.parent.emit(SIGNAL("refresh_balance()"))
@ -50,7 +46,7 @@ class Exchanger(threading.Thread):
pass pass
def _lookup_rate(self, response, quote_id): 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__": if __name__ == "__main__":
exch = Exchanger(("EUR", "USD", "GBP")) exch = Exchanger(("EUR", "USD", "GBP"))