This is a simple limit order taker example that utilise Jupiter quoting API to execute Jupiter Limit Order.
- Populate these environment variable to
.env
file
RPC_URL=<private rpc endpoint>
PRIVATE_KEY=<wallet private key>
JUPITER_API_URL=<self hosted Jupiter endpoint>
- Install dependencies
pnpm install
- Start the bot
pnpm start
- Get all the open orders from onchain and subscribe using websocket
- Group all the orders by input mint then output mint.
// {
// Sol: {
// USDC: [Order, Order, Order],
// USDT: [Order, Order, Order],
// }
// }
- Get the price of output mint vs input mint like grouping above
- Compare the price from quoting and the order, filters orders within 0.3% range of the quote price
- Get quote from Jupiter Swap API and check whether the order is profitable to execute.
- Bundle Jupiter Swap Ix with Limit Order Flash Fill Ix to execute the order.
It is similar concept with flash loan. The keeper first borrow the input amount from the order, then it use the input amount to swap in Jupiter and return with desired output amount.
Using this method will not required the keeper to hold any funds, it just need SOL for transaction fees and ata token accounts rent.