Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cryptorobot.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Strategies define the logic for automated trading. They combine technical indicators with entry/exit rules to generate buy and sell signals.

Creating a Strategy

Create a strategy with base parameters:
curl -X POST https://api.cryptorobot.ai/strategies \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "BTC Momentum",
    "interval": "1m",
    "stoploss": -0.036,
    "exit_profit_only": true,
    "exit_profit_offset": 10,
    "exit_sell_signal": true
  }'
Response
{
  "_id": "684b2f...",
  "name": "BTC Momentum",
  "interval": "1m",
  "stoploss": -0.036,
  "exit_profit_only": true,
  "exit_profit_offset": 10,
  "exit_sell_signal": true,
  "configured": false,
  "createdAt": "2024-01-15T10:00:00.000Z",
  "updatedAt": "2024-01-15T10:00:00.000Z"
}

Templates

Templates provide pre-configured strategy types (e.g., BbandRsi, MacdCrossover). When you assign a templateId, the template’s values propagate to the strategy on the first patch only.

List Templates

curl https://api.cryptorobot.ai/strategies/templates \
  -H "Authorization: Bearer $TOKEN"
Response
{
  "data": [
    {
      "_id": "tmpl-1",
      "name": "Bollinger RSI",
      "type": "BbandRsi",
      "description": "Bollinger Band breakout with RSI confirmation",
      "values": {
        "stoploss": -0.077,
        "interval": "1m",
        "timeinforce": "GTC",
        "exit_profit_only": false,
        "exit_profit_offset": 20,
        "exit_sell_signal": false
      }
    }
  ]
}

Apply Template with Indicators

Patching with templateId + indicators generates the strategy file and sets configured: true:
curl -X PATCH https://api.cryptorobot.ai/strategies/684b2f... \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "tmpl-1",
    "indicators": [
      {
        "_id": "ta.rsi",
        "alias": "rsi",
        "name": "RSI",
        "group": "Momentum Indicators",
        "description": "Relative Strength Index",
        "optInputs": [
          { "name": "optInTimePeriod", "displayName": "Time Period", "defaultValue": 14, "type": "integer_range" }
        ]
      },
      {
        "_id": "qtpylib.bb_upperband",
        "name": "Bollinger Band (High)",
        "group": "Bollinger Bands",
        "alias": "bb_upperband",
        "optInputs": []
      },
      {
        "_id": "qtpylib.bb_lowerband",
        "name": "Bollinger Band (Lower)",
        "group": "Bollinger Bands",
        "alias": "bb_lowerband",
        "optInputs": []
      }
    ]
  }'
Response
{
  "_id": "684b2f...",
  "name": "BTC Momentum",
  "interval": "1m",
  "stoploss": -0.077,
  "configured": true,
  "templateId": "tmpl-1",
  "file": { "id": "strategies/684b2f...py" },
  "strategies/indicators": [
    { "_id": "ta.rsi", "name": "RSI" },
    { "_id": "qtpylib.bb_upperband", "name": "Bollinger Band (High)" },
    { "_id": "qtpylib.bb_lowerband", "name": "Bollinger Band (Lower)" }
  ],
  "strategies/templates": {
    "_id": "tmpl-1",
    "name": "Bollinger RSI",
    "type": "BbandRsi"
  }
}
Once configured: true, subsequent patches will not re-apply template values. You can freely tune interval, stoploss, and other fields without overwrite.

Updating Parameters

After initial configuration, tune strategy parameters independently:
curl -X PATCH https://api.cryptorobot.ai/strategies/684b2f... \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "interval": "30m",
    "stoploss": -0.001,
    "exit_profit_offset": 12
  }'

Protections

Protections safeguard against rapid losses. Add them via patch:
curl -X PATCH https://api.cryptorobot.ai/strategies/684b2f... \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "protections": [
      { "enabled": true, "type": "coolDownPeriod", "method": "CooldownPeriod", "stop_duration_candles": 2 },
      { "enabled": true, "type": "maxDrawdown", "method": "MaxDrawdown", "stop_duration_candles": 4, "lookback_period_candles": 48, "trade_limit": 20, "max_allowed_drawdown": 0.2 },
      { "enabled": true, "type": "stoplossGuard", "method": "StoplossGuard", "stop_duration_candles": 2, "lookback_period_candles": 24, "trade_limit": 4, "only_per_pair": false },
      { "enabled": true, "type": "lowProfitPairs", "method": "LowProfitPairs", "stop_duration_candles": 60, "lookback_period_candles": 6, "trade_limit": 2, "required_profit": "2" }
    ]
  }'
