2022-01-07 22:46:30 +00:00
|
|
|
|
2022-01-11 14:36:43 +00:00
|
|
|
import requests, ring, os
|
2022-01-07 22:46:30 +00:00
|
|
|
from decouple import config
|
2022-01-14 14:57:56 +00:00
|
|
|
from statistics import median
|
2022-01-15 12:00:11 +00:00
|
|
|
|
2022-01-11 14:36:43 +00:00
|
|
|
market_cache = {}
|
2022-01-10 01:12:58 +00:00
|
|
|
|
2022-01-11 14:36:43 +00:00
|
|
|
@ring.dict(market_cache, expire=30) #keeps in cache for 30 seconds
|
2022-01-07 22:46:30 +00:00
|
|
|
def get_exchange_rate(currency):
|
2022-01-14 14:57:56 +00:00
|
|
|
'''
|
|
|
|
Checks for exchange rates in several public APIs.
|
|
|
|
Returns the median price.
|
|
|
|
'''
|
2022-01-15 00:28:19 +00:00
|
|
|
|
2022-01-14 14:57:56 +00:00
|
|
|
APIS = config('MARKET_PRICE_APIS', cast=lambda v: [s.strip() for s in v.split(',')])
|
|
|
|
exchange_rates = []
|
|
|
|
|
|
|
|
for api_url in APIS:
|
|
|
|
try:
|
|
|
|
if 'blockchain.info' in api_url:
|
|
|
|
blockchain_prices = requests.get(api_url).json()
|
|
|
|
exchange_rates.append(float(blockchain_prices[currency]['last']))
|
|
|
|
elif 'yadio.io' in api_url:
|
|
|
|
yadio_prices = requests.get(api_url).json()
|
|
|
|
exchange_rates.append(float(yadio_prices['BTC'][currency]))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return median(exchange_rates)
|
2022-01-11 14:36:43 +00:00
|
|
|
|
|
|
|
lnd_v_cache = {}
|
|
|
|
|
|
|
|
@ring.dict(lnd_v_cache, expire=3600) #keeps in cache for 3600 seconds
|
|
|
|
def get_lnd_version():
|
|
|
|
|
|
|
|
stream = os.popen('lnd --version')
|
|
|
|
lnd_version = stream.read()[:-1]
|
|
|
|
|
|
|
|
return lnd_version
|
|
|
|
|
|
|
|
robosats_commit_cache = {}
|
|
|
|
|
|
|
|
@ring.dict(robosats_commit_cache, expire=3600)
|
|
|
|
def get_commit_robosats():
|
|
|
|
|
|
|
|
stream = os.popen('git log -n 1 --pretty=format:"%H"')
|
|
|
|
lnd_version = stream.read()
|
|
|
|
|
|
|
|
return lnd_version
|
|
|
|
|