import { PerpsError, PerpsErrorCode } from '@lifi/perps-sdk';
try {
await perps.placeOrder({
address: userAddress,
provider: 'hyperliquid',
market: { marketId: 'BTC', categoryId: 'hyperliquid' },
side: 'BUY',
type: 'MARKET',
size: '0.1',
price: '95500.00',
});
} catch (error) {
if (error instanceof PerpsError) {
switch (error.code) {
case PerpsErrorCode.InsufficientMargin: // 2021
console.error('Not enough margin. Reduce size or add funds.');
break;
case PerpsErrorCode.InsufficientBalance: // 2022
console.error('Insufficient balance. Deposit more funds.');
break;
case PerpsErrorCode.MarketNotFound: // 2023
console.error('Invalid asset. Check available assets.');
break;
case PerpsErrorCode.AgentUnauthorized: // 2011
console.error('Agent not authorized. Complete authorization flow.');
break;
case PerpsErrorCode.NonceExpired: // 2042
console.error('Payload expired. Retry the operation.');
break;
default:
console.error(`Error ${error.code}: ${error.message}`);
}
}
}