Spaces:
Sleeping
Sleeping
fix: Adjusted approach with calling for HYPE Spot price
Browse files
app.py
CHANGED
|
@@ -34,36 +34,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
-
def
|
| 38 |
-
"""A tool that fetches the current
|
| 39 |
-
Args:
|
| 40 |
-
symbol: The trading symbol (defaults to 'HYPE' for HYPE/USDC pair).
|
| 41 |
-
"""
|
| 42 |
try:
|
| 43 |
-
#
|
| 44 |
url = "https://api.hyperliquid.xyz/info"
|
| 45 |
|
| 46 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
payload = {
|
| 48 |
-
"type": "
|
| 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 |
-
#
|
| 58 |
-
for market in data:
|
| 59 |
-
if market["
|
| 60 |
-
|
| 61 |
-
price
|
| 62 |
-
return f"Current {symbol}/USDC price on Hyperliquid is: {price} USD"
|
| 63 |
|
| 64 |
-
return
|
| 65 |
else:
|
| 66 |
-
return f"Error:
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
return f"Error fetching Hyperliquid price: {str(e)}"
|
|
@@ -92,7 +93,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 92 |
|
| 93 |
agent = CodeAgent(
|
| 94 |
model=model,
|
| 95 |
-
tools=[final_answer, webpage_tool, search_tool, image_generation_tool, get_current_time_in_timezone,
|
| 96 |
max_steps=6,
|
| 97 |
verbosity_level=1,
|
| 98 |
grammar=None,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
+
def get_hype_price() -> str:
|
| 38 |
+
"""A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market."""
|
|
|
|
|
|
|
|
|
|
| 39 |
try:
|
| 40 |
+
# API endpoint
|
| 41 |
url = "https://api.hyperliquid.xyz/info"
|
| 42 |
|
| 43 |
+
# Request headers
|
| 44 |
+
headers = {
|
| 45 |
+
"Content-Type": "application/json"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# Request payload for spot market data
|
| 49 |
payload = {
|
| 50 |
+
"type": "spotMetaAndAssetCtxs"
|
| 51 |
}
|
| 52 |
|
| 53 |
# Make the POST request
|
| 54 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 55 |
|
| 56 |
if response.status_code == 200:
|
| 57 |
data = response.json()
|
| 58 |
|
| 59 |
+
# Extract HYPE price from the response
|
| 60 |
+
for market in data[1]:
|
| 61 |
+
if market["coin"] == "HYPE":
|
| 62 |
+
price = float(market["markPx"])
|
| 63 |
+
return f"Current HYPE/USDC price on Hyperliquid is: {price} USD"
|
|
|
|
| 64 |
|
| 65 |
+
return "Error: HYPE market not found on Hyperliquid"
|
| 66 |
else:
|
| 67 |
+
return f"Error: API request failed with status code {response.status_code}"
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error fetching Hyperliquid price: {str(e)}"
|
|
|
|
| 93 |
|
| 94 |
agent = CodeAgent(
|
| 95 |
model=model,
|
| 96 |
+
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)
|
| 97 |
max_steps=6,
|
| 98 |
verbosity_level=1,
|
| 99 |
grammar=None,
|