New in QuantCraft v1.4.0. This page describes functionality that ships with v1.4.0, the next major release. The current release is v1.3.0, which does not include it yet.
The reference for people writing extensions: the qc functions, the qcext.json manifest, permissions, what a provider must return, errors and limits. The workflow is in Building extensions and runnable code is in Extension examples.
Editor typings for the SDK ship in the SDK package as qc-extension.d.ts.
Using the SDK
<scripttype="module"src="/_sdk/qc.js"></script>
const qc =awaitwindow.qc.ready;// resolves once QuantCraft has connected your page
Every call returns a promise and rejects with a qc.QcError whose code is one of the error codes.
The qc object
qc
Member
Kind
What it does
qc.ready
property
Promise resolving with qc once the host handshake is done: const qc = await window.qc.ready.
qc.info
property
After the handshake: { extId, name, version, theme, settings, permissions }.
qc.settings
property
This extension's current settings (updated by onSettingsChange).
qc.sdkVersion
property
SDK version string.
qc.apiVersion
property
Extension API version (1).
qc.QcError
property
Error class the SDK rejects with; code is stable (timeout, permission_denied, …).
defineFundamentals({ capabilities, getFundamentals({ symbol }), listSymbols({ cursor }) }): provide fundamentals (kind fundamentals).
qc.provider.defineBroker
function
defineBroker({ capabilities, getAccount, getPositions, getOrders, placeOrder, cancelOrder, … }): a brokerage account (kind broker, needs trade.place). Be idempotent on client_order_id.
qc.provider.emitBroker
function
emitBroker(): tell the host the account, positions or orders changed so it refetches (a hint). emitBroker({ type: 'snapshot', account?, positions?, orders? }) pushes the new state instead (declare updates: 'push'). Needs trade.place.
qc.provider.emit
function
emit({ symbol, kind: 'trade' | 'bar', … }): push a live trade or bar.
qc.provider.emitBatch
function
emitBatch([event, …]): push up to 500 live events in one call; resolves { accepted, dropped }.
qc.testing
Member
Kind
What it does
qc.testing.mockOhlcvProvider
function
mockOhlcvProvider(opts): a fake provider with deterministic bars and simulated trades.
qc.testing.mockBrokerProvider
function
mockBrokerProvider(opts): a fake brokerage with an in-memory account and options chain, and switches for rejects, outages, timeouts and dropped replies.
qc.testing.mockFundamentalsProvider
function
mockFundamentalsProvider(opts): a fake fundamentals provider with deterministic statements and a symbol list.
The manifest: qcext.json
A key that is not listed here is an error.
Top level
Field
Required
Rule
id
yes
publisher.name: lowercase letters, digits and -, at least one ., at most 64 characters. Fixed once published
version
yes
Semantic version, e.g. 1.0.0
apiVersion
yes
1 or up to 2. Use 2 if you use contributes.engines
name
yes
At most 48 characters
permissions
yes
A list of permissions (below); [] for none
description
no
At most 280 characters
publisher
no
At most 64 characters, usually a domain
icon
no
A relative .svg or .png
homepage, repository
no
https links
license
no
An SPDX id such as MIT
contributes
no
What the extension adds (below)
activation
no
When it starts: onStartup, onSidebarOpen, onProviderUse:<id>, onToolCall:<name>. Leave it out and it starts when first used
contributes
Key
Shape
Notes
sidebar
{ title, icon?, entry, modal? }
A sidebar icon that opens entry (an .html file) in a window. modal: width (320–2400), height (240–2000), minWidth, minHeight, resizable. Default 900×640. title at most 32 characters
footer
{ default? }
A status item in the app footer, set with qc.ui.setFooter. default: true shows it unless the user hides it. Needs no permission
dataProviders (up to 8)
{ id, name?, kinds, entry }
kinds: any of ohlcv, ticks, symbols, prices, fundamentals, broker. entry is a .js file (or engine for an engine-backed provider). Needs data.provide; kind broker also needs trade.place
aiTools (up to 32)
{ name, description, inputSchema?, engine? }
name: lowercase letters, digits and _, starting with a letter, at most 48 characters. The assistant sees it as ext_<id>__<name>. Needs ai.tools
themes (up to 8)
{ id, name, tokens }
tokens is a .json file { "base": "dark" | "light", "tokens": { "--c-accent": "#ff8800" } }. Token names start --c- (colours) or --r- (radii). No code
engines (up to 4)
{ id, runtime, limits? }
runtime.kind: wasm (module: { entry, sha256 }), python (entry, sha256, packages?) or binary (targets). Needs apiVersion 2 and engine.run
settings (up to 40)
{ key, label, type, … }
The extension's Settings form. type is one of secret, text, url, number, toggle, select, segmented. key: letters and digits, starting with a lowercase letter, at most 40, unique. label at most 60, help at most 200, optional required
A secret setting has no default, needs the secrets permission, and is read with qc.secrets.get(key). A number setting accepts min, max, step, unit and default; select and segmented take a list of options.
Permissions
List only what you use. Adding a permission in an update makes users approve again.
Permission
Risk
Shown to the user as
trade.place
high
Place orders in your brokerage account
secrets
high
Store and read secrets
net:<host>
medium
Connect to the listed domains
tools.backtest
medium
Start backtests and forward runs
tools.screener
medium
Run the screener
ai.chat
medium
Use your AI connection
ai.tools
low
Add AI tools
data.ohlcv
low
Read price bars
data.fundamentals
low
Read fundamentals
data.calendar
low
Read calendar events
data.provide
low
Provide market data
engine.run
medium
Run its own program
net:<host> is a hostname with at least two parts such as api.example.com: no https://, no port, no path, no wildcard, no IP address and not localhost; at most 20 per extension. A call to any other host is refused.
Reading QuantCraft data needs its data.* permission; running tools through qc.tools.call needs the matching tools.* permission and asks the user the first time.
What a provider must return
A provider is a .js file (listed under dataProviders) that calls one define… function at its top level. Its output is checked by QuantCraft: bars are sorted, duplicates and impossible values are dropped, and future bars are ignored.
a symbol list; last prices for list rows; historical trades for tick replay
Live events: qc.provider.emit({ symbol, kind: "trade" | "bar", … }), or qc.provider.emitBatch([...]) for up to 500 at once (it resolves { accepted, dropped }).
{ symbol, entityName?, incomeStatement: { quarterly: { "2024-03-31": { …fields, filing_date: "2024-05-02" } }, yearly: {} }, balanceSheet, cashFlow, ratios, … }. Tables are keyed by period end. Give every report its filing_date (the day it became public): without it QuantCraft assumes 45 days (quarterly) or 90 days (yearly) after the period end. Throw an error with code no_fundamentals when the vendor has nothing
listSymbols({ cursor })
{ symbols: [{ symbol, name, updatedAt }], next? }; return no next on the last page
Broker: qc.provider.defineBroker
Needs data.provide and trade.place, and works only for a Verified extension or your own project in Developer mode.
Function
Returns / notes
capabilities
{ name, mode: "paper" | "live" | "both", instruments: ["equity", "option", "crypto"], orderTypes, timeInForce, shorting, fractional, notional, extendedHours, replace, updates: "poll" | "push", rateLimit }. What you do not declare is never offered; an undeclared mode counts as paper
an array, or { orders, next_cursor } to page. status: open, closed, all
getOrder({ id, client_order_id })
one order. Used to find an order after a lost reply
placeOrder(order)
the order as placed. Idempotent on order.client_order_id: placing the same id twice returns the first order. Throw an error with one of rejected, invalid_order, insufficient_funds, not_tradable, market_closed, halted, unsupported, forbiddenonly when the broker definitely refused; any other failure is treated as unknown
cancelOrder({ id }), replaceOrder, closePosition
as named; replaceOrder only if replace is declared
listAssets({ asset_class, cursor, limit })
{ assets: [{ symbol, name, asset_class, exchange, tradable, … }], next_cursor? }: fills the Trade symbol list
optional; the option functions are needed only if option is declared
qc.provider.emitBroker(…)
{ type: "changed" } asks QuantCraft to refetch; { type: "snapshot", account?, positions?, orders? } pushes the new state (declare updates: "push")
Order status is one of new, accepted, partially_filled, filled, canceled, expired, rejected, replaced, pending_cancel, unknown.
Test helpers
qc.testing.mockOhlcvProvider(options), qc.testing.mockFundamentalsProvider(options) and qc.testing.mockBrokerProvider(options) register a fake provider with deterministic data and switches for failures, so you can build against a source that never fails or costs money.
AI tools
Answer calls with qc.handle("tool.call", async ({ name, args }) => result). Return plain JSON and keep it small; throw an Error with a clear message for bad input.
Errors
Code
Meaning
invalid_request
The message to QuantCraft was malformed.
unknown_method
That qc function does not exist.
invalid_params
The arguments are wrong; the message says which.
permission_denied
The permission is not in qcext.json, or the user turned it off.
consent_denied
The user said no when asked.
rate_limited
Too many calls; slow down and retry later.
payload_too_large
The message or result was too big.
unavailable
It is not available right now.
timeout
No answer in time.
internal_error
A QuantCraft problem; report it with the extension's log.
Your own provider and tool errors can carry a code; the useful ones are rate_limited, quota_exceeded, unsupported_timeframe and no_fundamentals, which QuantCraft treats specially (it stops instead of retrying).