Trading Operations on Solana
Execute sophisticated trading operations across Solana's DeFi ecosystem. Our SDK provides comprehensive support for market orders, limit orders, token swaps, and advanced trading strategies with built-in price optimization.
All trades are automatically routed through Jupiter Aggregator to ensure best execution price across all Solana DEXs.
Market Orders
Execute Market Orders
import { HexaAI } from '@hexaai/sdk';
// Initialize the SDK
const hexa = new HexaAI('your_api_key');
// Execute a market buy order
async function marketBuy() {
const order = await hexa.trading.executeMarketOrder({
tokenIn: 'USDC',
tokenOut: 'SOL',
amount: '100', // Amount in USDC
slippageBps: 50, // 0.5% max slippage
wallet: wallet, // Your initialized wallet
priorityFee: 'auto' // Automatic priority fee adjustment
});
console.log('Order executed:', order.signature);
return order;
}
// Execute a market sell with advanced options
async function marketSell() {
const order = await hexa.trading.executeMarketOrder({
tokenIn: 'SOL',
tokenOut: 'USDC',
amount: '2.5', // Amount in SOL
options: {
excludeDexes: ['aldrin', 'crema'], // Exclude specific DEXes
referralAccount: 'your_referral', // Optional referral
computeUnits: 'auto', // Automatic CU limit
minOutput: '95' // Minimum USDC to receive
}
});
return order;
}
Token Swaps
Advanced Token Swaps
// Execute a multi-hop swap
async function complexSwap() {
const route = await hexa.trading.findBestRoute({
tokenIn: 'USDC',
tokenOut: 'BONK',
amount: '50',
options: {
maxHops: 3, // Maximum routing hops
includeDexes: 'all', // Use all available DEXes
routeCount: 5 // Find top 5 routes
}
});
const swap = await hexa.trading.executeSwap({
route: route.best, // Use best route
slippageBps: 100, // 1% max slippage
wallet: wallet,
priorityFee: {
strategy: 'aggressive',
maxFee: 0.00001 // Max priority fee in SOL
}
});
return swap;
}
// Stream swap quotes
const quoteStream = hexa.trading.streamQuotes({
tokenIn: 'SOL',
tokenOut: 'USDC',
amount: '1',
options: {
interval: '1s', // Quote update interval
dexes: ['jupiter', 'raydium']
}
});
quoteStream.on('quote', (quote) => {
console.log('New quote:', quote.price);
});
Advanced Trading Features
Smart Route Optimization
Automatic route optimization across multiple DEXs with support for multi-hop trades and split routes for minimal price impact.
Real-time Price Feeds
WebSocket integration for real-time price updates and trade execution with sub-second latency.
MEV Protection
Built-in MEV protection with private transaction routing and automatic sandwich attack prevention.
Risk Management
Advanced order types including stop-loss, take-profit, and trailing stops with custom execution conditions.