Spaces:
Sleeping
Sleeping
Update app.py
Browse files36 unmodified lines3738394041424344454647484950515253545556575859606162636465666768697036 unmodified linesdef get_hype_price() -> str:"""A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market."""try:# API endpointurl = "https://api.hyperliquid.xyz/info"# Request headersheaders = {"Content-Type": "application/json"}# Request payload for spot market datapayload = {"type": "spotMetaAndAssetCtxs"}# Make the POST requestresponse = requests.post(url, headers=headers, json=payload)if response.status_code == 200:data = response.json()# Extract HYPE price from the responsefor market in data[1]:if market["coin"] == "HYPE":price = float(market["markPx"])return f"Current HYPE/USDC price on Hyperliquid is: {price} USD"return "Error: HYPE market not found on Hyperliquid"else:return f"Error: API request failed with status code {response.status_code}"except Exception as e:return f"Error fetching Hyperliquid price: {str(e)}"36 unmodified lines37383940414243444546474849505152535455565758596061626364656667686970717273747536 unmodified linesdef get_hype_price() -> str:"""A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market."""try:url = "https://api.hyperliquid.xyz/info"headers = {"Content-Type": "application/json"}# First, get spot meta to find HYPE's indexmeta_payload = {"type": "spotMeta"}meta_response = requests.post(url, headers=headers, json=meta_payload)if meta_response.status_code == 200:meta_data = meta_response.json()hype_index = None# Find HYPE's index in the universefor token in meta_data["universe"]:if token["name"] == "HYPE":hype_index = token["index"]breakif hype_index is not None:# Now get all midsmids_payload = {"type": "allMids"}mids_response = requests.post(url, headers=headers, json=mids_payload)if mids_response.status_code == 200:mids_data = mids_response.json()token_key = f"@{hype_index}"if token_key in mids_data:price = mids_data[token_key]return f"Current HYPE/USDC price on Hyperliquid is: {price} USDC"return "Error: HYPE market not found in current mids"else:return f"Error: API request failed with status code {meta_response.status_code}"except Exception as e:return f"Error fetching Hyperliquid price: {str(e)}"
app.py+27-22