Configuration
All trading parameters in one place.
Trading Parameters
Configure via the dashboard, POST /agent/config, or edit defaults in src/strategy/default/config.ts:
| Setting | Default | Description |
|---|---|---|
max_positions |
5 | Maximum concurrent positions |
max_position_value |
5000 | Maximum $ per position |
take_profit_pct |
10 | Auto-sell at this % profit |
stop_loss_pct |
5 | Auto-sell at this % loss |
risk_per_trade_pct |
0.75 | Maximum account risk per trade, applied with stop distance and ATR-aware sizing |
min_sentiment_score |
0.3 | Minimum sentiment to consider (0-1) |
min_signal_quality_score |
0.35 | Minimum source quality, freshness, volume, and direction-agreement score before research |
min_analyst_confidence |
0.6 | Minimum LLM confidence to trade (0-1) |
position_size_pct_of_cash |
15 | Max % of available cash per trade before candidate score and risk-budget sizing |
entry_require_technical_data |
false | Require RSI/SMA/Bollinger data before allowing entry-timing-filtered buys |
dynamic_tp_fallback_pct |
12 | Dynamic take-profit target used when ATR is unavailable |
unknown_sector_max_positions |
2 | Separate concentration cap for symbols whose sector cannot be inferred |
LLM Configuration
| Setting | Default | Description |
|---|---|---|
llm_provider |
openai-raw | openai-raw, ai-sdk, or cloudflare-gateway |
llm_model |
gpt-4o-mini | Model for bulk research (cheap, fast) |
llm_analyst_model |
gpt-4o | Model for trading decisions (smarter) |
Timing Parameters
Market timing uses the Alpaca clock (next_open, is_open) so it stays correct across timezones and holidays.
| Setting | Default | Description |
|---|---|---|
data_poll_interval_ms |
30000 | How often to fetch signals (30s) |
analyst_interval_ms |
120000 | How often to run trading logic (2min) |
premarket_plan_window_minutes |
5 | Generate a pre-market plan when within N minutes of next_open |
market_open_execute_window_minutes |
2 | Execute the pre-market plan if the market is open and within this window after open |
Optional Features
| Setting | Default | Description |
|---|---|---|
options_enabled |
false | Enable options trading |
crypto_enabled |
false | Enable 24/7 crypto trading |
crypto_symbols |
["BTC/USD", "ETH/USD", "SOL/USD"] | Which cryptos to trade |
stale_position_enabled |
true | Auto-exit positions that lose momentum |
ticker_blacklist |
[] | Symbols to never trade (e.g., insider restrictions) |
Data Source Credentials
Sentinel Settings is the preferred place to manage source credentials because it supports account rotation and connection tests. Worker secrets are useful as fallback defaults.
| Setting | Secret fallback | Description |
|---|---|---|
twitter_cookie_accounts |
TWITTER_COOKIES |
Multiple Twitter/X cookie accounts rotated for confirmation searches |
reddit_cookie_accounts |
REDDIT_COOKIES |
Multiple Reddit cookie accounts rotated by the Reddit gatherer |
reddit_user_agent |
REDDIT_USER_AGENT |
User-agent used for Reddit requests |
alpha_vantage_api_key |
ALPHA_VANTAGE_API_KEY |
Enables Alpha Vantage news sentiment catalyst signals |
Environment Variables
Set in .dev.vars (local) or via wrangler secret put (production):
| Variable | Required | Description |
|---|---|---|
MAHORAGA_API_TOKEN |
Yes | API auth token for all endpoints. Generate with: openssl rand -base64 48 |
ALPACA_API_KEY |
Yes | Your Alpaca API key |
ALPACA_API_SECRET |
Yes | Your Alpaca API secret |
ALPACA_PAPER |
Yes | true for paper trading (recommended) |
OPENAI_API_KEY |
Depends | Required if using openai-raw or ai-sdk with OpenAI |
KILL_SWITCH_SECRET |
Yes | Separate secret for emergency kill switch |
DISCORD_WEBHOOK_URL |
No | Get Discord alerts on BUY signals |
TWITTER_BEARER_TOKEN |
No | Optional fallback for Twitter confirmation if cookies are not configured |
TWITTER_COOKIES |
No | Optional single-account fallback; Sentinel config supports multiple accounts |
REDDIT_COOKIES |
No | Optional single-account fallback; Sentinel config supports multiple accounts |
ALPHA_VANTAGE_API_KEY |
No | Optional news sentiment source; can also be stored in runtime config |
Safety Features
These are enforced by the PolicyEngine (via PolicyBroker for autonomous trades, or via MCP for external tools):
| Feature | Description |
|---|---|
| Kill Switch | Emergency halt for all trading |
| Position Limits | Max positions and $ per position |
| Daily Loss Limit | Stops trading after 2% daily loss |
| Cooldown Period | 30-minute pause after losses |
| Approval Tokens | Orders expire after 5 minutes |
| LLM Confidence Gate | Trades require minimum confidence |
| No Margin | Cash-only trading |
| No Shorting | Long positions only |
API Endpoints
All endpoints require Authorization: Bearer $MAHORAGA_API_TOKEN
| Endpoint | Description |
|---|---|
GET /agent/status |
Full status: account, positions, signals, config |
GET /agent/enable |
Start the trading agent |
GET /agent/disable |
Stop the trading agent |
GET /agent/config |
Get current configuration |
POST /agent/config |
Update configuration (JSON body) |
GET /agent/logs |
Recent activity logs |
GET /agent/trade-review |
Indexed trade decisions with optional R2 snapshots for analysis |
POST /agent/twitter/test |
Test Twitter/X cookie accounts from Sentinel Settings |
POST /agent/reddit/test |
Test Reddit cookie accounts from Sentinel Settings |
GET /agent/costs |
LLM usage and costs |
GET /agent/signals |
Current signal cache |
GET /agent/trigger |
Manually trigger the agent loop (testing) |
GET /agent/kill |
Emergency stop (requires KILL_SWITCH_SECRET) |
Tuning Tips
Agent not making trades?
- Lower
min_analyst_confidenceto 0.5 - Lower
min_sentiment_scoreto 0.2 - Check
max_positions— you might be at the limit - Check
/agent/statusfor signal research results
Too many trades?
- Raise
min_analyst_confidenceto 0.7+ - Raise
min_sentiment_scoreto 0.4+ - Lower
max_positions
High LLM costs?
- Use
gpt-4o-minifor both models (cheapest) - Increase
data_poll_interval_msto 60000+ - Check
/agent/costsfor usage breakdown
Using a different LLM provider?
- Set
llm_providertoai-sdk - Set
llm_modeltoanthropic/claude-sonnet-4orgoogle/gemini-2.5-flash - Add the corresponding API key (e.g.,
ANTHROPIC_API_KEY)