Market LabDocs

Examples

Real command examples for sources, studies, and strategies.

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

Refresh the standalone snapshots

mlab markets --exchange binance --refresh
mlab markets --exchange binancef --refresh

Inspect a futures market

mlab markets --exchange binancef --symbol BTC

Binance Historical Data

Spot candles

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

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

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 for supported selectors and limits.

BULK Markets

Refresh and list the installed catalog

mlab markets --exchange bulkf --refresh
mlab markets --exchange bulkf

Inspect one market

mlab markets --exchange bulkf --symbol BTC

Get one rule set as JSON

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

Public orderbook

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

Historical candles

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

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

Market statistics and funding

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

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

BULK Execution

Preview a market order

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

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

Preview native stop and take-profit protection

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

Submit with terminal confirmation

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

Inspect account state

mlab positions
mlab orders --symbol BTC
mlab fills --symbol BTC

Preview cancellation and closing

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

Inspect the execution runtime

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

See Execution for order behavior, Configuration for TOML, and Daemon for runtime operation.

Hyperliquid

Refresh markets and inspect public data

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

mlab auth set hyperliquid

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

# 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

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, Hyperliquid Market Data, and Hyperliquid Execution.

XYZ scripts use the same shape with normalized base symbols:

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

Sources

Orderbook snapshot

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

Orderbook stream

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

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

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

VD range

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

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

OI range

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

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

Volumes range

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

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

Scripts

Backtest a JavaScript strategy

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

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

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

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

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

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

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 \
  --depth 20 \
  --output json

Depth

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

Imbalance

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

Slippage

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

VAMP

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

CVD

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

Preview the normalized schedule

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

Deploy a live TWAP job

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

mlab strategy run twap BTC \
  --venue bulkf \
  --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