Market LabDocs

v0.0.5

Native BULK execution, detached runtimes, multi-exchange scripting, execution-aware backtesting, and TWAP.

Market Lab moves beyond analysis into a complete execution runtime. This release adds native BULK market data and trading, persistent live jobs, a redesigned scripting contract, faster execution-aware backtests, and the first built-in execution strategy.

BULK Integration

  • Added BULK as a standalone exchange for public market data and live execution.
  • Added a versioned BULK market catalog with symbol mappings, tick sizes, lot sizes, minimum notionals, supported order types, time-in-force rules, and maximum leverage.
  • Added normalized BULK candles, orderbooks, trades, volume delta, open interest, volume bars, funding, ticker statistics, and market metadata.
  • Added BULK HTTP and WebSocket clients with normalized timestamps and account-aware data models.
  • Added mlab markets --exchange bulk for inspecting embedded execution rules without a network request or credential.
  • Standardized provider routing: standalone BULK uses --exchange bulk; multi-exchange MMT sources use --provider mmt --exchange <exchange>.
  • Added BULK source support to scripts through selectors such as candles@bulk:timeframe=5 and orderbook@bulk:depth=20.

Authentication and Account Security

  • Added BULK agent-wallet authorization through mlab auth set bulk.
  • The main wallet private key is accepted only through the hidden authorization prompt and is never persisted.
  • Generated agent credentials are stored in the operating-system keychain.
  • Added mlab auth set bulk --reauthorize to repair or replace an invalid delegated signer without deleting local state manually.
  • Added signer/account validation before every live mutation.
  • Added actionable unauthorized-signer errors that point directly to the reauthorization command.

Trading and Execution

  • Added direct perpetual commands for opening long and short positions.
  • Added market and limit orders, GTC/IOC/ALO time-in-force, reduce-only execution, cancellation, and position closing.
  • Added --margin as the collateral-based sizing input. Exposure is calculated as margin multiplied by leverage.
  • Retained --size for exact base-asset exposure without leverage multiplication.
  • Added leverage validation against the selected market and a BULK leverage update before applicable orders.
  • Added native stop-loss and take-profit protection through BULK on-fill conditional orders.
  • Added dry-run trade plans, interactive confirmation, normalized order receipts, and structured JSON output.
  • Added account commands for positions, open orders, fills, cancellation, and position closing.
  • Added estimated margin and exposure to trade plans and reports.
  • Added projected liquidation-price output support; the value remains unavailable when BULK cannot provide a pre-trade portfolio simulation.
  • Added deterministic BULK order-ID retention before submission.
  • Added ambiguous-timeout reconciliation against orderHistory, openOrders, and fills so an accepted order is not reported as failed or submitted twice.
  • Reconciled executions retain the original order ID and are identified in strategy logs.
  • Explicit exchange rejections remain failures and are never converted into successful reconciliations.

Persistent Runtime

  • Added the mlabd execution daemon as a separate packaged binary.
  • Added automatic daemon startup and runtime-version negotiation from the CLI.
  • Added owner-only local IPC, persisted runtime state, execution journals, and runtime error reporting.
  • Added mlab daemon start, status, stop, and events commands.
  • Moved live account, order, fill, and position updates from polling to BULK WebSocket subscriptions.
  • Added reconnect handling, gap recovery, account-stream health, and tracked-order lifecycle updates.
  • Added detached script and strategy worker processes so the terminal is released after deployment.
  • Added job status, heartbeat, stop, failure, completion, and log-file management.
  • Added safe decoding of persisted jobs created before newly added TWAP margin fields.

Scripting Runtime

  • Reworked scripts around one event-driven contract shared by live runs and backtests.
  • Removed script mode and manifest clock; every configured source event can now drive onData.
  • Added detached live script jobs with script jobs, status, logs, and stop commands.
  • Added optional script duration. Omitted duration runs indefinitely.
  • Added ctx.trade() and ctx.cancel() for live and simulated execution.
  • Added the asynchronous onExecution hook for order lifecycle events.
  • Added deterministic script order keys and idempotent command handling.
  • Added input.positions.open so scripts can inspect current managed positions.
  • Added native stop-loss and take-profit fields to scripted entry orders.
  • Added market and limit order support with time-in-force validation.
  • Added explicit perpetual position actions: open-long, open-short, close-long, and close-short.
  • Close actions are reduce-only internally and default to closing the full matching position when size is omitted.
  • Opposite directional entries require an explicit close first instead of silently reversing the position.
  • Added live execution gating through --venue bulk; market-data access alone never enables trading.
  • Removed returned signal/intent execution. Scripts perform actions directly and do not need to return a value.
  • Reduced live script logs to meaningful lifecycle, output, and execution events instead of appending the full hook payload continuously.

