Market LabDocs

Examples

Real command examples for sources, studies, and strategies.

Examples

This page focuses on the commands people will actually run first:

  • source
  • markets
  • study
  • script backtest
  • script runs list
  • script runs show
  • script jobs, status, logs, stop, and restart
  • strategy run twap
  • strategy jobs, status, logs, and stop
  • trade long
  • trade short
  • positions, orders, and fills
  • cancel and close
  • daemon

MMT examples below assume:

  • --provider mmt
  • millisecond timestamps at the CLI boundary

BULK source examples use --exchange bulk and omit --provider. Public BULK market data does not require credentials. Account and execution commands require an authorized BULK agent.

BULK Markets

List the embedded catalog

mlab markets --exchange bulk

Inspect one market

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

Get one rule set as JSON

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

These commands read the snapshot embedded in the binary and require no provider credentials or network request.

BULK Sources

Public orderbook

mlab source orderbook \
  --exchange bulk \
  --symbol BTC/USDT \
  --depth 100 \
  --output terminal

Historical candles

mlab source candles \
  --exchange bulk \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from 1780307559000 \
  --to 1780523645000 \
  --output json

Live order flow

mlab source vd \
  --exchange bulk \
  --symbol BTC/USDT \
  --stream \
  --output jsonl

Market statistics and funding

mlab source stats --exchange bulk --period 7d --output json
mlab source funding --exchange bulk --symbol BTC/USDT --stream --output jsonl

See BULK Provider for the exact range, snapshot, and stream contract of each source.

BULK Execution

Preview a market order

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

Dry-run output is the same normalized plan reviewed before a live order. It does not sign, submit, or start mlabd.

Preview an ALO limit order

mlab trade short BTC/USDT \
  --size 0.001 \
  --type limit \
  --price 65000 \
  --tif alo \
  --leverage 3 \
  --dry-run

Preview native stop and take-profit protection

mlab trade long BTC/USDT \
  --margin 100 \
  --leverage 5 \
  --sl 63000 \
  --tp 69000 \
  --dry-run

Submit with terminal confirmation

mlab trade long BTC/USDT --margin 100 --leverage 5

Inspect account state

mlab positions
mlab orders --symbol BTC/USDT
mlab fills --symbol BTC/USDT

Preview cancellation and closing

mlab cancel BTC/USDT <ORDER_ID> --dry-run
mlab close BTC/USDT --dry-run

Inspect the execution runtime

mlab daemon status
mlab daemon events --limit 20 --output jsonl
mlab daemon stop

See Execution for live confirmation rules, TOML configuration, validation, and runtime security.

Sources

Orderbook snapshot

mlab source orderbook \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --depth 100 \
  --output terminal

Orderbook stream

mlab source orderbook \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --depth 100 \
  --stream \
  --min-size 0.1 \
  --price-group 1 \
  --interval-ms 1000 \
  --buffer-size 20 \
  --output terminal

Candles range

mlab source candles \
  --provider mmt \
  --exchange binancef \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from 1779880000000 \
  --to 1779883600000 \
  --output json

Candles stream

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

VD range

mlab source vd \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from 1779620400000 \
  --to 1779624000000 \
  --bucket 1 \
  --output json

VD stream

mlab source vd \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --bucket 1 \
  --stream \
  --output jsonl

OI range

mlab source oi \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from 1779660000000 \
  --to 1779705600000 \
  --output json

OI stream

mlab source oi \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --stream \
  --output jsonl

Volumes range

mlab source volumes \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from 1779660000000 \
  --to 1779705600000 \
  --output json

Volumes stream

mlab source volumes \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 60 \
  --stream \
  --output jsonl

Scripts

Backtest a JavaScript strategy

mlab script backtest ./scripts/sma-cross.js \
  --symbol BTC/USDT \
  --from 1704067200000 \
  --to 1704667200000 \
  --source candles@bybitf@mmt:timeframe=60 \
  --param fast=20 \
  --param slow=50 \
  --param margin=1000 \
  --leverage 5 \
  --output json

