Hyperliquid Integration
Execute sophisticated perpetual futures trading strategies on Hyperliquid through our high-performance API. Access up to 50x leverage with advanced risk management and real-time position monitoring.
Trading with leverage carries significant risk. Our SDK includes built-in safety mechanisms and risk controls to help manage potential losses.
Position Management
Open and Manage Positions
import { HexaAI } from '@hexaai/sdk';
// Initialize the SDK
const hexa = new HexaAI('your_api_key');
// Open a leveraged long position
async function openLongPosition() {
const position = await hexa.hyperliquid.openPosition({
market: 'BTC-PERP',
side: 'long',
size: 1.0, // BTC size
leverage: 10, // 10x leverage
collateral: 'USDC',
options: {
slippage: 0.1, // 0.1% max slippage
timeInForce: 'GTC',
reduceOnly: false
}
});
console.log('Position opened:', position);
return position;
}
// Open a short position with advanced parameters
async function openShortPosition() {
const position = await hexa.hyperliquid.openPosition({
market: 'ETH-PERP',
side: 'short',
size: 10.0, // ETH size
leverage: 5, // 5x leverage
options: {
triggerPrice: 2500, // Optional entry trigger
postOnly: true, // Maker only
deadline: '5m' // Expires in 5 minutes
}
});
return position;
}
// Monitor position in real-time
const positionStream = hexa.hyperliquid.streamPosition({
market: 'BTC-PERP',
options: {
updateFrequency: '1s',
includeOrderbook: true
}
});
positionStream.on('update', (position) => {
console.log('Position update:', {
size: position.size,
entryPrice: position.entryPrice,
liquidationPrice: position.liquidationPrice,
unrealizedPnl: position.unrealizedPnl,
margin: position.margin
});
});
Advanced Orders
Complex Order Types
// Place a take-profit order
async function placeTakeProfit() {
const order = await hexa.hyperliquid.createOrder({
market: 'BTC-PERP',
type: 'takeProfit',
size: 1.0,
triggerPrice: 45000,
options: {
reduceOnly: true,
triggerType: 'mark_price'
}
});
return order;
}
// Place a trailing stop order
async function placeTrailingStop() {
const order = await hexa.hyperliquid.createOrder({
market: 'ETH-PERP',
type: 'trailingStop',
size: 5.0,
callbackRate: 1.0, // 1% callback rate
options: {
activation: {
type: 'price',
threshold: 2000 // Activates below $2000
}
}
});
return order;
}
// Place an OCO (One-Cancels-Other) order
async function placeOCO() {
const orders = await hexa.hyperliquid.createOCO({
market: 'BTC-PERP',
size: 1.0,
takeProfit: 45000,
stopLoss: 35000,
options: {
reduceOnly: true,
postOnly: false
}
});
return orders;
}
Risk Management
Position Monitoring
Real-time monitoring of position health, including leverage, margin ratio, and liquidation prices.
Auto-Deleveraging
Automatic position size and leverage adjustment based on market volatility and risk metrics.
Smart Take-Profit
Dynamic take-profit levels based on market volatility and momentum indicators.
Portfolio Hedging
Automated hedge position management across multiple markets and instruments.