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%.
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)
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.
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
- Track last_kline_price during kline processing
- Use last_kline_price instead of entry price for open position valuation
- Add final marked-to-market value to portfolio_values for max_drawdown calculation
- This fixes the issue where max_drawdown exceeded stop_loss percentage
Prototype implementation that allows:
1. Normal conversation with the AI
2. Tool-calling to update trading strategies
Created new ConversationalAgent that uses CrewAI with tools:
- get_current_strategy: Check current bot strategy
- update_trading_strategy: Update bot's trading configuration
The agent can now respond to questions like 'What is this?' without
forcing JSON output, and can update strategies when user provides
specific parameters.
Refs #51
- Use CrewAI's LLM class directly with api_base parameter instead of custom subclass
- Remove broken MiniMaxLLM inheritance from LLM
- Update agent creation to use LLM(model, api_key, api_base) pattern
The issue was that inheriting from CrewAI's LLM class caused the api_base
to be set to None. Now we use CrewAI's LLM directly with the correct parameters.
Fixes#43
Changes:
1. Updated API endpoint from api.minimax.chat to api.minimax.io
2. Changed default model from MiniMax-Text-01 to MiniMax-M2.7
(MiniMax-Text-01 is not available for all API key plans)
3. Updated .env.example with correct default model
MiniMax API docs: https://platform.minimax.io/docs/api-reference/text-anthropic-apiFixes#43
After successful registration, the backend now returns an access token
(along with token_type) so the frontend can:
- Store the token in localStorage
- Fetch the user profile
- Redirect to dashboard
Fixes#41
- Fix relative import path in crew.py (from ..core to ...core)
- Update __init__.py exports to match actual class names
- Remove incorrect CrewAgent and LLMConnector exports
Errors during price fetching are now logged and stored in an errors list,
allowing users to see error count/warnings in simulation results.
Acceptance Criteria:
- [x] Errors are logged (not silently swallowed)
- [x] User can see error count/warnings in simulation results
- [x] Simulation completes even if some price fetches fail (graceful degradation)
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
- Add lifespan handler to main.py for automatic DB table creation
- Expand .env.example with detailed variable documentation
- Add AUDIT_REPORT.md with comprehensive product/technical review
- Add STRATEGY_SCHEMA.md as single source of truth for strategy config
- Remove redundant init_db.py script (DB init now handled by app startup)
- Add tier field to User model for plan detection (free/normal/pro)
- Create AVE Cloud API client with all Data API endpoints:
- Token search (GET /v2/tokens)
- Batch prices (POST /v2/tokens/price)
- Token details (GET /v2/tokens/{id})
- Kline data (GET /v2/klines/token/{id})
- Trending tokens (GET /v2/tokens/trending)
- Token risk (GET /v2/contracts/{id})
- Add Trading API endpoints:
- Chain wallet quote (POST /v1/chain/quote)
- Chain wallet swap (POST /v1/chain/swap)
- Add tier gating with upsell messaging for Pro features
- Handle rate limiting gracefully with 429 responses
- Add Pydantic schemas for AVE API requests/responses
Fixes#11
Implement simulate engine for real-time signal detection via REST polling.
Changes:
- SimulateEngine service with configurable check interval (default 60s for free tier)
- REST polling for current prices using AveCloudClient
- Condition matching for real-time data (price_drop, price_rise, volume_spike, price_level)
- Signal logging with user-initiated start/stop
- Simulation API endpoints:
- POST /api/bots/{id}/simulate - Start simulation
- GET /api/bots/{id}/simulate/{run_id} - Get status/signals
- GET /api/bots/{id}/simulations - List all simulations
- POST /api/bots/{id}/simulate/{run_id}/stop - Stop simulation
- Updated SimulationCreate schema with check_interval field
- Free tier limited to 60s minimum check interval
- Signals stored in database for simulation signal history
Depends on issue #7 (Backtest Engine) which was merged in PR #18
Implements issue #7 - Backtest Engine for historical strategy testing.
Changes:
- Created AveCloudClient for fetching klines from AVE Cloud Data API
- Implemented BacktestEngine with condition matching (price_drop, price_rise, volume_spike, price_level)
- Implemented signal generation and portfolio simulation
- Calculates metrics: total_return, win_rate, max_drawdown, sharpe_ratio, total_trades
- Implemented async/background backtest execution via FastAPI BackgroundTasks
- Stores results in backtests table and signals table
- All backtest API endpoints with JWT auth and ownership validation
API Endpoints:
- POST /api/bots/{id}/backtest - Start backtest
- GET /api/bots/{id}/backtest/{run_id} - Get status/results
- GET /api/bots/{id}/backtests - List all backtests
- POST /api/bots/{id}/backtest/{run_id}/stop - Stop running backtest