commit 67bc6da7947a80800b4363f7050d32a4eafe089d
parent 6bd191966e2ddf389147e7003013f996816fb8d8
Author: Neil <kyuupichan@gmail.com>
Date: Fri, 16 Oct 2015 10:27:17 +0900
Merge pull request #1481 from nomoon/exchange_rate_fixes
Exchange rate fixes
Diffstat:
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git 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__
@@ -85,11 +93,22 @@ 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'])
+ 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', '/')
@@ -130,6 +149,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')