Backtest a VD script

mlab script backtest ./scripts/vd-summary.js \
  --symbol HYPE/USDT \
  --from 1780497965372 \
  --to 1780618018000 \
  --source vd@hyperliquid@mmt:timeframe=3600,bucket=1 \
  --param min_delta=500 \
  --output json

Compare candles across exchanges

mlab script backtest ./examples/cross-exchange-spread.js \
  --symbol BTC/USDT \
  --from 1704067200000 \
  --to 1704667200000 \
  --source candles@binancef@mmt:timeframe=60 \
  --source candles@okx@mmt:timeframe=60 \
  --output json

The script reads both histories with history.source("candles@binancef@mmt") and history.source("candles@okx@mmt") in backtests and live mode.

Backtest independent position exits

mlab script backtest ./scripts/dip-tp-positions.js \
  --symbol HYPE/USDT \
  --from 1780497965372 \
  --to 1780618018000 \
  --source candles@hyperliquid@mmt:timeframe=3600 \
  --param drop_bps=20 \
  --param take_profit_bps=50 \
  --param margin=1000 \
  --leverage 5 \
  --output terminal

This script opens separate long positions on dips and closes only the position whose position_id hits its take-profit condition.

Deploy a live analysis script

mlab script run ./scripts/all-sources-live.js \
  --symbol HYPE/USDT \
  --source candles@hyperliquid@mmt:timeframe=5 \
  --source orderbook@hyperliquid@mmt:depth=100 \
  --source vd@hyperliquid@mmt:timeframe=60,bucket=1

script run returns a detached job ID. It does not hold the terminal open.

Deploy a strategy with BULK execution

mlab script run ./examples/bulk-limit-protected.js \
  --symbol BTC/USDT \
  --source candles@bulk:timeframe=5 \
  --venue bulk \
  --param armed=true

The script calls ctx.trade directly. --venue bulk is required to enable live execution; the data provider can still be MMT or BULK.

Manage live script jobs

mlab script jobs
mlab script status <JOB_ID>
mlab script logs <JOB_ID> --follow
mlab script stop <JOB_ID>
mlab script restart <JOB_ID>

List script runtime reports

mlab script runs list

View a script runtime report

mlab script runs show <run-id>

Runtime reports are historical telemetry. Use script jobs and script status for deployed workers.

Studies

Spread

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

Depth

mlab study depth \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --levels 20 \
  --output json

Imbalance

mlab study imbalance \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --depth 50 \
  --output json

Slippage

mlab study slippage \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --side buy \
  --notional 100000 \
  --depth 100 \
  --output json

VAMP

mlab study vamp \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --depth 100 \
  --dollar-depth 250000 \
  --output json

CVD

mlab study cvd \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC/USDT \
  --timeframe 3600 \
  --from 1779620400000 \
  --to 1779624000000 \
  --bucket 1 \
  --output json

TWAP Strategy

Preview the normalized schedule

mlab strategy run twap BTC/USDT \
  --exchange bulk \
  --side buy \
  --margin 100 \
  --duration 300 \
  --interval 60 \
  --dry-run

Deploy a live TWAP job

mlab strategy run twap BTC/USDT \
  --exchange bulk \
  --side buy \
  --margin 100 \
  --duration 300 \
  --interval 60

The CLI asks for confirmation, submits the immutable plan to mlabd, prints the job ID, and returns.

Submit by size with structured output

mlab strategy run twap BTC/USDT \
  --exchange bulk \
  --side sell \
  --size 0.01 \
  --duration 600 \
  --interval 30 \
  --yes \
  --output json

Monitor and stop the job

mlab strategy jobs
mlab strategy status <JOB_ID>
mlab strategy logs <JOB_ID> --follow
mlab strategy stop <JOB_ID>

The current TWAP implementation uses market child orders. Stopping prevents later children; it does not reverse fills or close the resulting position. See TWAP.

On this page