Spaces:
Sleeping
Sleeping
fix: adjustments to HYPE index ID and information retrieval cleanup
Browse files
app.py
CHANGED
|
@@ -35,26 +35,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_hype_price() -> str:
|
| 38 |
-
"""A tool that fetches the current HYPE/USDC price from Hyperliquid
|
| 39 |
try:
|
| 40 |
url = "https://api.hyperliquid.xyz/info"
|
| 41 |
-
headers = {
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
# Request payload for
|
| 44 |
payload = {
|
| 45 |
-
"type": "
|
| 46 |
}
|
| 47 |
|
| 48 |
response = requests.post(url, headers=headers, json=payload)
|
| 49 |
|
| 50 |
if response.status_code == 200:
|
| 51 |
data = response.json()
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
return "Error: HYPE
|
| 58 |
else:
|
| 59 |
return f"Error: API request failed with status code {response.status_code}"
|
| 60 |
|
|
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_hype_price() -> str:
|
| 38 |
+
"""A tool that fetches the current HYPE/USDC price from Hyperliquid."""
|
| 39 |
try:
|
| 40 |
url = "https://api.hyperliquid.xyz/info"
|
| 41 |
+
headers = {
|
| 42 |
+
"Content-Type": "application/json"
|
| 43 |
+
}
|
| 44 |
|
| 45 |
+
# Request payload for spot market data
|
| 46 |
payload = {
|
| 47 |
+
"type": "spotMetaAndAssetCtxs"
|
| 48 |
}
|
| 49 |
|
| 50 |
response = requests.post(url, headers=headers, json=payload)
|
| 51 |
|
| 52 |
if response.status_code == 200:
|
| 53 |
data = response.json()
|
| 54 |
+
market_data = data[1] # Market data is in the second array element
|
| 55 |
+
|
| 56 |
+
for market in market_data:
|
| 57 |
+
if market.get("coin") == "@150": # HYPE's index
|
| 58 |
+
mark_price = float(market["markPx"])
|
| 59 |
+
mid_price = float(market["midPx"])
|
| 60 |
+
volume = float(market["dayNtlVlm"])
|
| 61 |
+
|
| 62 |
+
# Format with 2 decimal places as per szDecimals
|
| 63 |
+
return f"HYPE/USDC Price:\n" \
|
| 64 |
+
f"Mark Price: {mark_price:.2f} USDC\n" \
|
| 65 |
+
f"Mid Price: {mid_price:.2f} USDC\n" \
|
| 66 |
+
f"24h Volume: {volume:.2f} USDC"
|
| 67 |
|
| 68 |
+
return "Error: HYPE market not found in response"
|
| 69 |
else:
|
| 70 |
return f"Error: API request failed with status code {response.status_code}"
|
| 71 |
|