7 def __init__(self, quote_currencies, refresh_balance):
8 self.refresh_balance = refresh_balance
9 self.quote_currencies = {}
11 def exchange(self, btc_amount, quote_currency):
12 return btc_amount * self.quote_currencies[quote_currency]
15 connection = httplib.HTTPSConnection('intersango.com')
16 connection.request("GET", "/api/ticker.php")
17 response = connection.getresponse()
18 if response.status == 404:
20 response = json.loads(response.read())
26 self.quote_currencies["GBP"] = self.lookup_rate(response, 1)
27 self.quote_currencies["EUR"] = self.lookup_rate(response, 2)
28 self.quote_currencies["USD"] = self.lookup_rate(response, 3)
29 self.refresh_balance()
33 def lookup_rate(self, response, quote_id):
34 return decimal.Decimal(response[str(quote_id)]["last"])
36 if __name__ == "__main__":
37 exch = Exchanger(("EUR", "USD", "GBP"))
38 print exch.exchange(1, "EUR")