Commit Graph

166 Commits

Author SHA1 Message Date
shokollm
61b9da295b feat: Add /trending tool for popular tokens 2026-04-13 13:51:17 +00:00
shokollm
38e45b9fd0 fix: Use 'Commands:' instead of 'Usage:' to match issue spec 2026-04-13 13:48:17 +00:00
shokollm
e41d07486b feat: Add slash command help system for conversational interface
Implement slash command help system as described in issue #57:

- Add Tool Registry in backend with metadata for all available tools
- Add command parser for '/' prefix in ConversationalAgent
- Add slash command handling functions:
  - '/' shows list of all available tools
  - '/help' shows general help about Randebu
  - '/<tool-name>' shows detailed help for specific tool
- Update frontend ChatInterface to detect '/' and show formatted help dropdown
- Add keyboard navigation (Arrow keys, Tab, Enter, Escape) for slash menu
2026-04-13 13:05:08 +00:00
7e03101e7b Merge pull request 'feat: Add AVE Cloud Skills as conversational agent tools (#56)' (#58) from fix/issue-56 into main 2026-04-13 14:56:33 +02:00
shokollm
70dfba2ffc Merge fixes from pr-58 2026-04-13 12:53:44 +00:00
shokollm
6d204b537d feat: add AVE Cloud Skills integration for conversational agent
- Add subprocess-based AVE Cloud Skills CLI integration for token data
- Add new tools: search_tokens, get_token, get_price, get_risk, get_trending
- Add get_trending tool for trending tokens on BSC
- Replace direct API calls with CLI subprocess calls

Bug fixes:
- Fix repo_root path calculation (5 → 6 dirname() calls)
- Handle API response where data is a list instead of dict
- Add defensive type checking for all API responses
- Handle string values in market_cap and volume formatting
- Handle None values before calling len()
- Handle nested token data structure (data.token) and alternative field names
- Handle integer/bool types for honeypot check (1/0 vs true/false)
- Handle -1 as unknown for honeypot status
- Show raw API response for debugging when data is missing
2026-04-13 12:47:49 +00:00
shokollm
2b7f54703e refactor: use subprocess to call ave-cloud-skill CLI scripts
Instead of importing library functions directly, now calling the
ave_data_rest.py CLI script via subprocess. This follows the
recommended approach from the SKILL.md documentation.

Changes:
- Add _call_ave_script helper method for subprocess calls
- Update search_tokens, get_token, get_price, get_risk to use CLI
- Set AVE_USE_DOCKER=false to run scripts directly without Docker
- Remove direct imports of ave.http module
2026-04-13 10:24:42 +00:00
shokollm
99dded8d16 feat: add AVE Cloud Skills integration for conversational agent tools
- Add ave-cloud-skill as git submodule
- Create symlink for Python import at src/backend/app/ave
- Replace search_tokens with new library-based implementation
- Add get_token, get_price, get_risk tools using ave-cloud-skill library
- Update TOOLS array and SYSTEM_PROMPT_WITH_TOOLS

Implements issue #56
2026-04-13 09:55:04 +00:00
shokollm
29b7634c34 fix: import Simulation at module level 0.1.0 2026-04-12 14:51:50 +00:00
shokollm
fd5c2b56d7 fix: import Simulation model in _manage_simulation 2026-04-12 14:47:32 +00:00
shokollm
632e1bf524 feat: add simulation management as agent skill
Agent can now manage simulations via conversation:
- 'start' (run simulation on token)
- 'stop' (stop running simulation)
- 'status' (check if running, show progress)
- 'results' (get current/latest simulation results)

Example conversations:
- 'Run a simulation on GRIAN' → starts simulation
- 'How's the simulation going?' → shows status
- 'Stop the simulation' → stops and shows results
- 'Show me the results' → shows simulation results
2026-04-12 14:21:32 +00:00
shokollm
5ae1165ad9 fix: import asyncio in _execute_backtest method 2026-04-12 14:07:52 +00:00
shokollm
283573f5a8 feat: add backtest as agent skill
Agent can now run backtests via conversation:
- User can say 'backtest this strategy' or 'test on [token]'
- Agent extracts token address (from conversation or asks user)
- Agent runs backtest and presents results in chat with:
  - Total Return
  - Final Balance
  - Win Rate
  - Max Drawdown
  - Sharpe Ratio
- Agent suggests strategy adjustments based on results
2026-04-12 13:39:54 +00:00
shokollm
90fa66bd39 feat: add refresh button to simulation page
User can now click 'Refresh' to update simulation data (portfolio, signals, trade log) without reloading the page.
2026-04-12 08:39:55 +00:00
shokollm
84d8a6f4a6 fix: add portfolio to SimulationResponse schema
Portfolio data was being saved to DB but not returned in API responses.
2026-04-12 08:15:14 +00:00
shokollm
a8e0baf0c0 fix: save portfolio data to database
Portfolio (cash balance, position, etc.) is now saved to DB
during simulation so it persists and shows in frontend.
2026-04-12 07:41:56 +00:00
shokollm
6c39e4e89d fix: correctly update cash balance when selling
When selling, the sale proceeds (quantity * price) are now added to current_balance.
This ensures:
- Cash decreases when buying
- Cash increases when selling (including stop loss / take profit)
- Portfolio P&L is calculated correctly
2026-04-12 07:24:49 +00:00
shokollm
bba773251a feat: add portfolio summary to simulation page
Shows real-time portfolio metrics:
- Cash Balance
- Position (quantity and value)
- Entry Price / Current Price
- Unrealized P&L
- Total Value
- P&L (absolute and percentage)

Updates as simulation runs and trades are executed.
2026-04-12 07:15:11 +00:00
shokollm
3013326ded feat: add time labels to X axis of price chart
- Shows time (HH:MM) at 5 points along the X axis
- Legend moved up to make room for time labels
- More bottom padding for better display
2026-04-12 07:07:19 +00:00
shokollm
a82185de60 fix: syntax error in simulate.py finally block 2026-04-12 06:18:11 +00:00
shokollm
cadea23e40 fix: respect candle_delay from config, default to fast tests
- Tests now run with candle_delay=0 for fast execution
- Simulation defaults to candle_delay based on interval (e.g., 30s for 1m)
- Progress saved to DB every 5 seconds during simulation
- User can now see real-time updates while simulation runs

Tests: 14 passing in 0.15s
2026-04-12 05:24:43 +00:00
shokollm
984656c83c test: add full integration test for simulation
test_full_simulation_workflow_generates_signals_and_trades:
- Creates klines with clear price movements
- Uses very low threshold (0.1%) to ensure signals generated
- Verifies signals are NOT empty
- Verifies trade_log is NOT empty
- Verifies BUY signals are generated
- Verifies results contain signals and trade_log

This test ensures the simulation engine is working correctly.
2026-04-12 05:00:46 +00:00
shokollm
1505bc9913 fix: serialize datetime objects to ISO format for JSON storage
The signals contain datetime objects for created_at which can't be serialized to JSON directly. Convert them to ISO format strings before storing.
2026-04-12 04:50:24 +00:00
shokollm
dd61c32ea7 feat: add trade activity dashboard
Shows what happened at each candle:
- BUY/SELL/HOLD actions
- Price at that time
- Reason for action
- Entry price for positions

Trade log is stored in DB and displayed in frontend.
2026-04-12 04:28:40 +00:00
shokollm
01ec8bc539 fix: make SignalChart more robust
- Use ResizeObserver to handle width changes
- Use tick() to ensure DOM is ready before drawing
- Access reactive values in effect to trigger on changes
- Fixed canvas sizing to use percentage width
2026-04-12 04:11:34 +00:00
shokollm
a253aae766 fix: limit klines to 1 hour, fix chart parsing string to number
- Kline data now fetches only last hour of data
- SignalChart converts string 'close' prices to numbers
2026-04-12 03:57:22 +00:00
shokollm
13e899c851 fix: fetch klines synchronously before returning response
The background task wasn't completing before the response was returned.
Now we fetch klines synchronously (await) before returning the simulation.
2026-04-12 03:51:03 +00:00
shokollm
384f84e772 fix: fetch klines synchronously so chart shows immediately
The simulation engine completes in seconds, but the background task wasn't
saving klines to DB. Now we fetch klines first synchronously so the user
can see the price chart immediately after starting a simulation.

Also marks any stuck 'running' simulations as 'stopped'.
2026-04-12 03:18:42 +00:00
shokollm
cd1a41d1d7 feat: show price chart even when no signals 2026-04-12 03:02:51 +00:00
shokollm
6a20cc174f feat: add price chart to simulation and unit tests
Unit tests (13 passing):
- Kline fetching and processing
- Price drop condition triggers buy
- Stop loss and take profit risk management
- Multiple positions (buy again after sell)
- Max candles limit
- Stop interruption handling

Frontend:
- SignalChart now shows price movement even before signals
- Shows candle count even with no signals
- Chart displays buy/sell markers when signals exist
- Canvas-based chart with gradient fill

Backend:
- Simulation stores klines for chart display
- Returns klines in API response
- Simplified simulation run (no periodic saving)
2026-04-12 02:42:52 +00:00
shokollm
ce8a29c0a4 fix: update notice message for klines-based simulation 2026-04-12 02:22:17 +00:00
shokollm
f425ae08d7 feat: klines-based simulation instead of polling
- Fetch historical klines once from AVE API (10 CU per request)
- Process each candle as a time step
- Limit to 500 candles max per simulation
- No continuous polling - processes all data in seconds
- Frontend now selects kline interval (1m, 5m, 15m, 1h)
- Much more efficient API usage
2026-04-12 01:34:20 +00:00
shokollm
d4400f5dcd fix: simulation conditions now check properly from first iteration
The first price check was always skipped because last_price was None.
Now first iteration primes last_price, subsequent iterations check conditions.
2026-04-12 00:53:05 +00:00
shokollm
1591fcb1ca fix: remove check_interval restriction for non-pro plans
Simulation is paper trade only, so no need to restrict check_interval.
Allow 10 second intervals for all users.
2026-04-12 00:23:55 +00:00
shokollm
b0131aa566 fix: stop simulation always updates DB status
- Status was only updated if engine was in memory (race condition)
- Now always sets status to 'stopped' in DB
- Returns 'stopped' instead of 'stopping'
- Cleaned up 3 stale running simulations in DB
2026-04-12 00:15:41 +00:00
shokollm
52adc93b25 fix: show running simulation correctly, stop old ones when starting new
Frontend:
- Load simulations now prioritizes running simulation over most recent
- Clear signals before loading new simulation

Backend:
- When starting new simulation, stop any existing running simulation first
- Previously would return existing running simulation (confusing UX)
2026-04-12 00:10:10 +00:00
shokollm
79c3ec7d16 fix: typo in simulate page svelte 2026-04-12 00:00:47 +00:00
shokollm
3505cf4ade refactor: simplify simulation to run forever as paper trade
- No duration limit - runs forever until user stops
- Only 1 running simulation per bot (returns existing if already running)
- Always paper trade (no auto-execute option)
- Removed Pro upgrade banner
- Removed duration and auto-execute config options
- Simplified API to only require token, chain, check_interval
2026-04-11 23:52:00 +00:00
shokollm
1b1358353f feat: configurable simulation duration and periodic signal saving
Frontend:
- Added duration selector (1min, 5min, 10min, 30min)
- Added check interval selector (10s, 30s, 60s)

Backend:
- Signals are now saved to database every 30 seconds during simulation
- Can stop simulation early to see partial signals
2026-04-11 17:56:27 +00:00
shokollm
726e579f5f fix: get_token_price checking wrong status code
The AVE API returns status: 1 for success, not status: 200.
This was causing get_token_price to always return None, resulting
in no signals being generated during simulation.
2026-04-11 17:45:59 +00:00
shokollm
b111e4d79f fix: make SimulateEngine.stop() synchronous
The stop() method was async but called from a sync context,
causing 'RuntimeError: no running event loop'. Changed to sync
since it just sets flags.
2026-04-11 17:35:18 +00:00
shokollm
0d63a10ac8 fix: correct simulation API field names
The backend expects 'check_interval' not 'interval_seconds',
and 'chain' is required.
2026-04-11 17:22:45 +00:00
shokollm
19f28fc599 feat: use token from strategy config in simulation page
Like the backtest page, simulation now extracts the token from the
bot's strategy config instead of requiring user input. Shows token
name and truncated address.
2026-04-11 17:17:26 +00:00
shokollm
5f7667992e feat: display backtest config in history card
Show token, timeframe, and date range for each backtest in the history list:
- Token: PEPE
- TF: 1h
- Period: 2026-03-11 to 2026-04-09
2026-04-11 17:11:24 +00:00
shokollm
cd4583ca90 feat: add pagination for trade history in backtest
Backend:
- Added pagination to /trades endpoint with page and per_page params
- Returns paginated trades with metadata (page, total_pages, has_next, has_prev)

Frontend:
- Added pagination controls for trade history (Prev/Next buttons)
- Shows current page info and total trades
- Trades are loaded on-demand when expanded

API changes:
- GET /bots/{id}/backtest/{runId}/trades?page=1&per_page=5
- Response includes: trades, total_trades, page, per_page, total_pages, has_next, has_prev
2026-04-11 16:52:45 +00:00
shokollm
6cadb7a67b test: verify stop loss always results in loss
Add test case that ensures when stop loss is triggered after multiple
DCA buys with decreasing prices, the final balance is always less
than the initial balance.
2026-04-11 16:27:04 +00:00
shokollm
02e0b0ccab fix: proper DCA and max_drawdown calculations in backtest engine
Three bugs fixed:

1. **Weighted average entry price for risk management**:
   - Previously, entry_price was overwritten on each buy, causing stop loss
     to be calculated from the latest buy price instead of average
   - Added cost_basis tracking and average_entry_price property
   - Stop loss now correctly uses weighted average across all buys

2. **Portfolio value accumulation in _calculate_metrics**:
   - Bug: running_position = trade['quantity'] was OVERWRITING position
   - Fix: running_position += trade['quantity'] to properly accumulate DCA

3. **Risk management exit reset**:
   - Added cost_basis reset when position is closed

Max drawdown is now correctly bounded by stop loss percentage (~5%)
instead of showing inflated values like 59%.
2026-04-11 15:54:15 +00:00
shokollm
29ec67cced fix: handle floating point precision in take_profit check and final_balance calculation
Two bugs fixed:
1. final_balance was incorrectly calculated as balance + balance when position=0 due to expression structure
2. take_profit check needed epsilon for floating point precision (95 * 1.10 = 104.50000000000001 instead of 104.5)
2026-04-11 15:02:53 +00:00
shokollm
c86e71c3a3 fix: correct final_balance calculation in _calculate_metrics
Bug: The expression was evaluating incorrectly due to operator precedence:
  final_balance = balance + (position * price if condition else balance)

When condition=False (position=0), this became: balance + balance = 2x balance!

Fixed by restructuring to if/else block.
2026-04-11 15:00:52 +00:00
shokollm
44fb840731 fix: correctly track balance in portfolio value calculation for max_drawdown
The bug was that running_balance was set to trade['amount'] which is
the amount SPENT on a buy (not remaining balance), causing inflated
portfolio values and incorrect max drawdown calculation.

Now properly tracks:
- After BUY: balance decreases by amount spent
- After SELL: balance increases by amount received
2026-04-11 14:22:47 +00:00