Hyperliquid REST trailing stop JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.
We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.
@siebly/hyperliquid-api instead of hand-written HTTP request plumbing.Hyperliquid/Rest/rest-trailing-stop.ts.RestClient.resolveAsset(), submitTrailingStop().import { RestClient } from '@siebly/hyperliquid-api'; // or// import { RestClient } from '@siebly/hyperliquid-api'; /** * Place a reduce-only trailing stop for an existing ETH long on testnet. * Trailing stops are available for perpetuals only. * * Unix: * HYPERLIQUID_PRIVATE_KEY='<testnet-private-key>' npx tsx examples/Rest/rest-trailing-stop.ts */const privateKey = process.env.HYPERLIQUID_PRIVATE_KEY;if (!privateKey) { throw new Error('Missing HYPERLIQUID_PRIVATE_KEY.');} const client = new RestClient({ privateKey, testnet: true,}); async function main() { try { const asset = await client.resolveAsset('ETH'); const result = await client.submitTrailingStop({ asset: asset.assetId, isBuy: false, sz: '0.01', reduceOnly: true, retracement: { pct: '1.234%' }, // For a fixed price distance, use retracement: { px: '100' }. activationPx: null, }); console.log('trailing stop:', JSON.stringify(result, null, 2)); } catch (e) { console.error('request failed: ', e); }} main(); We use essential cookies and optional analytics. Read the Privacy Policy.
Essential cookies stay on. Toggle analytics if you want to share anonymous usage insights. You can revisit this anytime via Cookie Settings in the footer.