MarketDeck docs

trails

Real-wallet trailing stop-loss state — read, configure, and inspect the daemon-evaluated trails.

Hyperliquid has no native "trail this SL" primitive — it only accepts fixed trigger prices. MarketDeck keeps per-(wallet, coin) trail metadata in a sidecar JSON file and a daemon feed re-submits a tighter SL whenever price moves favourably enough.

Usage#

marketdeck trails <subcommand> [args]

Subcommands#

SubcommandWhat it does
listEvery active trail. Shows wallet, coin, trail %, last submitted SL, fail count, last update.
show <wallet> <coin>Single entry, full record.
set <wallet> <coin> --pct N [--sl X]Upsert a trail entry. --pct is the trail distance in percent; --sl seeds the last-submitted SL.
clear <wallet> <coin>Remove a trail.

<wallet> resolves by uuid / prefix / name.

Examples#

marketdeck trails list --format text
marketdeck trails set live BTC --pct 2 --sl 65000
marketdeck trails show live BTC
marketdeck trails clear live BTC

How the daemon evaluates them#

The trailing-stop loop lives at lib/daemon/feeds/real-trailing.js. Every 15 s the feed:

  1. Reads every trail entry.
  2. Groups by wallet so one userState HTTP round-trip serves every trail on that wallet.
  3. For each (wallet, coin), looks up the live position; if there's no open position, clears the trail.
  4. Reads the current mid via the daemon's mids feed (cached) or falls back to a one-shot assetInfo call.
  5. Computes the new SL: mark × (1 − trail_pct/100) for longs, mark × (1 + trail_pct/100) for shorts.
  6. Rounds to the exchange's pxDecimals.
  7. Submits only when the new SL is tighter than the previous one by at least 0.05 % (a "dead zone" against thrash).
  8. Submits via modifyBracketSlTp, preserving existing TPs.
  9. Records success / failure in the store. After three consecutive failures the feed emits a trail_failure event for the UI (throttled to one notify per 30 minutes per trail).

The math is unit-tested in test-trailing.js. The exchange half-path is exercised through manual smoke tests against a Testnet wallet — never let a never-tested change to this file go live unverified.

Channel + RPC#

Subscribe to realTrailing on the daemon to receive every ratchet / failure event live:

marketdeck daemon attach --channel realTrailing

RPC methods:

  • realTrailingStatus — counters (ticks, evaluated, ratcheted, failed) and last-tick timestamp.
  • realTrailingTickNow — force one tick out-of-band, useful right after a trails set.