fix: update token search to use trending endpoint (v2/tokens doesn't exist)
This commit is contained in:
@@ -194,7 +194,7 @@ class ConversationalAgent:
|
|||||||
{
|
{
|
||||||
"symbol": t.get("symbol", ""),
|
"symbol": t.get("symbol", ""),
|
||||||
"name": t.get("name", ""),
|
"name": t.get("name", ""),
|
||||||
"address": t.get("id") or t.get("contract_address", ""),
|
"address": t.get("token", ""), # trending API uses "token" for contract address
|
||||||
"chain": t.get("chain", "bsc")
|
"chain": t.get("chain", "bsc")
|
||||||
}
|
}
|
||||||
for t in tokens
|
for t in tokens
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ class AveCloudClient:
|
|||||||
chain: Optional[str] = None,
|
chain: Optional[str] = None,
|
||||||
limit: int = 20,
|
limit: int = 20,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
url = f"{self.DATA_API_URL}/v2/tokens"
|
# Use trending endpoint which supports chain filter
|
||||||
params = {"limit": limit}
|
url = f"{self.DATA_API_URL}/v2/tokens/trending"
|
||||||
if query:
|
params = {"limit": min(limit, 100)} # API returns max 100
|
||||||
params["query"] = query
|
|
||||||
if chain:
|
if chain:
|
||||||
params["chain"] = chain
|
params["chain"] = chain
|
||||||
|
|
||||||
@@ -36,8 +35,18 @@ class AveCloudClient:
|
|||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get("status") == 200:
|
if data.get("status") == 1: # 1 = SUCCESS
|
||||||
return data.get("data", [])
|
tokens = data.get("data", {}).get("tokens", [])
|
||||||
|
# Filter by query if provided
|
||||||
|
if query:
|
||||||
|
query_lower = query.lower()
|
||||||
|
tokens = [
|
||||||
|
t for t in tokens
|
||||||
|
if query_lower in t.get("symbol", "").lower()
|
||||||
|
or query_lower in t.get("name", "").lower()
|
||||||
|
]
|
||||||
|
return tokens[:limit]
|
||||||
|
return []
|
||||||
raise Exception(f"Failed to fetch tokens: {data}")
|
raise Exception(f"Failed to fetch tokens: {data}")
|
||||||
|
|
||||||
async def get_batch_prices(self, token_ids: List[str]) -> Dict[str, Dict[str, Any]]:
|
async def get_batch_prices(self, token_ids: List[str]) -> Dict[str, Dict[str, Any]]:
|
||||||
|
|||||||
Reference in New Issue
Block a user