Solana Jupiter Trading Bot
This is a simple demo uses Jupiter's Metis API and Quicknode's Metis add-on to create a simple Solana trading bot. The bot monitors price differences between token pairs and executes trades when profitable opportunities arise.

개요
This is a simple demo uses Jupiter's Metis API and Quicknode's Metis add-on to create a simple Solana trading bot. The bot monitors price differences between token pairs and executes trades when profitable opportunities arise.
This example is for educational purposes only. Quicknode does not provide financial advice or endorse any trading strategies. Always do your own research and consult with a financial advisor before making any investment decisions.
이 데모에서는 다음을 사용합니다:
- 솔라나 키트 (
@solana/kit) - Token program client (
@solana-program/token) - Address Lookup Table client (
@solana-program/address-lookup-table) - Jupiter API TypeScript client (
@jup-ag/api)
참고 자료:
- Written Guide - How to Use Jupiter API to Create a Solana Trading Bot
- Video Guide - How to Create a Solana Trading Bot
시작하기
의존성 설치
프로젝트 디렉터리를 엽니다:
cd solana/jupiter-bot
그런 다음, 종속성을 설치하세요:
npm install
# or
pnpm install
# or
bun install
Set Environment Variables
Make sure you have a Quicknode endpoint handy. You can get one here.
- Rename
.env.example~에.envand update with your Quicknode Solana Node and Metis Add-on Endpoints. - Specify your
SECRET_KEY(the private key of the wallet you want to use for the bot). You can generate a new one withsolana-keygen newcommand using the Solana CLI. - Specify your
SOLANA_ENDPOINT(get one here) andMETIS_ENDPOINT(get one here) or use the public endpoint,https://public.jupiterapi.com.
SECRET_KEY=[00, ..., 00]
SOLANA_ENDPOINT=https://example.solana-mainnet.quiknode.pro/abc123/
METIS_ENDPOINT=https://jupiter-swap-api.quiknode.pro/abc123
Ensure your wallet is funded and modify the trading strategy in bot.ts to suit your needs.
First, run the development server:
npm run start
# or
pnpm start
# or
bun start
How it Works
건축
- bot.ts # Main bot logic
- index.ts # Entry point
- .env # Environment variables
- package.json # Dependencies
ArbBot Class
The main class that handles all trading logic:
- constructor: Sets up the bot with configuration parameters including RPC endpoints, wallet details, and trading parameters
- init: Initializes the bot by checking wallet balances and starting the price monitoring
- initiatePriceWatch: Creates an interval to regularly check for arbitrage opportunities
- getQuote: Fetches current price quotes from Jupiter Exchange
- evaluateQuoteAndSwap: Analyzes quotes to determine if they meet profit thresholds
- executeSwap: Handles the creation and submission of swap transactions
- refreshBalances: Updates the current SOL and USDC balances
- logSwap: Records successful trades to a JSON file
- updateNextTrade: Prepares for the next trade after a successful swap
- terminateSession: Safely shuts down the bot when conditions require it
- jupiterInstructionToKitInstruction: Converts Jupiter API instruction format to
@solana/kitinstructions - getAddressLookupTableAccounts: Fetches address lookup tables for optimized transactions
- postTransactionProcessing: Handles tasks after a successful transaction
Main Application
A simple runner script that:
- Loads environment variables
- Creates an instance of the ArbBot with configuration
- Initializes and starts the bot
Example Trading Strategy
The bot uses a simple arbitrage strategy:
- Start with an initial token (USDC or SOL)
- Execute a trade when the price exceeds the target threshold
- Update parameters for the reverse trade with a profit margin
- Continue the cycle as long as profitable opportunities exist
This example is for educational purposes only. Quicknode does not provide financial advice or endorse any trading strategies. Always do your own research and consult with a financial advisor before making any investment decisions.
- 저장소를 포크하기
- 기능 브랜치 생성:git checkout -b feature/amazing-feature
- 변경 사항을 커밋하세요:git commit -m "멋진 기능 추가"
- 브랜치를 푸시하세요:git push origin feature/amazing-feature
- 풀 리퀘스트를 제출하세요.