Spaces:
Sleeping
Sleeping
fix: Adjusted approach with calling for HYPE Spot price
Browse files33 unmodified lines34353637383940413738394340414246434445464748494850515253525455565758575859606162596061626364646566666768697022 unmodified lines939495959697989933 unmodified lines return 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). """def get_hype_price() -> str: """A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market.""" try: # Hyperliquid Spot API endpoint # API endpoint url = "https://api.hyperliquid.xyz/info" # Payload for the POST request # Request headers headers = { "Content-Type": "application/json" } # Request payload for spot market data payload = { "type": "spotMarket" "type": "spotMetaAndAssetCtxs" } # Make the POST request response = requests.post(url, json=payload) response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() # Find the HYPE market data for market in data: if market["name"] == symbol: # The price is in USDC terms price = float(market["markPrice"]) return f"Current {symbol}/USDC price on Hyperliquid is: {price} USD" # Extract HYPE price from the response for market in data[1]: if market["coin"] == "HYPE": price = float(market["markPx"]) return f"Current HYPE/USDC price on Hyperliquid is: {price} USD" return f"Error: {symbol} market not found on Hyperliquid" return "Error: HYPE market not found on Hyperliquid" else: return f"Error: Unable to fetch price. Status code: {response.status_code}" 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 lines agent = 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) 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