Commit 7f178dc
Changed files (2)
src
src/price/coinmarketcap.py
@@ -44,7 +44,10 @@ async def get_cmc_fiat() -> list:
@cache.memoize(ttl=60)
async def get_cmc_price(coin: str, fiat: str = "USD") -> str:
- """Get the price of a crypto asset from CoinMarketCap."""
+ """Get the price of a crypto asset from CoinMarketCap.
+
+ If the market cap of the coin is less than 10M, we skip it.
+ """
cmc_coins = await get_cmc_coins()
if coin.upper() in cmc_coins:
params = {"symbol": coin.upper(), "convert": fiat}
@@ -58,6 +61,8 @@ async def get_cmc_price(coin: str, fiat: str = "USD") -> str:
if not data:
return f"CoinMarketCap price failed: {coin}"
stats = data["quote"][fiat]
+ if float(stats["market_cap"]) < 1000_0000: # 1000万
+ return ""
precision = 2 if float(stats["price"]) > 1 else 6
emoji = lambda x: "🟢" if float(x) > 0 else "🔴"
msg = f"🪙**{data['symbol']}** ({data['name']})\n"
@@ -81,7 +86,7 @@ async def cmc_convert_price(amount: float | str, base: str, quote: str) -> str:
base = base.upper()
quote = quote.upper()
if base not in all_coins or quote not in all_coins:
- return f"不支持转换: {amount} {base} → {quote}\n支持的发币:\n{', '.join(sorted(cmc_fiat))}"
+ return f"不支持转换: {amount} {base} → {quote}\n支持的法币:\n{', '.join(sorted(cmc_fiat))}"
url = "https://pro-api.coinmarketcap.com/v2/tools/price-conversion"
params = {"amount": float(amount), "symbol": base, "convert": quote}
response = await hx_req(url, params=params, headers=HEADERS, merge_headers=False, proxy=PROXY.CRYPTO, check_has_kv=["data"])
src/price/entrypoint.py
@@ -67,4 +67,4 @@ async def get_asset_price(client: Client, message: Message, **kwargs) -> None:
elif res := await get_cmc_price(text):
await send2tg(client, message, texts=res, **kwargs)
else:
- await send2tg(client, message, texts=f"不支持此Symbol: {text}\n\n{HELP}", **kwargs)
+ await send2tg(client, message, texts=f"不支持此Symbol: {text}\n{HELP}", **kwargs)