Browse Source

Sorted exchange_rate.py

Notice: no real changes
2.9.x
Alexx Saver 8 years ago
committed by ThomasV
parent
commit
4847fe5f41
  1. 135
      lib/exchange_rate.py

135
lib/exchange_rate.py

@ -88,6 +88,7 @@ class ExchangeBase(PrintError):
class BitcoinAverage(ExchangeBase): class BitcoinAverage(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('apiv2.bitcoinaverage.com', '/indices/global/ticker/short') json = self.get_json('apiv2.bitcoinaverage.com', '/indices/global/ticker/short')
return dict([(r.replace("BTC", ""), Decimal(json[r]['last'])) return dict([(r.replace("BTC", ""), Decimal(json[r]['last']))
@ -104,6 +105,17 @@ class BitcoinAverage(ExchangeBase):
return dict([(h['DateTime'][:10], h['Average']) return dict([(h['DateTime'][:10], h['Average'])
for h in history]) for h in history])
class Bitcointoyou(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('bitcointoyou.com', "/API/ticker.aspx")
return {'BRL': Decimal(json['ticker']['last'])}
def history_ccys(self):
return ['BRL']
class BitcoinVenezuela(ExchangeBase): class BitcoinVenezuela(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
@ -119,45 +131,58 @@ class BitcoinVenezuela(ExchangeBase):
return self.get_json('api.bitcoinvenezuela.com', return self.get_json('api.bitcoinvenezuela.com',
"/historical/index.php?coin=BTC")[ccy +'_BTC'] "/historical/index.php?coin=BTC")[ccy +'_BTC']
class BTCParalelo(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('btcparalelo.com', '/api/price')
return {'VEF': Decimal(json['price'])}
class Bitso(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('api.bitso.com', '/v2/ticker')
return {'MXN': Decimal(json['last'])}
class Bitmarket(ExchangeBase): class Bitmarket(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('www.bitmarket.pl', '/json/BTCPLN/ticker.json') json = self.get_json('www.bitmarket.pl', '/json/BTCPLN/ticker.json')
return {'PLN': Decimal(json['last'])} return {'PLN': Decimal(json['last'])}
class BitPay(ExchangeBase): class BitPay(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
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 Bitso(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('api.bitso.com', '/v2/ticker')
return {'MXN': Decimal(json['last'])}
class BitStamp(ExchangeBase): class BitStamp(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('www.bitstamp.net', '/api/ticker/') json = self.get_json('www.bitstamp.net', '/api/ticker/')
return {'USD': Decimal(json['last'])} return {'USD': Decimal(json['last'])}
class Bitvalor(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['total']['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')
return dict([(r, Decimal(json[r]['15m'])) for r in json]) return dict([(r, Decimal(json[r]['15m'])) for r in json])
class BTCChina(ExchangeBase): class BTCChina(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('data.btcchina.com', '/data/ticker') json = self.get_json('data.btcchina.com', '/data/ticker')
return {'CNY': Decimal(json['ticker']['last'])} return {'CNY': Decimal(json['ticker']['last'])}
class BTCe(ExchangeBase): class BTCe(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json_eur = self.get_json('btc-e.nz', '/api/3/ticker/btc_eur') json_eur = self.get_json('btc-e.nz', '/api/3/ticker/btc_eur')
json_rub = self.get_json('btc-e.nz', '/api/3/ticker/btc_rur') json_rub = self.get_json('btc-e.nz', '/api/3/ticker/btc_rur')
@ -166,14 +191,25 @@ class BTCe(ExchangeBase):
'RUB': Decimal(json_rub['btc_rur']['last']), 'RUB': Decimal(json_rub['btc_rur']['last']),
'USD': Decimal(json_usd['btc_usd']['last'])} 'USD': Decimal(json_usd['btc_usd']['last'])}
class BTCParalelo(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('btcparalelo.com', '/api/price')
return {'VEF': Decimal(json['price'])}
class Coinbase(ExchangeBase): class Coinbase(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('coinbase.com', json = self.get_json('coinbase.com',
'/api/v1/currencies/exchange_rates') '/api/v1/currencies/exchange_rates')
return dict([(r[7:].upper(), Decimal(json[r])) return dict([(r[7:].upper(), Decimal(json[r]))
for r in json if r.startswith('btc_to_')]) for r in json if r.startswith('btc_to_')])
class CoinDesk(ExchangeBase): class CoinDesk(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
dicts = self.get_json('api.coindesk.com', dicts = self.get_json('api.coindesk.com',
'/v1/bpi/supported-currencies.json') '/v1/bpi/supported-currencies.json')
@ -199,17 +235,23 @@ class CoinDesk(ExchangeBase):
json = self.get_json('api.coindesk.com', query) json = self.get_json('api.coindesk.com', query)
return json['bpi'] return json['bpi']
class Coinsecure(ExchangeBase): class Coinsecure(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('api.coinsecure.in', '/v0/noauth/newticker') json = self.get_json('api.coinsecure.in', '/v0/noauth/newticker')
return {'INR': Decimal(json['lastprice'] / 100.0 )} return {'INR': Decimal(json['lastprice'] / 100.0 )}
class Unocoin(ExchangeBase):
def get_rates(self, ccy): class Foxbit(ExchangeBase):
json = self.get_json('www.unocoin.com', 'trade?buy')
return {'INR': Decimal(json)} def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['exchanges']['FOX']['last'])}
class itBit(ExchangeBase): class itBit(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
ccys = ['USD', 'EUR', 'SGD'] ccys = ['USD', 'EUR', 'SGD']
json = self.get_json('api.itbit.com', '/v1/markets/XBT%s/ticker' % ccy) json = self.get_json('api.itbit.com', '/v1/markets/XBT%s/ticker' % ccy)
@ -218,7 +260,9 @@ class itBit(ExchangeBase):
result[ccy] = Decimal(json['lastPrice']) result[ccy] = Decimal(json['lastPrice'])
return result return result
class Kraken(ExchangeBase): class Kraken(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
ccys = ['EUR', 'USD', 'CAD', 'GBP', 'JPY'] ccys = ['EUR', 'USD', 'CAD', 'GBP', 'JPY']
pairs = ['XBT%s' % c for c in ccys] pairs = ['XBT%s' % c for c in ccys]
@ -227,58 +271,54 @@ class Kraken(ExchangeBase):
return dict((k[-3:], Decimal(float(v['c'][0]))) return dict((k[-3:], Decimal(float(v['c'][0])))
for k, v in json['result'].items()) for k, v in json['result'].items())
class LocalBitcoins(ExchangeBase): class LocalBitcoins(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('localbitcoins.com', json = self.get_json('localbitcoins.com',
'/bitcoinaverage/ticker-all-currencies/') '/bitcoinaverage/ticker-all-currencies/')
return dict([(r, Decimal(json[r]['rates']['last'])) for r in json]) return dict([(r, Decimal(json[r]['rates']['last'])) for r in json])
class Winkdex(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('winkdex.com', '/api/v0/price')
return {'USD': Decimal(json['price'] / 100.0)}
def history_ccys(self):
return ['USD']
def historical_rates(self, ccy):
json = self.get_json('winkdex.com',
"/api/v0/series?start_time=1342915200")
history = json['series'][0]['results']
return dict([(h['timestamp'][:10], h['price'] / 100.0)
for h in history])
class MercadoBitcoin(ExchangeBase): class MercadoBitcoin(ExchangeBase):
def get_rates(self, ccy): def get_rates(self, ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json') json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['exchanges']['MBT']['last'])} return {'BRL': Decimal(json['ticker_1h']['exchanges']['MBT']['last'])}
class Bitcointoyou(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('bitcointoyou.com', "/API/ticker.aspx")
return {'BRL': Decimal(json['ticker']['last'])}
def history_ccys(self): class NegocieCoins(ExchangeBase):
return ['BRL']
class Bitvalor(ExchangeBase):
def get_rates(self,ccy): def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json') json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['total']['last'])} return {'BRL': Decimal(json['ticker_1h']['exchanges']['NEG']['last'])}
def history_ccys(self):
return ['BRL']
class Foxbit(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['exchanges']['FOX']['last'])}
class NegocieCoins(ExchangeBase): class Unocoin(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json') def get_rates(self, ccy):
return {'BRL': Decimal(json['ticker_1h']['exchanges']['NEG']['last'])} json = self.get_json('www.unocoin.com', 'trade?buy')
return {'INR': Decimal(json)}
class Winkdex(ExchangeBase):
def get_rates(self, ccy):
json = self.get_json('winkdex.com', '/api/v0/price')
return {'USD': Decimal(json['price'] / 100.0)}
def history_ccys(self): def history_ccys(self):
return ['BRL'] return ['USD']
def historical_rates(self, ccy):
json = self.get_json('winkdex.com',
"/api/v0/series?start_time=1342915200")
history = json['series'][0]['results']
return dict([(h['timestamp'][:10], h['price'] / 100.0)
for h in history])
def dictinvert(d): def dictinvert(d):
@ -327,7 +367,6 @@ def get_exchanges_by_ccy(history=True):
return dictinvert(d) return dictinvert(d)
class FxThread(ThreadJob): class FxThread(ThreadJob):
def __init__(self, config, network): def __init__(self, config, network):

Loading…
Cancel
Save