mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-10 04:22:35 +02:00
feat: add exclude_to
list for btcprice providers (#2602)
This commit is contained in:
@@ -191,6 +191,7 @@ class Provider(NamedTuple):
|
|||||||
domain: str
|
domain: str
|
||||||
api_url: str
|
api_url: str
|
||||||
getter: Callable
|
getter: Callable
|
||||||
|
exclude_to: list = []
|
||||||
|
|
||||||
|
|
||||||
exchange_rate_providers = {
|
exchange_rate_providers = {
|
||||||
@@ -200,6 +201,7 @@ exchange_rate_providers = {
|
|||||||
"binance.com",
|
"binance.com",
|
||||||
"https://api.binance.com/api/v3/ticker/price?symbol={FROM}{TO}",
|
"https://api.binance.com/api/v3/ticker/price?symbol={FROM}{TO}",
|
||||||
lambda data, replacements: data["price"],
|
lambda data, replacements: data["price"],
|
||||||
|
["czk"],
|
||||||
),
|
),
|
||||||
"blockchain": Provider(
|
"blockchain": Provider(
|
||||||
"Blockchain",
|
"Blockchain",
|
||||||
@@ -212,18 +214,21 @@ exchange_rate_providers = {
|
|||||||
"exir.io",
|
"exir.io",
|
||||||
"https://api.exir.io/v1/ticker?symbol={from}-{to}",
|
"https://api.exir.io/v1/ticker?symbol={from}-{to}",
|
||||||
lambda data, replacements: data["last"],
|
lambda data, replacements: data["last"],
|
||||||
|
["czk", "eur"],
|
||||||
),
|
),
|
||||||
"bitfinex": Provider(
|
"bitfinex": Provider(
|
||||||
"Bitfinex",
|
"Bitfinex",
|
||||||
"bitfinex.com",
|
"bitfinex.com",
|
||||||
"https://api.bitfinex.com/v1/pubticker/{from}{to}",
|
"https://api.bitfinex.com/v1/pubticker/{from}{to}",
|
||||||
lambda data, replacements: data["last_price"],
|
lambda data, replacements: data["last_price"],
|
||||||
|
["czk"],
|
||||||
),
|
),
|
||||||
"bitstamp": Provider(
|
"bitstamp": Provider(
|
||||||
"Bitstamp",
|
"Bitstamp",
|
||||||
"bitstamp.net",
|
"bitstamp.net",
|
||||||
"https://www.bitstamp.net/api/v2/ticker/{from}{to}/",
|
"https://www.bitstamp.net/api/v2/ticker/{from}{to}/",
|
||||||
lambda data, replacements: data["last"],
|
lambda data, replacements: data["last"],
|
||||||
|
["czk"],
|
||||||
),
|
),
|
||||||
"coinbase": Provider(
|
"coinbase": Provider(
|
||||||
"Coinbase",
|
"Coinbase",
|
||||||
@@ -242,6 +247,7 @@ exchange_rate_providers = {
|
|||||||
"kraken.com",
|
"kraken.com",
|
||||||
"https://api.kraken.com/0/public/Ticker?pair=XBT{TO}",
|
"https://api.kraken.com/0/public/Ticker?pair=XBT{TO}",
|
||||||
lambda data, replacements: data["result"]["XXBTZ" + replacements["TO"]]["c"][0],
|
lambda data, replacements: data["result"]["XXBTZ" + replacements["TO"]]["c"][0],
|
||||||
|
["czk"],
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +261,9 @@ async def btc_price(currency: str) -> float:
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def fetch_price(provider: Provider):
|
async def fetch_price(provider: Provider):
|
||||||
|
if currency.lower() in provider.exclude_to:
|
||||||
|
raise Exception(f"Provider {provider.name} does not support {currency}.")
|
||||||
|
|
||||||
url = provider.api_url.format(**replacements)
|
url = provider.api_url.format(**replacements)
|
||||||
try:
|
try:
|
||||||
headers = {"User-Agent": settings.user_agent}
|
headers = {"User-Agent": settings.user_agent}
|
||||||
|
Reference in New Issue
Block a user