Compare commits
3 Commits
pr-58
...
70dfba2ffc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70dfba2ffc | ||
|
|
2b7f54703e | ||
|
|
99dded8d16 |
@@ -163,28 +163,6 @@ TOOLS = [
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_trending",
|
||||
"description": "Get trending tokens on a blockchain. Use when user asks what's trending, top tokens, or popular tokens right now.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"chain": {
|
||||
"type": "string",
|
||||
"description": "Blockchain chain (default: bsc)",
|
||||
"default": "bsc",
|
||||
},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"description": "Number of trending tokens to return (default: 10, max: 50)",
|
||||
"default": 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
@@ -253,7 +231,6 @@ You have access to tools:
|
||||
- get_token(address, chain): Get detailed information about a specific token. Use when user asks for token details.
|
||||
- get_price(token_ids): Get current price(s) for tokens. Use when user asks for token price.
|
||||
- get_risk(address, chain): Get risk analysis for a token. Use when user asks about token safety or honeypot analysis.
|
||||
- get_trending(chain, limit): Get trending tokens on a blockchain. Use when user asks what's trending, top tokens, or popular tokens.
|
||||
- run_backtest(token_address, timeframe, start_date, end_date): Run a backtest on historical data. Returns performance metrics. Use when user asks to backtest or check historical performance.
|
||||
- manage_simulation(action, token_address, kline_interval): Manage trading simulations. Actions: 'start' (begin new), 'stop' (stop running), 'status' (check if running), 'results' (get current/latest results).
|
||||
|
||||
@@ -318,11 +295,11 @@ class ConversationalAgent:
|
||||
},
|
||||
)
|
||||
|
||||
result = resp.json() or {}
|
||||
result = resp.json()
|
||||
|
||||
# Extract thinking from reasoning_content
|
||||
thinking = None
|
||||
if result.get("choices") and len(result.get("choices", [])) > 0:
|
||||
if "choices" in result and len(result["choices"]) > 0:
|
||||
choice = result["choices"][0]
|
||||
if "message" in choice:
|
||||
message = choice["message"]
|
||||
@@ -354,12 +331,7 @@ class ConversationalAgent:
|
||||
if code == 0:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
# Handle both dict with 'tokens' key and direct list
|
||||
data_field = data.get("data", [])
|
||||
if isinstance(data_field, list):
|
||||
tokens = data_field
|
||||
else:
|
||||
tokens = data_field.get("tokens", [])
|
||||
tokens = data.get("data", {}).get("tokens", [])
|
||||
if tokens:
|
||||
token_list = ""
|
||||
for t in tokens[:limit]:
|
||||
@@ -370,11 +342,7 @@ class ConversationalAgent:
|
||||
"token_price_change_24h", "N/A"
|
||||
)
|
||||
mc = t.get("market_cap", "N/A")
|
||||
try:
|
||||
mc_str = f"${float(mc):,.0f}"
|
||||
except (ValueError, TypeError):
|
||||
mc_str = str(mc)
|
||||
token_list += f"- **{symbol}** ({name}): `{addr}` - MC: {mc_str} - 24h: {price_change}%\n"
|
||||
token_list += f"- **{symbol}** ({name}): `{addr}` - MC: ${mc:,.0f} - 24h: {price_change}%\n"
|
||||
response_text = f"Here are the search results for '{keyword}' on BSC:\n\n{token_list}\nWould you like me to set up a strategy for any of these?"
|
||||
else:
|
||||
response_text = f"No tokens found for '{keyword}'. Try a different keyword."
|
||||
@@ -403,51 +371,24 @@ class ConversationalAgent:
|
||||
if code == 0:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
data_field = data.get("data")
|
||||
# Handle both dict and list responses
|
||||
token_data = data_field if isinstance(data_field, dict) else {}
|
||||
# Token details may be nested in 'token' key
|
||||
token_info = token_data.get("token", token_data)
|
||||
# Check if token has valid symbol/name (not None, not 'N/A')
|
||||
symbol = token_info.get("symbol") or token_data.get("symbol")
|
||||
name = token_info.get("name") or token_data.get("name")
|
||||
if not symbol or symbol == "N/A" or not name or name == "N/A":
|
||||
response_text = f"Token not found for {address}. Raw response: {output[:500]}"
|
||||
else:
|
||||
# Try different price field names
|
||||
price = (token_info.get("current_price_usd")
|
||||
or token_info.get("price_usd")
|
||||
or token_info.get("price")
|
||||
or token_data.get("price")
|
||||
or "N/A")
|
||||
mc = (token_info.get("market_cap")
|
||||
or token_info.get("fdv")
|
||||
or token_data.get("market_cap")
|
||||
or "N/A")
|
||||
vol = (token_info.get("tx_volume_u_24h")
|
||||
or token_info.get("volume_24h")
|
||||
or token_data.get("volume_24h")
|
||||
or "N/A")
|
||||
pairs = token_info.get("top_pairs") or token_data.get("top_pairs") or []
|
||||
token_data = data.get("data", {})
|
||||
if token_data:
|
||||
symbol = token_data.get("symbol", "N/A")
|
||||
name = token_data.get("name", "N/A")
|
||||
price = token_data.get("price", "N/A")
|
||||
mc = token_data.get("market_cap", "N/A")
|
||||
vol = token_data.get("volume_24h", "N/A")
|
||||
pairs = token_data.get("top_pairs", [])
|
||||
pairs_text = ""
|
||||
if pairs:
|
||||
pairs_text = "\n**Top Pairs:**\n"
|
||||
for p in pairs[:3]:
|
||||
liq = p.get('liquidity', 'N/A')
|
||||
try:
|
||||
liq_str = f"${float(liq):,.0f}"
|
||||
except (ValueError, TypeError):
|
||||
liq_str = str(liq)
|
||||
pairs_text += f"- {p.get('pair', 'N/A')}: {liq_str} liquidity\n"
|
||||
try:
|
||||
mc_str = f"${float(mc):,.0f}" if mc != "N/A" else "N/A"
|
||||
except (ValueError, TypeError):
|
||||
mc_str = str(mc)
|
||||
try:
|
||||
vol_str = f"${float(vol):,.0f}" if vol != "N/A" else "N/A"
|
||||
except (ValueError, TypeError):
|
||||
vol_str = str(vol)
|
||||
response_text = f"**{symbol}** ({name})\n\nPrice: ${price}\nMarket Cap: {mc_str}\n24h Volume: {vol_str}{pairs_text}"
|
||||
pairs_text += f"- {p.get('pair', 'N/A')}: ${p.get('liquidity', 'N/A'):,.0f} liquidity\n"
|
||||
response_text = f"**{symbol}** ({name})\n\nPrice: ${price}\nMarket Cap: ${mc:,.0f}\n24h Volume: ${vol:,.0f}{pairs_text}"
|
||||
else:
|
||||
response_text = (
|
||||
f"Token not found: {address}"
|
||||
)
|
||||
except json.JSONDecodeError:
|
||||
response_text = "Failed to parse token data."
|
||||
else:
|
||||
@@ -477,9 +418,6 @@ class ConversationalAgent:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
prices = data.get("data", {})
|
||||
# Ensure prices is a dict
|
||||
if not isinstance(prices, dict):
|
||||
prices = {}
|
||||
if prices:
|
||||
price_text = "**Token Prices:**\n"
|
||||
for (
|
||||
@@ -525,53 +463,27 @@ class ConversationalAgent:
|
||||
if code == 0:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
data_field = data.get("data")
|
||||
# Handle both dict and list responses
|
||||
risk_data = data_field if isinstance(data_field, dict) else {}
|
||||
risk_data = data.get("data", {})
|
||||
if risk_data:
|
||||
is_honeypot = risk_data.get(
|
||||
"is_honeypot", "unknown"
|
||||
)
|
||||
buy_tax = risk_data.get("buy_tax", 0)
|
||||
sell_tax = risk_data.get("sell_tax", 0)
|
||||
buy_tax = risk_data.get("buy_tax", "N/A")
|
||||
sell_tax = risk_data.get("sell_tax", "N/A")
|
||||
status = risk_data.get("status", "unknown")
|
||||
# Convert is_honeypot to string for comparison
|
||||
if isinstance(is_honeypot, bool):
|
||||
is_honeypot_str = str(is_honeypot).lower()
|
||||
elif isinstance(is_honeypot, int):
|
||||
if is_honeypot == 1:
|
||||
is_honeypot_str = "true"
|
||||
elif is_honeypot == 0:
|
||||
is_honeypot_str = "false"
|
||||
else:
|
||||
is_honeypot_str = "unknown" # -1 or other means couldn't determine
|
||||
else:
|
||||
is_honeypot_str = str(is_honeypot).lower() if is_honeypot else "unknown"
|
||||
|
||||
# Format honeypot display value
|
||||
if is_honeypot_str == "unknown":
|
||||
honeypot_display = "Unknown (could not determine)"
|
||||
else:
|
||||
honeypot_display = is_honeypot_str
|
||||
# Convert tax values to float for comparison
|
||||
try:
|
||||
buy_tax_val = float(buy_tax) if buy_tax not in (None, "N/A") else 0
|
||||
except (ValueError, TypeError):
|
||||
buy_tax_val = 0
|
||||
try:
|
||||
sell_tax_val = float(sell_tax) if sell_tax not in (None, "N/A") else 0
|
||||
except (ValueError, TypeError):
|
||||
sell_tax_val = 0
|
||||
risk_text = (
|
||||
f"**Risk Analysis for {address}**\n\n"
|
||||
)
|
||||
risk_text += f"- Status: {status}\n"
|
||||
risk_text += f"- Honeypot: {honeypot_display}\n"
|
||||
risk_text += f"- Honeypot: {is_honeypot}\n"
|
||||
risk_text += f"- Buy Tax: {buy_tax}%\n"
|
||||
risk_text += f"- Sell Tax: {sell_tax}%\n"
|
||||
if is_honeypot_str == "true":
|
||||
if is_honeypot.lower() == "true":
|
||||
risk_text += "\n⚠️ **Warning: This token appears to be a honeypot. Do not buy!**"
|
||||
elif buy_tax_val > 10 or sell_tax_val > 10:
|
||||
elif (
|
||||
float(buy_tax or 0) > 10
|
||||
or float(sell_tax or 0) > 10
|
||||
):
|
||||
risk_text += "\n⚠️ **Warning: High tax detected. Trade with caution!**"
|
||||
else:
|
||||
risk_text += "\n✅ This token appears safe to trade."
|
||||
@@ -593,49 +505,6 @@ class ConversationalAgent:
|
||||
"success": True,
|
||||
}
|
||||
|
||||
elif func_name == "get_trending":
|
||||
chain = args.get("chain", "bsc")
|
||||
limit = args.get("limit", 10)
|
||||
|
||||
code, output = self._call_ave_script(
|
||||
"trending",
|
||||
["--chain", chain, "--page-size", str(min(limit, 50))],
|
||||
)
|
||||
if code == 0:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
data_field = data.get("data")
|
||||
# Handle both dict and list responses
|
||||
tokens = data_field if isinstance(data_field, list) else data_field.get("tokens", [])
|
||||
if tokens:
|
||||
token_list = ""
|
||||
for t in tokens[:limit]:
|
||||
addr = t.get("token", "")
|
||||
symbol = t.get("symbol", "")
|
||||
name = t.get("name", "")
|
||||
price_change = t.get("token_price_change_24h", "N/A")
|
||||
mc = t.get("market_cap", "N/A")
|
||||
try:
|
||||
mc_str = f"${float(mc):,.0f}"
|
||||
except (ValueError, TypeError):
|
||||
mc_str = str(mc)
|
||||
token_list += f"- **{symbol}** ({name}): `{addr}` - MC: {mc_str} - 24h: {price_change}%\n"
|
||||
response_text = f"🔥 Trending tokens on {chain.upper()}:\n\n{token_list}\nWould you like me to set up a strategy for any of these?"
|
||||
else:
|
||||
response_text = f"No trending tokens found on {chain.upper()}."
|
||||
except json.JSONDecodeError:
|
||||
response_text = "Failed to parse trending data."
|
||||
else:
|
||||
response_text = f"Failed to get trending tokens: {output}"
|
||||
|
||||
return {
|
||||
"response": response_text,
|
||||
"thinking": thinking,
|
||||
"strategy_updated": False,
|
||||
"strategy_needs_confirmation": False,
|
||||
"success": True,
|
||||
}
|
||||
|
||||
elif func_name == "run_backtest":
|
||||
token_address = args.get("token_address")
|
||||
timeframe = args.get("timeframe", "1d")
|
||||
@@ -731,12 +600,7 @@ class ConversationalAgent:
|
||||
if code == 0:
|
||||
try:
|
||||
data = json.loads(output)
|
||||
# Handle both dict with 'tokens' key and direct list
|
||||
data_field = data.get("data", [])
|
||||
if isinstance(data_field, list):
|
||||
tokens = data_field
|
||||
else:
|
||||
tokens = data_field.get("tokens", [])
|
||||
tokens = data.get("data", {}).get("tokens", [])
|
||||
if tokens:
|
||||
token_list = ""
|
||||
for t in tokens[:limit]:
|
||||
@@ -747,11 +611,7 @@ class ConversationalAgent:
|
||||
"token_price_change_24h", "N/A"
|
||||
)
|
||||
mc = t.get("market_cap", "N/A")
|
||||
try:
|
||||
mc_str = f"${float(mc):,.0f}"
|
||||
except (ValueError, TypeError):
|
||||
mc_str = str(mc)
|
||||
token_list += f"- **{symbol}** ({name}): `{addr}` - MC: {mc_str} - 24h: {price_change}%\n"
|
||||
token_list += f"- **{symbol}** ({name}): `{addr}` - MC: ${mc:,.0f} - 24h: {price_change}%\n"
|
||||
response_text = f"Here are the search results for '{keyword}' on BSC:\n\n{token_list}\nWould you like me to set up a strategy for any of these?"
|
||||
else:
|
||||
response_text = f"No tokens found for '{keyword}'. Try a different keyword."
|
||||
@@ -775,7 +635,7 @@ class ConversationalAgent:
|
||||
if strategy_update:
|
||||
# Extract token name from conditions
|
||||
token_name = None
|
||||
for cond in (strategy_update.get("conditions") or []):
|
||||
for cond in strategy_update.get("conditions", []):
|
||||
if not cond.get("token_address") and cond.get("token"):
|
||||
token_name = cond.get("token")
|
||||
strategy_needs_confirmation = True
|
||||
@@ -790,12 +650,7 @@ class ConversationalAgent:
|
||||
)
|
||||
if code == 0:
|
||||
data = json.loads(output)
|
||||
# Handle both dict with 'tokens' key and direct list
|
||||
data_field = data.get("data", [])
|
||||
if isinstance(data_field, list):
|
||||
tokens = data_field
|
||||
else:
|
||||
tokens = data_field.get("tokens", [])
|
||||
tokens = data.get("data", {}).get("tokens", [])
|
||||
if tokens:
|
||||
token_search_results = [
|
||||
{
|
||||
@@ -1218,7 +1073,7 @@ Would you like me to adjust the strategy parameters based on these results?"""
|
||||
|
||||
settings = get_settings()
|
||||
repo_root = os.path.dirname(
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
)
|
||||
ave_skill_path = os.path.join(
|
||||
repo_root, "ave-cloud-skill", "scripts", "ave_data_rest.py"
|
||||
@@ -1237,11 +1092,7 @@ Would you like me to adjust the strategy parameters based on these results?"""
|
||||
env=env,
|
||||
timeout=30,
|
||||
)
|
||||
# Include stderr in output for debugging
|
||||
output = result.stdout
|
||||
if result.returncode != 0 and result.stderr:
|
||||
output = f"{output}\n{result.stderr}".strip()
|
||||
return result.returncode, output
|
||||
return result.returncode, result.stdout
|
||||
except subprocess.TimeoutExpired:
|
||||
return 1, "Error: Command timed out"
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user