Merge pull request #78 from pontius/master

Use blockchain.info instead of intersango.com for exchange rates
This commit is contained in:
ThomasV 2013-01-04 01:56:39 -08:00
commit 5bf144c7b8
2 changed files with 7 additions and 12 deletions

View File

@ -28,21 +28,16 @@ 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)
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()"))
@ -50,9 +45,9 @@ 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)]["15m"])
if __name__ == "__main__":
exch = Exchanger(("EUR", "USD", "GBP"))
exch = Exchanger(("BRL", "CNY", "EUR", "GBP", "RUB", "USD"))
print exch.exchange(1, "EUR")

View File

@ -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