Skip to content

feat(sdk): support the trailingStop exchange action - #175

Merged
joeblau merged 1 commit into
mainfrom
feat/trailing-stop
Oct 11, 2026
Merged

joeblau merged 1 commit into
mainfrom
feat/trailing-stop

Conversation

@joeblau

@joeblau joeblau commented Oct 11, 2026

Copy link
Copy Markdown

Summary

Adds SDK support for Hyperliquid's native trailing stop exchange action:

await client.trailingStop({
  coin: "BTC", // or asset: 0
  isBuy: true,
  sz: "0.1",
  reduceOnly: false,
  retracement: { pct: "1.5%" }, // or { px: "30000" }
  activationPx: null,
});
  • Method: trailingStop() + buildTrailingStop() canonical builder under api/exchange, actions/trailingStop entry point, ExchangeClient.trailingStop with coin-symbol resolution, package.json exports — following the established per-method pattern (twapOrder).
  • Error parsing: the action's success response carries data.oid directly rather than an order-style statuses array, so the parser gains a fourth error shape for data-level { error } responses — runtime (isErrorResponse/getErrorMessage) and type level (ExcludeErrorResponse narrows data to { oid: number }). Audited all existing response types: none carry error under data, so no false positives.
  • Tests: offline method tests (pinned-signature wire payload, both retracement variants, activationPx: null, validation rejections, data.oid success, data.error rejection), client/coin-resolution/error-shape/conformance entries.
  • Docs: clients.md symbol-orders inventory + example.

Validation

  • bun run check — format, lint, docs content, tsc (TS5), TS7 native, JSDoc/export/import sync gates: all pass
  • bun run test:offline — 2087 pass, 0 fail (244 live tests skipped by design)
  • bun run build — dist builds; published consumer contract checks pass

Note: the live test block follows the repo pattern but hasn't run against testnet yet (needs a funded key) — undocumented server-side retracement bounds could surface on its first live run.

Hyperliquid's dedicated trailing stop action places a native trailing stop
with a fixed retracement distance — { pct } as a percent string or { px } as
an absolute price — plus a nullable activationPx. Its success response
carries data.oid directly instead of an order-style statuses array, so the
error parser gains a fourth shape for data-level { error } responses, at
runtime (isErrorResponse/getErrorMessage) and at the type level
(ExcludeErrorResponse).

Wire it up end to end: trailingStop() and buildTrailingStop() under
api/exchange, an actions/trailingStop entry point, ExchangeClient.trailingStop
with coin-symbol resolution (CoinTrailingStopParameters), package.json
exports, offline + conformance tests, and the clients.md symbol-orders
inventory and example.
@joeblau
joeblau merged commit 78aa003 into main Oct 11, 2026
6 checks passed
@joeblau
joeblau deleted the feat/trailing-stop branch October 11, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant