# Examples (/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`
* readable UTC dates at the CLI boundary

Binance Spot and Binance USD-M perpetual futures are also standalone public-data sources. Use `--exchange binance` or `--exchange binancef`, omit `--provider`, and do not configure a Binance API key. MMT access such as `--provider mmt --exchange binancef` remains separate.

BULK source examples use `--exchange bulkf` and omit `--provider`. Public BULK market data does not require credentials. Account and execution commands require an authorized BULK agent. Mainnet is the default; `--testnet` selects the public testnet where supported.

Hyperliquid is also standalone. Use `hyperliquid` for Spot and `hyperliquidf` for every perpetual market. Core symbols look like `BTC`; HIP-3 symbols include their DEX, such as `xyz:TSLA` or `io:ANTH`. Use `hyperlink` for Spot and `hyperlinkf` for core or HIP-3 perpetual execution through HyperLink. Add `--testnet` to direct Hyperliquid commands when the market exists there; HyperLink is mainnet-only. Do not add `--provider` unless MMT should route the data.

## Binance Markets [#binance-markets]

### Refresh the standalone snapshots [#refresh-the-standalone-snapshots]

```bash
mlab markets --exchange binance --refresh
mlab markets --exchange binancef --refresh
```

### Inspect a futures market [#inspect-a-futures-market]

```bash
mlab markets --exchange binancef --symbol BTC
```

## Binance Historical Data [#binance-historical-data]

### Spot candles [#spot-candles]

```bash
mlab source candles \
  --exchange binance \
  --symbol BTC/USDT \
  --timeframe 60 \
  --from "2026-05-27 11:06:40" \
  --to "2026-05-27 12:06:40" \
  --output json
```

### USD-M perpetual futures volume bars [#usd-m-perpetual-futures-volume-bars]

```bash
mlab source volumes \
  --exchange binancef \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-05-27 11:06:40" \
  --to "2026-05-27 12:06:40" \
  --output json
```

Binance volume bars are derived from candle volume. Historical requests paginate automatically and stop at 5,000 records.

### Backtest a script [#backtest-a-script]

```bash
mlab script backtest ./scripts/sma-cross.js \
  --from 2024-01-01 \
  --to "2024-01-07 22:40:00" \
  --source btc@candles@binancef:timeframe=60 \
  --param fast=20 \
  --param slow=50 \
  --param margin=1000 \
  --param leverage=5 \
  --output json
```

Standalone Binance selectors are historical-only. See [Binance Market Data](/providers-market-data/binance) for supported selectors and limits.

## BULK Markets [#bulk-markets]

### Refresh and list the installed catalog [#refresh-and-list-the-installed-catalog]

```bash
mlab markets --exchange bulkf --refresh
mlab markets --exchange bulkf
```

### Inspect one market [#inspect-one-market]

```bash
mlab markets --exchange bulkf --symbol BTC
```

### Get one rule set as JSON [#get-one-rule-set-as-json]

```bash
mlab markets --exchange bulkf --symbol BTC --json
```

Only the refresh command makes a network request. The list and lookup commands read the installed snapshot and require no provider credential.

## BULK Sources [#bulk-sources]

### Public orderbook [#public-orderbook]

```bash
mlab source orderbook \
  --exchange bulkf \
  --symbol BTC \
  --depth 100 \
  --output terminal
```

### Historical candles [#historical-candles]

```bash
mlab source candles \
  --exchange bulkf \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-06-01 09:52:39" \
  --to "2026-06-03 21:54:05" \
  --output json
```

### Live order flow [#live-order-flow]

```bash
mlab source vd \
  --exchange bulkf \
  --symbol BTC \
  --stream \
  --output jsonl
```

### Market statistics and funding [#market-statistics-and-funding]

```bash
mlab source stats --exchange bulkf --period 7d --output json
mlab source funding --exchange bulkf --symbol BTC --stream --output jsonl
```

See [BULK Market Data](/providers-market-data/bulk) for the exact range, snapshot, and stream contract of each source.

## BULK Execution [#bulk-execution]

### Preview a market order [#preview-a-market-order]

