Posted By : Mohd
Hyperliquid is a high-performance decentralized perpetual exchange offering low-latency trading. For developers building algorithmic strategies, bots, or integrations, Hyperliquid exposes both REST and WebSocket APIs. This guide provides a step-by-step walk-through of how to place a basic order using the REST API in Node.js.
This script demonstrates how to place a limit sell order for the HYPE token on the Hyperliquid testnet using JavaScript. It utilizes the ethers library for wallet management and the @nktkas/hyperliquid SDK to interact with Hyperliquid's API.
import * as hl from '@nktkas/hyperliquid';
import { ethers } from 'ethers';
const privateKey = 'YOUR_PRIVATE_KEY';
const transport = new hl.HttpTransport({ isTestnet: true });
const wallet = new ethers.Wallet(privateKey);
const exchangeClient = new hl.ExchangeClient({
wallet,
transport,
isTestnet: true,
});
const infoClient = new hl.InfoClient({ transport });
HttpTransport: Establishes a connection to the Hyperliquid API. The isTestnet flag ensures you're connected to the testnet environment.
ethers.Wallet: Creates a wallet instance using your private key. This wallet is used to sign transactions.
ExchangeClient: Handles order placements and other trading operations.
InfoClient: Provides access to market metadata and other informational endpoints.
Also, Explore | Creating a Custom Hyperliquid Dashboard: Track Live Holdings in React
async function main() {
try {
const [meta] = await infoClient.metaAndAssetCtxs();
const assetIndex = meta.universe.findIndex(
(asset) => asset.name === 'HYPE'
);
if (assetIndex === -1) {
throw new Error('BTC asset not found.');
}
const orderParams = {
orders: [
{
a: assetIndex,
b: false, // true for buy, false for sell
p: '100', // Limit price as a string
s: '0.1', // Order size as a string
r: false, // Reduce-only flag
t: {
limit: {
tif: 'Gtc', // Time-in-force: Good 'til canceled
},
},
},
],
grouping: 'na', // No grouping
};
const response = await exchangeClient.order(orderParams);
console.log('Order placed successfully:', response);
} catch (error) {
console.error('Error placing order:', error);
console.error(
'Error details:',
error.response ? error.response.response.data : error.message
);
}
}
You may also like | How to Fetch Transaction History on Ethereum using Web3.py
User or API Wallet does not exist.
Also, Discover | Stablecoin Development with CDP (Collateralized Debt Positions)
In conclusion, this guide provides a straightforward approach to placing limit sell orders on the Hyperliquid testnet using the REST API in Node.js. By leveraging the @nktkas/hyperliquid SDK and ethers.js for wallet management, you can seamlessly integrate order placement into your algorithmic strategies or trading bots. However, remember to pay attention to essential considerations like wallet initialization, collateral requirements, and the network you're interacting with. With this setup, you're equipped to execute trades efficiently while building on Hyperliquid's low-latency, high-performance decentralized exchange.
If you are planning to launch your own DEX like Hyperliquid, connect with our skilled blockchain developers to get started.
July 9, 2025 at 12:17 pm
Your comment is awaiting moderation.