[POST /run]

Free evaluate endpoints: single-script /run and multi-script /run/batch over shared OHLCV.

POST /run and /run/batch

Abstract

/run is the primary free evaluate entry: accept Pine source + bar list, optionally wire request.* data sources, execute via Runtime, and return plots/series/events/drawings. /run/batch runs up to eight scripts on the same OHLCV (AXIS multi-indicator), isolating per-script errors so one failure does not discard siblings.

Conceptual model

Interface surface

POST /run

Request (RUN_SCHEMA)

FieldTypeRequiredDefaultNotes
scriptstringyesPine source
datalistyesOHLCV bar objects
symbolstringno"CHART"Syminfo / request wiring
data_sourcestringno""mock / ccxt / yahoo / …
data_optionsobjectno{}Provider options
modestringno"interpret""interpret" | "compile"

Unknown fields → UNKNOWN_FIELDS 400. Empty script/data still checked after schema with NO_SCRIPT / NO_DATA.

Bar shape (runtime expectation):

{ "time": 0, "open": 1, "high": 1, "low": 1, "close": 1, "volume": 1 }

Optional bid / ask per bar update runtime bid/ask state.

Success response

{
  "status": "success",
  "plots": [],
  "series": {},
  "plot_meta": {},
  "events": [],
  "drawings": [],
  "script_id": "16hex",
  "run_id": "16hex",
  "count": 0,
  "mode": "interpret",
  "data_source": "chart"
}
FieldMeaning
plotsPrimary series (first plot) — backward compatible list
seriesNamed multi-plot map title → values per bar
plot_metaPer-title color, linewidth, index
eventsStrategy events with script_id / run_id stamps
drawingsExported line/label/box registry for AXIS
script_idsha256(source)[:16]
run_idPer-Runtime instance id

Errors

HTTPcodeWhen
400MISSING_FIELD / INVALID_FIELD / UNKNOWN_FIELDS / INVALID_BODYSchema
400NO_SCRIPT / NO_DATAEmpty after defaults
400DATA_SOURCE_ERRORresolve_request_sources failed
500EXECUTION_ERRORRuntime returned error key

POST /run/batch

Request (RUN_BATCH_SCHEMA)

FieldTypeRequiredNotes
scriptslistyesstrings or {id, script} objects
datalistyesShared OHLCV
symbol / data_source / data_options / modeoptionalsame as /run

Hard cap: RUN_BATCH_MAX_SCRIPTS = 8TOO_MANY_SCRIPTS.

Response

{
  "status": "success" | "partial",
  "results": [ { "id": "…", "status": "success|error", … } ],
  "count": 2,
  "ok": 1,
  "data_source": "chart"
}

HTTP 200 for partial success (per-script errors inside results). Envelope validation failures still 400.

Internals

runtime = Runtime(symbol=str(symbol))
result = runtime.run(script, ohlcv, data_feed=…, data_provider=…, mode=…)

See runtime bridge for bar-loop details and compile mode.

Paths: backend/app.py (run_pine_script, run_pine_script_batch), backend/middleware/schemas.py.

Invariants and edge cases

  1. No API key on these routes — protect at the edge if needed.
  2. Batch isolates exceptions per script (try/except around runtime.run).
  3. Whitespace-only data_source coerced to None → chart default.
  4. Compile mode requires numba; errors surface as EXECUTION_ERROR message from runtime.
  5. Schema rejects extras — clients must not send AXIS-only fields without updating schema.

Worked example

curl -s http://127.0.0.1:5002/run \
  -H 'Content-Type: application/json' \
  -d '{
    "script": "//@version=5\nindicator(\"t\")\nplot(close)",
    "data": [
      {"time": 1, "open": 1, "high": 2, "low": 0.5, "close": 1.5, "volume": 10},
      {"time": 2, "open": 1.5, "high": 2.5, "low": 1.0, "close": 2.0, "volume": 12}
    ],
    "symbol": "TEST:DEMO"
  }'

Failure modes

SymptomCause
UNKNOWN_FIELDSTypo’d property (e.g. ohlcv instead of data)
Parse errors in messageInvalid Pine — same engine as CLI
Batch status: partialAt least one script failed; inspect results[i].message

See also