mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 12:30:07 +00:00
* Added BTCParalelo price index for Venezuelan Bolivar VEF
* Fixed all of the update_* functions on the exchange_rate.py plugin to indicate when there are SSL errors, there was a horrorous try-except-pass block that was drowning all the exceptions * Added get_json_insecure to allow exchange rates over HTTP Signed-off-by: John Miguel Villar Zavatti <johnvillarzavatti@gmail.com>
This commit is contained in:
parent
69ee0bd0de
commit
ea4bf4e91f
1 changed files with 87 additions and 3 deletions
|
@ -17,6 +17,7 @@ from electrum_gui.qt.amountedit import AmountEdit
|
||||||
|
|
||||||
EXCHANGES = ["BitcoinAverage",
|
EXCHANGES = ["BitcoinAverage",
|
||||||
"BitcoinVenezuela",
|
"BitcoinVenezuela",
|
||||||
|
"BTCParalelo",
|
||||||
"Bitcurex",
|
"Bitcurex",
|
||||||
"Bitmarket",
|
"Bitmarket",
|
||||||
"BitPay",
|
"BitPay",
|
||||||
|
@ -64,6 +65,26 @@ class Exchanger(threading.Thread):
|
||||||
raise
|
raise
|
||||||
return json_resp
|
return json_resp
|
||||||
|
|
||||||
|
def get_json_insecure(self, site, get_string):
|
||||||
|
""" get_json_insecure shouldn't be used in production releases
|
||||||
|
It doesn't use SSL, and so prices could be manipulated by a middle man
|
||||||
|
This should be used ONLY when developing plugins when you don't have a
|
||||||
|
SSL certificate that validates against HTTPSConnection
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
connection = httplib.HTTPConnection(site)
|
||||||
|
connection.request("GET", get_string, headers={"User-Agent":"Electrum"})
|
||||||
|
except Exception:
|
||||||
|
raise
|
||||||
|
resp = connection.getresponse()
|
||||||
|
if resp.reason == httplib.responses[httplib.NOT_FOUND]:
|
||||||
|
raise
|
||||||
|
try:
|
||||||
|
json_resp = json.loads(resp.read())
|
||||||
|
except Exception:
|
||||||
|
raise
|
||||||
|
return json_resp
|
||||||
|
|
||||||
|
|
||||||
def exchange(self, btc_amount, quote_currency):
|
def exchange(self, btc_amount, quote_currency):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -82,6 +103,7 @@ class Exchanger(threading.Thread):
|
||||||
update_rates = {
|
update_rates = {
|
||||||
"BitcoinAverage": self.update_ba,
|
"BitcoinAverage": self.update_ba,
|
||||||
"BitcoinVenezuela": self.update_bv,
|
"BitcoinVenezuela": self.update_bv,
|
||||||
|
"BTCParalelo": self.update_bpl,
|
||||||
"Bitcurex": self.update_bx,
|
"Bitcurex": self.update_bx,
|
||||||
"Bitmarket": self.update_bm,
|
"Bitmarket": self.update_bm,
|
||||||
"BitPay": self.update_bp,
|
"BitPay": self.update_bp,
|
||||||
|
@ -110,6 +132,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_cd(self):
|
def update_cd(self):
|
||||||
try:
|
try:
|
||||||
resp_currencies = self.get_json('api.coindesk.com', "/v1/bpi/supported-currencies.json")
|
resp_currencies = self.get_json('api.coindesk.com', "/v1/bpi/supported-currencies.json")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing coindesk")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -138,6 +163,9 @@ class Exchanger(threading.Thread):
|
||||||
try:
|
try:
|
||||||
resp_rate = self.get_json('api.itbit.com', "/v1/markets/XBT" + str(current_cur) + "/ticker")
|
resp_rate = self.get_json('api.itbit.com', "/v1/markets/XBT" + str(current_cur) + "/ticker")
|
||||||
quote_currencies[str(current_cur)] = decimal.Decimal(str(resp_rate["lastPrice"]))
|
quote_currencies[str(current_cur)] = decimal.Decimal(str(resp_rate["lastPrice"]))
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing itbit")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
@ -147,6 +175,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_wd(self):
|
def update_wd(self):
|
||||||
try:
|
try:
|
||||||
winkresp = self.get_json('winkdex.com', "/api/v0/price")
|
winkresp = self.get_json('winkdex.com', "/api/v0/price")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing winkdex")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"USD": 0.0}
|
quote_currencies = {"USD": 0.0}
|
||||||
|
@ -162,6 +193,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_cv(self):
|
def update_cv(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('www.cavirtex.com', "/api/CAD/ticker.json")
|
jsonresp = self.get_json('www.cavirtex.com', "/api/CAD/ticker.json")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing cavirtex")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"CAD": 0.0}
|
quote_currencies = {"CAD": 0.0}
|
||||||
|
@ -177,6 +211,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_bm(self):
|
def update_bm(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('www.bitmarket.pl', "/json/BTCPLN/ticker.json")
|
jsonresp = self.get_json('www.bitmarket.pl', "/json/BTCPLN/ticker.json")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing bitmarket")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"PLN": 0.0}
|
quote_currencies = {"PLN": 0.0}
|
||||||
|
@ -192,6 +229,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_bx(self):
|
def update_bx(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('pln.bitcurex.com', "/data/ticker.json")
|
jsonresp = self.get_json('pln.bitcurex.com', "/data/ticker.json")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing bitcurex")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"PLN": 0.0}
|
quote_currencies = {"PLN": 0.0}
|
||||||
|
@ -207,6 +247,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_CNY(self):
|
def update_CNY(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('data.btcchina.com', "/data/ticker")
|
jsonresp = self.get_json('data.btcchina.com', "/data/ticker")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing btcchina")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {"CNY": 0.0}
|
quote_currencies = {"CNY": 0.0}
|
||||||
|
@ -222,6 +265,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_bp(self):
|
def update_bp(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('bitpay.com', "/api/rates")
|
jsonresp = self.get_json('bitpay.com', "/api/rates")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing bitpay")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {}
|
quote_currencies = {}
|
||||||
|
@ -237,6 +283,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_cb(self):
|
def update_cb(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('coinbase.com', "/api/v1/currencies/exchange_rates")
|
jsonresp = self.get_json('coinbase.com', "/api/v1/currencies/exchange_rates")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing coinbase")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -255,6 +304,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_bc(self):
|
def update_bc(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('blockchain.info', "/ticker")
|
jsonresp = self.get_json('blockchain.info', "/ticker")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing blockchain")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {}
|
quote_currencies = {}
|
||||||
|
@ -270,6 +322,9 @@ class Exchanger(threading.Thread):
|
||||||
def update_lb(self):
|
def update_lb(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('localbitcoins.com', "/bitcoinaverage/ticker-all-currencies/")
|
jsonresp = self.get_json('localbitcoins.com', "/bitcoinaverage/ticker-all-currencies/")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing localbitcoins")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {}
|
quote_currencies = {}
|
||||||
|
@ -285,23 +340,52 @@ class Exchanger(threading.Thread):
|
||||||
|
|
||||||
def update_bv(self):
|
def update_bv(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('api.bitcoinvenezuela.com', "/")
|
jsonresp = self.get_json_insecure('api.bitcoinvenezuela.com', "/")
|
||||||
|
print("**WARNING**: update_bv is using an insecure connection, shouldn't be used on production")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing bitcoinvenezuela")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
quote_currencies = {}
|
quote_currencies = {}
|
||||||
try:
|
try:
|
||||||
for r in jsonresp["BTC"]:
|
for r in jsonresp["BTC"]:
|
||||||
quote_currencies[r] = Decimal(jsonresp["BTC"][r])
|
quote_currencies[r] = Decimal(jsonresp["BTC"][r])
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.quote_currencies = quote_currencies
|
self.quote_currencies = quote_currencies
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
print ("KeyError")
|
||||||
self.parent.set_currencies(quote_currencies)
|
self.parent.set_currencies(quote_currencies)
|
||||||
|
|
||||||
|
|
||||||
|
def update_bpl(self):
|
||||||
|
try:
|
||||||
|
jsonresp = self.get_json_insecure('btcparalelo.com', "/api/price")
|
||||||
|
print("**WARNING**: update_bpl is using an insecure connection, shouldn't be used on production")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing btcparalelo")
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
quote_currencies = {}
|
||||||
|
try:
|
||||||
|
quote_currencies = {"VEF": Decimal(jsonresp["price"])}
|
||||||
|
with self.lock:
|
||||||
|
self.quote_currencies = quote_currencies
|
||||||
|
except KeyError:
|
||||||
|
print ("KeyError")
|
||||||
|
self.parent.set_currencies(quote_currencies)
|
||||||
|
|
||||||
def update_ba(self):
|
def update_ba(self):
|
||||||
try:
|
try:
|
||||||
jsonresp = self.get_json('api.bitcoinaverage.com', "/ticker/global/all")
|
jsonresp = self.get_json('api.bitcoinaverage.com', "/ticker/global/all")
|
||||||
|
except SSLError:
|
||||||
|
print("SSL Error when accesing bitcoinaverage")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
quote_currencies = {}
|
quote_currencies = {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue