Add historical data for BitcoinAverage (via CSV)

This commit is contained in:
Tim Bellefleur 2015-10-15 14:56:23 -07:00
parent ad198c372b
commit e81814416a

View File

@ -8,6 +8,7 @@ import sys
from threading import Thread from threading import Thread
import time import time
import traceback import traceback
import csv
from decimal import Decimal from decimal import Decimal
from functools import partial from functools import partial
@ -43,6 +44,13 @@ class ExchangeBase(PrintError):
headers={'User-Agent' : 'Electrum'}) headers={'User-Agent' : 'Electrum'})
return response.json() 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): def name(self):
return self.__class__.__name__ return self.__class__.__name__
@ -90,6 +98,17 @@ class BitcoinAverage(ExchangeBase):
return dict([(r, Decimal(json[r]['last'])) return dict([(r, Decimal(json[r]['last']))
for r in json if r != 'timestamp']) 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): class BitcoinVenezuela(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('api.bitcoinvenezuela.com', '/') json = self.get_json('api.bitcoinvenezuela.com', '/')