-
Notifications
You must be signed in to change notification settings - Fork 704
Expand file tree
/
Copy pathtoken_analytics.py
More file actions
66 lines (50 loc) · 1.92 KB
/
token_analytics.py
File metadata and controls
66 lines (50 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import logging
from typing import Any, Dict
from langchain_core.runnables import RunnableConfig
from pydantic import BaseModel, Field
from skills.token.base import TokenBaseTool
from skills.token.constants import DEFAULT_CHAIN
logger = logging.getLogger(__name__)
class TokenAnalyticsInput(BaseModel):
"""Input for token analytics tool."""
address: str = Field(description="The token address to get analytics for.")
chain: str = Field(
description="The chain to query (e.g., 'eth', 'bsc', 'polygon').",
default=DEFAULT_CHAIN,
)
class TokenAnalytics(TokenBaseTool):
"""Tool for retrieving token analytics using Moralis.
This tool uses Moralis' API to fetch analytics for a token by token address,
including trading volume, buyer/seller data, and liquidity information.
"""
name: str = "token_analytics"
description: str = (
"Get analytics for a token by token address. "
"Returns trading volumes, number of buyers/sellers, and liquidity information over various time periods."
)
args_schema: type[BaseModel] = TokenAnalyticsInput
async def _arun(
self,
address: str,
chain: str = DEFAULT_CHAIN,
config: RunnableConfig = None,
**kwargs,
) -> Dict[str, Any]:
"""Fetch token analytics from Moralis.
Args:
address: The token address
chain: The blockchain to query
config: The configuration for the tool call
Returns:
Dict containing token analytics data
"""
context = self.context_from_config(config)
# Get the API key
api_key = self.get_api_key(context)
# Build query parameters
params = {"chain": chain}
# Call Moralis API
endpoint = f"/tokens/{address}/analytics"
return await self._make_request(
method="GET", endpoint=endpoint, api_key=api_key, params=params
)