From 80bf9952e8b5a2de616639a8d4cd8d541db82ef3 Mon Sep 17 00:00:00 2001 From: Tim Bellefleur Date: Thu, 15 Oct 2015 13:10:00 -0700 Subject: [PATCH 1/3] Fix method call to BitcoinAverage --- plugins/exchange_rate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 0ecaf29c..25603c76 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -85,7 +85,7 @@ class ExchangeBase(PrintError): class BitcoinAverage(ExchangeBase): - def update(self, ccy): + def get_rates(self, ccy): json = self.get_json('api.bitcoinaverage.com', '/ticker/global/all') return dict([(r, Decimal(json[r]['last'])) for r in json if r != 'timestamp']) From ad198c372bb3c5eda748d59c5122dc98084aa902 Mon Sep 17 00:00:00 2001 From: Tim Bellefleur Date: Thu, 15 Oct 2015 13:10:15 -0700 Subject: [PATCH 2/3] Add BitStamp to exchange rate options. --- plugins/exchange_rate.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 25603c76..df1323f9 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -130,6 +130,11 @@ class BitPay(ExchangeBase): json = self.get_json('bitpay.com', '/api/rates') return dict([(r['code'], Decimal(r['rate'])) for r in json]) +class BitStamp(ExchangeBase): + def get_rates(self, ccy): + json = self.get_json('www.bitstamp.net', '/api/ticker/') + return {'USD': Decimal(json['last'])} + class BlockchainInfo(ExchangeBase): def get_rates(self, ccy): json = self.get_json('blockchain.info', '/ticker') From e81814416a5e1687787181beee0493828c7fba4d Mon Sep 17 00:00:00 2001 From: Tim Bellefleur Date: Thu, 15 Oct 2015 14:56:23 -0700 Subject: [PATCH 3/3] Add historical data for BitcoinAverage (via CSV) --- plugins/exchange_rate.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index df1323f9..4ad6b655 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -8,6 +8,7 @@ import sys from threading import Thread import time import traceback +import csv from decimal import Decimal from functools import partial @@ -43,6 +44,13 @@ class ExchangeBase(PrintError): headers={'User-Agent' : 'Electrum'}) return response.json() + def get_csv(self, site, get_string): + url = "".join([self.protocol(), '://', site, get_string]) + response = requests.request('GET', url, + headers={'User-Agent' : 'Electrum'}) + reader = csv.DictReader(response.content.split('\n')) + return list(reader) + def name(self): return self.__class__.__name__ @@ -90,6 +98,17 @@ class BitcoinAverage(ExchangeBase): return dict([(r, Decimal(json[r]['last'])) for r in json if r != 'timestamp']) + def history_ccys(self): + return ['AUD', 'BRL', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'IDR', 'ILS', + 'MXN', 'NOK', 'NZD', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'USD', + 'ZAR'] + + def historical_rates(self, ccy): + history = self.get_csv('api.bitcoinaverage.com', + "/history/%s/per_day_all_time_history.csv" % ccy) + return dict([(h['datetime'][:10], h['average']) + for h in history]) + class BitcoinVenezuela(ExchangeBase): def get_rates(self, ccy): json = self.get_json('api.bitcoinvenezuela.com', '/')