Skip to main content

Variables & constants

The CLI exposes a fixed set of built-in constants as $tokens. Any one of them can appear wherever a price or a number is expected. They're resolved fresh on every command — there's no caching layer.

User-defined variables (@name) live under Aliases & user variables. This page covers the read-only $ tokens plus the math + offset grammar that operates on them.


Position-anchored prices

The focused position is the one for the symbol you have set with switch.

TokenReads
$entryEntry price of focused position
$lentryLong entry price (focused symbol, hedge-mode aware)
$sentryShort entry price (focused symbol, hedge-mode aware)
$liqLiquidation price — errors when ambiguous or zero

All four accept an inline offset.


Ticker-anchored prices

TokenReads
$bidTop-of-book bid
$askTop-of-book ask
$lastLast trade price
$markMark price
$indexIndex price
$mid / $midpriceExchange-published mid if present, else synthesized average

$bid, $ask, $last, $mark, $index accept inline offsets. $mid does not have an offset shortcut — combine with math ($mid +1*$ticksize) if you need one.

Why $mid is different: Hyperliquid publishes a true mid (ticker.midPrice) separate from (bid+ask)/2. The CLI prefers the exchange value when present.


Position sizes

TokenReads
$sizeTotal contracts of focused position (sum if hedged)
$lsizeLong position contracts
$ssizeShort position contracts

Balance, PnL, and exposure

TokenReads
$freeFree balance
$usedUsed / locked balance
$totalTotal balance
$upnlUnrealized PnL (exchange-reported, account-wide)
$pnlUnrealized PnL summed on the focused symbol
$totalupnlUnrealized PnL summed across all positions
$totallongusdLong notional (USD) across all positions
$totalshortusdShort notional (USD) across all positions
$totallong$totallongusd / $total
$totalshort$totalshortusd / $total
$marginFocused-symbol position margin (notional ÷ leverage)

Market shape

TokenReads
$ticksizemarket.precision.price for focused symbol
$minsizemarket.limits.amount.min for focused symbol

Synthesized

TokenReturns
$randomUniform in [0.35, 1) — re-evaluated per substitution

$random floor is 0.35, not 0 — to avoid sub-min-size rounding when used as a size multiplier (buy $100*$random).


UI-only constants   (web terminal)

These resolve only in the in-app web CLI. Standalone CLI throws "only available in the web terminal" if you reference them.

TokenReads
$clickLast chart-click price from a linked chart
$ordersizeCurrent size in the linked order form
$quick1$quick7Quick-size slots 1 through 7

Resolved through PreprocessContext.uiResolvers (apps/web/src/components/cli/uiTokenResolvers.ts).


Inline offsets

Any price anchor can be followed by a second token of shape [+-]<number>[%]. The anchor and offset collapse into a single absolute price before downstream parsing.

buy $100 at $entry +1% # buy 1% above entry
sell $100 at $liq -5% # 5% under liquidation
chase buy $100 to $bid +0.1%
stop at $entry -2%

Anchors that accept inline offsets:

$entry $lentry $sentry $liq $bid $ask $last $mark $index

Source: packages/cli-core/src/preprocess/substitute.ts:322-339.


Within-token math

Tokens shaped like <operand> <op> <operand> (with no spaces between, or spaces only between operands and operators) get evaluated as expressions.

ElementAllowed
OperandsFloat literals, $constants, @vars
Operators+ - * /
Precedence*// > +/-, left-to-right within a level
Unary minusAllowed on first operand only — -5*@x
ParensNot supported
FunctionsNot supported
sets @half $size/2
sets @stop $entry -3*$ticksize
buy $100*$random

Source: packages/cli-core/src/preprocess/math.ts.


Composing math with sets

set snapshots a value; sets re-evaluates on every read. The two combine cleanly with math:

sets @stopgap $entry -1% # reactive — re-reads $entry each time
set @epoch $last # snapshot — frozen at the moment you ran set
echo @stopgap # live
echo @epoch # frozen

See Aliases & user variables for the full set/sets/track/print lifecycle.


At-a-glance cheatsheet

PRICES SIZES + BALANCE MARKET
$entry $lentry $sentry $size $lsize $ssize $ticksize
$bid $ask $last $free $used $total $minsize
$mark $index $mid $upnl $pnl $totalupnl
$liq $totallongusd $totalshortusd
$totallong $totalshort
$margin

SYNTH WEB-ONLY
$random $click $ordersize $quick1..$quick7

INLINE OFFSET (any price anchor except $mid)
$entry +1% $liq -5% $bid +100 $ask -0.05%

MATH (within a single token, no parens)
$entry -3*$ticksize $size/2 $100*$random