```bash
mlab trade long BTC --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 [#preview-an-alo-limit-order]

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

### Preview native stop and take-profit protection [#preview-native-stop-and-take-profit-protection]

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

### Submit with terminal confirmation [#submit-with-terminal-confirmation]

```bash
mlab trade long BTC --margin 100 --leverage 5
```

### Inspect account state [#inspect-account-state]

```bash
mlab positions
mlab orders --symbol BTC
mlab fills --symbol BTC
```

### Preview cancellation and closing [#preview-cancellation-and-closing]

```bash
mlab cancel BTC <ORDER_ID> --dry-run
mlab close BTC --dry-run
```

### Inspect the execution runtime [#inspect-the-execution-runtime]

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

See [Execution](/execution) for order behavior, [Configuration](/configuration) for TOML, and [Daemon](/daemon) for runtime operation.

## Hyperliquid [#hyperliquid]

### Refresh markets and inspect public data [#refresh-markets-and-inspect-public-data]

```bash
mlab markets --exchange hyperliquidf --refresh
mlab markets --exchange hyperliquidf --symbol BTC
mlab source orderbook --exchange hyperliquidf --symbol BTC --depth 20
mlab source candles --exchange hyperliquidf --symbol BTC --timeframe 60 --from "2026-06-01 09:52:39" --to "2026-06-03 21:54:05" --output json
```

### Authorize mainnet and testnet [#authorize-mainnet-and-testnet]

```bash
mlab auth set hyperliquid
```

The authorization command configures separate API agents for both networks using the same master account. Preview either network explicitly:

```bash
# Hyperliquid mainnet
mlab trade long BTC \
  --venue hyperliquidf \
  --margin 100 \
  --leverage 5 \
  --dry-run

# Hyperliquid testnet
mlab trade long BTC \
  --venue hyperliquidf \
  --testnet \
  --margin 100 \
  --leverage 5 \
  --dry-run

# XYZ mainnet
mlab trade long xyz:TSLA \
  --venue hyperliquidf \
  --margin 100 \
  --leverage 5 \
  --dry-run

# EntropyIO mainnet
mlab trade long io:ANTH \
  --venue hyperliquidf \
  --margin 100 \
  --leverage 5 \
  --dry-run

# HyperLink mainnet execution
mlab trade long BTC \
  --venue hyperlinkf \
  --margin 100 \
  --leverage 5 \
  --dry-run
```

### Run a script on direct Hyperliquid data [#run-a-script-on-direct-hyperliquid-data]

```bash
mlab script run ./scripts/strategy.js \
  --source btc@candles@hyperliquidf:timeframe=5 \
  --source btc@orderbook@hyperliquidf:depth=20 \
  --venue hyperliquidf
```

This script executes on mainnet. Add `--testnet` to execute it on testnet. See [Authentication](/authentication#hyperliquid), [Hyperliquid Market Data](/providers-market-data/hyperliquid), and [Hyperliquid Execution](/providers-execution/hyperliquid).

XYZ scripts use the same shape with normalized base symbols:

```bash
mlab script run ./scripts/xyz.js \
  --source tsla@candles@hyperliquidf-xyz:timeframe=60 \
  --source tsla@orderbook@hyperliquidf-xyz:depth=20 \
  --venue hyperliquidf-xyz
```

## Sources [#sources]

### Orderbook snapshot [#orderbook-snapshot]

```bash
mlab source orderbook \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --depth 100 \
  --output terminal
```

### Orderbook stream [#orderbook-stream]

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

### Candles range [#candles-range]

```bash
mlab source candles \
  --provider mmt \
  --exchange binancef \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-05-27 11:06:40" \
  --to "2026-05-27 12:06:40" \
  --output json
```

### Candles stream [#candles-stream]

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

### VD range [#vd-range]

```bash
mlab source vd \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-05-24 11:00:00" \
  --to "2026-05-24 12:00:00" \
  --bucket 1 \
  --output json
```

### VD stream [#vd-stream]

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

### OI range [#oi-range]

```bash
mlab source oi \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-05-24 22:00:00" \
  --to "2026-05-25 10:40:00" \
  --output json
