TradeMaster API Documentation
Base URL
All API endpoints are relative to the base URL: http://localhost:5001
Authentication
Currently, the API does not require authentication.
Endpoints
Strategy Library (user-defined strategies)
The /api/strategies endpoints manage user-defined strategies (Phase 2: rule grammar + compliance).
All endpoints require a valid raxx_session cookie.
GET /api/strategies List current user's strategies (?active_only=1, ?limit=, ?offset=)
GET /api/strategies/active List active strategies (lightweight picker shape: id, name, strategy_type)
POST /api/strategies Create a new strategy (includes optional rule grammar fields)
GET /api/strategies/<id> Get one strategy by id
PATCH /api/strategies/<id> Partial update (name, description, strategy_type, is_active, rule fields)
DELETE /api/strategies/<id> Hard delete
strategy_type values: iron_condor, vertical_spread, equity_long, equity_short, custom.
Phase 2 rule grammar fields (all optional, null = no constraint):
- entry_symbol_allowlist — CSV of allowed symbols, e.g. "AAPL,MSFT,SPY"
- entry_max_position_size — max dollar amount per trade
- entry_allowed_sides — CSV: "buy", "sell", or "buy,sell"
- credit_min_amount — minimum credit amount for credit strategies
- exit_profit_target_pct — profit target as decimal (0.20 = 20%)
- exit_stop_loss_pct — stop loss as decimal (-0.50 = -50%)
- exit_max_dte — max days-to-expiry for options entries
Compliance check
POST /api/trading/compliance-check
Checks a proposed trade against a strategy's rule grammar. Session-gated.
Body: { strategy_id, symbol, qty, side, price?, order_type? }
Returns: { compliant: bool, strategy: {...}, violations: [{rule, message}, ...] }
This endpoint is used for client-side soft-warn display. When FLAG_TRADE_WINDOW_COMPLIANCE_ENFORCEMENT is ON, the order-submission routes (POST /api/trade-window/orders and POST /api/trade-window/options-orders) also enforce compliance server-side: non-compliant orders where strategy_id is present are rejected with HTTP 422 { "error": "compliance_violation", "violations": [...] }. Client-supplied compliance_compliant / compliance_checked booleans are ignored when the flag is ON.
Get Available Backtest Strategy Templates (legacy)
GET /api/strategies
Note: This endpoint is the legacy backtest template catalogue. The new user-defined Strategy Library above lives at the same
/api/strategiespath and supersedes this doc entry for authenticated users. The legacy backtest template endpoint will be renamed in a future cleanup.
Returns a list of available trading strategies with their parameters.
Response:
[
{
"id": "golden_cross",
"name": "Golden Cross",
"description": "A strategy that generates buy signals when the short-term moving average crosses above the long-term moving average, and sell signals when it crosses below.",
"parameters": [
{
"name": "short_window",
"type": "integer",
"default": 50,
"min": 5,
"max": 100,
"description": "Short-term moving average window"
},
{
"name": "long_window",
"type": "integer",
"default": 200,
"min": 50,
"max": 500,
"description": "Long-term moving average window"
}
]
},
// Additional strategies...
]
Get Symbols
GET /api/symbols
Returns a list of available stock symbols.
Query Parameters:
search(optional): Filter symbols by search term (minimum 2 characters)
Response:
[
{
"symbol": "AAPL",
"name": "Apple Inc."
},
{
"symbol": "MSFT",
"name": "Microsoft Corporation"
},
// Additional symbols...
]
Run Backtest Against Strategy Library (Phase 4a)
POST /api/backtest/run
Requires FLAG_BACKTEST_STRATEGY_LIBRARY=1. Replays a user's Strategy Library entry
deterministically against historical equity bars. Returns an equity curve, trade log,
and summary stats describing what DID happen over the selected period.
Request Body:
{
"strategy_id": 42,
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"starting_capital": 10000.0,
"symbols": ["AAPL", "MSFT"]
}
symbolsis optional; if omitted, uses the strategy'sentry_symbol_allowlist.starting_capitalmust be > 0 and ≤ $10,000,000. Date range must be ≤ 5 years.- Results are cached for 5 minutes (deterministic; same params → same result).
- When the strategy targets options only (iron_condor/vertical_spread), returns HTTP 200
with
{"error": "strategy_not_equity_compatible", "message": "..."}instead of an error.
Run Backtest (legacy — built-in strategies)
POST /api/backtest
Runs a backtest for a specified trading strategy on historical data.
Request Body:
{
"symbol": "AAPL",
"strategy": "golden_cross",
"start_date": "2022-01-01T00:00:00.000Z",
"end_date": "2022-12-31T00:00:00.000Z",
"initial_capital": 10000,
"data_feed": "delayed_sip",
"strategy_params": [
{
"name": "short_window",
"value": 50
},
{
"name": "long_window",
"value": 200
}
]
}
Notes:
- data_feed can be either "delayed_sip" (default) or "sip" (requires subscription)
- strategy_params is an array of parameter objects with name/value pairs
Response:
{
"symbol": "AAPL",
"strategy_name": "Golden Cross",
"start_date": "2022-01-01T00:00:00.000Z",
"end_date": "2022-12-31T00:00:00.000Z",
"initial_capital": 10000,
"final_capital": 12500,
"data_feed": "delayed_sip",
"total_return": 0.25,
"annualized_return": 0.22,
"sharpe_ratio": 1.2,
"max_drawdown": 0.15,
"win_rate": 0.65,
"profit_factor": 1.8,
"total_trades": 24,
"winning_trades": 16,
"losing_trades": 8,
"avg_profit": 350.25,
"avg_loss": -175.50,
"avg_holding_days": 15.3,
"dates": ["2022-01-01", "2022-01-02", ...],
"equity_curve": [10000, 10050, ...],
"drawdowns": [0, 0.005, ...],
"trades": [
{
"date": "2022-02-15T00:00:00.000Z",
"type": "BUY",
"price": 150.25,
"shares": 10,
"value": 1502.50,
"pnl": null,
"return": null,
"duration": null
},
{
"date": "2022-03-10T00:00:00.000Z",
"type": "SELL",
"price": 165.75,
"shares": 10,
"value": 1657.50,
"pnl": 155.00,
"return": 0.1032,
"duration": 23
}
// Additional trades...
]
}
Compare Strategies
POST /api/compare-strategies
Compares multiple trading strategies on the same historical data.
Request Body:
{
"symbol": "AAPL",
"strategies": ["golden_cross", "rsi_strategy"],
"start_date": "2022-01-01T00:00:00.000Z",
"end_date": "2022-12-31T00:00:00.000Z",
"initial_capital": 10000,
"data_feed": "delayed_sip"
}
Notes:
- data_feed can be either "delayed_sip" (default) or "sip" (requires subscription)
Response:
{
"symbol": "AAPL",
"start_date": "2022-01-01T00:00:00.000Z",
"end_date": "2022-12-31T00:00:00.000Z",
"initial_capital": 10000,
"data_feed": "delayed_sip",
"dates": ["2022-01-01", "2022-01-02", ...],
"strategies": [
{
"id": "golden_cross",
"name": "Golden Cross",
"equity_curve": [10000, 10050, ...],
"total_return": 0.25,
"annualized_return": 0.22,
"sharpe_ratio": 1.2,
"max_drawdown": 0.15,
"win_rate": 0.65,
"profit_factor": 1.8,
"total_trades": 24,
"winning_trades": 16,
"losing_trades": 8,
"avg_profit": 350.25,
"avg_loss": -175.50,
"avg_holding_days": 15.3
},
{
"id": "rsi_strategy",
"name": "RSI Strategy",
"equity_curve": [10000, 10020, ...],
"total_return": 0.18,
"annualized_return": 0.16,
"sharpe_ratio": 0.9,
"max_drawdown": 0.12,
"win_rate": 0.60,
"profit_factor": 1.5,
"total_trades": 32,
"winning_trades": 19,
"losing_trades": 13,
"avg_profit": 280.50,
"avg_loss": -190.25,
"avg_holding_days": 12.7
}
]
}
Data Feed Options
The TradeMaster API supports two data feed options:
-
delayed_sip (Default): Delayed market data that is available to all users. This data has a 15-minute delay from real-time market data.
-
sip (Premium): Real-time market data that requires an Alpaca API subscription. This provides up-to-the-minute market data for more accurate backtesting of recent periods.
Error Handling
The API returns standard HTTP status codes:
- 200: Success
- 400: Bad Request (invalid parameters)
- 404: Not Found
- 500: Server Error
Error responses include a message field with details:
{
"error": "Invalid symbol provided"
}