メインコンテンツへスキップ
サンプルアプリに戻る

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.

フロントエンドフレームワーク/ライブラリ:
Solanaキット
言語:
TypeScript
ビルドツール/開発サーバー:
Jupiter Metis API
サンプルアプリのプレビュー

概要

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.

このデモでは、以下の機能を使用しています:

参考資料:

はじめに

依存関係をインストールする

プロジェクトディレクトリを開きます:

cd solana/jupiter-bot

次に、依存関係をインストールします:

npm install
# or
pnpm install
# or
bun install

環境変数の設定

Make sure you have a Quicknode endpoint handy. You can get one here.


  • 名前を変更 .env.example ~へ .env and 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 with solana-keygen new command using the Solana CLI.
  • Specify your SOLANA_ENDPOINT (get one here) and METIS_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.

まず、開発サーバーを起動します:

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/kit instructions
  • 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:


  1. Start with an initial token (USDC or SOL)
  2. Execute a trade when the price exceeds the target threshold
  3. Update parameters for the reverse trade with a profit margin
  4. 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.

投稿とフィードバック
皆様からのご意見をお待ちしております。また、このサンプルアプリへのご協力も大歓迎です!
問題の報告やフィードバックをお寄せいただくには、GitHubのイシューを qn-ガイド-例 リポジトリ。
投稿するには、以下の手順に従ってください:
  1. リポジトリをフォークする
  2. フィーチャーブランチを作成する:
    git checkout -b feature/amazing-feature
  3. 変更内容をコミットします:
    git commit -m "素晴らしい機能を追加"
  4. ブランチをプッシュしてください:
    git push origin feature/amazing-feature
  5. プルリクエストを作成してください。