mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 10:56:24 +00:00
Add criptoya.com api to price providers (#748)
Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com>
This commit is contained in:
parent
441bad45fb
commit
af75c33b16
@ -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 = ''
|
||||
|
28
api/utils.py
28
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)
|
||||
|
Loading…
Reference in New Issue
Block a user