Spaces:
Sleeping
Sleeping
fix: simplified approach and pulling HYPE price from perps market instead
Browse files41 unmodified lines42434445464748495051525354555657585960616263646566676869707141 unmodified lines"Content-Type": "application/json"}# Request payload for spot market datapayload = {"type": "spotMetaAndAssetCtxs"}response = requests.post(url, headers=headers, json=payload)if response.status_code == 200:data = response.json()market_data = data[1] # Market data is in the second array elementfor market in market_data:if market.get("coin") == "@150": # HYPE's indexmark_price = float(market["markPx"])mid_price = float(market["midPx"])volume = float(market["dayNtlVlm"])# Format with 2 decimal places as per szDecimalsreturn f"HYPE/USDC Price:\n" \f"Mark Price: {mark_price:.2f} USDC\n" \f"Mid Price: {mid_price:.2f} USDC\n" \f"24h Volume: {volume:.2f} USDC"return "Error: HYPE market not found in response"else:return f"Error: API request failed with status code {response.status_code}"41 unmodified lines424344454647484950515253545556575859606141 unmodified lines"Content-Type": "application/json"}payload = {"type": "allMids"}response = requests.post(url, headers=headers, json=payload)if response.status_code == 200:data = response.json()if "HYPE" in data:price = float(data["HYPE"])return f"Current HYPE/USDC price: {price:.4f} USDC"return "Error: HYPE price not found in response"else:return f"Error: API request failed with status code {response.status_code}"
app.py+5-15