mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-05 22:10:10 +00:00
Add new api for external prices (non-tor only) bitpay
This commit is contained in:
parent
5728c66cca
commit
0f28990bea
@ -37,7 +37,7 @@ LND_GRPC_HOST='localhost:10009'
|
|||||||
REDIS_URL='redis://localhost:6379/1'
|
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.
|
# 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
|
MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC
|
||||||
|
|
||||||
# Host e.g. robosats.com
|
# Host e.g. robosats.com
|
||||||
HOST_NAME = ''
|
HOST_NAME = ''
|
||||||
|
@ -169,6 +169,9 @@ def cache_market():
|
|||||||
print("SOFT LIMIT REACHED. Could not fetch current external market prices.")
|
print("SOFT LIMIT REACHED. Could not fetch current external market prices.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not exchange_rates:
|
||||||
|
return
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for i in range(
|
for i in range(
|
||||||
len(Currency.currency_dict.values())
|
len(Currency.currency_dict.values())
|
||||||
|
23
api/utils.py
23
api/utils.py
@ -108,8 +108,27 @@ def get_exchange_rates(currencies):
|
|||||||
except Exception:
|
except Exception:
|
||||||
yadio_rates.append(np.nan)
|
yadio_rates.append(np.nan)
|
||||||
api_rates.append(yadio_rates)
|
api_rates.append(yadio_rates)
|
||||||
except Exception:
|
|
||||||
print(f"Could not fetch BTC prices from {api_url}")
|
# Tor proxied requests to bitpay.com will fail. Skip if USE_TOR is enabled.
|
||||||
|
elif "bitpay.com" in api_url and not USE_TOR:
|
||||||
|
headers = {
|
||||||
|
"X-Accept-Version": "2.0.0",
|
||||||
|
"Content-type": "application/json",
|
||||||
|
}
|
||||||
|
bitpay_prices = session.get(api_url, headers=headers).json()
|
||||||
|
bitpay_prices = {
|
||||||
|
item["code"]: item["rate"] for item in bitpay_prices["data"]
|
||||||
|
}
|
||||||
|
bitpay_rates = []
|
||||||
|
for currency in currencies:
|
||||||
|
try:
|
||||||
|
bitpay_rates.append(float(bitpay_prices[currency]))
|
||||||
|
except Exception:
|
||||||
|
bitpay_rates.append(np.nan)
|
||||||
|
api_rates.append(bitpay_rates)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Could not fetch BTC prices from {api_url}: {str(e)}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if len(api_rates) == 0:
|
if len(api_rates) == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user