0xMagnus commited on
Commit
21e3f4f
·
verified ·
1 Parent(s): 66bfcc3

fix: Adjusted approach with calling for HYPE Spot price

Browse files
Files changed (1) hide show
  1. app.py +19 -18
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 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)}"
@@ -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, get_hyperliquid_price], ## add your tools here (don't remove final answer)
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,