Limit Orders
The Fusion AMM SDK provides tools to manage limit orders in a FusionPool. Developers can open or close limit orders using straightforward SDK methods, as well as fetch Limit Orders by the owner.
Open Limit Order: creates a new limit order and adds the specified token amount. See
openLimitOrderInstructions
,increaseLimitOrderInstructions
functions of the high-level SDK package.Close Limit Order: removes all ordered or swapped amount (if partially or fully swapped), collects accrued fees, pays any applicable fees, and closes the order, as detailed in Fees and Incentives. See
closeLimitOrderInstructions
,decreaseLimitOrderInstructions
functions of the high-level SDK package.Fetch Limit Orders: fetches multiple limit orders according to input parameters. See
fetchLimitOrdersForOwner
function of the high-level SDK package.
Limit order amounts can also be increased or decreased independently, offering flexible management.
Examples:
1. Open Limit Order
import { openLimitOrderInstructions } from "@crypticdot/fusionamm-sdk";
import { sendTransaction } from "@crypticdot/fusionamm-tx-sender";
import { address, createSolanaRpc } from "@solana/kit";
export const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
export const signer = await loadKeypair(); // Load your wallet
// SOL/USDC pool address
let poolAddress = address("7VuKeevbvbQQcxz6N4SNLmuq6PYy4AcGQRDssoqo4t65");
let amount = 1_000_000_000n; // The limit order input amount
let aToB = true; // The limit order direction
const open = await openLimitOrderInstructions(
rpc,
poolAddress,
amount,
{ price: 140.0 },
aToB,
signer,
);
const signature = await sendTransaction(rpc, open.instructions, signer);
console.log("Transaction ID:", signature);
console.log("Initialization cost:", open.initializationCost);
console.log("Limit order mint:", open.limitOrderMint);
2. Close Limit Order
import { closeLimitOrderInstructions, openLimitOrderInstructions }
from "@crypticdot/fusionamm-sdk";
import { sendTransaction } from "@crypticdot/fusionamm-tx-sender";
import { address, createSolanaRpc } from "@solana/kit";
export const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
export const signer = await loadKeypair(); // Load your wallet
let limitOrderMint = address("HqoV7Qv27REUtmd9UKSJGGmCRNx3531t33bDG1BUfo9K");
const close = await closeLimitOrderInstructions(rpc, limitOrderMint, signer);
const signature = await sendTransaction(rpc, close.instructions, signer);
console.log("Transaction ID:", signature);
Last updated