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.
| Token | Reads |
|---|---|
$entry | Entry price of focused position |
$lentry | Long entry price (focused symbol, hedge-mode aware) |
$sentry | Short entry price (focused symbol, hedge-mode aware) |
$liq | Liquidation price — errors when ambiguous or zero |
All four accept an inline offset.
Ticker-anchored prices
| Token | Reads |
|---|---|
$bid | Top-of-book bid |
$ask | Top-of-book ask |
$last | Last trade price |
$mark | Mark price |
$index | Index price |
$mid / $midprice | Exchange-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
$midis different: Hyperliquid publishes a true mid (ticker.midPrice) separate from(bid+ask)/2. The CLI prefers the exchange value when present.
Position sizes
| Token | Reads |
|---|---|
$size | Total contracts of focused position (sum if hedged) |
$lsize | Long position contracts |
$ssize | Short position contracts |
Balance, PnL, and exposure
| Token | Reads |
|---|---|
$free | Free balance |
$used | Used / locked balance |
$total | Total balance |
$upnl | Unrealized PnL (exchange-reported, account-wide) |
$pnl | Unrealized PnL summed on the focused symbol |
$totalupnl | Unrealized PnL summed across all positions |
$totallongusd | Long notional (USD) across all positions |
$totalshortusd | Short notional (USD) across all positions |
$totallong | $totallongusd / $total |
$totalshort | $totalshortusd / $total |
$margin | Focused-symbol position margin (notional ÷ leverage) |
Market shape
| Token | Reads |
|---|---|
$ticksize | market.precision.price for focused symbol |
$minsize | market.limits.amount.min for focused symbol |
Synthesized
| Token | Returns |
|---|---|
$random | Uniform in [0.35, 1) — re-evaluated per substitution |
$randomfloor 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.
| Token | Reads |
|---|---|
$click | Last chart-click price from a linked chart |
$ordersize | Current size in the linked order form |
$quick1 … $quick7 | Quick-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.
| Element | Allowed |
|---|---|
| Operands | Float literals, $constants, @vars |
| Operators | + - * / |
| Precedence | *// > +/-, left-to-right within a level |
| Unary minus | Allowed on first operand only — -5*@x |
| Parens | Not supported |
| Functions | Not 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