Cache coin rates.

This commit is contained in:
tecnovert
2025-02-25 23:35:57 +02:00
parent 3cdab962d3
commit 5bedc6289f
11 changed files with 357 additions and 105 deletions

View File

@@ -31,6 +31,7 @@ from basicswap.basicswap_util import (
SwapTypes,
DebugTypes,
getLockName,
get_api_key_setting,
strBidState,
strSwapDesc,
strSwapType,
@@ -41,11 +42,10 @@ from basicswap.chainparams import (
Coins,
ticker_map,
)
default_chart_api_key = (
"95dd900af910656e0e17c41f2ddc5dba77d01bf8b0e7d2787634a16bd976c553"
from basicswap.explorers import (
default_chart_api_key,
default_coingecko_api_key,
)
default_coingecko_api_key = "CG-8hm3r9iLfpEXv4ied8oLbeUj"
def value_or_none(v):
@@ -973,23 +973,12 @@ def page_offers(self, url_split, post_string, sent=False):
coins_from, coins_to = listAvailableCoins(swap_client, split_from=True)
chart_api_key = swap_client.settings.get("chart_api_key", "")
if chart_api_key == "":
chart_api_key_enc = swap_client.settings.get("chart_api_key_enc", "")
chart_api_key = (
default_chart_api_key
if chart_api_key_enc == ""
else bytes.fromhex(chart_api_key_enc).decode("utf-8")
)
coingecko_api_key = swap_client.settings.get("coingecko_api_key", "")
if coingecko_api_key == "":
coingecko_api_key_enc = swap_client.settings.get("coingecko_api_key_enc", "")
coingecko_api_key = (
default_coingecko_api_key
if coingecko_api_key_enc == ""
else bytes.fromhex(coingecko_api_key_enc).decode("utf-8")
)
chart_api_key = get_api_key_setting(
swap_client.settings, "chart_api_key", default_chart_api_key
)
coingecko_api_key = get_api_key_setting(
swap_client.settings, "coingecko_api_key", default_coingecko_api_key
)
offers_count = len(formatted_offers)

View File

@@ -16,6 +16,9 @@ from basicswap.util import (
toBool,
InactiveCoin,
)
from basicswap.basicswap_util import (
get_api_key_setting,
)
from basicswap.chainparams import (
Coins,
)
@@ -168,23 +171,13 @@ def page_settings(self, url_split, post_string):
"debug_ui": swap_client.debug_ui,
"expire_db_records": swap_client._expire_db_records,
}
if "chart_api_key_enc" in swap_client.settings:
chart_api_key = html.escape(
bytes.fromhex(swap_client.settings.get("chart_api_key_enc", "")).decode(
"utf-8"
)
)
else:
chart_api_key = swap_client.settings.get("chart_api_key", "")
if "coingecko_api_key_enc" in swap_client.settings:
coingecko_api_key = html.escape(
bytes.fromhex(swap_client.settings.get("coingecko_api_key_enc", "")).decode(
"utf-8"
)
)
else:
coingecko_api_key = swap_client.settings.get("coingecko_api_key", "")
chart_api_key = get_api_key_setting(
swap_client.settings, "chart_api_key", escape=True
)
coingecko_api_key = get_api_key_setting(
swap_client.settings, "coingecko_api_key", escape=True
)
chart_settings = {
"show_chart": swap_client.settings.get("show_chart", True),