Multi-Exchange Sources

  • Added exchange- and provider-qualified selectors for scripts.
  • MMT selectors support forms such as candles@binancef@mmt:timeframe=60 and orderbook@lighterf@mmt:depth=20.
  • BULK remains an exchange selector, for example orderbook@bulk:depth=100, even when a script also consumes MMT sources.
  • A single script can consume the same source type from multiple exchanges and providers simultaneously.
  • Script manifests declare required source kinds while runtime selectors determine the concrete exchanges, providers, and source parameters.
  • Added selector-keyed access through input.sources[selector].
  • Removed redundant nested shapes such as input.candles.candles.
  • A selector requested by a script but not configured at runtime remains empty rather than silently binding to another exchange.
  • Added source metadata describing the triggering selector, exchange, provider, timeframe, bucket, and depth.
  • Added TOML source arrays and CLI-over-config merging for qualified selectors.
  • Script parameters can be declared as direct TOML keys without an unnecessary grouping table.

Live History

  • Added bounded per-selector history to the third onData(ctx, input, history) argument.
  • Added history.source(selector) for the retained list and history.source(selector, offset) for one record.
  • Offset 0 is the newest record, offset 1 is the previous record, and unavailable offsets return no record.
  • History is isolated per exact selector, so multiple exchanges never overwrite one another.
  • Added configurable manifest lookback retention with a minimum of two records and a maximum of 5,000.
  • Repeated updates with the same timestamp replace the current record instead of creating false historical bars.
  • Live history begins when the script starts and does not imply provider-side historical backfill.

Live Time-Series Aggregation

  • Added trade-stream aggregation for live MMT and BULK candle construction.
  • Live scripts can request custom second-based candle timeframes instead of waiting for exchange-native intervals.
  • The incomplete interval in progress when a script starts is discarded.
  • Emission begins at the next clean timeframe boundary to avoid publishing partial OHLCV data.
  • Historical backtests remain limited by the granularity stored by the selected provider.

Script Studies and Runtime Safety

  • Added persistent QuickJS sessions instead of rebuilding the JavaScript runtime for every source event.
  • Added bounded runtime resources, cancellation, hook telemetry, crash reports, and script run history.
  • Exposed Rust study implementations directly to JavaScript.
  • Added SMA, EMA, CVD, spread, depth, imbalance, slippage, and VAMP helpers under ctx.study.
  • Added input validation and stable normalized return shapes for study helpers.
  • Added incremental source history so moving studies naturally operate from script start through the current event.

Backtesting

  • Reworked script backtests around one chronologically merged timeline containing every configured source event.
  • Removed candle-only clocking; orderbook and other source updates can now trigger script logic during a backtest.
  • Added a persistent JavaScript session and incremental history, substantially reducing multi-thousand-record execution time.
  • Added simulation for market orders, resting limit orders, cancellation, and next-event limit fills.
  • Added native stop-loss, take-profit, and deterministic same-bar protective-order handling.
  • Added explicit open/close position simulation matching the live perpetual action contract.
  • Added partial and full close support, reduce-only semantics, and prevention of accidental directional reversal.
  • Added net managed-position behavior instead of creating an independent open position for every signal.
  • Added realized and unrealized PnL, capital required, return, win rate, profit factor, average/best/worst trade, Sharpe ratio, and maximum drawdown.
  • Added compact trade and open-position output with --verbose for the full ledger.
  • Added analysis-only backtests; a script is no longer required to call ctx.trade() merely to complete.
  • Added multi-exchange backtests using the same exact selectors as live scripts.

Built-In Strategies

  • Removed the legacy Rust SMA-crossover strategy and its old command structure.
  • Added TWAP as the first built-in execution strategy.
  • Added side, margin or exact size, leverage, duration, child interval, reduce-only, dry-run, and confirmation inputs.
  • TWAP divides the normalized parent size across the full schedule without dropping lot-size remainders.
  • Live TWAP runs as a detached mlabd job so the initiating terminal remains free.
  • Added TWAP plan output, per-child logs, job status, log following, stopping, completion summaries, and failure reports.
  • Added strict child sequence and plan validation inside the daemon.
  • Every child order carries the configured leverage and sizing semantics.
  • Stopping a TWAP prevents future children; it does not reverse children already filled.
  • Timed-out child submissions are reconciled by deterministic order ID before the schedule continues.

CLI, Configuration, and Distribution

  • Expanded marketlab.toml to cover sources, scripts, strategies, execution, and direct script parameters.
  • Added consistent CLI-over-config precedence and validation.
  • Added qualified script selectors to both repeated CLI flags and TOML arrays.
  • Added source funding and source stats command surfaces.
  • Added normalized terminal, JSON, and JSONL reporting across runtime and execution commands.
  • Added market-lab as a library target alongside the mlab and mlabd binaries.
  • Updated release packaging to ship both CLI and daemon binaries.
  • Updated install and upgrade workflows for the expanded runtime.
  • Removed obsolete example scripts and added one current SMA-crossover script using the new source, history, position, and execution contracts.

On this page