mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-22 22:25:47 +01:00
feat: add exclude_to
list for btcprice providers (#2602)
This commit is contained in:
parent
a844711530
commit
97de4eda18
1 changed files with 9 additions and 0 deletions
|
@ -191,6 +191,7 @@ class Provider(NamedTuple):
|
|||
domain: str
|
||||
api_url: str
|
||||
getter: Callable
|
||||
exclude_to: list = []
|
||||
|
||||
|
||||
exchange_rate_providers = {
|
||||
|
@ -200,6 +201,7 @@ exchange_rate_providers = {
|
|||
"binance.com",
|
||||
"https://api.binance.com/api/v3/ticker/price?symbol={FROM}{TO}",
|
||||
lambda data, replacements: data["price"],
|
||||
["czk"],
|
||||
),
|
||||
"blockchain": Provider(
|
||||
"Blockchain",
|
||||
|
@ -212,18 +214,21 @@ exchange_rate_providers = {
|
|||
"exir.io",
|
||||
"https://api.exir.io/v1/ticker?symbol={from}-{to}",
|
||||
lambda data, replacements: data["last"],
|
||||
["czk", "eur"],
|
||||
),
|
||||
"bitfinex": Provider(
|
||||
"Bitfinex",
|
||||
"bitfinex.com",
|
||||
"https://api.bitfinex.com/v1/pubticker/{from}{to}",
|
||||
lambda data, replacements: data["last_price"],
|
||||
["czk"],
|
||||
),
|
||||
"bitstamp": Provider(
|
||||
"Bitstamp",
|
||||
"bitstamp.net",
|
||||
"https://www.bitstamp.net/api/v2/ticker/{from}{to}/",
|
||||
lambda data, replacements: data["last"],
|
||||
["czk"],
|
||||
),
|
||||
"coinbase": Provider(
|
||||
"Coinbase",
|
||||
|
@ -242,6 +247,7 @@ exchange_rate_providers = {
|
|||
"kraken.com",
|
||||
"https://api.kraken.com/0/public/Ticker?pair=XBT{TO}",
|
||||
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):
|
||||
if currency.lower() in provider.exclude_to:
|
||||
raise Exception(f"Provider {provider.name} does not support {currency}.")
|
||||
|
||||
url = provider.api_url.format(**replacements)
|
||||
try:
|
||||
headers = {"User-Agent": settings.user_agent}
|
||||
|
|
Loading…
Add table
Reference in a new issue