Spaces:
Sleeping
Sleeping
fix: simplified approach and pulling HYPE price from perps market instead
Browse files
app.py
CHANGED
|
@@ -42,30 +42,20 @@ def get_hype_price() -> str:
|
|
| 42 |
"Content-Type": "application/json"
|
| 43 |
}
|
| 44 |
|
| 45 |
-
# Request payload for spot market data
|
| 46 |
payload = {
|
| 47 |
-
"type": "
|
| 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 |
-
|
| 57 |
-
|
| 58 |
-
|
| 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
|
| 69 |
else:
|
| 70 |
return f"Error: API request failed with status code {response.status_code}"
|
| 71 |
|
|
|
|
| 42 |
"Content-Type": "application/json"
|
| 43 |
}
|
| 44 |
|
|
|
|
| 45 |
payload = {
|
| 46 |
+
"type": "allMids"
|
| 47 |
}
|
| 48 |
|
| 49 |
response = requests.post(url, headers=headers, json=payload)
|
| 50 |
|
| 51 |
if response.status_code == 200:
|
| 52 |
data = response.json()
|
|
|
|
| 53 |
|
| 54 |
+
if "HYPE" in data:
|
| 55 |
+
price = float(data["HYPE"])
|
| 56 |
+
return f"Current HYPE/USDC price: {price:.4f} USDC"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
return "Error: HYPE price not found in response"
|
| 59 |
else:
|
| 60 |
return f"Error: API request failed with status code {response.status_code}"
|
| 61 |
|