Add new api for external prices (non-tor only) bitpay

This commit is contained in:
Reckless_Satoshi 2023-05-10 13:57:33 -07:00
parent 5728c66cca
commit 0f28990bea
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 25 additions and 3 deletions

View File

@ -37,7 +37,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
MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC
# Host e.g. robosats.com
HOST_NAME = ''

View File

@ -169,6 +169,9 @@ def cache_market():
print("SOFT LIMIT REACHED. Could not fetch current external market prices.")
return
if not exchange_rates:
return
results = {}
for i in range(
len(Currency.currency_dict.values())

View File

@ -108,8 +108,27 @@ def get_exchange_rates(currencies):
except Exception:
yadio_rates.append(np.nan)
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
if len(api_rates) == 0: