The Problem
Solana DEXs like Jupiter don't natively support limit orders or stop-losses. You can only do market swaps.
The Solution: Background Price Monitoring
Build limit orders by polling prices and executing when conditions are met.
const orders = [];
async function checkOrders() {
for (const order of orders) {
const currentPrice = await getTokenPrice(order.token);
if (order.type === 'limit_buy' && currentPrice <= order.targetPrice) {
await executeSwap(order);
notifyUser(order.userId, `Limit buy at $${currentPrice}`);
}
if (order.type === 'stop_loss' && currentPrice <= order.targetPrice) {
await executeSell(order);
notifyUser(order.userId, `Stop-loss triggered at $${currentPrice}`);
}
}
}
setInterval(checkOrders, 30000);
Price Feeds
-
Jupiter Price API —
price.jup.ag/v4/price?ids=<mint> - DexScreener API — real-time DEX prices
- Pyth Network — oracle prices
Ready-Made Solution
My Telegram trading bot has all of this built in:
/limit <token> <price> <amount>
/stoploss <token> <price>
/orders
Full source (4,500 lines): devtools-site-delta.vercel.app/sol-bot-source
Top comments (0)