Create a run
/runsStarts a run of a saved script, or of inline source, on one instrument, timeframe and window, and can hold the call until it finishes. Every run is asynchronous: start it, wait on it, then read what it produced.
Scope | Heavy call | Long poll | CLI |
|---|---|---|---|
| Yes |
|
|
Guidance
The usual loop: create the run with
waitat 0, poll Get a run withwait=30untilstatusissucceeded,failedorcancelled, then readsummaryfor counts or Get run results for everything.waiton this call keeps its heavy place for as long as it holds. Starting several runs withwaitset gets429 busyquickly; waiting on Get a run does not, because it is not a heavy call.waithere is fine for one quick run.Send an
Idempotency-Keyon every create, and reuse it when you retry. A retry with the same key returns the first run instead of starting a second. Use a new key for each run you mean to start.scripttakes a ref:my-ema(your script, latest version),my-ema@3(a version that never changes),jane/orb-breakout@7(someone else's indicator or definition in your library, run without seeing its source) orchartnaut/rsi(a built-in). Search the library gives each script'sref. Pin a version when you compare runs.Another author's script runs only once it is in your library, as in the app. Until then the run is refused with
409 not_in_library, anddetailsholdsadd, the request that adds it, withneeds,confirmandcannot_addas Check what a script needs returns them. Add it with Add to your library once the person agrees, then start the run again. Your own scripts andchartnaut/built-ins never need adding.Inline
sourceruns an indicator or definition without saving anything, which is the fast loop while you write one. Check it with Validate a script first: source with errors gets422 script_invalidand nothing runs.A study runs only from your own saved studies, by ref. Trade studies run in the app, over a set of trades: the API refuses one with
400 invalid_requeston every plan. Every definition it declares must be yours, a built-in or in your library. One that is not is refused before anything runs:409 not_in_librarywithdetails.definitions, one entry per definition to add, or409 not_sharedwithdetails.cannot_addwhen one is not shared with you at all. Before it starts, Chartnaut runs each definition it reads over the window wherever that definition has no events yet, for up to 20 minutes;progress.phaseshowscollectingmeanwhile.The window ends on the last closed bar, and warmup is fetched before it without counting in results. Its start moves to where your plan's history or the instrument's data begins. One window holds at most 50,000 bars: 90 days of
5mfits, 90 days of1mdoes not.Two kinds of
429 busy: past your heavy calls at once (Retry-After: 2), or your API runs queued or running are full (Retry-After: 15). Your account can have its runs at once plus 4 API runs queued or running. Wait forRetry-Afterand retry with the sameIdempotency-Key.Indicator and definition results are kept for 7 days. Study results do not expire.
Headers
Name | Required | Description |
|---|---|---|
| No | Up to 128 characters. A retry with the same key returns the first run. See Idempotency |
Request body
Field | Type | Required | Description |
|---|---|---|---|
| string | One of | A saved ref: |
| object | One of | Inline code for an indicator or definition, saved nowhere: |
| string | Yes | Canonical or short symbol |
| string | Yes | One of the timeframes. Upper case is lowered |
| object | Yes | Fields below |
| object | No | Setting values keyed by setting id. Anything left out uses the script's default |
| object | No | Study runs only. |
| integer | No | Seconds to hold the call until the run finishes, 0 to 30. Default 0. Values outside the range are clamped |
| string | No | Free text, returned on the run |
window object
Send exactly one of from, last and bars.
Field | Type | Description |
|---|---|---|
| string | RFC 3339 start |
| string | A span back from |
| integer | This many bars of the run's timeframe back from |
| string | RFC 3339 end, with any of the three. Defaults to now; a later time is cut to now |
Response
Returns a Run: 200 when it finished within wait, 202 while it is still queued or running.
Status codes
Status | Code | Meaning |
|---|---|---|
| - | The run finished within |
| - | The run is |
|
| The body is not JSON; both or neither of |
|
| The run would pass a plan cap, such as your definition events |
|
|
|
|
|
|
|
| The window ends before your plan's history, or the instrument's data, begins |
|
| No script by that ref you can run, or no such version |
|
| One of your studies shares the slug with an indicator or definition. Runs cannot choose between them |
|
|
|
|
| Your study declares a definition that is not shared with you, so it cannot run. |
|
| Inline |
|
| Past your heavy calls at once ( |
