Build a non-custodial Solana take-profit and stop-loss trading bot with Mobula Advanced Orders, price targets, custom token triggers, signed intents, and automatic swap execution.
Alpha feature: Advanced Orders are gated and not publicly available yet. Reach out to the Mobula team to enable access for your account and to receive the deposit wallet for your environment.
This cookbook shows how to build a Take Profit / Stop Loss trading bot using Mobula Advanced Orders. The bot creates signed, deposit-backed intents; Mobula watches market data and Token Details; then the execution engine quotes and sends the swap only when the order condition is satisfied.Use this pattern for:
Solana take-profit and stop-loss automation.
Trading bots that draw TP / SL lines on a chart and convert them to orders.
Custom trigger orders based on priceUSD, volume24hUSD, holder stats, liquidity, or security flags.
Non-custodial exits where the user signs an intent but never gives the bot a wallet private key or reusable approval.
Advanced Orders are deposit-backed intents. The user keeps custody of their wallet keys and never gives Mobula a reusable approval, session key, or delegated signing power. The only funds Mobula can execute with are the exact tokens the user transfers to the Mobula deposit wallet for that order.
The deposited amount is held in the Mobula deposit wallet while the order is open. If the order is cancelled, expires, or cannot execute, the settlement flow refunds the confirmed deposit to the owner.
Step
Actor
What happens
1
Integrator
Use the Mobula-provided deposit wallet for the environment. The end user must not choose this address.
2
User wallet
Transfer exactly amountRaw of tokenIn from ownerAddress to the Mobula deposit wallet.
3
Client
Call POST /api/2/swap/advanced-orders/intent with the deposit transaction hash and all order parameters.
4
Mobula API
Normalizes the payload, resolves the server deposit wallet, validates addresses and amounts, then returns the canonical message to sign.
5
User wallet
Signs the canonical message. This signature covers the chain, owner, recipient, tokens, amounts, trigger settings, expiry, deposit transaction, routing restrictions, and fees.
6
Client
Call POST /api/2/swap/advanced-orders with the same fields plus intentSignature.
7
Mobula API
Verifies the owner signature and stores the order idempotently by intent hash.
8
Mobula worker
Polls open orders every few seconds and verifies the deposit transaction on-chain. The deposit must be finalized, successful, sent by ownerAddress, sent to the Mobula deposit wallet, and match tokenIn + amountRaw.
9
Mobula worker
Watches swaps-stream for relevant token/pair updates. For TP/SL it pre-checks quote movement; for Triggers it confirms the configured Token Details fields through getTokenData.
10
Mobula execution engine
Claims the order, builds a fresh quote with the order constraints, checks minAmountOutRaw, signs only the swap transaction for the deposit wallet, and broadcasts it.
11
Mobula settlement
Confirms the broadcasted transaction. If filled, output funds are sent to recipientAddress. If cancelled, expired, or non-executable, the confirmed deposit is refunded to ownerAddress.
Advanced Orders are deposit-backed. A single deposit transaction can only back one order because the API stores orders idempotently by intent and enforces unique deposit usage.For a TP/SL bot, choose one model:
Model
How it works
One active exit
Create either the take-profit or the stop-loss order, then cancel/replace it when the strategy changes.
Split position
Split the position into two deposits, one backing the take-profit order and one backing the stop-loss order.
OCO bracket
Not available yet as one atomic order. Do not reuse the same deposit for both TP and SL.
Use triggerAmountOutRaw for classic TP/SL quote thresholds. Use triggers when the bot wants to trigger from Token Details fields like priceUSD, volume24hUSD, or security.noMintAuthority.
Custom triggers are checked through getTokenData / Token Details. This is useful when the bot should only execute after both a price condition and safety conditions match.
When triggers is present, Mobula confirms that trigger expression first. The execution engine still quotes the swap and rejects execution if the quote does not satisfy minAmountOutRaw.