Market LabDocs

JSON Output

Compact machine output, verbose mode, and stream-friendly JSONL behavior.

JSON Output

Market Lab has two priorities:

  • good human terminal output
  • compact machine-readable output

Market Catalog JSON

The markets command uses a dedicated --json flag:

mlab markets --exchange bulk --json

Full catalog JSON contains:

  • schemaVersion
  • provider
  • sourceUrl
  • fetchedAt
  • markets

Requesting one symbol returns that market object directly:

mlab markets --exchange bulk --symbol BTC/USDT --json

Each market contains symbol mapping, status, precision, tick and lot sizes, minimum notional, maximum leverage, order types, and time-in-force values. This output is an embedded rules snapshot, not live market data.

Default JSON

Study JSON is intentionally compact. Built-in strategy submission returns a persistent job record, while strategy worker activity is written as JSONL job output.

That means the default output includes only the fields an agent or script usually needs.

Script JSON follows the same rule: default output stays compact, while runtime reports can be inspected separately with script runs list and script runs show.

Verbose JSON

Add --verbose to include expanded context.

Examples:

mlab study spread --provider mmt --exchange bybitf --symbol BTC/USDT --depth 20 --output json --verbose

Stream JSONL

Use jsonl for stream-oriented commands.

Examples:

mlab source candles --provider mmt --exchange binancef --symbol BTC/USDT --timeframe 60 --stream --output jsonl

Execution JSON

Execution commands support terminal, json, and jsonl. CSV and Parquet are rejected.

A dry-run trade emits the normalized TradePlan directly:

mlab trade long BTC/USDT --margin 10 --dry-run --output json

The plan contains:

  • creation timestamp and venue
  • account, internal symbol, and venue symbol
  • direction and order side
  • order kind and time in force
  • requested margin or exact size, plus normalized size
  • limit price or market reference price
  • estimated margin and exposure, leverage, and reduce-only state
  • optional native stop-loss and take-profit prices
  • projected liquidation price (null before execution because BULK computes it from portfolio state)

A submitted trade emits both the reviewed plan and venue receipt:

mlab trade long BTC/USDT --margin 10 --yes --output json
{
  "plan": {},
  "receipt": {
    "venue": "bulk",
    "account": "...",
    "order_id": "...",
    "status": "...",
    "terminal": false,
    "submitted_at_ms": 1780000000000,
    "raw_status": {}
  },
  "post_trade_position": {}
}

The same plan/result behavior applies to cancel. positions, orders, and fills emit JSON arrays of normalized account records.

Structured live execution cannot prompt, so it requires --yes. Use --dry-run first.

Daemon JSON and Events

Inspect runtime state:

mlab daemon status --output json

Status contains:

  • runtime protocol version
  • running and pid
  • started_at_ms
  • account_stream_connected
  • last_account_event_ms and last_recovery_ms
  • last_error
  • tracked_orders
  • script_jobs
  • strategy_jobs

Read the lifecycle journal as a JSON array or JSONL stream:

mlab daemon events --limit 20 --output json
mlab daemon events --limit 20 --output jsonl

Current event names are:

  • order_submitted
  • order_cancelled
  • order_tracking_started
  • order_status
  • account_ws
  • account_recovery_fill

Every event has ts_ms and event. Submission events add plan and receipt; tracking events add normalized order state; account events carry the raw BULK account payload.

Study Shape

Default compact study JSON contains:

  • type
  • version
  • provider
  • exchange
  • symbol
  • ts_ms
  • stream
  • metrics

Verbose study JSON also includes:

  • inputs
  • meta

Strategy Shape

strategy run deploys a detached native job. Structured live execution requires --yes:

mlab strategy run twap BTC/USDT \
  --side buy \
  --margin 100 \
  --duration 300 \
  --interval 60 \
  --yes \
  --output json

The returned record contains:

  • job id and status
  • worker pid
  • the tagged strategy definition and immutable TWAP configuration
  • symbol, side, target margin and exposure, normalized total size, duration, interval, leverage, and reduce-only state
  • created, started, stopped, and heartbeat timestamps
  • last worker error

List and inspect strategy jobs:

mlab strategy jobs --output json
mlab strategy status <JOB_ID> --output json

Worker output is stored as JSONL and includes strategy.plan, strategy.child_order, strategy.run.finished, and strategy.run.failed records:

mlab strategy logs <JOB_ID> --follow --output jsonl

Use --dry-run --output json to receive the normalized TWAP plan instead of creating a job.

Script Backtest Shape

Script hooks may return:

  • metrics
  • optional meta
  • null when the hook only performs execution calls

Strategy behavior comes from ctx.trade and ctx.cancel. The backtest runtime intercepts those calls with its simulator.

Default script backtest JSON contains:

  • type
  • version
  • provider
  • exchange
  • symbol
  • ts_ms
  • script
  • summary
  • performance
  • params

The summary includes submitted, pending, and cancelled simulated orders alongside closed trades and open positions.

Performance reports capital_required as the peak simulated margin in use. Leverage belongs to each open-long or open-short request rather than to the backtest command as a whole.

Verbose script backtest JSON also includes:

  • window with the requested from and to timestamps
  • closed_trades
  • open_positions
  • latest_output when the script explicitly returned non-empty diagnostics
  • meta

Closed trades and open positions include their stable script order_id and events_held count when they came from ctx.trade. Open positions also include simulated stop_loss_price and take_profit_price when configured.

Script Job Shape

script run deploys a detached job and returns its job record rather than a stream result:

mlab script run ./strategy.js \
  --symbol BTC/USDT \
  --source candles@bulk:timeframe=5 \
  --venue bulk \
  --output json

The record contains:

  • job id and status
  • worker pid
  • immutable script definition and snapshot path
  • provider, exchange, symbol, sources, params, and execution venue
  • created, started, stopped, and heartbeat timestamps
  • last worker error
  • execution-event sequence and acknowledged cursor

List and inspect records:

mlab script jobs --output json
mlab script status <JOB_ID> --output json

Worker output is JSONL internally. Tail it directly:

mlab script logs <JOB_ID> --follow --output jsonl

An explicit non-empty { metrics, meta } return from live onData is stored as script.run.result. Returning nothing, null, or {} stores no routine result. Execution delivery uses script.execution.event, optionally including non-empty hook diagnostics. A command-routing failure is appended as script.execution.error.

The onExecution event envelope uses camel-case fields:

  • seq, jobId, tsMs, and type
  • optional orderId, key, venue, venueOrderId, and status
  • terminal
  • provider payload in data

Script Runtime Reports

Script runtime reports are stored locally and can be viewed from the CLI.

mlab script runs list --output json
mlab script runs show <run-id> --output json

Runtime report JSON contains:

  • script
  • command
  • provider
  • exchange
  • symbol
  • started_at_ms
  • ended_at_ms
  • duration_ms
  • status
  • limits
  • runtime
  • error

On this page