Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 139 additions & 138 deletions docs/endpointFunctionList.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions examples/Rest/rest-trailing-stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { RestClient } from '../../src/index.js';

// 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();
23 changes: 23 additions & 0 deletions examples/apidoc/RestClient/submitTrailingStop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RestClient } from '@siebly/hyperliquid-api';
// or, if require is preferred:
// const { RestClient } = require('@siebly/hyperliquid-api');

// This example shows how to call this Hyperliquid API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "@siebly/hyperliquid-api" for Hyperliquid exchange
// This Hyperliquid API SDK is available on npm via "npm install @siebly/hyperliquid-api"
// ENDPOINT: /exchange (trailingStop)
// METHOD: POST
// PUBLIC: NO

const client = new RestClient({
privateKey: 'insert_private_key_here',
// If this is an API/agent wallet, also pass the master account:
// accountAddress: '0x...',
});

client.submitTrailingStop(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
Loading
Loading