ProtectionDescription
CooldownPeriodWait N candles after a trade before opening new ones
MaxDrawdownPause trading if drawdown exceeds threshold
StoplossGuardPause if too many stoplosses trigger in lookback period
LowProfitPairsStop trading pairs with low profit in recent candles

Backtesting

Test strategy performance against historical data. Requires data download first.

Download Data

curl -X POST https://api.cryptorobot.ai/exchanges/download \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeId": "683a1f...",
    "overrides": {
      "timerange": "20240101-",
      "timeframes": ["5m"]
    }
  }'

Run Backtest

curl -X POST https://api.cryptorobot.ai/strategies/backtest \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "strategyId": "684b2f...",
    "traderId": "685c3a...",
    "exchangeId": "683a1f...",
    "overrides": {
      "max_open_trades": 10,
      "dry_run_wallet": 10000
    },
    "options": {
      "eps": true,
      "protections": true
    },
    "start": "20240101",
    "end": "20240115"
  }'
Response
{
  "_id": "bt-789",
  "strategyId": "684b2f...",
  "traderId": "685c3a...",
  "exchangeId": "683a1f...",
  "status": "SUCCEEDED",
  "results": {
    "total_trades": 87,
    "trade_count_long": 52,
    "trade_count_short": 35,
    "profit_total": 0.452,
    "profit_mean": 0.0052,
    "profit_median": 0.003,
    "total_volume": 150000,
    "avg_stake_amount": 1724,
    "best_pair": "ETH/USDT",
    "worst_pair": "DOGE/USDT",
    "results_per_pair": [...],
    "exit_reason_summary": [...],
    "locks": [...]
  },
  "took": 12500
}

Hyperparameter Optimization

Find optimal strategy parameters automatically:
curl -X POST https://api.cryptorobot.ai/strategies/hyperopt \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "strategyId": "684b2f...",
    "traderId": "685c3a...",
    "exchangeId": "683a1f...",
    "function": "OnlyProfitHyperOptLoss",
    "epochs": 500,
    "overrides": {
      "max_open_trades": 10,
      "dry_run_wallet": 10000
    },
    "options": {
      "eps": true,
      "protections": true
    },
    "days": 20
  }'

AI Generation

Generate a strategy from a natural language prompt:
curl -X POST https://api.cryptorobot.ai/strategies/generate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Generate a momentum and mean-reversion strategy with 4+ distinct indicators",
    "context": "freqtrade strategy",
    "auto": {
      "hyperopt": {
        "enabled": true,
        "function": "OnlyProfitHyperOptLoss",
        "epochs": 500,
        "overrides": { "max_open_trades": 10, "dry_run_wallet": 10000 },
        "options": { "eps": true, "protections": true },
        "days": 20,
        "exchangeId": "683a1f...",
        "traderId": "685c3a..."
      }
    }
  }'
Response
{
  "_id": "gen-101",
  "prompt": "Generate a momentum and mean-reversion strategy with 4+ distinct indicators",
  "context": "freqtrade strategy",
  "status": "SUCCEEDED",
  "templateId": "tmpl-gen-1",
  "strategyId": "684c4b..."
}

Key Fields

FieldTypeDescription
namestringStrategy display name
intervalstringCandle timeframe: 1m, 5m, 15m, 30m, 1h, 4h, 1d
stoplossnumberStop-loss as negative decimal (e.g. -0.036 = -3.6%)
exit_profit_onlybooleanOnly exit on profit
exit_profit_offsetnumberMinimum profit offset before allowing exit
exit_sell_signalbooleanAllow exit on sell signal
timeinforcestringOrder time-in-force (e.g. GTC)
templateIdstringApplied template ID
configuredbooleanWhether strategy file has been generated
indicatorsarrayTechnical indicators attached to the strategy
protectionsarrayRisk management protections
fileobjectGenerated strategy file reference