Compare commits

..

3 Commits

Author SHA1 Message Date
8d33ea9a44 Merge pull request 'fix: flatten strategy config schema (backtesting broken)' (#35) from fix/issue-25 into main 2026-04-09 09:32:49 +02:00
shokollm
d81464b869 fix: flatten strategy config schema to match engine expectations
LLM was outputting nested params structure but engines expect flat fields.
This caused backtesting and simulation to never trigger any trades.

Changes:
- llm_connector.py: Update prompt to output flat condition structure
- crew.py: Update StrategyValidator to validate flat structure
- crew.py: Update StrategyExplainer to read flat structure

Fixes #25
2026-04-09 07:31:09 +00:00
55b008d4e8 Merge pull request 'fix: validate chain is 'bsc' for Phase 1' (#34) from fix/issue-31 into main 2026-04-09 09:10:55 +02:00
2 changed files with 27 additions and 34 deletions

View File

@@ -33,29 +33,24 @@ class StrategyValidator:
errors.append(f"Condition {i}: unsupported type '{cond_type}'") errors.append(f"Condition {i}: unsupported type '{cond_type}'")
continue continue
params = condition.get("params", {})
if cond_type in ["price_drop", "price_rise", "volume_spike"]: if cond_type in ["price_drop", "price_rise", "volume_spike"]:
if "token" not in params: if "token" not in condition:
errors.append(f"Condition {i}: missing 'token'") errors.append(f"Condition {i}: missing 'token'")
if "threshold_percent" not in params: if "threshold" not in condition:
errors.append(f"Condition {i}: missing 'threshold_percent'") errors.append(f"Condition {i}: missing 'threshold'")
elif not isinstance(params["threshold_percent"], (int, float)): elif not isinstance(condition["threshold"], (int, float)):
errors.append( errors.append(f"Condition {i}: 'threshold' must be a number")
f"Condition {i}: 'threshold_percent' must be a number" elif condition["threshold"] <= 0:
) errors.append(f"Condition {i}: 'threshold' must be positive")
elif params["threshold_percent"] <= 0:
errors.append(
f"Condition {i}: 'threshold_percent' must be positive"
)
elif cond_type == "price_level": elif cond_type == "price_level":
if "token" not in params: if "token" not in condition:
errors.append(f"Condition {i}: missing 'token'") errors.append(f"Condition {i}: missing 'token'")
if "price" not in params: if "price" not in condition:
errors.append(f"Condition {i}: missing 'price'") errors.append(f"Condition {i}: missing 'price'")
if "direction" not in params: if "direction" not in condition:
errors.append(f"Condition {i}: missing 'direction'") errors.append(f"Condition {i}: missing 'direction'")
elif params["direction"] not in ["above", "below"]: elif condition["direction"] not in ["above", "below"]:
errors.append( errors.append(
f"Condition {i}: direction must be 'above' or 'below'" f"Condition {i}: direction must be 'above' or 'below'"
) )
@@ -85,23 +80,22 @@ class StrategyExplainer:
explanations.append("This strategy will trigger when:") explanations.append("This strategy will trigger when:")
for cond in cond_list: for cond in cond_list:
cond_type = cond.get("type") cond_type = cond.get("type")
params = cond.get("params", {}) token = cond.get("token", "the token")
token = params.get("token", "the token")
if cond_type == "price_drop": if cond_type == "price_drop":
pct = params.get("threshold_percent", 0) pct = cond.get("threshold", 0)
explanations.append(f" - {token} price drops by {pct}%") explanations.append(f" - {token} price drops by {pct}%")
elif cond_type == "price_rise": elif cond_type == "price_rise":
pct = params.get("threshold_percent", 0) pct = cond.get("threshold", 0)
explanations.append(f" - {token} price rises by {pct}%") explanations.append(f" - {token} price rises by {pct}%")
elif cond_type == "volume_spike": elif cond_type == "volume_spike":
pct = params.get("threshold_percent", 0) pct = cond.get("threshold", 0)
explanations.append( explanations.append(
f" - {token} trading volume increases by {pct}%" f" - {token} trading volume increases by {pct}%"
) )
elif cond_type == "price_level": elif cond_type == "price_level":
price = params.get("price", 0) price = cond.get("price", 0)
direction = params.get("direction", "unknown") direction = cond.get("direction", "unknown")
explanations.append( explanations.append(
f" - {token} price crosses {direction} ${price}" f" - {token} price crosses {direction} ${price}"
) )

View File

@@ -61,9 +61,9 @@ class MiniMaxConnector:
system_prompt = """You are a trading strategy designer. Parse the user's natural language request into a JSON strategy_config object. system_prompt = """You are a trading strategy designer. Parse the user's natural language request into a JSON strategy_config object.
Supported conditions (MVP): Supported conditions (MVP):
- price_drop: Token price drops by X% (requires: token, threshold_percent) - price_drop: Token price drops by X% (requires: token, threshold)
- price_rise: Token price rises by X% (requires: token, threshold_percent) - price_rise: Token price rises by X% (requires: token, threshold)
- volume_spike: Trading volume increases X% (requires: token, threshold_percent) - volume_spike: Trading volume increases X% (requires: token, threshold)
- price_level: Price crosses above/below X (requires: token, price, direction) - price_level: Price crosses above/below X (requires: token, price, direction)
Output ONLY valid JSON with this schema: Output ONLY valid JSON with this schema:
@@ -71,18 +71,17 @@ Output ONLY valid JSON with this schema:
"conditions": [ "conditions": [
{ {
"type": "price_drop|price_rise|volume_spike|price_level", "type": "price_drop|price_rise|volume_spike|price_level",
"params": { "token": "TOKEN_SYMBOL",
"token": "TOKEN_SYMBOL", "chain": "bsc",
"threshold_percent": number, // for price_drop, price_rise, volume_spike "threshold": number, // for price_drop, price_rise, volume_spike
"price": number, // for price_level "price": number, // for price_level
"direction": "above|below" // for price_level "direction": "above|below", // for price_level
} "timeframe": "1h"
} }
], ],
"actions": [ "actions": [
{ {
"type": "buy|sell|notify", "type": "buy|sell|notify"
"params": {}
} }
] ]
} }