Spaces:
Sleeping
Sleeping
feat: Added new @tool for fetch HYPE price on Hyperliquid Spot Market
Browse files
app.py
CHANGED
|
@@ -33,6 +33,41 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def get_hyperliquid_price(symbol: str = "HYPE") -> str:
|
| 38 |
+
"""A tool that fetches the current price of the HYPE token from Hyperliquid Spot market.
|
| 39 |
+
Args:
|
| 40 |
+
symbol: The trading symbol (defaults to 'HYPE' for HYPE/USDC pair).
|
| 41 |
+
"""
|
| 42 |
+
try:
|
| 43 |
+
# Hyperliquid Spot API endpoint
|
| 44 |
+
url = "https://api.hyperliquid.xyz/info"
|
| 45 |
+
|
| 46 |
+
# Payload for the POST request
|
| 47 |
+
payload = {
|
| 48 |
+
"type": "spotMarket"
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Make the POST request
|
| 52 |
+
response = requests.post(url, json=payload)
|
| 53 |
+
|
| 54 |
+
if response.status_code == 200:
|
| 55 |
+
data = response.json()
|
| 56 |
+
|
| 57 |
+
# Find the HYPE market data
|
| 58 |
+
for market in data:
|
| 59 |
+
if market["name"] == symbol:
|
| 60 |
+
# The price is in USDC terms
|
| 61 |
+
price = float(market["markPrice"])
|
| 62 |
+
return f"Current {symbol}/USDC price on Hyperliquid is: {price} USD"
|
| 63 |
+
|
| 64 |
+
return f"Error: {symbol} market not found on Hyperliquid"
|
| 65 |
+
else:
|
| 66 |
+
return f"Error: Unable to fetch price. Status code: {response.status_code}"
|
| 67 |
+
|
| 68 |
+
except Exception as e:
|
| 69 |
+
return f"Error fetching Hyperliquid price: {str(e)}"
|
| 70 |
+
|
| 71 |
|
| 72 |
final_answer = FinalAnswerTool()
|
| 73 |
|