Raxx · internal docs

internal · gated ↑ index

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

Get Available Strategies

GET /api/strategies

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:

Response:

[
  {
    "symbol": "AAPL",
    "name": "Apple Inc."
  },
  {
    "symbol": "MSFT",
    "name": "Microsoft Corporation"
  },
  // Additional symbols...
]

Run Backtest

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:

  1. delayed_sip (Default): Delayed market data that is available to all users. This data has a 15-minute delay from real-time market data.

  2. 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:

Error responses include a message field with details:

{
  "error": "Invalid symbol provided"
}