Merge pull request #1481 from nomoon/exchange_rate_fixes
Exchange rate fixes
This commit is contained in:
commit
67bc6da794
|
@ -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__
|
||||||
|
|
||||||
|
@ -85,11 +93,22 @@ class ExchangeBase(PrintError):
|
||||||
|
|
||||||
|
|
||||||
class BitcoinAverage(ExchangeBase):
|
class BitcoinAverage(ExchangeBase):
|
||||||
def update(self, ccy):
|
def get_rates(self, ccy):
|
||||||
json = self.get_json('api.bitcoinaverage.com', '/ticker/global/all')
|
json = self.get_json('api.bitcoinaverage.com', '/ticker/global/all')
|
||||||
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', '/')
|
||||||
|
@ -130,6 +149,11 @@ class BitPay(ExchangeBase):
|
||||||
json = self.get_json('bitpay.com', '/api/rates')
|
json = self.get_json('bitpay.com', '/api/rates')
|
||||||
return dict([(r['code'], Decimal(r['rate'])) for r in json])
|
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):
|
class BlockchainInfo(ExchangeBase):
|
||||||
def get_rates(self, ccy):
|
def get_rates(self, ccy):
|
||||||
json = self.get_json('blockchain.info', '/ticker')
|
json = self.get_json('blockchain.info', '/ticker')
|
||||||
|
|
Loading…
Reference in New Issue