fix: search for token first to get proper token_id before fetching klines
This commit is contained in:
@@ -46,14 +46,31 @@ class BacktestEngine:
|
|||||||
start_date = self.config.get("start_date", "")
|
start_date = self.config.get("start_date", "")
|
||||||
end_date = self.config.get("end_date", "")
|
end_date = self.config.get("end_date", "")
|
||||||
|
|
||||||
token_id = (
|
# Search for token to get proper token_id (contract address)
|
||||||
f"{token}-{chain}"
|
try:
|
||||||
if token and not token.endswith(f"-{chain}")
|
tokens = await self.ave_client.get_tokens(query=token, chain=chain, limit=10)
|
||||||
else token
|
if not tokens:
|
||||||
)
|
raise ValueError(f"Token '{token}' not found on {chain}")
|
||||||
|
|
||||||
if not token_id or token_id == f"-{chain}":
|
# Find matching token
|
||||||
raise ValueError("Token ID is required")
|
token_info = None
|
||||||
|
for t in tokens:
|
||||||
|
if t.get("symbol", "").upper() == token.upper() or t.get("name", "").upper() == token.upper():
|
||||||
|
token_info = t
|
||||||
|
break
|
||||||
|
|
||||||
|
if not token_info:
|
||||||
|
# Use first result if exact match not found
|
||||||
|
token_info = tokens[0]
|
||||||
|
|
||||||
|
token_id = token_info.get("id") or token_info.get("contract_address")
|
||||||
|
if not token_id:
|
||||||
|
raise ValueError(f"Could not find token ID for '{token}'")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.status = "failed"
|
||||||
|
self.results = {"error": f"Failed to find token: {str(e)}"}
|
||||||
|
return self.results
|
||||||
|
|
||||||
start_ts = None
|
start_ts = None
|
||||||
end_ts = None
|
end_ts = None
|
||||||
|
|||||||
Reference in New Issue
Block a user