market cap fixes

This commit is contained in:
2025-10-25 19:58:52 +02:00
parent 5805601218
commit fe5cc8e1d1
5 changed files with 184 additions and 44 deletions

View File

@ -11,7 +11,7 @@ def update_coin_mapping():
"""
Fetches all assets from Hyperliquid and all coins from CoinGecko,
then creates and saves a mapping from the Hyperliquid symbol to the
CoinGecko ID.
CoinGecko ID using a robust matching algorithm.
"""
setup_logging('normal', 'CoinMapUpdater')
logging.info("Starting coin mapping update process...")
@ -20,13 +20,8 @@ def update_coin_mapping():
try:
logging.info("Fetching assets from Hyperliquid...")
info = Info(constants.MAINNET_API_URL, skip_ws=True)
# The meta object contains the 'universe' list with asset details
meta, asset_contexts = info.meta_and_asset_ctxs()
# --- FIX: The asset names are in the 'universe' list inside the meta object ---
# The 'universe' is a list of dictionaries, each with a 'name'
hyperliquid_assets = [asset['name'] for asset in meta['universe']]
hyperliquid_assets = meta['universe']
logging.info(f"Found {len(hyperliquid_assets)} assets on Hyperliquid.")
except Exception as e:
logging.error(f"Failed to fetch assets from Hyperliquid: {e}")
@ -38,8 +33,11 @@ def update_coin_mapping():
response = requests.get("https://api.coingecko.com/api/v3/coins/list")
response.raise_for_status()
coingecko_coins = response.json()
# Create a lookup table: {symbol: id}
coingecko_lookup = {coin['symbol'].upper(): coin['id'] for coin in coingecko_coins}
# Create more robust lookup tables
cg_symbol_lookup = {coin['symbol'].upper(): coin['id'] for coin in coingecko_coins}
cg_name_lookup = {coin['name'].upper(): coin['id'] for coin in coingecko_coins}
logging.info(f"Found {len(coingecko_coins)} coins on CoinGecko.")
except requests.exceptions.RequestException as e:
logging.error(f"Failed to fetch coin list from CoinGecko: {e}")
@ -47,24 +45,41 @@ def update_coin_mapping():
# --- 3. Create the mapping ---
final_mapping = {}
# Use manual overrides for critical coins where symbols are ambiguous
manual_overrides = {
"BTC": "bitcoin",
"ETH": "ethereum",
"SOL": "solana",
"BNB": "binancecoin",
"HYPE": "hyperliquid",
"PUMP": "pump-fun",
"ASTER": "astar",
"ZEC": "zcash",
"SUI": "sui",
"ACE": "endurance",
# Add other important ones you watch here
}
logging.info("Generating symbol-to-id mapping...")
for asset_symbol in hyperliquid_assets:
# Check for manual overrides first
for asset in hyperliquid_assets:
asset_symbol = asset['name'].upper()
asset_name = asset.get('name', '').upper() # Use full name if available
# Priority 1: Manual Overrides
if asset_symbol in manual_overrides:
final_mapping[asset_symbol] = manual_overrides[asset_symbol]
continue
# Try to find a direct match in the CoinGecko lookup table
if asset_symbol in coingecko_lookup:
final_mapping[asset_symbol] = coingecko_lookup[asset_symbol]
# Priority 2: Exact Name Match
if asset_name in cg_name_lookup:
final_mapping[asset_symbol] = cg_name_lookup[asset_name]
continue
# Priority 3: Symbol Match
if asset_symbol in cg_symbol_lookup:
final_mapping[asset_symbol] = cg_symbol_lookup[asset_symbol]
else:
logging.warning(f"No direct match found for '{asset_symbol}' on CoinGecko. It will be excluded.")
logging.warning(f"No match found for '{asset_symbol}' on CoinGecko. It will be excluded.")
# --- 4. Save the mapping to a file ---
map_file_path = os.path.join("_data", "coin_id_map.json")