Skip to content

Validate ​

Compiles a dxScript source file, executes it on a synthetic candle snapshot, and returns declared metadata or a structured error.

Service: dxscript.indicators.v1.IndicatorService
Method: validate
Interaction: request / response

HTTP ​

http
POST /dxscript.indicators.v1.indicatorservice/validate
Content-Type: application/json

Request ​

FieldTypeRequiredDescription
langstringyesMust be dxscript-js
contentstringyesFull script source

Examples ​

Indicator validation (success) ​

bash
curl -sS -X POST 'https://dxlink-dxscript-http-demo.dxkube.com/dxscript.indicators.v1.indicatorservice/validate' \
  -H 'Content-Type: application/json' \
  -d '{
    "lang": "dxscript-js",
    "content": "const n = input.double(\"length\", 14);\nfunction onTick() {\n  output(\"rsi\", ta.rsi(close, n));\n  spline(ta.rsi(close, n), {title: \"RSI\"});\n}"
  }'

Request body:

json
{
  "lang": "dxscript-js",
  "content": "const n = input.double(\"length\", 14);\nfunction onTick() {\n  output(\"rsi\", ta.rsi(close, n));\n  spline(ta.rsi(close, n), {title: \"RSI\"});\n}"
}

Response 200 — error is absent:

json
{
  "inParameters": [
    {
      "name": "length",
      "type": "INPUT_TYPE_DOUBLE",
      "doubleParam": {
        "defaultValue": 14.0
      }
    }
  ],
  "outputs": [
    { "name": "rsi" }
  ],
  "splines": [
    {
      "id": 0,
      "title": "RSI",
      "style": "LINE",
      "offset": 0,
      "overlay": true
    }
  ],
  "compilationTime": "0.006493433s",
  "executionTime": "0.018204370s",
  "executionTotalTicks": 1000,
  "calculationResult": {
    "output": {
      "rsi": {
        "values": ["NaN"]
      }
    },
    "spline": {
      "0": {
        "value": "NaN",
        "style": "LINE",
        "offset": 0,
        "title": "RSI",
        "overlay": true
      }
    }
  }
}

Empty layer lists (backgroundColors, barColors, shapes) are omitted. Timing and executionTotalTicks depend on server configuration (snapshotSize was 1000 on this stand).

First-bar samples reflect the synthetic snapshot only. Each output channel is { "values": [value] } with at most one entry. RSI returns "NaN" on the first bar when the lookback is not satisfied yet — that is still a successful validation. Non-finite doubles serialize as JSON strings ("NaN", "Infinity", "-Infinity"), not null.

Validation error (runtime) ​

bash
curl -sS -X POST 'https://dxlink-dxscript-http-demo.dxkube.com/dxscript.indicators.v1.indicatorservice/validate' \
  -H 'Content-Type: application/json' \
  -d '{
    "lang": "dxscript-js",
    "content": "function onTick() {\n  spline(undefinedSeries, {title: \"Broken\"});\n}"
  }'

Response 200 — error is set; calculationResult and timing fields are absent:

json
{
  "error": {
    "id": "8104ca8b-e57c-405d-b6b8-37de865bf143",
    "type": "RUNTIME",
    "scriptName": "test_validate",
    "startLine": 2,
    "startColumn": 10,
    "endLine": 2,
    "endColumn": 24,
    "message": "undefinedSeries is not defined",
    "scriptStack": [
      { "functionName": "onTick", "line": 2, "column": 10 }
    ]
  }
}

Validation error (syntax) ​

bash
curl -sS -X POST 'https://dxlink-dxscript-http-demo.dxkube.com/dxscript.indicators.v1.indicatorservice/validate' \
  -H 'Content-Type: application/json' \
  -d '{
    "lang": "dxscript-js",
    "content": "const x = ;"
  }'

Response 200:

json
{
  "error": {
    "id": "8a3caf2c-f629-4884-a60c-8821335bbd53",
    "type": "SYNTAX",
    "scriptName": "test_validate",
    "startLine": 1,
    "startColumn": 11,
    "endLine": 1,
    "endColumn": 11,
    "message": "Expected an operand but found ;"
  }
}

On failure, error is the only payload field. scriptStack is omitted when empty. scriptName is assigned by the server.

Response fields ​

FieldTypeDescription
inParametersarrayDeclared input() parameters with typed defaults
outputsarray{ name } entries from output()
splinesarraySpline layer metadata (id, title, style, offset, overlay)
backgroundColorsarraybgColor() layer metadata; omitted when empty
barColorsarraybarColor() layer metadata; omitted when empty
shapesarrayshape() layer metadata; omitted when empty
metaobjecttitle, shortTitle when declared by indicator() or strategy()
compilationTimestringDuration (e.g. "0.240804875s"); present on success only
executionTimestringWall-clock script execution duration; present on success only
executionTotalTicksintNumber of candles the script ran over; present on success only
calculationResultobjectFirst-bar samples (see below); present on success only
strategyAnalyticsobjectPerformance summary of a strategy() run (performance only); omitted for non-strategy scripts
errorobjectStructured script error; present on failure only

inParameters types ​

Each parameter has name, type, and exactly one typed payload:

typePayload fieldDescription
INPUT_TYPE_BOOLboolParam{ defaultValue }
INPUT_TYPE_DOUBLEdoubleParam{ defaultValue, min?, max?, step?, options? }
INPUT_TYPE_STRINGstringParam{ defaultValue, options? }
INPUT_TYPE_SOURCEsourceParam{ defaultValue, options? }
INPUT_TYPE_COLORcolorParam{ defaultValue, defaultAlpha? }
INPUT_TYPE_SESSIONsessionParam{ defaultValue, options?, value, timeZone? }
INPUT_TYPE_ENUMenumParam{ defaultValue, options? }

calculationResult ​

First-bar samples only, one value per series or layer:

ChannelMap keyValue shape
outputoutput channel name{ values: [value] } — first bar only (at most one entry); empty values when there is no sample. Numbers or non-finite strings ("NaN", "Infinity", "-Infinity")
splinelayer id ("0", "1", …)Spline knot with value (number or "NaN" string), optional color, style, offset, title, overlay
backgroundColorlayer name{ color, offset?, title?, numberOfLast?, overlay }
barColorlayer name{ color, offset?, title?, numberOfLast? }
shapeseries name{ value, color?, textColor?, text?, shapeStyle?, offset?, title?, location?, overlay? }

Unset channels are omitted from calculationResult. Colors use { "value": "<hex or palette name>", "alpha"?: number }.

WebSocket RPC ​

Call validate on service dxscript.indicators.v1.IndicatorService through the dxLink WebSocket session using the same ValidateRequest / ValidateResponse protobuf messages. JSON field names match the HTTP mapping.

Strategy scripts ​

Strategy support can be disabled on a deployment. In that case, scripts that call strategy() fail validation at compile time.

For a strategy script the response also carries the run's performance summary in strategyAnalytics.performance, in the shape the backtest response uses. It is present for every strategy run, including one that traded nothing. The rest of what a backtest returns — equitySeries, barCloseSeries, fills, trades and orders — is left out, as calculationResult is cut to first-bar samples: one value per bar would make up most of the response and describe nothing real.

The candles are generated, not market data. The summary shows that the strategy compiled and ran; its numbers describe the synthetic series and say nothing about any instrument. Use Backtest for a run over real candles.

See also ​