```

### OI stream [#oi-stream]

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

### Volumes range [#volumes-range]

```bash
mlab source volumes \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --timeframe 60 \
  --from "2026-05-24 22:00:00" \
  --to "2026-05-25 10:40:00" \
  --output json
```

### Volumes stream [#volumes-stream]

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

## Scripts [#scripts]

### Backtest a JavaScript strategy [#backtest-a-javascript-strategy]

```bash
mlab script backtest ./scripts/sma-cross.js \
  --from 2024-01-01 \
  --to "2024-01-07 22:40:00" \
  --source btc@candles@bybitf@mmt:timeframe=60 \
  --param fast=20 \
  --param slow=50 \
  --param margin=1000 \
  --leverage 5 \
  --output json
```

### Backtest a VD script [#backtest-a-vd-script]

```bash
mlab script backtest ./scripts/vd-summary.js \
  --from "2026-06-03 14:46:05" \
  --to "2026-06-05 00:06:58" \
  --source btc@vd@hyperliquidf@mmt:timeframe=3600,bucket=1 \
  --param min_delta=500 \
  --output json
```

### Compare candles across exchanges [#compare-candles-across-exchanges]

```bash
mlab script backtest ./examples/cross-exchange-spread.js \
  --from 2024-01-01 \
  --to "2024-01-07 22:40:00" \
  --source btc@candles@binancef@mmt:timeframe=60 \
  --source btc@candles@okx@mmt:timeframe=60 \
  --output json
```

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

### Backtest independent position exits [#backtest-independent-position-exits]

```bash
mlab script backtest ./scripts/dip-tp-positions.js \
  --from "2026-06-03 14:46:05" \
  --to "2026-06-05 00:06:58" \
  --source btc@candles@hyperliquidf@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 [#deploy-a-live-analysis-script]

```bash
mlab script run ./scripts/all-sources-live.js \
  --source btc@candles@hyperliquidf@mmt:timeframe=5 \
  --source btc@orderbook@hyperliquidf@mmt:depth=100 \
  --source btc@vd@hyperliquidf@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 [#deploy-a-strategy-with-bulk-execution]

```bash
mlab script run ./examples/bulk-limit-protected.js \
  --source btc@candles@bulkf:timeframe=5 \
  --venue bulkf \
  --param armed=true
```

The script calls `ctx.trade` directly. `--venue bulkf` is required to enable BULK execution; the market data can still come from MMT, BULK, Hyperliquid, or a combination.

### Manage live script jobs [#manage-live-script-jobs]

```bash
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 [#list-script-runtime-reports]

```bash
mlab script runs list
```

### View a script runtime report [#view-a-script-runtime-report]

```bash
mlab script runs show <run-id>
```

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

## Studies [#studies]

### Spread [#spread]

```bash
mlab study spread \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --depth 20 \
  --output json
```

### Depth [#depth]

```bash
mlab study depth \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --levels 20 \
  --output json
```

### Imbalance [#imbalance]

```bash
mlab study imbalance \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --depth 50 \
  --output json
```

### Slippage [#slippage]

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

### VAMP [#vamp]

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

### CVD [#cvd]

```bash
mlab study cvd \
  --provider mmt \
  --exchange bybitf \
  --symbol BTC \
  --timeframe 3600 \
  --from "2026-05-24 11:00:00" \
  --to "2026-05-24 12:00:00" \
  --bucket 1 \
  --output json
```

## TWAP Strategy [#twap-strategy]

### Preview the normalized schedule [#preview-the-normalized-schedule]

```bash
mlab strategy run twap BTC \
  --venue bulkf \
  --side buy \
  --margin 100 \
  --duration 300 \
  --interval 60 \
  --dry-run
```

### Deploy a live TWAP job [#deploy-a-live-twap-job]

```bash
mlab strategy run twap BTC \
  --venue bulkf \
  --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 [#submit-by-size-with-structured-output]

```bash
mlab strategy run twap BTC \
  --venue bulkf \
  --side sell \
  --size 0.01 \
  --duration 600 \
  --interval 30 \
  --yes \
  --output json
```

### Monitor and stop the job [#monitor-and-stop-the-job]

```bash
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](/strategies/twap).
