Spaces:
Sleeping
Sleeping
fix: Adjusted approach with calling for HYPE Spot price
Browse files33 unmodified lines34353637383940414243444546474849505152535455565758596061626364656667686922 unmodified lines9293949596979833 unmodified linesreturn f"Error fetching time for timezone '{timezone}': {str(e)}"@tooldef get_hyperliquid_price(symbol: str = "HYPE") -> str:"""A tool that fetches the current price of the HYPE token from Hyperliquid Spot market.Args:symbol: The trading symbol (defaults to 'HYPE' for HYPE/USDC pair)."""try:# Hyperliquid Spot API endpointurl = "https://api.hyperliquid.xyz/info"# Payload for the POST requestpayload = {"type": "spotMarket"}# Make the POST requestresponse = requests.post(url, json=payload)if response.status_code == 200:data = response.json()# Find the HYPE market datafor market in data:if market["name"] == symbol:# The price is in USDC termsprice = float(market["markPrice"])return f"Current {symbol}/USDC price on Hyperliquid is: {price} USD"return f"Error: {symbol} market not found on Hyperliquid"else:return f"Error: Unable to fetch price. Status code: {response.status_code}"except Exception as e:return f"Error fetching Hyperliquid price: {str(e)}"22 unmodified linesagent = CodeAgent(model=model,tools=[final_answer, webpage_tool, search_tool, image_generation_tool, get_current_time_in_timezone, get_hyperliquid_price], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,33 unmodified lines3435363738394041424344454647484950515253545556575859606162636465666768697022 unmodified lines9394959697989933 unmodified linesreturn f"Error fetching time for timezone '{timezone}': {str(e)}"@tooldef 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)}"22 unmodified linesagent = CodeAgent(model=model,tools=[final_answer, webpage_tool, search_tool, image_generation_tool, get_current_time_in_timezone, get_hype_price], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,
app.py+19-18