From af75c33b1625728acba9f0f5864252238467935a Mon Sep 17 00:00:00 2001 From: Felix <51097237+f321x@users.noreply.github.com> Date: Mon, 24 Jul 2023 19:49:55 +0200 Subject: [PATCH] Add criptoya.com api to price providers (#748) Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com> --- .env-sample | 2 +- api/utils.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.env-sample b/.env-sample index a1dc628c..27f0bc03 100644 --- a/.env-sample +++ b/.env-sample @@ -42,7 +42,7 @@ LND_GRPC_HOST='localhost:10009' REDIS_URL='redis://localhost:6379/1' # List of market price public APIs. If the currency is available in more than 1 API, will use median price. -MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC +MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC, https://criptoya.com/api/btc # Host e.g. robosats.com HOST_NAME = '' diff --git a/api/utils.py b/api/utils.py index 6348e43e..5c3ab103 100644 --- a/api/utils.py +++ b/api/utils.py @@ -127,6 +127,32 @@ def get_exchange_rates(currencies): bitpay_rates.append(np.nan) api_rates.append(bitpay_rates) + # Tor proxied requests to criptoya.com will fail. Skip if USE_TOR is enabled. + elif "criptoya.com" in api_url and not USE_TOR: + criptoya_supported_currencies = [ + "ARS", + "COP", + "MXN", + "BRL", + "PEN", + "CLP", + "USD", + "VES", + ] + criptoya_rates = [] + for currency in currencies: + if currency in criptoya_supported_currencies: + criptoya_exchanges = session.get(f"{api_url}/{currency}").json() + exchange_medians = [ + np.median([exchange["ask"], exchange["ask"]]) + for exchange in criptoya_exchanges.values() + if exchange["ask"] > 0 and exchange["bid"] > 0 + ] + criptoya_rates.append(round(np.median(exchange_medians), 2)) + else: + criptoya_rates.append(np.nan) + api_rates.append(criptoya_rates) + except Exception as e: print(f"Could not fetch BTC prices from {api_url}: {str(e)}") pass @@ -171,7 +197,6 @@ robosats_commit_cache = {} @ring.dict(robosats_commit_cache, expire=99999) def get_robosats_commit(): - # .git folder is included in .dockerignore. The build workflow will drop the commit_sha file in root with open("commit_sha") as f: commit_hash = f.read() @@ -184,7 +209,6 @@ premium_percentile = {} @ring.dict(premium_percentile, expire=300) def compute_premium_percentile(order): - queryset = Order.objects.filter( currency=order.currency, status=Order.Status.PUB, type=order.type ).exclude(id=order.id)